针对单个应用程序的REST和SOAPWeb服务



我们使用Spring构建了一个应用程序,并将其与Tomcat一起部署。我们有一个可工作的REST接口,但是我们的一个客户端只有SOAP客户端。

我的理解是,SOAP web服务和REST web服务不能共存于同一个端口或应用程序。

在尽可能少的开发中,我有哪些选择可以接受SOAP请求。我应该通过rest接口接受soap数据包并解析XML吗?或者我可以设置一个SOAP接口与我的REST接口通信并进行响应吗?

我使用Gradle作为我的构建工具。将解决方案作为单个WAR文件

的一部分会很好

根据我的经验,如果您非常小心JAXB的XML名称空间,可以在同一应用程序中混合SOAP和REST。然而,我不建议这样做,因为更新其中一个意味着危及另一个的稳定性。以下是我的建议。。。

  1. 在渐变中设置多项目构建
  2. 创建三个项目,一个用于业务逻辑、一个用于REST接口和一个用于SOAP接口
  3. 修改REST/SOAP接口以使用通用业务逻辑项目
  4. 作为两个独立的WAR部署

我应该通过rest接口接受soap数据包并解析XML吗?

SOAP是一种协议,而不仅仅是一种格式,因此它可能不适用于大多数(任何?)框架。

或者我可以设置一个SOAP接口与我的REST接口通信并进行响应吗?

您可能会以牺牲性能和/或可维护性为代价。

我们有一个具有类似需求的项目。我们仍然需要支持SOAP,我们正在推进ReST.

两者没有理由会发生冲突。由于您使用的是spring,您甚至可以拥有与响应相同的域对象,并将其整理为XML和JSON作为您的首选。

您要做的是为两者创建不同的URI。例如用于SOAP的someService/**和用于ReST实现的CCD_。您可以有一个服务层来处理共享逻辑(主要是端点上所需的代码,其余的控制器是从服务层获取所需的数据并将其发送到整理)

只需在web.xml文件中添加一些条目,以指示其余路径和端点路径。。。

听起来您的web服务主要是REST(现在是2013年),但您必须在有限的情况下支持soap。我在设计web服务时主要考虑rest,但可能会使用一种单独的机制向服务器指示客户端需要soap支持。如果可能的话,让soap客户端发送一个http请求头,或者使用可能以.soap结尾的修改后的URL。在任何情况下,都没有理由不能在同一个应用程序上支持这两种协议。

您可以按照以下步骤进行操作:

 -Add annotation of both Rest and Soap on class implementation.
 -Creating interface to hold the method annotation for Soap.
 -Put Rest annotation on method in class implementation.
 -Configure "web.xml" file to add "servlet" for Rest implementation you use.  
 -Don't forget to create class extend Application like [ApplicationConfiguration.class].

1-类实现

@javax.jws.WebService(endpointInterface = "com.test.ebpp.autopayment.tess.ejb.GService", targetNamespace = "http://ejb.test.autopayment.ebpp.tess.com/", serviceName = "ApplicationBusinessFacadeService", portName = "ApplicationBusinessFacadePort")
@Path(value = "/ApplicationBusinessFacadeService")
public class ApplicationBusinessFacadePortBindingImpl implements
    ApplicationBusinessFacade {
    @Override
    @POST
    @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
    @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
    public ProcessResponse process(Process request) {
        //type your code 
    }
}

2-服务接口

@WebService(name = "ApplicationBusinessFacade", targetNamespace =   "http://ejb.gateway.ebpp.com/")
@XmlSeeAlso({
com.ebpp.gateway.ejb.ObjectFactory.class,
com.ebpp.ifxmessages.ObjectFactory.class
})
public interface ApplicationBusinessFacade {
@WebMethod
@WebResult(targetNamespace = "")
@RequestWrapper(localName = "process", targetNamespace = "http://ejb.gateway.ebpp.com/", className = "com.ebpp.gateway.ejb.Process")
@ResponseWrapper(localName = "processResponse", targetNamespace = "http://ejb.gateway.ebpp.com/", className = "com.ebpp.gateway.ejb.ProcessResponse")
public ProcessResponse process(
    @WebParam(name = "arg0", targetNamespace = "")
    Process arg0);
 }

3-web.xml

 <servlet>        
        <servlet-name>com.ebpp.core.rs.config.ApplicationConfiguration</servlet-name>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>com.ebpp.core.rs.config.ApplicationConfiguration</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>
 </servlet>

最新更新