WebService's history and related technologies
Reference: http://www.cnblogs.com/doosmile/archive/2012/06/21/2557351.html
WebService technology is now very mature, big wave after the sand, the current Java Development WebService framework mainly includes AXIS2 and CXF.
Axis2 and CXF are all Apache-owned products, but their purpose is different, resulting in webservice development methods. Two frameworks have been supported by developers. It is necessary to compare the two.
| |
Axis2 |
CXF |
| Goal |
WebService engine |
A simple SOA framework that can be used as an ESB |
| ws* Standard Support |
Ws-policy not supported |
Ws-addressing,ws-policy, WS-RM, Ws-security,ws-i Basic profile |
| Data binding Support |
XMLBeans, JiBX, JaxMe, Jaxbri, ADB |
JAXB, Aegis, XMLBeans, SDO, JiBX |
| Spring integration |
Not supported |
Support |
| Application integration |
Difficult |
Simple |
| Multi-lingual |
Support for C + + |
Not supported |
| Deployment |
Web Apps |
Embedded |
| Service Monitoring and management |
Support |
Not supported |
Conclusion:
- If you want to implement webservice in a consistent way, especially if you have cross-language requirements, you should use Axis2
- If you need to add WebService support to existing Java programs, including Web apps, you should use CXF
CXF Server and Client server-side POM files
<!--service End---->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>3.1.10</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>3.1.10</version>
</dependency>
<!--client--
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-client</artifactId>
<version>3.1.10</version>
</dependency>
Web. XML configuration
<!--set Spring container Load profile path--
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext-server.xml</param-value>
</context-param>
<!--load Spring container configuration--
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>CXFService</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CXFService</servlet-name>
<url-pattern>/webservice/*</url-pattern>
</servlet-mapping>
</web-app>
Spring file
Adding header files in XML
Http://cxf.apache.org/jaxws
Http://cxf.apache.org/schemas/jaxws.xsd
Http://cxf.apache.org/jaxrs
Http://cxf.apache.org/schemas/jaxrs.xsd
Specific implementation:
<bean id= "Greetingserviceimpl" class= "com.Mycompany.webservice.server.GreetingServiceImpl"/>
<jaxws:endpoint id= "Greetingservice" implementor= "#greetingServiceImpl" address= "/greeting" />
Interface
Package com.mycompany.webservice.server;
Import Javax.jws.WebService;
@WebService
Public interface Greeting {
public string Greeting (string userName);
}
Implementation class
Package com.mycompany.webservice.server;
Import Java.util.Calendar;
Import Javax.jws.WebService;
@WebService (endpointinterface = "com.mycompany.webservice.server.Greeting")
public class Greetingserviceimpl implements greeting {
public string Greeting (string userName) {
Return "Hello" + UserName + ", CurrentTime is"
+ calendar.getinstance (). GetTime ();
}
}
Client
public class Greetingserviceclient {
public static void Main (string[] args) {
Create a WebService Client Agent factory
Jaxwsproxyfactorybean factory = new Jaxwsproxyfactorybean ();
Registering the WebService interface
Factory.setserviceclass (Greeting.class);
Set WebService Address
Factory.setaddress ("http://localhost:8080/yourprogramname/webservice/greeting");
Greeting Greetingservice = (greeting) factory.create ();
System.out.println ("Invoke WebService ...");
SYSTEM.OUT.PRINTLN ("Message context is:" +greetingservice.greeting ("Gary"));
}
}
CXF fast and simple implementation of WebService calls