ssh项目上添加webservice
- 博客分类:
- JAVA 编程
最近一个ssh的项目需要添加webservice接口的。
就这个配置捣鼓了半天,下面在这里记录一下具体的流程方便下次使用哦。
我的环境是:
MyEclipse6.5+ tomcat6 +jdk1.6
刚开始在网站找了一个篇webservice项目的例子。试着做了一下。
这个项目是在创建项目的时候就添加了webservice。
参考例子:
http://www.cnblogs.com/simle/archive/2011/10/31/2230091.html
下面记录一下我是我现有的ssh项目添加的webservice
步骤一:
在项目上面加载webservice库 点击 项目右键 → myeclipse → add xfire webservice Capabilities 一直下一步,完成。
步骤二:
在web.xml里面添加XFire的配置
<context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/xfire-servlet.xml</param-value> </context-param>
<!-- begin XFire 配置 --> <servlet> <servlet-name>xfire</servlet-name> <servlet-class>org.codehaus.xfire.spring.XFireSpringServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>xfire</servlet-name> <url-pattern>*.ws</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>xfire</servlet-name> <url-pattern>/services/*</url-pattern> </servlet-mapping> <servlet> <!-- 配合Spring容器中XFire一起工作的Servlet--> <servlet-name>xfireServlet</servlet-name> <servlet-class>org.codehaus.xfire.spring.XFireSpringServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>xfireServlet</servlet-name> <!-- 在这个URI下开放Web Service服务 --> <url-pattern>/service/*</url-pattern> </servlet-mapping> <!-- end XFire 配置 -->
这里里配置的时候得注意一点。在加载webservice库的时候会自动增加一些配置在这里面。注意看一下。这里是和spring相配置的。把他丢给spring管理。
步骤三:
在WEB-INF下面新建xfire-servlet.xml ,在步骤二里面已经引用到了。。。
我的xfire-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"> <!-- For configuring Authentication with XFire and Acegi, please see: http://jroller.com/page/sqyuan?entry=using_acegi_for_authentication_authorization --> <import resource="classpath:org/codehaus/xfire/spring/xfire.xml"/> <!-- If you want to use JAXB instead of XmlBeans, you'll need to add the following dependency to your pom.xml. <dependency> <groupId>org.codehaus.xfire</groupId> <artifactId>xfire-jaxb2</artifactId> <version>${xfire.version}</version> </dependency> --> <!--<bean id="jaxbTypeMappingRegistry" class="org.codehaus.xfire.jaxb2.JaxbTypeRegistry" init-method="createDefaultMappings"/>--> <bean id="xmlbeansTypeRegistry" class="org.codehaus.xfire.xmlbeans.XmlBeansTypeRegistry"/> <bean id="webAnnotations" class="org.codehaus.xfire.annotations.jsr181.Jsr181WebAnnotations"/> <bean id="handlerMapping" class="org.codehaus.xfire.spring.remoting.Jsr181HandlerMapping"> <!--<property name="typeMappingRegistry" ref="jaxbTypeMappingRegistry"/>--> <property name="typeMappingRegistry" ref="xmlbeansTypeRegistry"/> <property name="xfire" ref="xfire"/> <property name="webAnnotations" ref="webAnnotations"/> </bean> <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="urlMap"> <map> <entry key="/"> <ref bean="handlerMapping"/> </entry> </map> </property> </bean> </beans>
步骤四:
在src下面 新建一个包 cn.service ,在包里面建一个借口一个类试一下
接口IWebService .java:
package cn.service; import javax.jws.WebService; //Generated by MyEclipse @WebService public interface IWebService { public String example(String message); public String test(String s ); }
实现类:
package cn.service; import javax.jws.WebService; //Generated by MyEclipse @WebService(serviceName = "service789", endpointInterface = "cn.service.IWebService") public class WebServiceImpl implements IWebService { public String example(String message) { return message; } public String test(String s ){ String n = "this's "; String t = n+s; return t; } }
在这里得注意接口上面和实现类上面的注解。
步骤五:
交给了spring来管理。就在spring 的配置文件配置bean
<bean id="service123" class="cn.service.WebServiceImpl"> </bean>
步骤六:
启动tomcat访问 这里访问路径得注意,访问bean下面配置的name路径会自动跳转到实现类注解上面的serviceName。
步骤七:
错误提示。
启动tomcat的的时候会报错:
错误一:
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanDefinitionStoreException: Line 8 in XML document from ServletContext resource [/WEB-INF/classes/applicationContext-common.xml] is invalid; nested exception is org.xml.sax.SAXParseException: Document root element "beans", must match DOCTYPE root "null".
org.xml.sax.SAXParseException: Document root element "beans", must match DOCTYPE root "null".
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
这个错误是因为原本我ssh项目配置里面已经有一个spring包了。我在加载webservice的时候又给自动添加了一个spring包。两个包冲突所引起的。我这里 一个spring.jar 一个spring-1.2.6.jar 我是删掉了spring-1.2.6.jar这个包。
解决了刚才那个问题有出现了
错误二:
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.codehaus.xfire.xmlbeans.XmlBeansTypeRegistry] for bean with name 'xmlbeansTypeRegistry' defined in ServletContext resource [/WEB-INF/xfire-servlet.xml]; nested exception is java.lang.ClassNotFoundException: org.codehaus.xfire.xmlbeans.XmlBeansTypeRegistry
这个错误提示是说缺少包。缺少了一个叫做xfire-xmlbeans-1.2.6.jar 的包。。
这个包在xfire-servlet.xml 配置文件里面用到了。
将这包添加进去后再次启动tomcat就ok了
我的访问路径是
http://localhost:8080/demo/services/ 这样他会自动找到你配置的webservice
http://localhost:8080/demo/services/service123?wsdl 这里service123是bean里面配置的name
他们两个路径最终的目的就是访问到webservice的实现类里面去。
http://localhost:8080/smsmanage/services/service789?wsdl 这里的service789就是在实现类上面servicename
正确访问会在浏览器上面出现一下类似于xml 的格式的内容
<?xml version="1.0" encoding="UTF-8" ?> - <wsdl:definitions targetNamespace="http://service.cn" xmlns:soapenc12="http://www.w3.org/2003/05/soap-encoding" xmlns:tns="http://service.cn" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap11="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc11="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> - <wsdl:types> - <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://service.cn"> - <xsd:element name="test"> - <xsd:complexType> - <xsd:sequence> <xsd:element maxOccurs="1" minOccurs="1" name="in0" nillable="true" type="xsd:string" /> </xsd:sequence> </xsd:complexType> </xsd:element> - <xsd:element name="testResponse"> - <xsd:complexType> - <xsd:sequence> <xsd:element maxOccurs="1" minOccurs="1" name="out" nillable="true" type="xsd:string" /> </xsd:sequence> </xsd:complexType> </xsd:element> - <xsd:element name="example"> - <xsd:complexType> - <xsd:sequence> <xsd:element maxOccurs="1" minOccurs="1" name="in0" nillable="true" type="xsd:string" /> </xsd:sequence> </xsd:complexType> </xsd:element> - <xsd:element name="exampleResponse"> - <xsd:complexType> - <xsd:sequence> <xsd:element maxOccurs="1" minOccurs="1" name="out" nillable="true" type="xsd:string" /> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema> </wsdl:types> - <wsdl:message name="exampleResponse"> <wsdl:part name="parameters" element="tns:exampleResponse" /> </wsdl:message> - <wsdl:message name="exampleRequest"> <wsdl:part name="parameters" element="tns:example" /> </wsdl:message> - <wsdl:message name="testResponse"> <wsdl:part name="parameters" element="tns:testResponse" /> </wsdl:message> - <wsdl:message name="testRequest"> <wsdl:part name="parameters" element="tns:test" /> </wsdl:message> - <wsdl:portType name="service789PortType"> - <wsdl:operation name="test"> <wsdl:input name="testRequest" message="tns:testRequest" /> <wsdl:output name="testResponse" message="tns:testResponse" /> </wsdl:operation> - <wsdl:operation name="example"> <wsdl:input name="exampleRequest" message="tns:exampleRequest" /> <wsdl:output name="exampleResponse" message="tns:exampleResponse" /> </wsdl:operation> </wsdl:portType> - <wsdl:binding name="service789HttpBinding" type="tns:service789PortType"> <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" /> - <wsdl:operation name="test"> <wsdlsoap:operation soapAction="" /> - <wsdl:input name="testRequest"> <wsdlsoap:body use="literal" /> </wsdl:input> - <wsdl:output name="testResponse"> <wsdlsoap:body use="literal" /> </wsdl:output> </wsdl:operation> - <wsdl:operation name="example"> <wsdlsoap:operation soapAction="" /> - <wsdl:input name="exampleRequest"> <wsdlsoap:body use="literal" /> </wsdl:input> - <wsdl:output name="exampleResponse"> <wsdlsoap:body use="literal" /> </wsdl:output> </wsdl:operation> </wsdl:binding> - <wsdl:service name="service789"> - <wsdl:port name="service789HttpPort" binding="tns:service789HttpBinding"> <wsdlsoap:address location="http://localhost:8080/smsmanage/services/service789" /> </wsdl:port> </wsdl:service> </wsdl:definitions>
由于刚接触这个webservice。了解不是很深。。可能描述的也是有点糟糕哦。。
发表评论
-
Myeclipse 快捷键自动补全
2014-01-05 12:33 1117就比如在myeclipse里 ... -
java 异常
2013-08-20 16:23 611运行时异常: ArithmeticException ... -
去时间加减处理
2012-09-14 11:15 845转:不错的时间处理方法的文章 http://alexfc.i ... -
去String里面的数字组成数组
2012-09-06 16:06 1185/** * 将一串字符串取出数字放入数组里面 ... -
Display Tag使用
2012-09-05 13:47 656转: http://shirnie.blog.163.com/ ... -
HQL查简单询语句用法Query
2012-09-03 09:55 122201. HQL查简单询语句用法Query // ... -
Hibernate中HQL函数
2012-09-03 09:52 1009Criteria查询对查询条件进行了面向对象封装,符合编程 ... -
java类文件获取页面的request,session.response
2012-08-28 15:24 838HttpSession session = WebContex ... -
jsp form 提交action 乱码
2012-05-19 11:10 2702今天遇到的一个乱码问题。 感觉很奇怪。 我的jsp的编码 ... -
HQL like 模糊查询
2012-05-19 10:50 19051一个做过的例子。。 public List<Telep ... -
hibernate环境搭建
2012-03-21 12:14 2476我的环境是:eclipse ... -
maven 配置
2011-11-09 23:31 794在 下面上传了一个maven maven需要在环境变量里面 ... -
Persistence.xml 配置说明
2011-11-04 17:31 1375JPA规范要求在类路径的META-INF目录下放置persi ... -
表单提交的几种方法
2011-10-22 12:34 959普通提交: 方法一(submit): < ... -
File 转byte[]
2011-10-18 15:00 936/** * 文件File转化为字节数组byte[ ... -
XStream实现实体类跟XML文件互相转换
2011-10-18 14:57 1365public static Object xmlToO ... -
hibernate oracle自动增长
2011-09-28 11:05 1019在oracle里面的注解用sequence cre ... -
java 统计网站访问量
2011-09-26 15:01 2674转: import java.io.BufferedRead ... -
获取路径的几种方法
2011-08-29 14:18 759转: 关于绝对路径和相对路径: 绝对路径就是你的主 ... -
Java中File,byte[],Object间的转换 .
2011-08-26 11:32 771转: http://blog.csdn.net/gu ...
相关推荐
ssh+webservice 环境
ssh框架整合cxf(webservice),ssh案例(增、删、改、查),发布webservice,客户端调用,该工程自带jar包,mysql连接池,自动建库、建表。 ①直接解压,导入ssh2cxf项目 ②用tomcat启动ssh2cxf项目 ③在浏览器输入...
今天特意将项目中用Axis2集成SSH实现WebService的过程记录下来,一方面做一下笔记,另一方面,方便广大码农朋友,希望能跟大家交流学习。 本文介绍用Axis2集成SSH搭建WebService。会达到的效果: 1.按照传统我们用...
SSH整合cxf webservice实例
ssh1+webservice(axis) 配置框架 ssh1+webservice(axis) 配置框架
ssh2+cxf搭建webservice实例文档说明,收藏备用
在已存在的项目(Struts2+Spring3)搭建webservice服务,选用了CXF2.6。 适合新手维护老系统搭建webservice,非注解,比较老的方式。
SSH整合WebService框架XFire搭建总结.pdf
Axis2集成SSH搭建WebService项目的源代码,这个里面不包含各种依赖jar包,需要的朋友在我的CSDN里面找自行下载吧!另外,我写了一篇文章,详细介绍了如何搭建的,图文源码都有,还有测试用例。希望对大家有所帮助。
在j2ee web 原有项目中添加 webservice 服务端
Axis2集成SSH搭建WebService支持事务(图文详解含核心代码).zip
SSH CXF webservice 开发笔记demo(包含步骤文档及所需war包)
帮你快速搭建ssh下的webservice的方法,下载所有jar加入lib剩下的就是简单的写一个配置文件了,相信你能很容易搭建起xfire webservice,祝你好运!
ssh+cxf整合发布webservice实例,详细解释配置过程,下载解压即可使用。
使用axis2与ssh整合开发webService文档与源码!其中包括客户端访问的lib包与源码demo
如果需要在web项目中新增或者添加webservice服务时,本例子中介绍了如何来操作,其中每一步骤很详细。
Axis2集成SSH搭建WebService支持事务,WebService服务还是挺多人用的
该例子包括ssh2注解 Lucene 全文检索与WebService,技术是拿来分享的,以后有什么好例子我都会拿出来与大家分享的,真心技术交流 QQ:4218380
关于ssh demo 演示验证码及图片流显示在界面中,XFire+Spring构建WebService整合
webService添加basic验证,为了WebService的安全,将webservice添加basic验证,用户在调用时需要提供授权信息进行调用