Java – web client for Web Services

When I access it from a J2SE (desktop) application, I have a working web service To access this service, I will follow:

>Use the Java wsimport tool to generate a stub class through a WSDL link > then I use the generated class to create a service and run one of the WSDL operations It looks like this:

MyWebServiceService webService = new MyWebServiceService();

MyWebService port = webService. getMyWebServicePort();

webService. run( “XYZ”);

I'm sorry that it works well when I use it in a stand - alone application But... When I try to access the web service in the same way but access it from servlet client, using the generated stub, I get the following error:

java.lang.ClassCastException: com.sun.xml.bind.v2.runtime.JAXBContextImpl cannot be cast to com.sun.xml.bind.api.JAXBRIContext
org.jboss.ws.Metadata.umdm.EndpointMetaData.eagerInitializeAccessors(EndpointMetaData.java:686)
org.jboss.ws.Metadata.umdm.EndpointMetaData.initializeInternal(EndpointMetaData.java:567)
org.jboss.ws.Metadata.umdm.EndpointMetaData.eagerInitialize(EndpointMetaData.java:553)
org.jboss.ws.Metadata.builder.jaxws.JAXWSClientMetaDataBuilder.rebuildEndpointMetaData(JAXWSClientMetaDataBuilder.java:314)
org.jboss.ws.core.jaxws.spi.ServiceDelegateImpl.getPortInternal(ServiceDelegateImpl.java:271)
org.jboss.ws.core.jaxws.spi.ServiceDelegateImpl.getPort(ServiceDelegateImpl.java:202)
javax.xml.ws.Service.getPort(Service.java:143...

I searched Google for a long time, but I didn't find any useful topics Some topics show examples of accessing web services from servlets, but unfortunately I can't do this... (and I don't know why

Application server: JBoss 4.2 3GA

Can I connect to a web service from a servlet? What about?

I have tried to use @ webserviceref annotation, but it seems that the web container cannot inject web service stubs I don't think the container itself can do this because the stub classes have been generated by the wsimport tool and it uses these classes to access Web services

Generate the stub class using the following command:

wsimport -keep -p com.myhost.ws http://www.myhost.com/services/MyWebService?wsdl

Solution

Are you sure your classpath does not contain multiple jax-b jars with different versions? The exception looks like a version conflict Application servers typically have some sort of "approved" lib directory that contains jars that are always added before the web application classpath Maybe your application server has a conflicting jax-b implementation there?

If you use Maven to package your application, make sure that passing dependencies does not introduce unwanted jax-b jars (use 'MVN dependency: tree' to check this)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>