Hi Steven,
thanks for your reply, I created a new XSLTTransformer for now, based on the
code you suggested in your mail. Since we're talking feature requests, I
think it would also make sense to provide a PipelineComponent that allows to
access XML documents through authenticated URLs. I'm using the following for
now:
...
public class AuthenticatedUrlXmlProducer extends AbstractXMLProducer
implements Starter {
private URL url;
private String username;
private String password;
public AuthenticatedUrlXmlProducer(URL url, String username, String
password) {
super();
this.url = url;
this.username = username;
this.password = password;
}
public void execute() {
try {
String encoding = new sun.misc.BASE64Encoder().encode((username
+ ":" + password).getBytes());
URLConnection uc = url.openConnection();
uc.setRequestProperty("Authorization", "Basic " + encoding);
XMLUtils.toSax(uc.getInputStream(), this.getXMLConsumer());
} catch (IOException e) {
throw new ProcessingException(e);
}
}
}
I think the alpha release of Cocoon 3 looks great and I'm looking forwards
to see where the journey is going with the first beta!
Cheers, Nils
Hello Nils,
>
> I'm afraid there is currently no support for accessing URLs that require
> authentication.
>
> While I think this is a feature all components should have, it will take
> some time to add this and you'd have to wait for the next release or change
> to the trunk in order to use it.
> A faster way would be to create a new XSLTTransformer and add the
> authentication to it.
>
> The code for accessing the URL (currently in the createTransformerHandler()
> method) should look like this (just top off my head, no guarantees ;-) )
>
> String userPassword = "Username" + ":" + "Password";
> String encoded = new
> sun.misc.BASE64Encoder().encode(userPassword.getBytes());
> URLConnection connection = this.source.openConnection();
> connection.setRequestProperty("Authorization", "Basic " + encoded);
> InputStream inputStream = connection.getInputStream();
>
> InputSource inputSource = new InputSource();
> inputSource.setByteStream(inputStream);
>
> XMLReader xmlReader = XMLReaderFactory.createXMLReader();
> xmlReader.setContentHandler(templatesHandler);
> xmlReader.parse(inputSource);
>
> inputStream.close();
>
>
> But as I said above, this is a sound feature request and you can expect
> this to be in one of the next releases...
>
> Regards,
> Steven
>
>
> Nils Preusker schrieb:
>
> Hi all,
>>
>> I just started trying out cocoon 3 alpha 1 and I'm wondering if there is a
>> solution for the following scenario: I'm retrieving all my XML and XSLT
>> content via URLs that require authentication. Without the authentication I
>> could simply create a pipeline like this:
>> ...
>> Pipeline pipeline = new NonCachingPipeline();
>> pipeline.addComponent(new StringGenerator("<x></x>"));
>> pipeline.addComponent(new XSLTTransformer(new URL("
>> http://example.com/somexslt.xslt")));
>> pipeline.addComponent(new XMLSerializer());
>>
>> ByteArrayOutputStream baos = new ByteArrayOutputStream();
>> pipeline.setup(baos);
>>
>> pipeline.execute();
>> ...
>> That's almost the same as the example on the cocoon website. The only
>> difference is that instead of a file I'm using a URL to provide the XSLT.
>> This works if I disable authentication for my XML/XSLT repository. But when
>> I enable authentication, I'll end up with an exception and a 401 from apache
>> somewhere in the stack trace...
>>
>> So in short: I'm wondering if there is a way to create an XSLTTransformer
>> that can retrieve data from URLs that require authentication?
>>
>> Any help would be greatly appreciated! Cheers, Nils
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>