- 浏览: 173147 次
- 性别:
- 来自: 厦门
文章分类
- 全部博客 (186)
- Ant (11)
- Axis2 (15)
- Car (9)
- Eclipse (1)
- Java (19)
- Java-EM (4)
- Javascript (11)
- Jsp (1)
- Hibernate (9)
- Mysql (1)
- Ms-Dos (5)
- Music (0)
- Oracle (3)
- Postgresql (0)
- Photoshop (1)
- Spring (17)
- Struts (8)
- Selenium (5)
- Ubuntu (13)
- News (17)
- Others (7)
- SSH (11)
- 算法 (5)
- FreeMarker (4)
- Tomcat (2)
- Linux (5)
最新评论
6, 修改配置文件spring-ws-servlet.xml.
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- 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-2.0.xsd">
- <bean id="payloadMapping" class="org.springframework.ws.server.endpoint.mapping.PayloadRootQNameEndpointMapping">
- <property name="endpointMap">
- <map>
- <entry key=”{http://www.fuxueliang.com/ws/hello}HelloRequest” />
- <ref bean="helloEndpoint" />
- </entry>
- </map>
- </property>
- </bean>
- <bean id="hello" class="org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition">
- <property name="wsdl" value="/WEB-INF/hello.wsdl"/>
- </bean>
- <bean id="helloEndpoint" class="org.rondy.ws.HelloEndPoint">
- <property name="helloService" ref="helloService" />
- </bean>
- <bean id="helloService" class="org.rondy.service.HelloServiceImpl" />
- </beans>
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" 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-2.0.xsd"> <bean id="payloadMapping" class="org.springframework.ws.server.endpoint.mapping.PayloadRootQNameEndpointMapping"> <property name="endpointMap"> <map> <entry key=”{http://www.fuxueliang.com/ws/hello}HelloRequest” /> <ref bean="helloEndpoint" /> </entry> </map> </property> </bean> <bean id="hello" class="org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition"> <property name="wsdl" value="/WEB-INF/hello.wsdl"/> </bean> <bean id="helloEndpoint" class="org.rondy.ws.HelloEndPoint"> <property name="helloService" ref="helloService" /> </bean> <bean id="helloService" class="org.rondy.service.HelloServiceImpl" /> </beans>
注: 其中最主要的bean就是payloadMapping, 它定义了接收到的message与endpoint之间的mapping关系:将SOAP Body中包含的xml的根节点的QName为{http://www.fuxueliang.com/ws/hello}HelloRequest交给helloEndpoint处理.
SimpleWsdl11Definition这个bean则是定义了这个服务的wsdl, 访问地址是:http://localhost:8080/springws/hello.wsdl.
7, 客户端(saaj实现)的代码如下:
- /**
- *
- * @author Rondy.F
- *
- */
- public class HelloWebServiceClient {
- public static final String NAMESPACE_URI = "http://www.fuxueliang.com/ws/hello";
- public static final String PREFIX = "tns";
- private SOAPConnectionFactory connectionFactory;
- private MessageFactory messageFactory;
- private URL url;
- public HelloWebServiceClient(String url) throws SOAPException, MalformedURLException {
- connectionFactory = SOAPConnectionFactory.newInstance();
- messageFactory = MessageFactory.newInstance();
- this.url = new URL(url);
- }
- private SOAPMessage createHelloRequest() throws SOAPException {
- SOAPMessage message = messageFactory.createMessage();
- SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
- Name helloRequestName = envelope.createName("HelloRequest", PREFIX, NAMESPACE_URI);
- SOAPBodyElement helloRequestElement = message.getSOAPBody().addBodyElement(helloRequestName);
- helloRequestElement.setValue("Rondy.F");
- return message;
- }
- public void callWebService() throws SOAPException, IOException {
- SOAPMessage request = createHelloRequest();
- SOAPConnection connection = connectionFactory.createConnection();
- SOAPMessage response = connection.call(request, url);
- if (!response.getSOAPBody().hasFault()) {
- writeHelloResponse(response);
- } else {
- SOAPFault fault = response.getSOAPBody().getFault();
- System.err.println("Received SOAP Fault");
- System.err.println("SOAP Fault Code :" + fault.getFaultCode());
- System.err.println("SOAP Fault String :" + fault.getFaultString());
- }
- }
- @SuppressWarnings("unchecked")
- private void writeHelloResponse(SOAPMessage message) throws SOAPException {
- SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
- Name helloResponseName = envelope.createName("HelloResponse", PREFIX, NAMESPACE_URI);
- Iterator childElements = message.getSOAPBody().getChildElements(helloResponseName);
- SOAPBodyElement helloResponseElement = (SOAPBodyElement) childElements.next();
- String value = helloResponseElement.getTextContent();
- System.out.println("Hello Response [" + value + "]");
- }
- public static void main(String[] args) throws Exception {
- String url = "http://localhost:8080/springws";
- HelloWebServiceClient helloClient = new HelloWebServiceClient(url);
- helloClient.callWebService();
- }
- }
/** * * @author Rondy.F * */ public class HelloWebServiceClient { public static final String NAMESPACE_URI = "http://www.fuxueliang.com/ws/hello"; public static final String PREFIX = "tns"; private SOAPConnectionFactory connectionFactory; private MessageFactory messageFactory; private URL url; public HelloWebServiceClient(String url) throws SOAPException, MalformedURLException { connectionFactory = SOAPConnectionFactory.newInstance(); messageFactory = MessageFactory.newInstance(); this.url = new URL(url); } private SOAPMessage createHelloRequest() throws SOAPException { SOAPMessage message = messageFactory.createMessage(); SOAPEnvelope envelope = message.getSOAPPart().getEnvelope(); Name helloRequestName = envelope.createName("HelloRequest", PREFIX, NAMESPACE_URI); SOAPBodyElement helloRequestElement = message.getSOAPBody().addBodyElement(helloRequestName); helloRequestElement.setValue("Rondy.F"); return message; } public void callWebService() throws SOAPException, IOException { SOAPMessage request = createHelloRequest(); SOAPConnection connection = connectionFactory.createConnection(); SOAPMessage response = connection.call(request, url); if (!response.getSOAPBody().hasFault()) { writeHelloResponse(response); } else { SOAPFault fault = response.getSOAPBody().getFault(); System.err.println("Received SOAP Fault"); System.err.println("SOAP Fault Code :" + fault.getFaultCode()); System.err.println("SOAP Fault String :" + fault.getFaultString()); } } @SuppressWarnings("unchecked") private void writeHelloResponse(SOAPMessage message) throws SOAPException { SOAPEnvelope envelope = message.getSOAPPart().getEnvelope(); Name helloResponseName = envelope.createName("HelloResponse", PREFIX, NAMESPACE_URI); Iterator childElements = message.getSOAPBody().getChildElements(helloResponseName); SOAPBodyElement helloResponseElement = (SOAPBodyElement) childElements.next(); String value = helloResponseElement.getTextContent(); System.out.println("Hello Response [" + value + "]"); } public static void main(String[] args) throws Exception { String url = "http://localhost:8080/springws"; HelloWebServiceClient helloClient = new HelloWebServiceClient(url); helloClient.callWebService(); } }
几点看法:
1, 从上面代码可以看出, 比较麻烦的部分就是客户端和服务端对xml处理
发表评论
-
webservice之axis2方式开发总结
2008-11-04 09:33 691webservice之axis2方式开发总结 关键字: we ... -
基于Axis2开发WebService代码详解
2008-11-04 09:34 884基于Axis2开发WebService代码详解 关键字: we ... -
基于Tomcat5.0和Axis2开发Web Service应用实例
2008-11-04 09:38 735基于Tomcat5.0和Axis2开发Web Service应 ... -
使用Axis2来构建Web Service客户端
2008-11-04 09:46 728使用Axis2来构建Web Service客户端 2 ... -
webservice-之使用axis+spring开发
2008-11-04 17:42 601... -
webservice-之使用axis+spring开发2
2008-11-04 17:42 769三、配置文件 (全部放在 ... -
Axis 开发WebService
2008-11-04 18:16 694Axis 开发WebService Axis 开发WebSe ... -
spring与axis的整合
2008-11-04 18:23 669spring与axis的整合 eclipse resin ax ... -
在Eclipse中创建基于Axis2的web services
2008-11-05 09:04 1002本实验的目的是让你尽可能快的创建使用 Axis2 的服务和客户 ... -
Axis2快速上手指南
2008-11-05 09:06 685本指南的目的是让你尽可能快的创建使用Axis2的服务和客户端, ... -
Axis2快速上手指南2
2008-11-05 09:07 662创建服务 在这个部分,我们将看看根据StockQuoteSe ... -
Axis2快速上手指南4
2008-11-05 09:08 824使用ADB生成一个客户端 执行以下步骤来使用Axis Dat ... -
Axis2 Integration With The Spring Framework
2008-11-05 09:16 843Axis2 Integration With The Spri ... -
定义web service接口的十点注意事项
2008-11-05 14:03 1206一、接口是自说明的。 也就是说,接口的名字、参数和返回值在一看 ...
相关推荐
自己辛苦整理的网上的JBoss ESB学习笔记 ,非常详细,代码操作都有截图; 希望大家多支持! 学习笔记PDF的目录如下: 1——搭建ESB开发环境 2 2——第一个ESB代码...16——第十五个ESB代码Web Service Consumer 1 151
Struts2,Spring,Hibernate是Java Web开发中最为常见的3种框架,掌握这3种框架是每个Java Web开发人员的基本功。 然而,很多初学者在集成这3个框架的时候,总是会遇到各种各样的问题。 我在读大学刚刚学习SSH的...
涵盖更多内容,列举了大量典型实例具有超强的实用性,另外,《Java Web开发技术大全:JSP+Servlet+Struts+Hibernate+Spring+Ajax》各篇独立,适合读者全面学习或对部分内容重点学习。 读者对象 有Java基础,想进一步...
2.1.1 比Hello World更适用的实例 2.1.2 实例功能简介 2.2 环境准备 2.2.1 创建库表 2.2.2 建立工程 2.2.3 类包及Spring配置文件规划 2.3 持久层 2.3.1 建立领域对象 2.3.2 UserDao 2.3.3 LoginLogDao 2.3.4 在...
涵盖更多内容,列举了大量典型实例具有超强的实用性,另外,《Java Web开发技术大全:JSP+Servlet+Struts+Hibernate+Spring+Ajax》各篇独立,适合读者全面学习或对部分内容重点学习。 读者对象 有Java基础,想...
本节中的例子将演示Spring 3环境的创建过程,并创建一个可以部署到Tomcat中的“Hello World”应用。然后我们再完成一个更复杂的应用来了解Spring 3 REST支持的重要概念,如多种MIME类型表示支持和JAXB支持。另外,...
本指南将引导您完成使用Spring创建“ Hello World” 。 你会建立什么 您将在以下位置构建将接受HTTP GET请求的服务: http://localhost:8080/greeting 并以问候语的表示形式进行响应: { " id " : 1 , " content ...
构建RESTful Web服务Spring入门指南 Spring入门-构建RESTful Web服务 按照学习使用创建“ Hello World” RESTful Web服务的过程。
2.1.1 比Hello World更适用的实例 2.1.2 实例功能简介 2.2 环境准备 2.2.1 创建库表 2.2.2 建立工程 2.2.3 类包及Spring配置文件规划 2.3 持久层 2.3.1 建立领域对象 2.3.2 UserDao 2.3.3 LoginLogDao 2.3.4 在...
使用XFire+Spring构建Web Service。自己参考网上的讲解写的例子。里面有help.txt 介绍了我参考的xfire+spring集成的网址。
标签专案休息弹簧框架 目录本指南将引导您完成使用Spring创建“ Hello World” 。你会建立什么您将在以下位置构建将接受HTTP GET请求的服务: http://localhost:8080/greeting 并以问候语的表示形式进行响应: { " ...
本指南将指导您使用Spring Boot Actuator创建一个“世界,您好”的RESTful Web服务。 您将构建一个接受以下HTTP GET请求的服务: $ curl http://localhost:9000/hello-world 它使用以下JSON进行响应: { " id " : 1...
RESTful Web Service DemoS with Jersey,Hibernate,Mysql,Spring,JQuery,AngularJS ...跟随我创建一个完整的Web应用程序。 随便去吧! 这是有关如何逐步构建项目的文章,每个演示都是一个小项目: 1.用泽西...
目录本指南将引导您完成使用Spring创建“ Hello,World” RESTful Web服务的过程,该服务在响应中包括跨域资源共享(CORS)的标头。 您可以在此找到有关Spring CORS支持的更多信息。你会建立什么您将构建一个服务,...
Indeed, the fact that a simple Spring Boot Hello World application can fit into a tweet is a radical departure from what the same functionality required on the vm only a few short years ago. Out-of-...
Jetty和Maven HelloWorld教程 Jetty(6)入门 (www.itjungle.com) Jetty Start.jar 配置Jetty 如何设置上下文(Context Path) 如何知道使用了那些jar包 如何配置SSL 如何使用非root用户监听80端口 如何配置连接器...
0: 下载 安装 运行 HelloWorld 1 安装运行 Mysql, MySQL-Front 管理, JDBCHelloWorld 开发 2 用 MyEclipse Database Explorer 管理 MySQL 数据库 3 MyEclipse Hibernate 快速入门开发 4 MyEclipse JPA 快速入门开发 ...
标签专案休息弹簧框架 目录本指南将引导您完成使用Spring创建“ Hello World” 。你会建立什么您将在以下位置构建将接受HTTP GET请求的服务: http://localhost:8080/greeting 并以问候语的表示形式进行响应: { " ...
17.3 实例——分布式的HelloWorld 260 17.4 小结 264 第18章 Java消息服务 265 18.1 消息系统和JMS 265 18.1.1 JMS API 265 18.1.2 点对点消息模式 266 18.1.3 发布者/订阅者模式 267 18.1.4 同步和...