java ssh cxf_SSH整合cxf 发布web Service

S2S4H3整合cxf

准备:

我是已经有了一个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放行

cxf

org.apache.cxf.transport.servlet.CXFServlet

30

sshserver

/sshserver/*

struts2

org.hxb.struts2.Filter.LetCxfGoFilter

③在spring的配置文件ApplicationContext.xml中添加新的配置如下:

其中红色字体为cxf新添的配置。

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">

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;

/**

*

自定义Filter 为cxf放行

*

*/

public class LetCxfGoFilter extends StrutsPrepareAndExecuteFilter {

@Override

public 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的接口:

packageorg.hxb.WebService;

importjavax.jws.WebMethod;

importjavax.jws.WebService;

@WebService

publicinterfaceServer {

@WebMethod

publicString getGasData();

}

}

⑥Web Service的实现:

packageorg.hxb.WebService;

importjavax.jws.WebService;

@WebService

publicclassServerImplimplementsServer {

@Override

publicString getGasData() {

System.out.println("INFO:Server已经启动!");

return"Service";

}

}

⑦启动后:浏览器访问:http://localhost:8080/sshtest/sshserver/ServerPublish?wsdl

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值