1
我使用的是cfx 2.5.1和guice 2.0。錯誤500當與cxf和guice聯繫webservice時
我有這個接口爲WS
@WebService(targetNamespace="http://com.example.firstapp/")
public interface IWSEchoService {
@WebMethod(operationName="echoService")
String echoService(@WebParam(name="id") String id,@WebParam(name="payload") String payload) throws SOAPFault;
@WebMethod(operationName="testAttachment")
DataHandler testAttachment(DataHandler attachment) throws SOAPFault;
}
和實現
@WebService(targetNamespace = "http://com.example.firstapp/")
public class WSEchoServiceImpl implements IWSEchoService {
protected Log logger = LogFactory.getLog(this.getClass());
@WebMethod(operationName = "echoService")
public String echoService(String id, String payload) throws SOAPFault {
return id + "|" + payload;
}
@WebMethod(operationName = "testAttachment")
public DataHandler testAttachment(DataHandler attachment) throws SOAPFault {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
FileUtil.copyInputStream(attachment.getInputStream(), baos);
logger.debug(baos.toString());
} catch (IOException ex) {
logger.error(ex);
}
logger.info("Attachment ok! Size: " + baos.size());
return attachment;
}
}
我也有
public class ContextStartup implements ServletContextListener {
private Log logger = LogFactory.getLog(ContextStartup.class);
private CamelContext camelContext;
public void contextInitialized(ServletContextEvent sce) {
try {
camelContext = new GuiceCamelContext(Guice.createInjector(Stage.DEVELOPMENT, new MyModule()));
camelContext.start();
startWS();
} catch (Exception ex) {
logger.error(ex);
}
}
.....
private void startWS() {
String address = "http://localhost:8191/ws/echoService";
Endpoint.publish(address, new WSEchoServiceImpl());
}
private class MyModule extends CamelModuleWithMatchingRoutes {
@Override
protected void configure() {
super.configure();
// bind camel component
}
}
}
最後web.xml中爲Tomcat現在
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<listener>
<description>Start and destroy CamelContext</description>
<listener-class>com.example.firstapp.ContextStartup</listener-class>
</listener>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
當我的瀏覽器我叫
http://localhost:8191/ws/echoService?wsdl
或
http://localhost:8191/ws/echoService
我有一個HTTP 500錯誤,但在控制檯或在Tomcat登錄我還沒有我也用這個指南http://jax-ws-commons.java.net/guice/任何異常或錯誤
,但我有同樣的結果
也許有人有什麼建議嗎? – user1332226
打開tomcat /您的應用程序中的跟蹤日誌記錄。 –