HTTP Headers from URL generator (or other processor)

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

HTTP Headers from URL generator (or other processor)

Steve Bayliss
Message
Is there any way of retrieving HTTP response headers from a request made by the URL generator (or any other processor that might do the job)?
 
eg being able to get
- the response code
- the content-type
 
Ideally ability to customise the request also, eg to do an HTTP HEAD and then examine the resulting response headers.
 
If there's nothing that will do the job currently, any hints on where to start to write such a thing would be great!
 
Steve


--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: HTTP Headers from URL generator (or other processor)

Jeff Jones
Steve,

I can't think of any way to get response header information from the URL
generator, but maybe someone else can help with that.

If you want/need to do it yourself, though, it's not that hard. Start
here for information on how to write a processor:

http://www.orbeon.com/ops/doc/reference-processor-api

I've used Apache HTTPClient to build a specialized URL-generator-like
processor specifically because it offers a lot of ways to tinker with
the request and the response.

http://hc.apache.org/httpclient-3.x/

In my case, I'm always retrieving XML, so I use Dom4J to very easily
parse the returned document:

import java.xml.transform.Source;
import org.dom4j.Document;
import org.apache.commons.httpclient.methods.GetMethod;
import org.dom4j.io.SAXReader;
import org.orbeon.oxf.xml.dom4j.Dom4jUtils;

public static Document getDoc(String url, /* other stuff */) {
     SAXReader reader = new SAXReader(false); // don't validate
     GetMethod m = new GetMethod(url);
     InputStream is = method.getResponseBodyAsStream();
     Document content = reader.read(is);
     return content;

     /* if you need to return a Source instead, there's a handy
        utility class to help with that:
     return Dom4jUtils.getDocumentSource(content);
     */
}

Your processor's generateXXXX() method (whatever you choose to call your
output) can then use an org.dom4j.io.SAXWriter to write the document out
into the ContentHandler that is passed in.

I hope this helps, and I hope that anyone who can offer a better way
will share that with the list too.

</Jeff>


Steve Bayliss wrote:

> Is there any way of retrieving HTTP response headers from a request made
> by the URL generator (or any other processor that might do the job)?
>  
> eg being able to get
> - the response code
> - the content-type
>  
> Ideally ability to customise the request also, eg to do an HTTP HEAD and
> then examine the resulting response headers.
>  
> If there's nothing that will do the job currently, any hints on where to
> start to write such a thing would be great!
>  
> Steve


--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Re: HTTP Headers from URL generator (or other processor)

Erik Bruchez
Administrator
That's right, the URL generator does not provide header information ATM.

If you do a submission with XForms, you have access to more  
information. In theory, headers can be accessed, although I think we  
don't yet implement that (but it wouldn't be too hard to do).

-Erik

On Apr 16, 2008, at 7:28 AM, Jeff Jones wrote:

> Steve,
>
> I can't think of any way to get response header information from the  
> URL generator, but maybe someone else can help with that.
>
> If you want/need to do it yourself, though, it's not that hard.  
> Start here for information on how to write a processor:
>
> http://www.orbeon.com/ops/doc/reference-processor-api
>
> I've used Apache HTTPClient to build a specialized URL-generator-
> like processor specifically because it offers a lot of ways to  
> tinker with the request and the response.
>
> http://hc.apache.org/httpclient-3.x/
>
> In my case, I'm always retrieving XML, so I use Dom4J to very easily  
> parse the returned document:
>
> import java.xml.transform.Source;
> import org.dom4j.Document;
> import org.apache.commons.httpclient.methods.GetMethod;
> import org.dom4j.io.SAXReader;
> import org.orbeon.oxf.xml.dom4j.Dom4jUtils;
>
> public static Document getDoc(String url, /* other stuff */) {
>    SAXReader reader = new SAXReader(false); // don't validate
>    GetMethod m = new GetMethod(url);
>    InputStream is = method.getResponseBodyAsStream();
>    Document content = reader.read(is);
>    return content;
>
>    /* if you need to return a Source instead, there's a handy
>       utility class to help with that:
>    return Dom4jUtils.getDocumentSource(content);
>    */
> }
>
> Your processor's generateXXXX() method (whatever you choose to call  
> your output) can then use an org.dom4j.io.SAXWriter to write the  
> document out into the ContentHandler that is passed in.
>
> I hope this helps, and I hope that anyone who can offer a better way  
> will share that with the list too.
>
> </Jeff>
>
>
> Steve Bayliss wrote:
>> Is there any way of retrieving HTTP response headers from a request  
>> made by the URL generator (or any other processor that might do the  
>> job)?
>> eg being able to get
>> - the response code
>> - the content-type
>> Ideally ability to customise the request also, eg to do an HTTP  
>> HEAD and then examine the resulting response headers.
>> If there's nothing that will do the job currently, any hints on  
>> where to start to write such a thing would be great!
>> Steve
>
> --
> You receive this message as a subscriber of the [hidden email]  
> mailing list.
> To unsubscribe: mailto:[hidden email]
> For general help: mailto:[hidden email]?subject=help
> OW2 mailing lists service home page: http://www.ow2.org/wws
--
Orbeon Forms - Web Forms for the Enterprise Done the Right Way
http://www.orbeon.com/



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Reply | Threaded
Open this post in threaded view
|

RE: Re: Re: HTTP Headers from URL generator (or other processor)

Steve Bayliss
Jeff, Erik,

Thanks, looks like a custom processor using HTTPClient will do the job, I'll
give that a go.

Steve

-----Original Message-----
From: Erik Bruchez [mailto:[hidden email]]
Sent: 16 April 2008 20:28
To: [hidden email]
Subject: [ops-users] Re: Re: HTTP Headers from URL generator (or other
processor)


That's right, the URL generator does not provide header information ATM.

If you do a submission with XForms, you have access to more  
information. In theory, headers can be accessed, although I think we  
don't yet implement that (but it wouldn't be too hard to do).

-Erik

On Apr 16, 2008, at 7:28 AM, Jeff Jones wrote:

> Steve,
>
> I can't think of any way to get response header information from the
> URL generator, but maybe someone else can help with that.
>
> If you want/need to do it yourself, though, it's not that hard.
> Start here for information on how to write a processor:
>
> http://www.orbeon.com/ops/doc/reference-processor-api
>
> I've used Apache HTTPClient to build a specialized URL-generator-
> like processor specifically because it offers a lot of ways to  
> tinker with the request and the response.
>
> http://hc.apache.org/httpclient-3.x/
>
> In my case, I'm always retrieving XML, so I use Dom4J to very easily
> parse the returned document:
>
> import java.xml.transform.Source;
> import org.dom4j.Document;
> import org.apache.commons.httpclient.methods.GetMethod;
> import org.dom4j.io.SAXReader;
> import org.orbeon.oxf.xml.dom4j.Dom4jUtils;
>
> public static Document getDoc(String url, /* other stuff */) {
>    SAXReader reader = new SAXReader(false); // don't validate
>    GetMethod m = new GetMethod(url);
>    InputStream is = method.getResponseBodyAsStream();
>    Document content = reader.read(is);
>    return content;
>
>    /* if you need to return a Source instead, there's a handy
>       utility class to help with that:
>    return Dom4jUtils.getDocumentSource(content);
>    */
> }
>
> Your processor's generateXXXX() method (whatever you choose to call
> your output) can then use an org.dom4j.io.SAXWriter to write the  
> document out into the ContentHandler that is passed in.
>
> I hope this helps, and I hope that anyone who can offer a better way
> will share that with the list too.
>
> </Jeff>
>
>
> Steve Bayliss wrote:
>> Is there any way of retrieving HTTP response headers from a request
>> made by the URL generator (or any other processor that might do the  
>> job)?
>> eg being able to get
>> - the response code
>> - the content-type
>> Ideally ability to customise the request also, eg to do an HTTP  
>> HEAD and then examine the resulting response headers.
>> If there's nothing that will do the job currently, any hints on  
>> where to start to write such a thing would be great!
>> Steve
>
> --
> You receive this message as a subscriber of the [hidden email]
> mailing list.
> To unsubscribe: mailto:[hidden email]
> For general help: mailto:[hidden email]?subject=help
> OW2 mailing lists service home page: http://www.ow2.org/wws
--
Orbeon Forms - Web Forms for the Enterprise Done the Right Way
http://www.orbeon.com/




--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws