Web service in servlet - #WebServiceRef annotation gives 500 error. - java

After playing around with example SOAP application Calculator from NetBeans, I began making my own app, using some third-party WSDL's as service models.
I managed to successfully create a web service classes from this WSDL, unfortunately, when I try to inject this service into my servlet (called ClientServlet), I got 500 error
"javax.servlet.ServletException: Error instantiating servlet class clients.ClientServlet".
The service interface methods are defined in Interface class MyServiceInterface. Don't ask me why it is that way - this service is made by third party.
When I comment out this annotation, and subsequent field declaration, then it works (but I can't use this service).
My code snippet:
#WebServiceRef(wsdlLocation="url/to/wsdl/of/my/service.wsdl")
public MyServiceInterface service;
Of course, I tried to do this without dependency injection, by direct creation of the instance of this class:
service1 = new MyService().getMyService();
MyService.java was created during importing a service from WSDL. GetMyService() method should return instance of the class that is implementing MyServiceInterface. But instead, Java throws me
exception at javax.xml.ws.Service.getPort(Service.java:92)
I am using Apache Tomcat 7.0 and Netbeans 7.0 IDE. What I should do now?

SOLVED - I just made it from scratch using GlassFish 3.1 server.

Related

How to call a JAX-WS web service with mandatory transaction from Java SE?

There is an EJB stateless bean representing a JAX-WS web service that has the following annotation:
#Transactional(value = Transactional.TransactionFlowType.MANDATORY, version = Transactional.Version.DEFAULT)
I need to invoke this web service from a Java SE app (actually, from an executable jar, not sure if it changes things). I've generated required classes using wsimport but get the following error when calling web service:
Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: transaction context is required to be inflowed
at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:178)
at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:117)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:108)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78)
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:135)
From what I understand, client must be in a transaction when calling web service. I've tried searching online for a solution but to no avail. What are the ways to accomplish this task?

Axis2 1.4 Client Side Concurrency Issue (Re-Using Stub)

I've been assigned a piece of work to investigate and propose a fix for an intermittent and (apparently) non-replicable bug which is causing web service calls to fail with the following error:
Message does not conform to configured policy [ TimestampPolicy(S) AuthenticationTokenPolicy(S) ]: No Security Header found
The application is the Spring based back end for an online public facing high traffic web site. The web services are accessed with a Axis2 1.4 client.
I think I've managed to track the issue down to a possible concurrency issue, but it doesn't seem to be tied to load exactly, the failure statistics don't support it (sometimes days with low load are worse than days with high load).
Anyway, all of client code for the web services is contained within a single class with a #Repository annotation. Classes in the wider application that need access to this WebServiceClient class have it declared at class scope with #Resource annotation where it is autowired in as required.
The problem as I see it is that in the WebServiceClient the stubs are declared at class scope like so:
private ValidationStub validationStub;
private CustInfoStub custInfoStub;
and are initialised in method scope when the web service is called
this.validationStub= new ValidationStub (this.url);
prepareStub(this.validationPort, username, password);
where the prepareStub method creates the security header and adds it as follows:
stub._getServiceClient().addHeader(element);
I think if I move the stubs from class scope to method scope it will solve the issue, like so:
ValidationStub validationStub = new ValidationStub(this.url);
Has anyone ran into a similar issue? I'm a bit concerned that making this change will have a performance impact.

Same Package, Same Class in two Maven Projects a WAR and a JAR, classpath issue

I am having some classpath issue. I have a Web Application which is a web service. It uses JaxB and CXF. The web service has a dependecy of another JAR which is a Web Service Client. Now both the client and the service codes are generated by using wsdl2java plugin. The problem looks like this:
Parent WebService WAR
--PackageA
--ClassB
Dependency Jar
--PackageA
--ClassB
So both of them have the same package and the same class name and since these are generated by the plugin, it makes difficult to refactor one of the package so that they would not be identical.
The WebService calls the client and in client code initializes the parent classB from web service instead of the classB from web service client Jar. The only problem in this ClassB is that they have one method which takes differnet parameter, in one class B it takes, Date whereas in another classB it takes XmlGregorianCalendar. So while calling the client i am getting nosuchmethodexception.
Here is what i tried so far without luck:
1: In the Client jar i tried giving the full package and class name to initialize the ClassB
2: In the Client jar i tried wiring the classes using Spring bean and surprisingly it is still wiring the class from the webService instead of the client
3: In the web service ClassB, i tried adding the same method that takes the right parameter. This works partially but result in another exception which is not good.
Looking forward for your help. Thanks!
Solved the issue by passing extra args to wsdl2java plugin while generating classes from the wsdl as per user2880879 suggestion like this:
<extraarg>-p</extraarg>
<extraarg>http://www.example.com=mypackagename</extraarg>
I believe you are creating webservice using top down approach, means write java class first using jaxws annotations and then create wsdl using cxf maven plugin or ant, and use this wsdl to create client ?
If you are following this approach then you can provide binding file when you generate web service client code. click here to know what is binding file and how to write.
In this binding file you can specify package name you want to change for client code.

Generate Wsdl/Client Stubs For Web Service

I have been doing some reading up on web services programming with Java, Eclipse, etc. and I found one particular example where the person created the web service and client by doing the following:
define the web service java class (interface + impl)
deploy the web service using Endpoint.publish
grab the wsdl from the url of the web service (eg, localhost://greeting?wsdl)
use wsimport to generate stubs
create a client class using generated stubs
Is there another way to generate the wsdl without having to publish the web service and download it? Perhaps a maven plugin to auto-generate wsdl and client stubs?
Update: Rather than creating a new question I am just going to piggyback on this one.
I have created my web service by defining an interface:
#WebService
public interface HelloWorldWs {
#WebMethod
public String sayHello(String name);
}
and an impl class:
#WebService(endpointInterface = "com.me.helloworldws.HelloWorldWs")
public class HelloWorldWsImpl implements HelloWorldWs {
#Override
#WebMethod
public String sayHello(String name) {
return "Hello World Ws, " + name;
}
}
When I run wsgen I get the following error:
The #javax.jws.WebMethod annotation cannot be used in with #javax.jws.WebService.endpointInterface element.
Eclipse seems to be okay with it.
Any idea why?
Note, I originally did not have the annotation but when I tried to call my webservice I got the following error:
com.me.helloworldws.HelloWorldWsImpl is not an interface
The JSR 224 says in 3.1 section:
An SEI is a Java interface that meets all of the following criteria:
Any of its methods MAY carry a javax.jws.WebMethod annotation (see 7.11.2).
javax.jws.WebMethod if used, MUST NOT have the exclude element set to true.
If the implementation class include the javax.jws.WebMethod, then you cant put #WebMethod(exclude=true) and that in not possible, according to specification.
Depends of custom version of Eclipse, shows a warning for this. e.g. Rational Application Developer for Websphere shows:
JSR-181, 3.1: WebMethod cannot be used with the endpointInterface
property of WebService
While programming/building a project (with some advanced IDE) normally you should be able to find it between auto-generated stuff - the IDE should generate it. Just check carefully.

How are you supposed to access EJB when using Easyrest?

I have been trying to get Resteasy to work (and not it dose). However I now have another headache with accessing the EJB:s. I have tried injecting them, looking them up with jndi and most other solutions but none of them works.
I get massages like: java.lang.RuntimeException: Class is not a root resource.
Or: java.lang.IllegalArgumentException: Wrong target.
Or just: NullPointer
Using JBoss 5.1.0.GA and Resteasy 1.2.1.GA... Can't find any documentation on how this could be done. Do anybody know?
Have you seen this: EJB Integration?
Resteasy currently only has simple integration with EJBs. To make an EJB a JAX-RS resource, you must annotate an SLSB's #Remote or #Local interface with JAX-RS annotations:
Next, in RESTeasy's web.xml file you must manually register the EJB with RESTeasy using the resteasy.jndi.resources

Categories