Apache CXF issue on Glassfish - glassfish

I created a web-service app based on Apache CXF (2.7.5), deployed it on a Glassfish 3.0.1 and it works fine till I turn on WS-Sec support. Then I get the following exception when I try to do a web-service request:
Caused by: javax.xml.crypto.NoSuchMechanismException: class configured for XMLSignatureFactory(provider: ApacheXMLDSig)cannot be found.
at javax.xml.crypto.dsig.XMLDSigSecurity.doGetImpl(Unknown Source) ~[webservices-osgi.jar:1.0]
at javax.xml.crypto.dsig.XMLDSigSecurity.getImpl(Unknown Source) ~[webservices-osgi.jar:1.0]
at javax.xml.crypto.dsig.XMLDSigSecurity.getImpl(Unknown Source) ~[webservices-osgi.jar:1.0]
at javax.xml.crypto.dsig.XMLSignatureFactory.findInstance(Unknown Source) ~[webservices-osgi.jar:1.0]
at javax.xml.crypto.dsig.XMLSignatureFactory.getInstance(Unknown Source) ~[webservices-osgi.jar:1.0]
at org.apache.ws.security.message.WSSecSignature.init(WSSecSignature.java:127) ~[wss4j-1.6.10.jar:1.6.10]
at org.apache.ws.security.message.WSSecSignature.<init>(WSSecSignature.java:120) ~[wss4j-1.6.10.jar:1.6.10]
at org.apache.cxf.ws.security.wss4j.policyhandlers.AbstractBindingBuilder.getSignatureBuilder(AbstractBindingBuilder.java:1730) ~[cxf-rt-ws-security-2.7.5.jar:2.7.5]
at org.apache.cxf.ws.security.wss4j.policyhandlers.AsymmetricBindingHandler.doSignature(AsymmetricBindingHandler.java:546) ~[cxf-rt-ws-security-2.7.5.jar:2.7.5]
at org.apache.cxf.ws.security.wss4j.policyhandlers.AsymmetricBindingHandler.doSignBeforeEncrypt(AsymmetricBindingHandler.java:147) ~[cxf-rt-ws-security-2.7.5.jar:2.7.5]
... 273 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.apache.jcp.xml.dsig.internal.dom.DOMXMLSignatureFactory
at org.apache.felix.framework.ModuleImpl.findClassOrResourceByDelegation(ModuleImpl.java:744) ~[felix.jar:na]
at org.apache.felix.framework.ModuleImpl.access$100(ModuleImpl.java:61) ~[felix.jar:na]
at org.apache.felix.framework.ModuleImpl$ModuleClassLoader.loadClass(ModuleImpl.java:1656) ~[felix.jar:na]
at java.lang.ClassLoader.loadClass(ClassLoader.java:247) ~[na:1.6.0_43]
It seems that CXF invokes the XMLSignatureFactory class contained by Glassfish's default webservice provider implementation instead of invoking it's own one (it's in the xmlsec.jar file). All CXF files are packed into my war file and also have the <class-loader delegate="false" /> set in sun-web.xml.
Can someone help me why the Glassfish classloader works this way and how could I fix this?

I managed to find out that Glassfish (at least the 3.0.1 version) modifies the default class loading behavior to "protect" some packages (mostly javax. packages) in it's classpath. That's the reason why it finds and uses classes in it's modules directory instead of the one in my war's lib.
To solve this a JVM option should be added to the domain.xml:
<jvm-options>-Dcom.sun.enterprise.overrideablejavaxpackages=javax.xml.crypto,javax.xml.crypto.dsig</jvm-options>
With this Glassfish will allow to use your libs in your war file. But even with this setting it's problematic to use CXF with WS-Securityy along with Metro. The better solution is to use a Glassfish with only Web Profile not Full Profile as Web Profile doesn't have Metro included.

Related

java.lang.ClassCastException: ... Lucene40PostingsFormat

I'm trying to use Hibernate-Search in one of my JavaEE projects and seem to run into the exact same problem as described by Rallenaldo:
My Maven-project is using
Java JDK 1.8.0_73
Hibernate 5.0.6.Final
Hibernate-Search 5.5.2.Final (which uses Lucene 5.3.1)
and try to deploy on a Glassfish 4.1.1 application server (with just minimal changes to the standard configuration).
When deploying my application the deployment process ends in the following ClassCastException, when Lucene tries to load codecs from the package lucene-backward-codecs (version 5.3.1):
java.lang.ClassCastException: class org.apache.lucene.codecs.lucene40.Lucene40PostingsFormat
at java.lang.Class.asSubclass(Class.java:3404)
at org.apache.lucene.util.SPIClassIterator.next(SPIClassIterator.java:141)
at org.apache.lucene.util.NamedSPILoader.reload(NamedSPILoader.java:65)
at org.apache.lucene.util.NamedSPILoader.<init>(NamedSPILoader.java:47)
at org.apache.lucene.util.NamedSPILoader.<init>(NamedSPILoader.java:37)
at org.apache.lucene.codecs.PostingsFormat$Holder.<clinit>(PostingsFormat.java:49)
at org.apache.lucene.codecs.PostingsFormat.forName(PostingsFormat.java:112)
at org.apache.lucene.codecs.lucene40.Lucene40Codec.<init>(Lucene40Codec.java:115)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at java.lang.Class.newInstance(Class.java:442)
at org.apache.lucene.util.NamedSPILoader.reload(NamedSPILoader.java:67)
at org.apache.lucene.util.NamedSPILoader.<init>(NamedSPILoader.java:45)
at org.apache.lucene.util.NamedSPILoader.<init>(NamedSPILoader.java:37)
at org.apache.lucene.codecs.Codec$Holder.<clinit>(Codec.java:47)
at org.apache.lucene.codecs.Codec.forName(Codec.java:113)
at org.apache.lucene.index.SegmentInfos.readCodec(SegmentInfos.java:469)
...
As has been elsewhere suggested, I have already verified that on my computer there is no other version of Lucene nor Hibernate-Search.
If I exclude the lucene-backward-codecs dependecy from the Maven-project, I get a similar ClassCastException at the exact same location in the Lucene-code:
java.lang.ClassCastException: class org.apache.lucene.codecs.lucene50.Lucene50PostingsFormat
at java.lang.Class.asSubclass(Class.java:3404)
at org.apache.lucene.util.SPIClassIterator.next(SPIClassIterator.java:141)
at org.apache.lucene.util.NamedSPILoader.reload(NamedSPILoader.java:65)
at org.apache.lucene.util.NamedSPILoader.<init>(NamedSPILoader.java:47)
at org.apache.lucene.util.NamedSPILoader.<init>(NamedSPILoader.java:37)
at org.apache.lucene.codecs.PostingsFormat$Holder.<clinit>(PostingsFormat.java:49)
at org.apache.lucene.codecs.PostingsFormat.forName(PostingsFormat.java:112)
at org.apache.lucene.codecs.lucene53.Lucene53Codec.<init>(Lucene53Codec.java:160)
at org.apache.lucene.codecs.lucene53.Lucene53Codec.<init>(Lucene53Codec.java:80)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
...
I was not able to find a solution to this problem. And I am aware that Rallenaldo's question is actally also still open. Does someone know what causes this problem? Is this a Glassfish 4.1.1 problem?
Edit: I want to add the following observation to my original post: part of my project generates an standalone application packed as a self executable jar-file with the identical hibernate and lucene related dependencies, where I also use an entity manager with essentially the same configuration for the presistence context. In this case I do not have the above problem with hibernate-search. It starts without any problem and I can see it generate the expected index files. Here are the relevant lines from the persistence.xml:
<persistence-unit name="puName" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<properties>
...
<property name="hibernate.search.default.directory_provider" value="filesystem"/>
<property name="hibernate.search.default.indexBase" value="/path/to/lucene/indexes"/>
...
</properties>
</persistence-unit>
Ok. Here is better answer. The solution (workaround) for us was to put lucene-analyzers-common-5.3.1.jar and lucene-core-5.3.1.jar directly into domain lib folder. After debugging I have found that class Lucene40PostingsFormat is being loaded by two classloaders and then instantiated from first classloader as a subclass of another (it gives class cast exception). I assume there is one unnecessary loading but I do not know why and how to change it with configuration only.

log4j-jul-2.1 and Glassfish 3.1.2 usage

I am trying to redirect Java Util Logging logs to Log4j 2.1 using the birdge provided log4j-jul-2.1, but stuck with classpath problems. I have all the log4j jars in the domains lib directory and used the following JVM parameter as mentioned in log4j documentation:
-Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager
The problem is that the bridge LogManager provided by log4j is not available in Glassfish AppClassLoader during startup and it causes the exception below. I can fix that by modifying server main classpath (provided by -cp argument), but this is bad. Is there any other/better looking way to achieve that? Simply putting it into server main lib directory does not also work as its again not AppClassLoader.
Could not load Logmanager "org.apache.logging.log4j.jul.LogManager"
java.lang.ClassNotFoundException: org.apache.logging.log4j.jul.LogManager
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.util.logging.LogManager$1.run(LogManager.java:167)
at java.security.AccessController.doPrivileged(Native Method)
at java.util.logging.LogManager.<clinit>(LogManager.java:157)
at java.util.logging.Logger.getLogger(Logger.java:287)
at com.sun.enterprise.glassfish.bootstrap.ASMainHelper.<clinit>(ASMainHelper.java:67)
at com.sun.enterprise.glassfish.bootstrap.ASMain.main(ASMain.java:54)
I finally decided to use SLF4J and its SLF4JBridgeHandler for handling Java Util Logging calls. The main benefit of it is that it can be initialized at some later point when all the classes are loaded and after all required static initializations.
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
I also switched to Logback as a backend as with this solution Log4j encounters performance problems for disable JUL loggers.

Jboss6EAP java.lang.NoSuchMethodError: org.springframework.beans.factory.config.ConfigurableListableBeanFactory.registerResolvableDependency

I am moving a simple web application from Jboss 4.3 to Jboss 6 EAP (Jboss AS 7.2). However, I am unable to deploy the war because of the error
07:43:17,773 ERROR [org.springframework.web.context.ContextLoader] (ServerService Thread Pool -- 63) Context initialization failed: java.lang.NoSuchMethodError: org.springframework.beans.factory.config.ConfigurableListableBeanFactory.registerResolvableDependency(Ljava/lang/Class;Ljava/lang/Object;)V
at org.springframework.context.support.AbstractApplicationContext.prepareBeanFactory(AbstractApplicationContext.java:458) [spring-2.5.5.jar:2.5.5]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:356) [spring-2.5.5.jar:2.5.5]
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255) [spring-2.5.5.jar:2.5.5]
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199) [spring-2.5.5.jar:2.5.5]
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45) [spring-2.5.5.jar:2.5.5]
at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3339) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3777) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
at org.jboss.as.web.deployment.WebDeploymentService.doStart(WebDeploymentService.java:156) [jboss-as-web-7.2.1.Final-redhat-10.jar:7.2.1.Final-redhat-10]
at org.jboss.as.web.deployment.WebDeploymentService.access$000(WebDeploymentService.java:60) [jboss-as-web-7.2.1.Final-redhat-10.jar:7.2.1.Final-redhat-10]
at org.jboss.as.web.deployment.WebDeploymentService$1.run(WebDeploymentService.java:93) [jboss-as-web-7.2.1.Final-redhat-10.jar:7.2.1.Final-redhat-10]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [rt.jar:1.7.0_60]
at java.util.concurrent.FutureTask.run(Unknown Source) [rt.jar:1.7.0_60]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.7.0_60]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.7.0_60]
at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_60]
at org.jboss.threads.JBossThread.run(JBossThread.java:122)
I am not sure what needs to be done. The Spring libraries the war file uses is version 2.5.5 and is bundled within the war 0 within the WEB-INF/lib directory.
Any help in resolving my problem, would be much appreciated. Thanks.
I was able to solve this issue. Would like to share with others, in case they run into the same issue. The war file we were using had Spring libraries and was included within the war file.
The problem was with the versions of the spring.jar and spring-context.jar. The former was 2.0.3 but the latter was version 2.5.5. I downgraded the spring-context.jar to 2.0.3 and it did the trick.
Not sure, why there was no problem in Jboss 4.3. Anyway, I don't have the problem now.
I would like to add that this problem could persist - after clearing out the dependencies (using exclusions), there could still be a wrong version in the Eclipse classpath.
You can figure this out running f.ex. a test with two methods:
in Eclipse
using Maven
mvn clean test -Dtest=com.example.HelloTest
Compare error messages / the stack traces, they might be different, or the Maven test runs fine while in Eclipse the test fails.

Apache HttpClient inside JAR looking for JBoss reference?

I am using the Apache HttpClient libs to handle my communication with an API. All of my code compiles and runs without error when I unit test the exploded code. However, when I JAR my source and test the code in a isolated integration test I get this error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/jboss/logmanager/Logger$AttachmentKey
at org.slf4j.impl.Slf4jLoggerFactory.<clinit>(Slf4jLoggerFactory.java:31)
at org.slf4j.impl.StaticLoggerBinder.getLoggerFactory(StaticLoggerBinder.java:33)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:240)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:208)
at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:155)
at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:131)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:645)
at org.apache.http.impl.client.AbstractHttpClient.<init>(AbstractHttpClient.java:159)
at org.apache.http.impl.client.DefaultHttpClient.<init>(DefaultHttpClient.java:178)
at opart.api.client.trasnsport.Transport.get(Transport.java:81)
at opart.api.client.dao.objects.ObjectsDao.getInterestingObjects(ObjectsDao.java:70)
at opart.api.client.OpartApiClient.getInterestingObjects(OpartApiClient.java:79)
at ApiTest.interesting(ApiTest.java:32)
at ApiTest.main(ApiTest.java:21)
Caused by: java.lang.ClassNotFoundException: org.jboss.logmanager.Logger$AttachmentKey
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
... 14 more
When I try to instantiate a DefaultHttpClient object thusly:
DefaultHttpClient defaultHttpClient = new DefaultHttpClient();
The libs I have included in my JAR are:
guava-r09.jar
commons-logging-1.1.1.jar
httpclient-4.1.2.jar
httpcore-4.1.2.jar
gson-1.7.1.jar
Any ideas as to why it is trying to reference JBoss?
The solution I found was to use the zipfileset ant target which safely explodes the contents of the JARchives inside the root of the uber JAR.

Axis2 generated Client to web service call - Unable to access unsupported property javax.xml.stream.supportDTD

I am getting the following exception when I access the web service from my Axis2 generated stub client.
Can anyone put some light one it?
Thanks.
Caused by: org.apache.axis2.AxisFault: Unable to access unsupported property javax.xml.stream.supportDTD
at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:123)
at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:67)
at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:354)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:417)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at amdocs.cl.utils.CollectionsServiceStub.GetEquipmentInfo(CollectionsServiceStub.java:267)
at amdocs.cl.utils.DDPCollectionConnectorUtils.getEquipmentInfo(DDPCollectionConnectorUtils.java:162)
... 7 more
Caused by: java.lang.IllegalArgumentException: Unable to access unsupported property javax.xml.stream.supportDTD
at weblogic.xml.stax.ConfigurationContextBase.check(ConfigurationContextBase.java:60)
at weblogic.xml.stax.ConfigurationContextBase.setProperty(ConfigurationContextBase.java:54)
at weblogic.xml.stax.XMLStreamInputFactory.setProperty(XMLStreamInputFactory.java:280)
at org.apache.axiom.util.stax.dialect.StAXDialectUtils.disallowDoctypeDecl(StAXDialectUtils.java:40)
at org.apache.axiom.util.stax.dialect.UnknownStAXDialect.disallowDoctypeDecl(UnknownStAXDialect.java:39)
at org.apache.axiom.om.util.StAXParserConfiguration$4.configure(StAXParserConfiguration.java:116)
at org.apache.axiom.om.util.StAXUtils$7.run(StAXUtils.java:520)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.axiom.om.util.StAXUtils.newXMLInputFactory(StAXUtils.java:495)
at org.apache.axiom.om.util.StAXUtils.getXMLInputFactory_perClassLoader(StAXUtils.java:566)
at org.apache.axiom.om.util.StAXUtils.getXMLInputFactory(StAXUtils.java:172)
at org.apache.axiom.om.util.StAXUtils.getXMLInputFactory(StAXUtils.java:137)
at org.apache.axiom.om.util.StAXUtils.createXMLStreamReader(StAXUtils.java:196)
at org.apache.axis2.builder.SOAPBuilder.processDocument(SOAPBuilder.java:64)
at org.apache.axis2.transport.TransportUtils.createDocumentElement(TransportUtils.java:197)
at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:145)
at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:108)
I too had the same issue and finally found that the problem is with incorrect context config.
Axis2 configuration context is being created with weblogic.jar file instead of axis2 jar, so change the build class path order. First point all the axis2 jars and atlast point the weblogic.jar in class path.
I resolved this by adding jax-rt jar in my classPath.
Or Add below dependency in your pom
<depepdency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.2.10</version>
</dependency>