SSH整合cxf 发布web Service
2015-03-25 21:29
246 查看
S2S4H3整合cxf
为了发布WebService,要做一些前期准备,当然S2S4H3的项目肯定要有了,在这里我就不解释SSH的整合啦,关注我的下篇文档吧。
① 准备cxf的jar包:
我用的是cxf 2.5.9,在官网可以下载到的,此整合教程是使用与3.0前的版本,因为cxf 3.0之后的配置是不一样的。 cxf-2.5.9.jar cxf-2.5.9.jar geronimo-servlet_2.5_spec-1.1.2.jar neethi-3.0.2.jar stax2-api-3.1.1.jar woodstox-core-asl-4.1.4.jar xmlschema-core-2.0.3.jar② 在web.xml中新添如下配置:
还有一问题需要注意:因为struts2 的默认过滤器默认是过滤捕捉所以请求的,所以需要自定义Filter为cxf放行 <servlet> <servlet-name>cxf</servlet-name> <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> <load-on-startup>30</load-on-startup> </servlet>
<!-- 需要注意:cxfServlet与struts2的URL不能都写/*,需要区分,在自定义Filter中对cxf放行,不然请求时会在struts2里出错-->
<servlet-mapping> <servlet-name>sshserver </servlet-name> <url-pattern>/sshserver/*</url-pattern> </servlet-mapping>
<!-- 配置struts2的filter:自定义的Filter(为了给cxf放行)-->
<filter> <filter-name>struts2</filter-name> <filter-class>org.hxb.struts2.Filter.LetCxfGoFilter</filter-class> </filter>
③ 在spring的配置文件ApplicationContext.xml中添加新的配置如下:
其中红色字体为cxf新添的配置。
<?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:context="http: //www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"xmlns:aop="http://www.springframework.org/schema/aop" xmlns:p="http://www.springframework.org/schema/p"xmlns:jaxws="http://cxf.apache.org/jaxws" xsi:schemaLocation="http://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd http://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-4.0.xsd"> <!-- 导入cxf资源文件 --> <importresource="classpath:META-INF/cxf/cxf.xml" /> <importresource="classpath:META-INF/cxf/cxf-extension-soap.xml" /> <importresource="classpath:META-INF/cxf/cxf-servlet.xml" /> <!--发布服务--> <jaxws:endpointid="orderProcess" implementor="org.hxb.WebService.ServerImpl" address="/ServerPublish"/> ④ 自定义的Filter:
前面已经提过自定义Filter的目的是为了给cxf放行:
package org.hxb.struts2.Filter;import java.io.IOException;import javax.servlet.FilterChain;import javax.servlet.ServletException;import javax.servlet.ServletRequest;import javax.servlet.ServletResponse;import javax.servlet.http.HttpServletRequest;importorg.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter;
/** * <p>自定义Filter 为cxf放行</p>* */
public class LetCxfGoFilter extends StrutsPrepareAndExecuteFilter {@Overridepublic void doFilter(ServletRequest arg0, ServletResponsearg1,FilterChain arg2) throws IOException, ServletException { HttpServletRequestrequest = (HttpServletRequest) arg0;
//如果路径包含sshserver则放行。if(request.getRequestURI().contains("sshserver")){ arg2.doFilter(arg0, arg1); }else{ super.doFilter(arg0,arg1, arg2);}}}
⑤ Web Service的接口:
package org.hxb.WebService; import javax.jws.WebMethod; import javax.jws.WebService; @WebService publicinterface Server { @WebMethod public String getGasData(); } }
⑥ Web Service的实现:
package org.hxb.WebService; import javax.jws.WebService; @WebService publicclass ServerImpl implements Server { @Override public String getGasData() { System.out.println("INFO:Server已经启动!"); return"Service"; } }⑦ 启动后:浏览器访问:http://localhost:8080/sshtest/sshserver/ServerPublish?wsdl
准备:
我是已经有了一个S2S4H3的整合项目,由于需要,整合了cxf,估计看见这篇文档的人都是知道cxf框架是干什么的吧,为了发布WebService,要做一些前期准备,当然S2S4H3的项目肯定要有了,在这里我就不解释SSH的整合啦,关注我的下篇文档吧。
① 准备cxf的jar包:
我用的是cxf 2.5.9,在官网可以下载到的,此整合教程是使用与3.0前的版本,因为cxf 3.0之后的配置是不一样的。 cxf-2.5.9.jar cxf-2.5.9.jar geronimo-servlet_2.5_spec-1.1.2.jar neethi-3.0.2.jar stax2-api-3.1.1.jar woodstox-core-asl-4.1.4.jar xmlschema-core-2.0.3.jar② 在web.xml中新添如下配置:
还有一问题需要注意:因为struts2 的默认过滤器默认是过滤捕捉所以请求的,所以需要自定义Filter为cxf放行 <servlet> <servlet-name>cxf</servlet-name> <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> <load-on-startup>30</load-on-startup> </servlet>
<!-- 需要注意:cxfServlet与struts2的URL不能都写/*,需要区分,在自定义Filter中对cxf放行,不然请求时会在struts2里出错-->
<servlet-mapping> <servlet-name>sshserver </servlet-name> <url-pattern>/sshserver/*</url-pattern> </servlet-mapping>
<!-- 配置struts2的filter:自定义的Filter(为了给cxf放行)-->
<filter> <filter-name>struts2</filter-name> <filter-class>org.hxb.struts2.Filter.LetCxfGoFilter</filter-class> </filter>
③ 在spring的配置文件ApplicationContext.xml中添加新的配置如下:
其中红色字体为cxf新添的配置。
<?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:context="http: //www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"xmlns:aop="http://www.springframework.org/schema/aop" xmlns:p="http://www.springframework.org/schema/p"xmlns:jaxws="http://cxf.apache.org/jaxws" xsi:schemaLocation="http://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd http://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-4.0.xsd"> <!-- 导入cxf资源文件 --> <importresource="classpath:META-INF/cxf/cxf.xml" /> <importresource="classpath:META-INF/cxf/cxf-extension-soap.xml" /> <importresource="classpath:META-INF/cxf/cxf-servlet.xml" /> <!--发布服务--> <jaxws:endpointid="orderProcess" implementor="org.hxb.WebService.ServerImpl" address="/ServerPublish"/> ④ 自定义的Filter:
前面已经提过自定义Filter的目的是为了给cxf放行:
package org.hxb.struts2.Filter;import java.io.IOException;import javax.servlet.FilterChain;import javax.servlet.ServletException;import javax.servlet.ServletRequest;import javax.servlet.ServletResponse;import javax.servlet.http.HttpServletRequest;importorg.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter;
/** * <p>自定义Filter 为cxf放行</p>* */
public class LetCxfGoFilter extends StrutsPrepareAndExecuteFilter {@Overridepublic void doFilter(ServletRequest arg0, ServletResponsearg1,FilterChain arg2) throws IOException, ServletException { HttpServletRequestrequest = (HttpServletRequest) arg0;
//如果路径包含sshserver则放行。if(request.getRequestURI().contains("sshserver")){ arg2.doFilter(arg0, arg1); }else{ super.doFilter(arg0,arg1, arg2);}}}
⑤ Web Service的接口:
package org.hxb.WebService; import javax.jws.WebMethod; import javax.jws.WebService; @WebService publicinterface Server { @WebMethod public String getGasData(); } }
⑥ Web Service的实现:
package org.hxb.WebService; import javax.jws.WebService; @WebService publicclass ServerImpl implements Server { @Override public String getGasData() { System.out.println("INFO:Server已经启动!"); return"Service"; } }⑦ 启动后:浏览器访问:http://localhost:8080/sshtest/sshserver/ServerPublish?wsdl
相关文章推荐
- 9.Web Service Spring整合CXF之发布服务
- spring boot整合cxf发布webservice服务和cxf客户端调用
- Android调用Axis、Axis2、Cxf发布的web service
- 用cxf发布和调用web service
- Spring整合CXF,发布RSETful 风格-配置WebService
- Android开发中调用Spring CXF整合发布的WebService接口为什么抛出异常错误?
- cxf整合spring发布webservice
- ssh 整合 cxf
- Spring整合CXF,发布RSETful 风格WebService
- spring boot整合cxf发布webservice服务和spring boot整合cxf客户端调用webservice服务
- SpringBoot整合cxf发布WebService服务和客户端调用WebService服务
- 基于Maven在Spring中集成CXF,发布Web Service
- Spring整合CXF,发布RSETful 风格WebService--编写客户端代码,调用RESTful WebService
- CXF实现和Spring整合发布WebService
- CXF学习-与Spring整合(暴露web Service接口给其他程序使用)
- Spring boot 整合CXF开发web service
- Spring boot 整合CXF开发web service
- CXF WebService 7 - Spring整合CXF,发布RSETful 风格WebService
- 基于 Spring 整合 CXF 的 Web Service 超时时间配置
- 7、CXF与Spring整合,发布WebService服务