I am working on a Web Service example on eclipse using the jboss 4.2 server. I have Created a service implementation class as below:
import java.util.HashMap;
import java.util.Map;
import javax.jws.WebMethod;
import javax.jws.WebService;
@WebService
public class CarWebServiceImpl {
private final Map<String, Integer> prices = new HashMap<String, Integer>();
public CarWebServiceImpl() {
prices.put("audi", Integer.valueOf(10000));
prices.put("bmw", Integer.valueOf(150000));
prices.put("fiat", Integer.valueOf(5000));
}
@WebMethod
public Response getCarPrice(String carId) {
int price = prices.get(carId);
Response resp = new Response();
resp.setPrice(price);
return resp;
}
}
The Web Service is automatically deployed into the server and i can see my service at
http://127.0.0.1:8080/jbossws/services/
I have created another project and have use the wsconsume utility to generate the client side class file. Then I instantiated the service class as follow:
public class Client {
public static void main(String[] args) {
CarWebServiceImplService service = new CarWebServiceImplService();
CarWebServiceImpl port = service.getCarWebServiceImplPort();
port.getCarPrice("audi");
}
}
But when i am trying to run client code I am getting the following error
Exception in thread "main" javax.xml.ws.WebServiceException: No Content-type in the header!
at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:172)
at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:83)
at com.sun.xml.internal.ws.transport.DeferredTransportPipe.processRequest(DeferredTransportPipe.java:105)
at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:587)
at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:546)
at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:531)
at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:428)
at com.sun.xml.internal.ws.client.Stub.process(Stub.java:211)
at com.sun.xml.internal.ws.client.sei.SEIStub.doProcess(SEIStub.java:124)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:98)
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:107)
at $Proxy25.getCarPrice(Unknown Source)
at wsclient.Client.main(Client.java:7)
I don't know what is wrong with my approach. Please help. Thanks in advance.
It turned out that a few of the jar were missing in the JBoss's endorsed folder.
jbossws-jaxws.jar
jbossws-jaxws-ext.jar
jbossws-jaxrpc.jar
jbossws-saaj.jar
I moved these jars to /lib/endorsed from /client and restarted the server and the code worked without flaw.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With