Nav*_*lam 5 java eclipse jboss web-services
我正在使用jboss 4.2服务器处理Eclipse上的Web服务示例。我创建了一个服务实现类,如下所示:
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;
}
}
Run Code Online (Sandbox Code Playgroud)
Web服务自动部署到服务器中,我可以在以下位置看到我的服务
http://127.0.0.1:8080/jbossws/services/
Run Code Online (Sandbox Code Playgroud)
我创建了另一个项目,并使用了wsconsume实用程序来生成客户端类文件。然后,我将服务类实例化如下:
public class Client {
public static void main(String[] args) {
CarWebServiceImplService service = new CarWebServiceImplService();
CarWebServiceImpl port = service.getCarWebServiceImplPort();
port.getCarPrice("audi");
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试运行客户端代码时,出现以下错误
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)
Run Code Online (Sandbox Code Playgroud)
我不知道我的方法有什么问题。请帮忙。提前致谢。
事实证明,JBoss 认可的文件夹中缺少一些 jar。
jbossws-jaxws.jar
jbossws-jaxws-ext.jar
jbossws-jaxrpc.jar
jbossws-saaj.jar
Run Code Online (Sandbox Code Playgroud)
我将这些 jar 从 /client 移动到 /lib/endorsed 并重新启动服务器,代码工作正常。
归档时间: |
|
查看次数: |
6662 次 |
最近记录: |