I know there are lots of question about that, but the problem is that, I searched and googled everything around it, but nothing found that could help me.
I try to implement SOAP based web service client using Apache CXF/Wildfly 8x/Java 1.7/Maven 3+/Eclipse.
I generate proxy classes successfully, implemented ws-security options, add keystore and trustore, but found a very strange problem.
[io.undertow.request] (default task-18) UT005023: Exception handling request to /service/DummyServiceCaller: java.lang.NoClassDefFoundError: org/apache/cxf/frontend/ClientProxy
at com.ddrc.service.Service.core.config.ServiceManager.beforeExecute(ServiceManager.java:17) [:]
at com.ddrc.service.service.core.ServiceManager.executeService(ServiceServiceManager.java:36) [:]
at com.ddrc.service.DummyServiceCaller.doGet(DummyServiceCaller.java:37) [:]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:687) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final]
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:63) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.jrHandle(ServletInitialHandler.java) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at org.zeroturnaround.javarebel.integration.servlet.undertow.cbp.ServletInitialHandlerCBP.handleRequest(ServletInitialHandlerCBP.java:100) [undertow-servlet-jr-plugin-6.2.7.jar:]
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:261) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:247) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:76) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:166) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:197) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:759) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [jrebel-bootstrap-39173be574c0f43be80eb922241c6711.jar:1.7.0_75]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [jrebel-bootstrap-39173be574c0f43be80eb922241c6711.jar:1.7.0_75]
at java.lang.Thread.run(Thread.java:745) [jrebel-bootstrap-39173be574c0f43be80eb922241c6711.jar:1.7.0_75]
As i read about that exception, it means that,
This is caused when there is a class file that your code depends on and it is present at compile time but not found at runtime. Look for differences in your build time and runtime classpaths.
Source stackoverflow explanation
- Of course, I cleaned and rebuild project, restart eclipse but no reaction.
- Then I made a simple small project and copied the code there, still same problem.
- Then I searched the class in maven repos, found it, opened jar and found the class too.
- Then I created runnable jar and copied in my mates PC, checked there and same problem.
- Searched a lot but nothing special found.
- The only interesting article I found was here CXF but could not understand.
ClientProxy.getClient(proxy) is no longer needed for most use cases. The client proxy instances now implement the Client API directly. A direct cast to Client should work.
I do not even know how to start fixing this, how to debug this. Here is the code I wrote.
private void adjustServiceConfiguration(Object port, String address) throws IOException {
org.apache.cxf.endpoint.Client client = ClientProxy.getClient(port);
HTTPConduit http = (HTTPConduit) client.getConduit();
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setConnectionTimeout(/* uccConnectionTimeout.value() */6 * 1000);
httpClientPolicy.setReceiveTimeout(/* uccTimeout.value() */7 * 1000);
http.setClient(httpClientPolicy);
((BindingProvider) port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, address);
((BindingProvider) port).getRequestContext().put("set-jaxb-validation-event-handler", "false");
Map<String, Object> outProps = new HashMap<>();
outProps.put(WSHandlerConstants.ACTION, "Timestamp Signature Encrypt");//
outProps.put(WSHandlerConstants.PASSWORD_TYPE, "PasswordDigest");
outProps.put(WSHandlerConstants.USER, "ucc-agent");
outProps.put(WSHandlerConstants.SIGNATURE_USER, "ucc-agent");
outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, "com.ddrc.service.service.ws.KeyStorePasswordsCallback");
outProps.put(WSHandlerConstants.ENCRYPTION_USER, "ucc");
if (encryptionProps == null || signProps == null) {
try {
encryptionProps = new Properties();
signProps = new Properties();
try (FileInputStream fis1 = new FileInputStream(
uccEncryptionPropFile);
FileInputStream fis2 = new FileInputStream(
uccSignaturePropFile);) {
encryptionProps.load(fis1);
signProps.load(fis2);
}
} catch (IOException ex) {
throw ex;
// log.error("Error occurred during UCC WS-Security configuration file lookup",
// ex);
}
}
outProps.put("encryptionProps", encryptionProps);
outProps.put("signProps", signProps);
outProps.put(WSHandlerConstants.ENC_PROP_REF_ID, "encryptionProps");
outProps.put(WSHandlerConstants.SIG_PROP_REF_ID, "signProps");
Map<String, Object> inProps = new HashMap<>();
inProps.put(WSHandlerConstants.ACTION, "Timestamp Signature Encrypt");
inProps.put(WSHandlerConstants.PASSWORD_TYPE, "PasswordText");
inProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, "com.ddrc.service.service.ws.KeyStorePasswordsCallback");
inProps.put(WSHandlerConstants.ALLOW_RSA15_KEY_TRANSPORT_ALGORITHM, "true");
inProps.put("signProps", signProps);
inProps.put("encryptionProps", encryptionProps);
inProps.put(WSHandlerConstants.DEC_PROP_REF_ID, "signProps");
inProps.put(WSHandlerConstants.SIG_PROP_REF_ID, "encryptionProps");
client.getInInterceptors().add(new WSS4JInInterceptor(inProps));
client.getOutInterceptors().add(new WSS4JOutInterceptor(outProps));
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());
}
The problem is in ClientProxy
class
Here is an error from small project.
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/cxf/common/i18n/UncheckedException
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at ge.test.Run.main(Run.java:16)
Caused by: java.lang.ClassNotFoundException: org.apache.cxf.common.i18n.UncheckedException
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 13 more
and the whole class :)
package ge.test;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
public class Run {
public static void main(String[] args) {
Client c = ClientProxy.getClient(null);
}
}