webservice中调用本地session,request

1利用apache cxf编写webservice(在此总结并分享,有错误不吝指教(暂时是个小菜鸟。。))

2cxf-servlet中添加元素

<jaxws:endpoint
   id="helloWorld"
   implementor="com.xxx.xxx.impl.HelloWorldServiceImp"
   address="/HelloWorld" />

3导入jetty,jetty-util.jar

4service inteface:

 @WebService
 public interface HelloWorldService{
    public String test();
}

5 service implement:

@WebService(endpointInterface = "com.xxx.xxx.HelloWorldService")
public class HelloWorldServiceImp implements HelloWorldService {
//引入webserviceContext ,提供各web元素

@Resource
 private WebServiceContext context;
 @Override
 public String test() {
  System.out.println(context.getMessageContext().get(MessageContext.SERVLET_CONTEXT));
  return "AA";
 }

}
6测试:

public class Client{


 public Client() {
  // TODO 自动生成构造函数存根
 }

 

 public static void main(String[] args) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
  JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
  factory.setServiceClass(HelloWorldService.class);
  factory.setAddress("http://localhost:8080/xxx/xxx/HelloWorld");
  HelloWorldService client = (HelloWorldService) factory.create();

  System.out.println(client.test());
 }

 

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值