WebService跨平台调用

导入CXF相关的jar包

在  web.xml  中加入 CXF Service  配置:

<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>/cxfTest/*</url-pattern>
  </servlet-mapping>   

在配置struts2的拦截器时要注意可能会与CXF冲突:

<filter>
      <filter-name>struts2</filter-name>
     <filter-class>com.xxxxxxxx.Struts2Filter</filter-class>
  </filter>
  <filter-mapping>
      <filter-name>struts2</filter-name>
     <url-pattern>/*</url-pattern>
  </filter-mapping>

struts2会拦截cxf的请求,解决方法使用自定义的拦截器:

public class Struts2Filter extends StrutsPrepareAndExecuteFilter {

	public void doFilter(ServletRequest req, ServletResponse response, FilterChain chain)throws IOException, ServletException {

		HttpServletRequest request = (HttpServletRequest) req;
		if(request.getRequestURI().contains("/cxfTest")){
			chain.doFilter(request, response);
		}else{
			super.doFilter(request, response, chain);
		}

	}
	
}

application-cxf.cml:

<?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:cxf="http://cxf.apache.org/core"
    xmlns:jaxws="http://cxf.apache.org/jaxws"
    xmlns:jaxrs="http://cxf.apache.org/jaxrs"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://cxf.apache.org/core
        http://cxf.apache.org/schemas/core.xsd
        http://cxf.apache.org/jaxws
        http://cxf.apache.org/schemas/jaxws.xsd
        http://cxf.apache.org/jaxrs
        http://cxf.apache.org/schemas/jaxrs.xsd">
	<bean id="weatherService" class="com.********.WeatherService">
	</bean>	
	
	<jaxws:server address="/weather">
	    <jaxws:serviceBean >
	         <ref bean="weatherService" />
	    </jaxws:serviceBean>
	</jaxws:server>
	
	
		

</beans>

发布webService之后:

使用

wsimport -s .  http://localhost:8888/WeatherService/cxfTest/weather?wsdl

命令来生成方法。

配置application-cxf.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" xmlns:cxf="http://cxf.apache.org/core"
	xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:jaxrs="http://cxf.apache.org/jaxrs"
	xsi:schemaLocation="
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://cxf.apache.org/core
        http://cxf.apache.org/schemas/core.xsd
        http://cxf.apache.org/jaxws
        http://cxf.apache.org/schemas/jaxws.xsd
        http://cxf.apache.org/jaxrs
        http://cxf.apache.org/schemas/jaxrs.xsd
        ">
     <description>CXF</description>

	<jaxws:client id="weatherClient" address="http://localhost:8888/WeatherService/cxfTest/weather?wsdl" serviceClass="com.*****.WeatherService"></jaxws:client>


</beans>

利用生成的接口进行调用即可。

支持传统C++开发及运行的跨平台的Web网站服务器端环境,建立在Apache平台上,knewcode0.93a版。 测试运行:(测试环境,Windows7) 1、将本目录拷贝到D盘根目录;(如果需要拷贝到其他目录,请自行修改Apache的配置文件“debug\httpd-2.2.25-win32\Apache22\conf\httpd.conf”) 2、运行“D:\knewcode0.93a\StartDebug.bat”启动Apache及knewcode运行环境; 3、在浏览器中,输入“http://127.0.0.1:8090/hello_world.kc”,测试“hello_world_cpp”例子; 4、在浏览器中,输入“http://127.0.0.1:8090/”,测试“exam_blog”例子; 5、“D:\knewcode0.93a\sample\src\webservice_client(c#)”是C#的Webservice客户端例子,可直接运行“webservice_client.exe”测试。 Linux下安装:(测试环境,Ubuntu14.04 32位版) 1、将本目录拷贝到“/home”目录下;(如果需要拷贝到其他目录,请自行修改“kc_apache_mod.conf”和“kc_apache_mod.load”文件) 2、使用超级管理员权限,运行“/home/knewcode0.93a/debug/linux_apache_setup/setup.sh”脚本,拷贝2个配置文件到Apache环境下; 3、修改Apache的相关配置文件,将“/home/knewcode0.93a/sample”目录设置为Apache的主页目录,并设置权限; 4、修改目录权限,设置“/home/knewcode0.93a”目录为可运行和可读写,“/home/knewcode0.93a/sample”目录的所有者改为“www-data”; 5、目前只在Ubuntu14.04 32位版下测试过,其他版本Linux请自行验证,并反馈问题给我,谢谢;目前只支持32位版的Linux。 系统目前尚处于测试阶段,如遇任何问题,请反馈到如下邮箱,谢谢! zogy@163.com ******************************************************************************************** 2015-11-11:knewcode0.93a版 1、增加print的简化关键字“p”; 2、增加“exec”关键字,用于执行自定义脚本; 3、字符串中增加用2个双引号表示1个双引号的转义字符; 4、增加变量定义的“--ref--”选项,用于定义同名外部变量的引用(如无对应的外部变量,则重新定义一个); 5、增加“delay”关键字,用于延迟脚本在特定的位置执行; 6、增加变量定义的“--static--”选项,防止重复定义的变量被覆盖; 7、修复了一些,在负载测试中,因高并发的进程或线程,引起的系统崩溃的bug; 8、修复了db_action和so_session应用中的一些内存泄漏等的bug。 2015-09-21:knewcode0.92a版 增加信号处理,降低因段错误,浮点错误,除0错误等异常,引起的系统崩溃。 2015-09-14:knewcode0.91a版 初始版本。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值