@WebService
public interface IReaderService {
public Reader getReader(@WebParam(name="name") String name,@WebParam(name="password") String password);
public List<Reader> getReaders();
}
@WebService(endpointInterface="com.cxf.servlet.IReaderService",serviceName="readerService")
public class ReaderService implements IReaderService{
public Reader getReader(@WebParam(name="name") String name,@WebParam(name="password") String password) {
return new Reader(name,password);
}
public List<Reader> getReaders(){
List<Reader> readerList = new ArrayList<Reader>();
readerList.add(new Reader("shun1","123"));
readerList.add(new Reader("shun2","123"));
return readerList;
}
}
public class Reader{
private static final long serialVersionUID = 1L;
private String name;
private String password;
public Reader(){}
public Reader(String name,String password) {
this.name = name;
this.password = password;
}
//Get/Set方法省略
public String toString(){
return "Name:"+name+",Password:"+password;
}
}
public static void main(String[] args) {
System.out.println("Server is starting...");
ReaderService readerService = new ReaderService();
Endpoint.publish("http://localhost:8080/readerService",readerService);
System.out.println("Server is started...");
}
public static void main(String[] args) {
JaxWsProxyFactoryBean factoryBean = new JaxWsProxyFactoryBean();
factoryBean.setServiceClass(IReaderService.class);
factoryBean.setAddress("http://localhost:8080/readerService");
IReaderService readerService = (IReaderService)factoryBean.create();
Reader reader = readerService.getReader("shun","123");
System.out.println("Reader:"+reader);
}
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/beans.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/webservice/*</url-pattern>
</servlet-mapping>
</web-app>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<jaxws:endpoint id="readerServicce2"
implementor="com.cxf.servlet.ReaderService" address="/readerService2" />
</beans>
@XmlRootElement
public class Reader implements Serializable{
private static final long serialVersionUID = 1L;
private String name;
private String password;
public Reader(){}
public Reader(String name,String password) {
this.name = name;
this.password = password;
}
//省略Get/Set方法
public String toString(){
return "Name:"+name+",Password:"+password;
}
}
@Path("/readerService/{name}/{password}")
public class ReaderService {
@GET
@Produces(MediaType.APPLICATION_JSON)
public Reader getReader(@PathParam("name") String name,@PathParam("password") String password) {
return new Reader(name,password);
}
public static void main(String[] args) throws IllegalArgumentException, IOException, URISyntaxException {
HttpServer server = HttpServerFactory.create("http://localhost:8080/");
server.start();
}
}
public class ReaderClient {
public static void main(String[] args) {
Client client = Client.create();
WebResource resource = client.resource("http://localhost:8080/readerService/shun/123213");
Reader reader = resource.get(Reader.class);
System.out.println(reader);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
WebResource resource = client.resource("http://localhost:8080/jerseyWebService/rest/readerService/shun/123213");
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有