You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Christopher Schultz <ch...@christopherschultz.net> on 2011/02/25 17:54:58 UTC

Setting URLConnection User-Agent String

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

All,

I'm using Cocoon 2.1.11 with some pipelines that fetch data from another
webapp via Apache httpd which logs the requests with the User-Agent
being "Java/whatever". I'm wondering if Cocoon offers the ability to
tweak the User-Agent string that is used when fetching data from http://
resources?

I believe I can set the http.agent system property, but I was wondering
if anyone has another (better?) technique to do this?

Thanks,
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk1n3uIACgkQ9CaO5/Lv0PAjqwCdEeS0fpVuAHhXEeyEXKehyTO6
54IAoLWV0wHj6TjiAXihOTUZAwOMHRRB
=e1Ma
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


[ANN]VTD-XML 2.10

Posted by Jimmy Zhang <cr...@comcast.net>.
VTD-XML 2.10 is now released. It can be downloaded at
https://sourceforge.net/projects/vtd-xml/files/vtd-xml/ximpleware_2.10/.
This release includes a number of new features and enhancement.

* The core API of VTD-XML has been expanded. Users can now perform
cut/paste/insert on an empty element.
* This release also adds the support of deeper location cache support for
parsing and indexing. This feature is useful for application performance
tuning for
processing various XML documents.
* The java version also added support for processing zip and gzip files.
Direct processing of httpURL based XML is enhanced.
* Extended Java version now support Iso-8859-10~16 encoding.
* A full featured C++ port is released.
* C version of VTD-XML now make use of thread local storage to achieve
thread safety for multi-threaded application.
* There are also a number of bugs fixed. Special thanks to Jozef Aerts, John
Sillers, Chris Tornau and a number of other users for input and suggestions


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Setting URLConnection User-Agent String

Posted by warrell harries <wa...@gmail.com>.
Yep, do it in the setup....

public void setup(SourceResolver resolver, Map objectModel, String src,
Parameters par) throws ProcessingException, SAXException, IOException
{
super.setup(resolver,objectModel,src,par);
try
{
Source inputSource = resolver.resolveURI(super.source);
this.source = inputSource.getURI();
}
catch(SourceException se)
{
throw SourceUtil.handle("Unable to Resolve " + super.source, se);
}
this.customHeader = par.getParameter(WORLD_LOGGER, new String());
this.httpClient = this.getHttpClient();
}

Re: Setting URLConnection User-Agent String

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Warren,

Resurrecting an old thread: I hadn't noticed your reply back in March.

On 3/1/2011 5:46 AM, warrell harries wrote:
> It doesn't make any difference - it's plain old HTTP despite the
> jargon :)

Of course.

> If you have already seen this 
> http://www.mail-archive.com/users@cocoon.apache.org/msg34182.html
> 
> then investigate the original Generator code at 
> /cocoon-2.1.11/src/blocks/proxy/java/org/apache/cocoon/generation/WebServiceProxyGenerator.java
>
>  It could be that this will be sufficient for your requirements.

So, I'm using a simple XML-over-HTTP request as my generator, like this:

        <map:part src="http://host/service.xml" />

I'm using the default set of Cocoon generators with default="file", or
org.apache.cocoon.generation.FileGenerator. The request is definitely
using an HTTP connection, as this URL is not otherwise reachable (and
it's showing up in our request logs, too).

But, it's not a web service. Maybe that's not relevant, but I thought
I'd point it out as you directed me towards WebServiceProxyGenerator.java.

I took a look at how WSPG works, and it's a relatively straightforward
use of commons-httpclient, which has an addUserAgentRequestHeader
method available.

The question is how to get the setting from the sitemap into the
object that actually makes the connection.

Is the setup(..., Parameters par) method the right place to do such
things? If so, a simple patch like this:

if(par.isParameter("user-agent"))
  this.httpClient.getParams(HttpParam.USER_AGENT,
                            par.getParameter("user-agent"));

Would this be the right place to put such code, and how does one
configure parameters to <map:generator>? Using attributes like
<map:generator ... user-agent="MyUserAgent" /> or using sub-elements?

Thanks,
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk6LKO4ACgkQ9CaO5/Lv0PBT2gCfVAgtjQSTjPi24/7q3YX1KTbf
q7wAn3ZmyoSa+qWrMICb8PSY398UGOwh
=KKRy
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Setting URLConnection User-Agent String

Posted by warrell harries <wa...@gmail.com>.
Hi Chris,

It doesn't make any difference - it's plain old HTTP despite the jargon :)

If you have already seen this
http://www.mail-archive.com/users@cocoon.apache.org/msg34182.html

then investigate the original Generator code at
/cocoon-2.1.11/src/blocks/proxy/java/org/apache/cocoon/generation/WebServiceProxyGenerator.java

It could be that this will be sufficient for your requirements.

Best regards,

Warrell


On 28 February 2011 16:13, Christopher Schultz <chris@christopherschultz.net
> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Warrell,
>
> On 2/28/2011 6:41 AM, warrell harries wrote:
> > Please see recent discussion regarding proxying to another server. In
> > brief, I usually deploy a custom transformer based on the web service
> > proxy transformer but setting the user agent header before invoking the
> > web service.
>
> I was talking about a vanilla HTTP request that returns an XML document,
> not a formal web service. Not sure if that changes your suggestion(s).
>
> > Seems like this is a common requirement and it would be good if the
> > desired header could be passed in as a sitemap parameter to an existing
> > component. I am not aware of any existing component that provides this
> > facility.
>
> That would be cool. I've had a hard time penetrating the Cocoon code
> base in the past. Any pointers on where to look to possibly implement this?
>
> Thanks,
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAk1rybAACgkQ9CaO5/Lv0PAA8wCfWcDOcdJ/U4SiB3X9UTuRBqK0
> FG4AoKsjKpjN4Cdy/msD8N6WmCJ0yMHT
> =U07J
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>

Re: Setting URLConnection User-Agent String

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Warrell,

On 2/28/2011 6:41 AM, warrell harries wrote:
> Please see recent discussion regarding proxying to another server. In
> brief, I usually deploy a custom transformer based on the web service
> proxy transformer but setting the user agent header before invoking the
> web service.

I was talking about a vanilla HTTP request that returns an XML document,
not a formal web service. Not sure if that changes your suggestion(s).

> Seems like this is a common requirement and it would be good if the
> desired header could be passed in as a sitemap parameter to an existing
> component. I am not aware of any existing component that provides this
> facility.

That would be cool. I've had a hard time penetrating the Cocoon code
base in the past. Any pointers on where to look to possibly implement this?

Thanks,
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk1rybAACgkQ9CaO5/Lv0PAA8wCfWcDOcdJ/U4SiB3X9UTuRBqK0
FG4AoKsjKpjN4Cdy/msD8N6WmCJ0yMHT
=U07J
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Setting URLConnection User-Agent String

Posted by warrell harries <wa...@gmail.com>.
Please see recent discussion regarding proxying to another server. In brief,
I usually deploy a custom transformer based on the web service proxy
transformer but setting the user agent header before invoking the web
service.

Seems like this is a common requirement and it would be good if the desired
header could be passed in as a sitemap parameter to an existing component. I
am not aware of any existing component that provides this facility.

Regards,

Warrell
On 25 Feb 2011 16:55, "Christopher Schultz" <ch...@christopherschultz.net>
wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> All,
>
> I'm using Cocoon 2.1.11 with some pipelines that fetch data from another
> webapp via Apache httpd which logs the requests with the User-Agent
> being "Java/whatever". I'm wondering if Cocoon offers the ability to
> tweak the User-Agent string that is used when fetching data from http://
> resources?
>
> I believe I can set the http.agent system property, but I was wondering
> if anyone has another (better?) technique to do this?
>
> Thanks,
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAk1n3uIACgkQ9CaO5/Lv0PAjqwCdEeS0fpVuAHhXEeyEXKehyTO6
> 54IAoLWV0wHj6TjiAXihOTUZAwOMHRRB
> =e1Ma
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>