我正在使用 cfx 2.5.1 和 guice 2.0。
我有这个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
}
}
}
最后是tomcat的web.xml
<?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/但我得到了相同的结果