I think there's an even easier way to do this, and it's probably the
better one. I've attached a simple class (MyAuthenticator.java) which
you can adjust to your purposes. You can inspect the parameters for the
password authentication and return a username and password depending on
those values. FOP (or rather Java's java.net.URL subsystem) will
use your MyAuthenticator class as soon as you call it's "install()"
method somewhere in the initialization code of your
application/servlet/whatever.

Here's where I got the idea from:
http://www.javaworld.com/javaworld/javatips/jw-javatip46.html

No need for a complicated URIResolver using Jakarta Commons HttpClient
or something like that. :-)

On 22.02.2006 14:04:39 Jeremias Maerki wrote:
> I'll see if I have a little time later to set up a Wiki page describing
> this. If anyone beats me to it, all the better. :-) It's really no
> witchcraft.
> 
> On 22.02.2006 11:44:40 jelka.kosir wrote:
> > I have the FopTrunk version on my computer (JDK 1.3) and testing it for 
> > issues I had in previous version FOP, so I can decide if we change fop 
> > version.
> > 
> > This (see history of this mail) was one of the issues I had (how to pass 
> > to fop basic authentication for retrieving resources from application 
> > server). 
> > I solved this with workaround that David suggested (created a Servlet that 
> > adds authentication and fetches image).
> > 
> > Now I was wondering if this basic authentication can be done more elegant 
> > in new version and how to do it. 
> > Currently I'm testing from FOP command line and when I'm done testing I 
> > will use FOP embedded in application.
> > 
> > Jeremias wrote: 
> > > you will have
> > > the ability to plug in a URIResolver to manually fetch an InputStream to
> > > a resource based on a URI.)
> > 
> > I'm quite week at Java programming and am not sure how to "plug a 
> > URIResolver". 
> > I would need a few instructions how to do this. 
> > I guess I have to implement an URIResolver for the resources that need 
> > authentication and use the default one for resources that don't need 
> > authentication.
> > Where do I create my class? Do I create it in my Java application that I 
> > call FOP from and how do I convince FOP to use my implementation when 
> > needed?
> > 
> > I will be glad for any instructions/useful tips on my URIResolver.
> > 
> > Thank you!
> > 
> > Jelka
> > 
> > In addition I add some responses to Jeremias:
> > 
> > ------
> > Jeremias wrote:
> > > On the other side it's strange that wget is able to get the image with
> > > the uid/pwd encoded in the URL and FOP is not. Maybe FOP 0.20.5 does
> > > something bad with the URL. It would be great if someone could check
> > > this case with FOP Trunk so we can fix any problems like that for the
> > > next release.
> > 
> > I did try the "http://username:[EMAIL PROTECTED]/resource.gif" notation 
> > with the new FOP Trunk and I'm getting error 401 code (Unauthorized).
> > This url works in wget. Should a bug report be submitted ?
> > This is the error message that displays when I run Fop Trunk from command 
> > line:
> > 
> > Error with opening URL '//user:[EMAIL PROTECTED]/image.gif': Server 
> > retu
> > rned HTTP response code: 401 for URL: 
> > http://user:[EMAIL PROTECTED]/image.gif
> > java.io.IOException: Server returned HTTP response code: 401 for URL: 
> > http://user:[EMAIL PROTECTED]/image.gif
> > ------
> > 
> > I also tried this notation in my custom config file (I use custom fonts 
> > because character set we use is Latin 2) I set 
> > <base>http://user:[EMAIL PROTECTED]/</base>
> > and this produces Error 401 when I run FOP Trunk from command line (wget 
> > is able to retrieve with this url).
> > 
> > Error with opening URL 'arial.xml': Server returned HTTP response code: 
> > 401 for
> > URL: http://user:[EMAIL PROTECTED]/arial.xml
> > java.io.IOException: Server returned HTTP response code: 401 for URL: 
> > http://user:[EMAIL PROTECTED]/arial.xml
> > 
> > Mismatch: page-sequence (http://www.w3.org/1999/XSL/Format) vs. root 
> > (http://www
> > .w3.org/1999/XSL/Format)
> > Error with opening URL 'arial.xml': Server returned HTTP response code: 
> > 401 for
> > URL: http://user:[EMAIL PROTECTED]/arial.xml
> > java.io.IOException: Server returned HTTP response code: 401 for URL: 
> > http://user:[EMAIL PROTECTED]/arial.xml
> > 
> > javax.xml.transform.TransformerException: java.lang.RuntimeException: 
> > Cannot loa
> > d font: failed to create Source from metrics file arial.xml
> > Exception
> > javax.xml.transform.TransformerException: java.lang.RuntimeException: 
> > Cannot loa
> > d font: failed to create Source from metrics file arial.xml
> > ------
> > 
> > 
> > 
> > 
> > 
> > 
> > Jeremias Maerki <[EMAIL PROTECTED]> 
> > 13.10.2005 16:49
> > Please respond to
> > fop-users@xmlgraphics.apache.org
> > 
> > 
> > To
> > fop-users@xmlgraphics.apache.org
> > cc
> > 
> > Subject
> > Re: how to pass to fop user and password needed for basic authentication 
> > to get image resource from Notes database
> > 
> > 
> > 
> > 
> > 
> > 
> > BTW, the redesigned FOP will make things like that easier. You will have
> > the ability to plug in a URIResolver to manually fetch an InputStream to
> > a resource based on a URI. This will make work-arounds like David's
> > servlet unnecessary.
> > 
> > On the other side it's strange that wget is able to get the image with
> > the uid/pwd encoded in the URL and FOP is not. Maybe FOP 0.20.5 does
> > something bad with the URL. It would be great if someone could check
> > this case with FOP Trunk so we can fix any problems like that for the
> > next release.
> > 
> > On 13.10.2005 16:26:33 David Delbecq wrote:
> > > Then i guess your solution is to write a servlet which access files
> > > using the api and get credits token lik this:
> > > 
> > > 
> > http://domino.example.com/myServlet?doc=/0/A3402F5B583F538AC1257093004C41C8/$File/image.gif&user=someUser&pass=somePass
> > 
> > > 
> > > If image tag of .fo were to use the InputSource schem of xml document,
> > > you could have created an Inputsource which
> > > manage the authentification. Unfortunately, as i discovered some time
> > > before, fop does not use inputsource to load pictures.
> > > (really, it uses a simple URL())
> > > I think this will be handled in next version, but if you followed this
> > > maling list, lots of things will change in next version,
> > > so it might not be availbe for a few time :)
> > > Ha yeah, you can also try to add your custom protocol to URL (like
> > > dominoContent://) but a mpretty sure you don't even want
> > > to try as it is jvm-wide modification :)
> > > 
> > > [EMAIL PROTECTED] a écrit :
> > > 
> > > >
> > > > Yes, I did try this notation and the error came up the same (Could not
> > > > load external SVG: ... error)
> > > >
> > > > If I try to use such url in a web browser for example, when first
> > > > requesting this url a "page not found" is displayed and all next
> > > > responses to this
> > > > same request retrieve an empty page (there is some html but the <body>
> > > > tag is empty so blank page is displayed).
> > > >
> > > > I also noticed that with using wget with this type of url, the image
> > > > is retrieved from the server correctly.
> > > >
> > > > Thank you David for the suggestion, I was kind of sad to notice that
> > > > this doesn't work as I thought it would.
> > > >
> > > >
> > > >
> > > >
> > > > *David Delbecq <[EMAIL PROTECTED]>*
> > > >
> > > > 13.10.2005 15:33
> > > > Please respond to
> > > > fop-users@xmlgraphics.apache.org
> > > >
> > > >
> > > > 
> > > > To
> > > >              fop-users@xmlgraphics.apache.org
> > > > cc
> > > > 
> > > > Subject
> > > >              Re: how to pass to fop user and password needed for basic
> > > > authentication to get image resource from Notes database
> > > >
> > > >
> > > >
> > > > 
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Did you try this kind of url?
> > > > 
> > http://user:[EMAIL 
> > PROTECTED]/database.nsf/0/A3402F5B583F538AC1257093004C41C8/$File/image.gif
> > 
> > > > [EMAIL PROTECTED] a écrit :
> > > >
> > > > >
> > > > > I will describe my situation.
> > > > >
> > > > > I have an application server (Domino) and on it running a web
> > > > > application.
> > > > >
> > > > > On this web application users have a basic editor (uses xhtml) to
> > > > > input basic text/formats/tables and upload images that are included 
> > in
> > > > > the document
> > > > >
> > > > >
> > > > > Images are uploaded in notes database and url is passed into this
> > > > > editor (xml source for this is standard html like <img
> > > > >
> > > > src="
> > http://domino.example.com/database.nsf/0/A3402F5B583F538AC1257093004C41C8/$File/image.gif
> > "
> > > > > />) and I parse it like this:
> > > > >
> > > > > part of xsl file:
> > > > > .        <xsl:template match="img">
> > > > >                 <fo:block space-after="12pt">
> > > > >                         <fo:external-graphic src="[EMAIL PROTECTED]"> 
> > > > >  
> > > > > 
> > > > >                                 <xsl:if test="@width">
> > > > >                                         <xsl:attribute
> > > > > name="width"><xsl:choose><xsl:when test="contains(@width,
> > > > > 'px')"><xsl:value-of
> > > > > select="@width"/></xsl:when><xsl:otherwise><xsl:value-of
> > > > > select="concat(@width,
> > > > > 'px')"/></xsl:otherwise></xsl:choose></xsl:attribute>
> > > > >                                 </xsl:if>
> > > > >                                 <xsl:if test="@height">
> > > > >                                         <xsl:attribute
> > > > > name="height"><xsl:choose><xsl:when test="contains(@height,
> > > > > 'px')"><xsl:value-of
> > > > > select="@height"/></xsl:when><xsl:otherwise><xsl:value-of
> > > > > select="concat(@height,
> > > > > 'px')"/></xsl:otherwise></xsl:choose></xsl:attribute>
> > > > >                                 </xsl:if>
> > > > >                         </fo:external-graphic>
> > > > >                 </fo:block>
> > > > >         </xsl:template>
> > > > >
> > > > > Users have a possibility to create pdf of created document from this
> > > > > application. All works fine - I generate xml on demand and transform
> > > > > it with xsl file that is prepared.
> > > > >
> > > > > The problem is when transformer fetches image from database I do not
> > > > > know how to pass username and password for authentication and the
> > > > > process that requests the image now gets a Login Page instead (html
> > > > > response) and when trying to include it into PDF an error that is
> > > > > printed in the log:
> > > > >
> > > > > [ERROR] Could not load external SVG: White spaces are required 
> > between
> > > > > publicId and systemId.
> > > > > [ERROR] Error while creating area : No ImageReader for this type of
> > > > > image
> > > > >
> > > > (
> > http://domino.example.com/database.nsf/0/A3402F5B583F538AC1257093004C41C8/$File/image.gif
> > )
> > > > >
> > > > >
> > > > > So my question is:
> > > > > Is there a way to set username and password for fop to use when
> > > > > fetching image from publicly not accessible database resources?
> > > > >
> > > > > Thank you all for helping.
> > > > >
> > > > > Jelka



Jeremias Maerki

Attachment: MyAuthenticator.java
Description: Binary data

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to