开发者

fop in glassfish fail to render external resources

I am generating a PDF file via fop 1.0 out of a java library. The unit tests are running fine and the PDF is rendered as expected, including an external graphic:

<fo:external-graphic content-width="20mm" src="url('images/image.png')" />

If I render this within a Java EE application in glassfish 3.1, I always get the following error:

Image not found. URI: images/image.png. (No context info available)

I double-checked whether the image is available. It is available within the .jar file in the .ear file and should therfore be available by the ClasspathUriResolver. This is a code-snipplet of how I setup the fop-factory:

FopFactory fopFactory = FopFactory.newInstance();
URIResolver uriResolver = new ClasspathUriResolver();
fopFactory.setURIResolver(uriResolver);
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);
...

I also assigned the URI resolver to the TransformerFactory and the Transformer with no success. Would be great if someone can hel开发者_运维技巧p me out.

-- Wintermute

Btw: the ClasspathUriResolver() looks like this

public class ClasspathUriResolver implements URIResolver {

  @Override
  public Source resolve(String href, String base) throws TransformerException {
    Source source = null;
    InputStream inputStream = ClassLoader.getSystemResourceAsStream(href);
    if (inputStream != null) {
      source = new StreamSource(inputStream);
    }
    return source;
  }
}


You consider a different class loader then ClassLoader.getSystemResourceAsStream(href);

Try InputStream inputStream = getClass().getResourceAsStream(href); or something else, maybe.

Does it work, then?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜