1

私は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/も使用しましたが、同じ結果が得られました

4

1 に答える 1

0

localhost を IP に置き換えてみましたか? 同じ問題に直面し、これで問題が解決しました。

于 2016-07-18T15:47:22.890 に答える