TEIC / oxygen-tei

Automatically exported from code.google.com/p/oxygen-tei
15 stars 6 forks source link

jTEI PDF transformation fails with "ERROR StatusLogger Could not register mbeans" #45

Closed rvdb closed 3 years ago

rvdb commented 3 years ago

It seems the jTEI PDF transformation is broken in Oxygen 23 and 22. On my machine (Windows 10, OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_232-b09)), it produces following error:

transform-fo:
   [delete] Deleting: F:\jTEI\trunk\submissions\jtei-test-pdf.fo
     [java] ERROR StatusLogger Could not register mbeans
     [java]  java.security.AccessControlException: access denied ("javax.management.MBeanTrustPermission" "register")
     [java]     at java.security.AccessControlContext.checkPermission(Unknown Source)
     [java]     at java.lang.SecurityManager.checkPermission(Unknown Source)
     [java]     at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.checkMBeanTrustPermission(Unknown Source)
     [java]     at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(Unknown Source)
     [java]     at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(Unknown Source)
     [java]     at org.apache.logging.log4j.core.jmx.Server.register(Server.java:393)
     [java]     at org.apache.logging.log4j.core.jmx.Server.reregisterMBeansAfterReconfigure(Server.java:168)
     [java]     at org.apache.logging.log4j.core.jmx.Server.reregisterMBeansAfterReconfigure(Server.java:141)
     [java]     at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:629)
     [java]     at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:691)
     [java]     at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:708)
     [java]     at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:263)
     [java]     at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:153)
     [java]     at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
     [java]     at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
     [java]     at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:602)
     [java]     at ro.sync.xml.transformer.p.<clinit>(Unknown Source)
     [java]     at ro.sync.xml.transformer.saxonee.SaxonEEUtilImpl.supplySaxonLicenseAndSchemaResolver(Unknown Source)
     [java]     at net.sf.saxon.Configuration.newConfiguration(Configuration.java:292)
     [java]     at net.sf.saxon.s9api.Processor.<init>(Processor.java:63)
     [java]     at net.sf.saxon.Transform.doTransform(Transform.java:316)
     [java]     at net.sf.saxon.Transform.main(Transform.java:80)
     [java]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     [java]     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
     [java]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
     [java]     at java.lang.reflect.Method.invoke(Unknown Source)
     [java]     at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:218)
     [java]     at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:155)
     [java]     at org.apache.tools.ant.taskdefs.Java.run(Java.java:861)
     [java]     at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:231)
     [java]     at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:135)
     [java]     at org.apache.tools.ant.taskdefs.Java.execute(Java.java:108)
     [java]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
     [java]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     [java]     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
     [java]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
     [java]     at java.lang.reflect.Method.invoke(Unknown Source)
     [java]     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
     [java]     at org.apache.tools.ant.Task.perform(Task.java:350)
     [java]     at org.apache.tools.ant.Target.execute(Target.java:449)
     [java]     at org.apache.tools.ant.Target.performTasks(Target.java:470)
     [java]     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1391)
     [java]     at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
     [java]     at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
     [java]     at org.apache.tools.ant.Project.executeTargets(Project.java:1254)
     [java]     at org.apache.tools.ant.Main.runBuild(Main.java:830)
     [java]     at org.apache.tools.ant.Main.startAnt(Main.java:223)
     [java]     at org.apache.tools.ant.launch.Launcher.run(Launcher.java:284)
     [java]     at org.apache.tools.ant.launch.Launcher.main(Launcher.java:101)

@martindholmes , could I ask if you're seeing this issue as well? And does anyone have an idea how it could be solved?

Best,

Ron

martindholmes commented 3 years ago

@rvdb Confirmed, I see the same error. Lots of references to this on the Internets, and it seems to be a security policy issue; perhaps the Oxygen folks can help? I've posted in their "Common Problems" forum.

rvdb commented 3 years ago

Hi @martindholmes , thanks for your help. Meanwhile, I think I have found a solution (that's working on my machine, anyway). Could you try if it works when you add @fork="true" and @clonevm="true" to the <java> task?

<target name="transform-fo">
  <delete file="${cfd}/${dest.file.basename}.fo"/>
  <java classname="net.sf.saxon.Transform" fork="true" clonevm="true">
    <arg value="-target:HE"/>
    <arg value="-s:${cfd}/${cfne}"/>
    <arg value="-xsl:${transformations.base}/pdf/to.xsl"/> 
    <arg value="-o:${cfd}/${dest.file.basename}.fo"/>
  </java>
</target>
AlexJitianu commented 3 years ago

Hello,

First of all, the exception is harmless. If you take a look at org.apache.logging.log4j.core.jmx.Server.reregisterMBeansAfterReconfigure(MBeanServer), you'll notice how it catches the exception, logs it, and moves forward without JMX support. The log4j JMX support allows one to connect and control the logging system. It is not something that we ever intended to use. We can edit the JTEI PDF scenario and add this property in the JVM Arguments field: -Dlog4j2.disable.jmx=true and the exception will no longer appear.

It's not entirely clear to me why this exception appears. Oxygen does have a security manager active, but we don't set any restrictions when transforming a document. We usually take precautions when automatically validating a document or when various operations try to connect to remote resource. Beside, I reproduced the exception even when I manually disabled this security manager.

AlexJitianu commented 3 years ago

Alternatively, one could set the system property in the build file, but I'm not sure if that's the best approach since the issue only appears in Oxygen.

<java classname="net.sf.saxon.Transform">
      <sysproperty key="log4j2.disable.jmx" value="true"/>
      <arg value="-target:HE"/>
      <arg value="-s:${cfd}/${cfne}"/>
      <arg value="-xsl:${transformations.base}/pdf/to.xsl"/> 
      <arg value="-o:${cfd}/${dest.file.basename}.fo"/>
    </java>
rvdb commented 3 years ago

Many thanks, @AlexJitianu : adding the JVM argument does work. I've created a PR which adds this argument to both jTEI ANT transformations.