Nils Preusker schrieb:
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);
        }
    }
}

Yes, that looks nice.

Basically every pipeline component uses URLs to access resources. That's why I think there should be a rather easy way to support authentication in each and every component currently in existence.

I have created a new Jira issue for this (https://issues.apache.org/jira/browse/COCOON3-35) to keep track of the progress and collect all relevant information there. We will have to do some refactoring to provide a flexible and easy way that is working for the components we have now and the ones that will come in the future, but I'm very confident that this easily done.

Please feel free to add your comments and thoughts to the issue...


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!

Very glad to hear this, of course. Thank you!

Steven


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]
    <mailto:[email protected]>
    For additional commands, e-mail: [email protected]
    <mailto:[email protected]>




---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to