Infinite scan for fonts in Apache FOP on CentOS

不想你离开。 提交于 2019-12-24 07:16:07

问题


I use Apache Batik to convert SVG into PDF in one of the projects. The project is Spring application running in Tomcat 7. Everything works OK on development machine which runs under Ubuntu with Tomcat being started using $CATALINA_HOME/bin/startup.sh. But when I try to run the app on production server with CentOS 6 and Tomcat started using service tomcat7 start command the app falls into infinite loop on convertation. I've tried to debug the problem and found this piece of code:

/**
 * Creates the {@link FontInfo} instance for the given configuration.
 * @param cfg the configuration
 * @param useComplexScriptFeatures true if complex script features enabled
 * @return the font collection
 * @throws FOPException if an error occurs while setting up the fonts
 */
public static FontInfo createFontInfo(Configuration cfg, boolean useComplexScriptFeatures)
    throws FOPException {
    FontInfo fontInfo = new FontInfo();
    final boolean strict = false;
    if (cfg != null) {
        URI thisUri = new File(".").getAbsoluteFile().toURI();
        InternalResourceResolver resourceResolver
                = ResourceResolverFactory.createDefaultInternalResourceResolver(thisUri);
        //TODO The following could be optimized by retaining the FontManager somewhere
        FontManager fontManager = new FontManager(resourceResolver, FontDetectorFactory.createDefault(),
                FontCacheManagerFactory.createDefault());

        //TODO Make use of fontBaseURL, font substitution and referencing configuration
        //Requires a change to the expected configuration layout

        DefaultFontConfig.DefaultFontConfigParser parser
                = new DefaultFontConfig.DefaultFontConfigParser();
        DefaultFontConfig fontInfoConfig = parser.parse(cfg, strict);
        DefaultFontConfigurator fontInfoConfigurator
                = new DefaultFontConfigurator(fontManager, null, strict);
        List<EmbedFontInfo> fontInfoList = fontInfoConfigurator.configure(fontInfoConfig);
        fontManager.saveCache();
        FontSetup.setup(fontInfo, fontInfoList, resourceResolver, useComplexScriptFeatures);
    } else {
        FontSetup.setup(fontInfo, useComplexScriptFeatures);
    }
    return fontInfo;
}

in PDFDocumentGraphics2DConfigurator class. When I'm running the app on developer machine the line URI thisUri = new File(".").getAbsoluteFile().toURI(); results with thisUri being assigned with ~/tomcat/bin/. folder. When the app is running on production machine it is assigned with /. value. I think that this is the main problem because the value of thisUri is the folder in which FOP starts fonts search and on the production machine this is the root of file system and recursive search on the whole FS structure is very slow. I tried to add fop.xconf file to the WEB-INF directory with fonts configuration but it didn't affected the behavior of FOP. And I can't start Tomcat on production server the same way as I start on the dev machine. Has anyone ideas on how to configure the base directory for font scan of FOR? Or am I doing something wrong?


回答1:


I've found the workaround for the problem. I'm not sure if its wright or wrong to do stuff like that but it works. The workaround is based on the fact that File.getAbsolutFile() by default returns the directory resolved against the directory defined by user.dir option. So I need some way to pass this option on Tomcat service start. The only way I've found to do this is to add -Duser.dir=/%CATALINA_HOME/ to the CATALINA_OPTS variable defined in %CATALINA_HOME/bin/setenv.sh file. After that the font scan process took normal amount of time and my app started to work fine.



来源:https://stackoverflow.com/questions/39919003/infinite-scan-for-fonts-in-apache-fop-on-centos

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!