联系webservice与cxf和guice时出错500

时间:2012-05-12 09:28:57

标签: cxf guice apache-camel

我正在使用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/,但我的结果相同

1 个答案:

答案 0 :(得分:0)

您是否尝试过IP替换localhost? 我们遇到了同样的问题,这解决了这个问题。