For the choice of soap webservice and restful webservice, the first thing to understand is that soap is biased towards activity-oriented, with strict specifications and standards, including security, transactions, and so on, while soap emphasizes the separation of operations and operations objects, The WSDL file specification and the XSD file are defined separately. While rest emphasizes resource-oriented, we can use the rest architecture style as long as the objects we want to manipulate can be abstracted as resources.
Application-context-cxf.xml
<?xml version= "1.0" encoding= "UTF-8"?> <beans xmlns= "Http://www.springframework.org/schem A/beans "xmlns:context=" Http://www.springframework.org/schema/context "xmlns:jaxws=" Http://cxf.apache.org/jaxws " xmlns:jaxrs= "Http://cxf.apache.org/jaxrs" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/ Beans/spring-beans-4.1.xsd Http://www.springframework.org/schema/context htt P://www.springframework.org/schema/context/spring-context-4.1.xsd Http://cxf.apache.org/jaxws Http://cxf.apache.org/schemas/jaxws.xsd Http://cxf.apache.org/jaxrs Http://cxf.apache.org/schemas/jaxrs.xsd "> <import resource=" classpath:meta-in F/cxf/cxf.xml "/> <import resourCe= "Classpath:meta-inf/cxf/cxf-servlet.xml"/> <import resource= "classpath:meta-inf/cxf/ Cxf-extension-soap.xml "/> <bean id=" Springcontextutil "class=" Com.sharp.slc.common.SpringContextUtil "/> <!--DeviceManager Service--<!--<jaxws:endpoint id= "DeviceManager" implementor= "Com.sharp . Slc.agent.purifier.webservice.impl.DeviceManagerServiceImpl "address="/devicemanagerservice "/>--&L T;bean id= "Agentservice" class= "Com.sharp.slc.agent.purifier.webservice.impl.AgentServiceImpl"/> <jaxw S:server id= "Agentsoapservice" serviceclass= "Com.sharp.slc.agent.purifier.webservice.impl.AgentServiceImpl" address= "/agentsoapservice" > <jaxws:serviceBean> <ref bean= "Agentservice"/> < /jaxws:servicebean> </jaxws:server> <bean id= "agentservicefortcp" class= "Com.sharp.slc.agent". Purifier.webservice.impl.AgentServiceForTcpImpl "/&Gt <jaxws:server id= "agentsoapservicefortcp" serviceclass= " Com.sharp.slc.agent.purifier.webservice.impl.AgentServiceForTcpImpl "address="/agentsoapservicefortcp "> <jaxws:serviceBean> <ref bean= "agentservicefortcp"/> </jaxws:serviceBean> </jaxw S:server> <!--HMS Server Service <jaxws:endpoint id= "HMS" Implementor= "Com.sharp.slc.agent.purif Ier.webservice.impl.HMSServiceImpl "address="/hmsservice "/>-<!--agent CXF RESTful Publish --<jaxrs:server id= "Agentservicecontainer" address= "/agentwebservice" > <JAXRS:SERVICEBEANS&G T <ref bean= "Agentwebbean"/> </jaxrs:serviceBeans> <jaxrs:extensionMappings> < ; entry key= "JSON" value= "Application/json"/> <entry key= "xml" value= "Application/xml"/> </ Jaxrs:extensionmappings> <jaxrs:languagemappings> <entry key= "en" value= "en-gb"/> </jaxrs:languageMappings> </jaxrs:ser ver> <bean id= "Agentwebbean" class= "Com.webservice.impl.ReceiveHMSDataImpl"/> <!--WeChat CLI ENT-<!--<jaxws:client id= "wechatclient" serviceclass= "Com.sharp.slc.wechat.webservice.WeChatI Nterface "address=" Http://localhost:8080/SharpCloudWeb/webservice/weChatService "/>--<j Axws:client id= "wechatclient" serviceclass= "Com.sharp.slc.wechat.webservice.WeChatInterface" address= "${we Chat.endpoint} "/> <jaxws:client id=" tcpClient "serviceclass=" Com.sharp.slc.net.webservice.ITCPService "Address=" ${tcpserver.endpoint} "/> <!--<bean id=" WeChat "class=" Com.sharp.slc.wechat.webservice. WeChat "factory-bean=" wechatproxyfactory "factory-method=" create "/> <bean id=" socketproxyfactory "class=" Org.apache.cxf.jaxws.JaxWsproxyfactorybean "> <property name=" serviceclass "value=" Com.sharp.slc.net.webservice.Socket "/> & Lt;property name= "Address" value= "Http://localhost:8080/sharp-slc-net/SocketService"/> </bean> -</beans>
Ireceivehmsdata.java
Package Com.webservice;import Javax.jws.webservice;import Javax.servlet.http.httpservletrequest;import Javax.servlet.http.httpservletresponse;import Javax.ws.rs.post;import Javax.ws.rs.path;import Javax.ws.rs.produces;import javax.ws.rs.core.context;import Javax.ws.rs.core.MediaType; @Path ("/receivehmsserver" ) @WebServicepublic interface Ireceivehmsdata { /** * @param servletrequest * @param servletresponse * @return */ @POST @Path ("/notifydevicemodification") @Produces ({Mediatype.application_json}) String notifydevicemodification (@Context httpservletrequest servletrequest, @Context httpservletresponse Servletresponse); }
Receivehmsdataimpl.java
Package Com.webservice.impl; @WebService (endpointinterface = "Com.sharp.slc.sharpcloud.webservice.IReceiveHMSData" public class Receivehmsdataimpl implements Ireceivehmsdata {@POST @path ("/notifydevicemodification") @Produces ({ Mediatype.application_json}) Public String notifydevicemodification (@Context httpservletrequest request, @Context HttpServletResponse response) {return "";}}
Interface code for SOAP
Package Com.sharp.slc.wechat.webservice;import Java.util.list;import Javax.jws.WebService; @WebServicepublic Interface Wechatinterface {/** * obtain device information based on MACAddress * * @param openId * @return */public void Sendconnstatustowechat (L Ist<string> openidlist, String deviceId, string status)/** * Obtain device information according to MACAddress * * @param openidlist * @param Message */public void Sendtextmessagetowechat (list<string> openidlist, String message);/** * obtain device information according to MACAddress * * @param OpenID * @param devicestatus * @return */public void Senddevicestatustowechat (String OpenID, String devicest ATUS);/** * Send binding success Information * * @param OpenID * @param deviceId * @return */public void Sendbindsuccesstowechat (String openId , String deviceId);}
Spring Integrated CXF releases restful and SOAP interfaces