我正在使用自顶向下的方法处理Web服务,使用JAX-WS'wsimport从WSDL生成服务类型和接口。这提供了一个端口类型的接口,如下所示,我执行。以编程方式获取JAX-WS WebService实现的Servlet实例?
/**
* This class was generated by the JAX-WS RI.
* JAX-WS RI 2.2.4-b01
* Generated source version: 2.2
*/
@WebService(name = "ExamplePortType", targetNamespace = "http://example.com")
public interface ExamplePortType {
/**
* @param example
* @return java.lang.String
* @throws ExampleException
*/
@WebMethod
@WebResult(name = "exampleResponse", targetNamespace = "http://example.com")
@RequestWrapper(localName = "sendExample", targetNamespace = "http://example.com", className = "com.example.SendExample")
@ResponseWrapper(localName = "sendExampleResponse", targetNamespace = "http://example.com", className = "com.example.SendExampleResponse")
public String sendExample(
@WebParam(name = "example", targetNamespace = "http://example.com")
ExampleRequest example)
throws ExampleException
;
}
好像这个服务添加到您的应用程序服务器的正常方式(在我的情况下,Tomcat),是实现类添加到web.xml的servlet和添加WSServletContextListener作为一个倾听者。非常粗略的看起来,在初始化上下文时,监听器会构造包装实现bean的ServletAdapter,并将它们添加到由WSServlet调用的WSServletDelegate。然后由WSServlet处理对您的实现的请求,并由代理根据您设置的任何URL模式传递给您的bean。
有没有办法做到以上编程?我想要一个接受上述接口的实例并返回给我一个Servlet的实例的方法,如果在ServletContext中注册的话,会将相应的请求路由到包装的实现。喜欢的东西:
Servlet exampleServlet = new ServletAdapter().wrap(new ExamplePortTypeImpl());
的一个要求是,我不能依靠静态配置文件(如web.xml中或阳光jaxws.xml)。 JAX-WS或相关库(即:Axis2等)是否提供这种功能?
道歉,如果有什么不明确;这是我第一次来:)。任何指针赞赏。
当前使用JAX-WS 2.1,Tomcat 7,Servlet 3.0。