Error java.lang.NoClassDefFoundError: javax/jws/WebService in Java 11 - java

In my cxf webservice invocation while I set the JaxWsProxyFactoryBean service class, I get a fatal error whose trace I have given below. I am migrating my code from java 8 to java 11.
I have set all the required library jars,cxf bundle and jax-ws jars at my build path but still I am unable to resolve the error.
Here is my code:
APIWS _stub = null;
JaxWsProxyFactoryBean fac = new JaxWsProxyFactoryBean();
fac.setAddress(API_WS_URL);
fac.setServiceClass(APIWS.class);
_stub = (APIWS) fac.create();
Client c = ClientProxy.getClient(_stub);
HTTPConduit http = (HTTPConduit)c.getConduit();
HTTPClientPolicy policy = new HTTPClientPolicy();
policy.setConnectionTimeout(0);
policy.setReceiveTimeout(0);
http.setClient(policy);
c.getInInterceptors().add(new LoggingInInterceptor());
c.getInInterceptors().add(new LoggingOutInterceptor());
ApiWS.aboutCall(_stub);
List<String> output = ApiWS.invokeLiqApiWebService(_stub, transformedQueue);
outputFileList.addAll(output);
Error:
java.lang.NoClassDefFoundError: javax/jws/WebService
at org.apache.cxf.jaxws.support.JaxWsImplementorInfo.initialize(JaxWsImplementorInfo.java:273)
at org.apache.cxf.jaxws.support.JaxWsImplementorInfo.<init>(JaxWsImplementorInfo.java:60)
at org.apache.cxf.jaxws.JaxWsClientFactoryBean.setServiceClass(JaxWsClientFactoryBean.java:43)
at org.apache.cxf.frontend.ClientProxyFactoryBean.setServiceClass(ClientProxyFactoryBean.java:224)
at com.qnb.ib.loaniq.inbound.interfaces.process.LIQProcess.callLiqAPI(LIQProcess.java:331)
at com.qnb.ib.loaniq.inbound.interfaces.process.LIQProcess.process(LIQProcess.java:154)
at com.qnb.ib.loaniq.inbound.interfaces.process.LIQJobManager.processJob(LIQJobManager.java:106)
at com.qnb.ib.loaniq.inbound.interfaces.process.LIQJobManager.main(LIQJobManager.java:132)
Caused by: java.lang.ClassNotFoundException: javax.jws.WebService
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 8 more
Need help resolving this issue.
Thanks

These are the jars I have added in my build path to resolve the issue with calling the Web Services.
FastInfoset-1.2.15.jar
gmbal-api-only-3.1.0-b001.jar
-ha-api-3.1.9.jar
istack-commons-runtime-3.0.7.jar
javax.activation-1.2.0.jar
javax.activation-api-1.2.0.jar
javax.annotation-api-1.3.2.jar
javax.jws-api-1.1.jar
javax.xml.soap-api-1.4.0.jar
jaxb-api-2.3.1.jar
jaxb-runtime-2.3.1.jar
jaxws-api-2.3.1.jar
jaxws-ri-2.3.1.pom
jaxws-rt-2.3.1.jar
management-api-3.0.0-b012.jar
mimepull-1.9.10.jar
policy-2.7.5.jar
saaj-impl-1.5.0.jar stax2-api-4.1.jar
stax-ex-1.8.jar
streambuffer-1.5.6.jar
-txw2-2.3.1.jar
woodstox-core-5.1.0.jar
Hope this helps those who are facing similar issue in java 11

Related

Problem with creating Rest API with embedded jetty11 and jersey 3 [duplicate]

This question already has answers here:
Jersey stopped working with InjectionManagerFactory not found
(7 answers)
Closed 12 months ago.
I am having troubles trying to hook up jersey3 with jetty11 embedded server.
My code is
ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
servletContextHandler.setContextPath("/");
ResourceConfig resourceCfg = new ResourceConfig();
resourceCfg.packages(TestResource.class.getPackage().getName());
ServletContainer servletContainer = new ServletContainer(resourceCfg);
ServletHolder servletHolder = new ServletHolder(servletContainer);
servletContextHandler.addServlet(servletHolder, "/api/*");
this.setHandler(servletContextHandler);
This code exactly throws an error
Exception in thread "main" jakarta.servlet.ServletException: org.glassfish.jersey.servlet.ServletContainer-22356acd==org.glassfish.jersey.servlet.ServletContainer#d1f8ecbc{jsp=null,order=-1,inst=true,async=true,src=EMBEDDED:null,STARTED}
at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:651)
at org.eclipse.jetty.servlet.ServletHolder.initialize(ServletHolder.java:415)
at org.eclipse.jetty.servlet.ServletHandler.lambda$initialize$2(ServletHandler.java:690)
at java.base/java.util.stream.SortedOps$SizedRefSortingSink.end(SortedOps.java:357)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:510)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at java.base/java.util.stream.StreamSpliterators$WrappingSpliterator.forEachRemaining(StreamSpliterators.java:310)
at java.base/java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:735)
at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:762)
at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:714)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:392)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:896)
at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:306)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:93)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:171)
at org.eclipse.jetty.server.Server.start(Server.java:469)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:89)
at org.eclipse.jetty.server.Server.doStart(Server.java:414)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:93)
at org.projectsanatan.restsanatan.RestSanatan.start(RestSanatan.java:27)
at org.projectsanatan.restsanatan.Main.main(Main.java:21)
Caused by: java.lang.IllegalStateException: InjectionManagerFactory not found.
at org.glassfish.jersey.internal.inject.Injections.lambda$lookupInjectionManagerFactory$0(Injections.java:74)
at java.base/java.util.Optional.orElseThrow(Optional.java:403)
at org.glassfish.jersey.internal.inject.Injections.lookupInjectionManagerFactory(Injections.java:74)
at org.glassfish.jersey.internal.inject.Injections.createInjectionManager(Injections.java:69)
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:261)
at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:311)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:154)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:339)
at jakarta.servlet.GenericServlet.init(GenericServlet.java:178)
at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:633)
... 21 more
However, adding this.setHandler(new HandlerList()), doesn't cause that error. I think this is because .setHandler method overwrites the other handlers. I still do not know what could be the reason that causes the error. Help would be appreciated!
You don't have all of the dependencies you need to run Jersey 3.
You seem to be missing the org.glassfish.jersey.internal.inject.InjectionManagerFactory class.
Found in the following maven coordinates...
https://search.maven.org/search?q=fc:org.glassfish.jersey.internal.inject.InjectionManagerFactory
See past answers for help identifying which artifact fits your needs...
Jersey stopped working with InjectionManagerFactory not found
HTTP Status 500 - Servlet.init()
BTW, you can get the Servlet to init on startup, so you don't need to send a request to trigger this setup issue.
ServletHolder servletHolder = new ServletHolder(servletContainer);
servletHolder.setInitOrder(1); // <-- this line
servletContextHandler.addServlet(servletHolder, "/api/*");

HttpClientBuilder issue : Could not initialize class sun.security.ssl.SSLContextImpl$CustomizedTLSContext

In my java code below, I randomly receive the following error.
final HttpClient client = HttpClientBuilder.create().build();
final HttpGet request = new HttpGet(requestParameters);
final HttpResponse response = client.execute(request);
Error:
java.lang.NoClassDefFoundError: Could not initialize class sun.security.ssl.SSLContextImpl$CustomizedTLSContext
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:291)
at java.base/java.security.Provider$Service.getImplClass(Provider.java:1848)
at java.base/java.security.Provider$Service.newInstance(Provider.java:1824)
at java.base/sun.security.jca.GetInstance.getInstance(GetInstance.java:236)
at java.base/sun.security.jca.GetInstance.getInstance(GetInstance.java:164)
at java.base/javax.net.ssl.SSLContext.getInstance(SSLContext.java:168)
at org.apache.http.ssl.SSLContexts.createDefault(SSLContexts.java:51)
at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:977)
I can't reproduce the issue as it is random. Does that mean that the ssl/tls handshake has failed?
would Implementing a retry policy help remediate this issue ?
public DefaultHttpRequestRetryHandler() {
this(3, false);
}
https://jar-download.com/artifacts/org.apache.httpcomponents/httpclient/4.5.2/source-code/org/apache/http/impl/client/DefaultHttpRequestRetryHandler.java
Below are the java libraries I am using :
UPDATE: While I thought I would get rid of this issue by moving from the HttpClientBuilder to the java.net.HttpUrlConnection, unfortunately, I am getting the same error :
java.lang.NoClassDefFoundError: Could not initialize class sun.security.ssl.SSLContextImpl$DefaultSSLContext
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:291)
at java.base/java.security.Provider$Service.getImplClass(Provider.java:1848)
at java.base/java.security.Provider$Service.newInstance(Provider.java:1824)
at java.base/sun.security.jca.GetInstance.getInstance(GetInstance.java:236)
at java.base/sun.security.jca.GetInstance.getInstance(GetInstance.java:164)
at java.base/javax.net.ssl.SSLContext.getInstance(SSLContext.java:168)
at java.base/javax.net.ssl.SSLContext.getDefault(SSLContext.java:99)
at java.base/javax.net.ssl.SSLSocketFactory.getDefault(SSLSocketFactory.java:123)
at java.base/javax.net.ssl.HttpsURLConnection.getDefaultSSLSocketFactory(HttpsURLConnection.java:335)
at java.base/javax.net.ssl.HttpsURLConnection.<init>(HttpsURLConnection.java:292)
at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.<init>(HttpsURLConnectionImpl.java:95)
at java.base/sun.net.www.protocol.https.Handler.openConnection(Handler.java:62)
at java.base/sun.net.www.protocol.https.Handler.openConnection(Handler.java:57)
at java.base/java.net.URL.openConnection(URL.java:1051)
My Java version was 1.8.0_171. By upgrading to 1.8.0_261, same problem was solved.

Play framework : UnexpectedException: While applying class play.classloading.enhancers.LVEnhancer

I am using for the first time Play framework, on Ubuntu 14, with an existing project. When I try to run the application, I get the following error:
Internal Server Error (500) for request GET /
Oops: UnexpectedException
Unexpected error : While applying play.CorePlugin#44821a96 on models.BookingDTO, caused by exception UnexpectedException: While applying class play.classloading.enhancers.LVEnhancer on models.BookingDTO
play.exceptions.UnexpectedException: While applying play.CorePlugin#44821a96 on models.BookingDTO
at play.plugins.PluginCollection.enhance(PluginCollection.java:582)
at play.classloading.ApplicationClasses$ApplicationClass.enhance(ApplicationClasses.java:242)
at play.classloading.ApplicationClassloader.loadApplicationClass(ApplicationClassloader.java:164)
at play.classloading.ApplicationClassloader.getAllClasses(ApplicationClassloader.java:431)
at play.Play.start(Play.java:527)
at play.Play.detectChanges(Play.java:647)
at play.Invoker$Invocation.init(Invoker.java:205)
at Invocation.HTTP Request(Play!)
Caused by: play.exceptions.UnexpectedException: While applying class play.classloading.enhancers.LVEnhancer on models.BookingDTO
at play.CorePlugin.enhance(CorePlugin.java:314)
at play.plugins.PluginCollection.enhance(PluginCollection.java:577)
... 7 more
Caused by: play.exceptions.UnexpectedException: LVEnhancer: cannot enhance the behavior 'models.BookingDTO.findAllNextBookings(java.lang.String)'
at play.classloading.enhancers.LVEnhancer.enhanceThisClass(LVEnhancer.java:112)
at play.CorePlugin.enhance(CorePlugin.java:309)
... 8 more
Caused by: java.lang.NullPointerException
at bytecodeparser.CodeParser.parse(CodeParser.java:53)
at bytecodeparser.analysis.stack.StackAnalyzer.init(StackAnalyzer.java:91)
What's wrong?
Thank you very much for your answer.
I found the solution : I didn't have the version of javassist that didin't match with the project files.
With the Playframework 1.3, javassist-3.20xxx didn't work. I had to install javassist-3.19xxx

java.lang.ExceptionInInitializerError at activator.ActivatorCli$$anonfun$apply$1.apply$mcI$sp(ActivatorCli.sca la:21)

I am using git bash in windows. I downloaded and unzip the play framework and set the path also, but as soon as I run activator new it gives following error
$ activator new
java.lang.ExceptionInInitializerError
at activator.ActivatorCli$$anonfun$apply$1.apply$mcI$sp(ActivatorCli.sca
la:21)
at activator.ActivatorCli$$anonfun$apply$1.apply(ActivatorCli.scala:19)
at activator.ActivatorCli$$anonfun$apply$1.apply(ActivatorCli.scala:19)
at activator.ActivatorCli$.withContextClassloader(ActivatorCli.scala:179
)
at activator.ActivatorCli$.apply(ActivatorCli.scala:19)
at activator.ActivatorLauncher.run(ActivatorLauncher.scala:28)
at xsbt.boot.Launch$$anonfun$run$1.apply(Launch.scala:109)
at xsbt.boot.Launch$.withContextLoader(Launch.scala:129)
at xsbt.boot.Launch$.run(Launch.scala:109)
at xsbt.boot.Launch$$anonfun$apply$1.apply(Launch.scala:36)
at xsbt.boot.Launch$.launch(Launch.scala:117)
at xsbt.boot.Launch$.apply(Launch.scala:19)
at xsbt.boot.Boot$.runImpl(Boot.scala:44)
at xsbt.boot.Boot$.main(Boot.scala:20)
at xsbt.boot.Boot.main(Boot.scala)
Caused by: java.lang.RuntimeException: BAD URI: file://f:/Play/activator-1.2.10-
minimal
at activator.properties.ActivatorProperties.uriToFilename(ActivatorPrope
rties.java:106)
at activator.properties.ActivatorProperties.ACTIVATOR_HOME_FILENAME(Acti
vatorProperties.java:113)
at activator.properties.ActivatorProperties.ACTIVATOR_TEMPLATE_LOCAL_REP
O(ActivatorProperties.java:179)
at activator.UICacheHelper$.<init>(UICacheHelper.scala:31)
at activator.UICacheHelper$.<clinit>(UICacheHelper.scala)
... 15 more
Caused by: java.lang.IllegalArgumentException: URI has an authority component
at java.io.File.<init>(File.java:397)
at activator.properties.ActivatorProperties.uriToFilename(ActivatorPrope
rties.java:101)
... 19 more
Error during sbt execution: java.lang.ExceptionInInitializerError
can any one help how shall i proceed.
It is pretty much clear if you read your (own) stack trace carefully:
Caused by: java.lang.RuntimeException: BAD URI: file://f:/Play/activator-1.2.10-minimal
You are trying to access a file via an URI which is malformed.
A correct URI would be either file:/f:/Play/activator-1.2.10-minimal or file:///f:/Play/activator-1.2.10-minimal (see also this answer).
Amit... probably he dont know (how to) "play" ....
check this up...
https://github.com/typesafehub/activator/issues/648

No encryption crypto object found exception in Apache CXF

I am trying to build a Java client that communicates with .NET WCF services that use WS-Trust.
My .net STS uses WS2007Http binding and UserNameToken-based authentication, hosted on http endpoint.
var binding = new WS2007HttpBinding();
binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
binding.Security.Mode = SecurityMode.Message;
binding.Security.Message.NegotiateServiceCredential = false;
The setting NegotiateServiceCredential is set to false to suppress using SslContextToken that is unsupported by Apache CXF.
My Java client code is following:
public static void main(String[] args) throws Exception {
SpringBusFactory bf = new SpringBusFactory();
URL busFile = Main.class.getResource("/cxf.xml");
Bus bus = bf.createBus(busFile.toString());
STSClient sts = new STSClient(bus);
sts.setWsdlLocation("http://localhost:19308/MainTenantManager/SecurityTokenService?singlewsdl");
sts.setServiceName("{http://schemas.microsoft.com/ws/2008/06/identity/securitytokenservice}SecurityTokenService");
sts.setEndpointName("{http://schemas.microsoft.com/ws/2008/06/identity/securitytokenservice}WS2007HttpBinding_IWSTrust13Sync");
sts.setSpnego(true);
sts.setSecureConv(true);
sts.setSoap12();
Properties p = new Properties();
p.setProperty("org.apache.ws.security.crypto.merlin.keystore.type", "jks");
p.setProperty("org.apache.ws.security.crypto.merlin.keystore.password", "pass1234!");
p.setProperty("org.apache.ws.security.crypto.merlin.keystore.alias", "localhost!");
p.setProperty("org.apache.ws.security.crypto.merlin.file", "keystore.jks");
org.apache.ws.security.components.crypto.Merlin m = new Merlin(p);
sts.getRequestContext().put(SecurityConstants.ENCRYPT_CRYPTO, m);
sts.getRequestContext().put(SecurityConstants.USERNAME, "admin");
sts.getRequestContext().put(SecurityConstants.PASSWORD, "qwe");
sts.requestSecurityToken("http://localhost:19308/MainTenantManager/Service");
}
The result is an exception:
1437 [main] WARN org.apache.cxf.phase.PhaseInterceptorChain - Interceptor for {http://docs.oasis-open.org/ws-sx/ws-trust/200512/wsdl}SecurityTokenService#{http://docs.oasis-open.org/ws-sx/ws-trust/200512/wsdl}RequestSecurityToken has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: No encryption crypto object found.
at org.apache.cxf.ws.security.wss4j.policyhandlers.SymmetricBindingHandler.doSignBeforeEncrypt(SymmetricBindingHandler.java:395)
at org.apache.cxf.ws.security.wss4j.policyhandlers.SymmetricBindingHandler.handleBinding(SymmetricBindingHandler.java:124)
at org.apache.cxf.ws.security.wss4j.PolicyBasedWSS4JOutInterceptor$PolicyBasedWSS4JOutInterceptorInternal.handleMessage(PolicyBasedWSS4JOutInterceptor.java:162)
at org.apache.cxf.ws.security.wss4j.PolicyBasedWSS4JOutInterceptor$PolicyBasedWSS4JOutInterceptorInternal.handleMessage(PolicyBasedWSS4JOutInterceptor.java:89)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:262)
at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:531)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:464)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:367)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:320)
at org.apache.cxf.ws.security.trust.STSClient.requestSecurityToken(STSClient.java:757)
at org.apache.cxf.ws.security.trust.STSClient.requestSecurityToken(STSClient.java:635)
at org.apache.cxf.ws.security.trust.STSClient.requestSecurityToken(STSClient.java:627)
at org.apache.cxf.ws.security.policy.interceptors.SecureConversationOutInterceptor.issueToken(SecureConversationOutInterceptor.java:159)
at org.apache.cxf.ws.security.policy.interceptors.SecureConversationOutInterceptor.handleMessage(SecureConversationOutInterceptor.java:69)
at org.apache.cxf.ws.security.policy.interceptors.SecureConversationOutInterceptor.handleMessage(SecureConversationOutInterceptor.java:44)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:262)
at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:531)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:464)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:367)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:320)
at org.apache.cxf.ws.security.trust.STSClient.requestSecurityToken(STSClient.java:757)
at org.apache.cxf.ws.security.trust.STSClient.requestSecurityToken(STSClient.java:635)
at org.apache.cxf.ws.security.trust.STSClient.requestSecurityToken(STSClient.java:627)
at com.medius.cxf.client.Main.main(Main.java:55)
Caused by: org.apache.cxf.ws.policy.PolicyException: No encryption crypto object found.
at org.apache.cxf.ws.security.wss4j.policyhandlers.AbstractBindingBuilder.policyNotAsserted(AbstractBindingBuilder.java:307)
at org.apache.cxf.ws.security.wss4j.policyhandlers.AbstractBindingBuilder.setEncryptionUser(AbstractBindingBuilder.java:1590)
at org.apache.cxf.ws.security.wss4j.policyhandlers.AbstractBindingBuilder.getEncryptedKeyBuilder(AbstractBindingBuilder.java:1413)
at org.apache.cxf.ws.security.wss4j.policyhandlers.SymmetricBindingHandler.setupEncryptedKey(SymmetricBindingHandler.java:827)
at org.apache.cxf.ws.security.wss4j.policyhandlers.SymmetricBindingHandler.doSignBeforeEncrypt(SymmetricBindingHandler.java:296)
... 23 more
Which seems to be totally wrong since, the crypto object is set in code. I have tried both configuring the encryption though jaxws:client configuration using .properties file and setting it up in code.
What version of CXF are you using? The style of creating a Properties Object, and instantiating a Merlin Object with it + then using it for ENCRYPT_CRYPTO works with both the latest CXF trunk + 2.7.x-fixes code. If you are using an older version of CXF, perhaps try with a more recent version?
Colm.

Categories