EJB 2.1 Web服务端点@WebContext

时间:2017-06-09 13:41:18

标签: java web-services soap ejb ejb-2.x

我有一个定义事件操作的WSDL文件。

需要定义 SOAP Web服务端点,该端点由第三方调用,其中包含WSDL文件中指定的一些参数。

该项目使用 EJB 2.1

无法使终点工作(404错误):

http://localhost:28080/myapp/ws/ClassCallBack

以下类位于EAR文件根文件夹中包含的JAR文件中。

有什么不对吗? 我是否必须在某些xml中将此类声明为EJB? (在ejb-jar.xml中,声明了所有EJB会话Bean,但这不是会话bean)

@WebService
public interface ClassCallBackWs {

@WebMethod
  public void event(@WebParam(name = "event") ClassParameter event) 
      throws Exception;      
}

=====================================

@Stateless(name = "ClassCallBackEjb")
@SOAPBinding(style = SOAPBinding.Style.RPC)
@WebService(name = "ClassCallBackWs", portName = "ClassCallBackWs",
        serviceName = "ClassCallBackWsService",
        targetNamespace = "http://test.serverurl.org.com/",
        endpointInterface = "ClassCallBackWs")
@WebContext(contextRoot = "/myapp/ws/", 
            urlPattern = "/v0/ClassCallBackWsImpl", 
            transportGuarantee = "NONE", secureWSDLAccess = false)
public class ClassCallBackWsImpl implements ClassCallBackWs {

    @WebMethod
    public void event(@WebParam(name = "event") ClassParameter event) throws Exception {
    }

}

1 个答案:

答案 0 :(得分:0)

下面给出一个可能解决方案的示例。 创建了一个自定义servlet,它通过在XML中定义JAX WS端点来实现到实现类的映射

(隐瞒了与最终解决方案相关的所有名称,如同私人所有。如果由于此而出现错误,请抱歉。)

Servlet映射/ XML:

<servlet-mapping>
    <servlet-name>testws</servlet-name>
    <url-pattern>/myapp/ws/v0/</url-pattern>
</servlet-mapping>

用作端点的servlet的XML配置:

    <jaxws:endpoint
        id="CallBackWs" implementor="org.test.ClassCallBackWsImpl "
        wsdlLocation="WEB-INF/wsdl/CallBackTest.wsdl"
        address="/ClassCallBackWsImpl"
        bindingUri="ClassCallBackWsImpl">
    </jaxws:endpoint>

终点Impl类:

   @WebService(
      portName = "CallBackWs",
      serviceName = "CallBackWsService", 
      targetNamespace = "http://test.server.callback.ws/", 
      endpointInterface = "org.test.CallBackWs") 
   public class ClassCallBackWsImpl implements ClassCallBackWs{    
       public void event(ClassParameter event) throws Exception { 
       } 
   }

接口类:

@WebService(targetNamespace = "http://test.server.callback.ws/", name = "ClassCallBackWs")
public interface Ws {
    @RequestWrapper(localName = "event", targetNamespace = "http://test.server.callback.ws/", className = "org.test.ClassParameter")
    @WebMethod
    public void event(
        @WebParam(name = "event", targetNamespace = "")
        org.test.ClassParameter event
    ) throws Exception;
}