cxf webservice 服务端使用注解的方式接收客户端请求头中的参数@WebParam

1 篇文章 0 订阅
1 篇文章 0 订阅

使用@WebParm

soap请求无论是接收Header还是Body中的key-value值都是使用@WebParam这个注解,区别是接收Header时,要把参数header设置为true(默认为false)。

@WebParam(name = "hostAddress", header = true)  捕捉header中的key-value

@WebParam(name = "username") 捕捉body中的key-value

举例说明

下面是soap请求示例

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:log="http://LoginService">
   <soapenv:Header>
   	<log:hostAddress>abc</log:hostAddress>
   	<log:macAddress>tan</log:macAddress>
   </soapenv:Header>
   <soapenv:Body>
      <log:login>
         <username>naoms</username>
         <password>123456</password>
      </log:login>
   </soapenv:Body>
</soapenv:Envelope>

下面是服务端接收参数示例:

@WebService(name = "LoginService",
        targetNamespace = "http://LoginService")
public interface LoginService {

    @WebMethod
    @WebResult(name = "LoginResult")
    LoginResult login(@WebParam(name = "username") String username, @WebParam(name = "password") String password
            , @WebParam(name = "hostAddress", header = true) String hostAddress, @WebParam(name = "macAddress", header = true) String macAddress
            );
}

从@WebParam的源码可以看出,header默认为false,false是接收body中的key-value,true是接收header中的key-value

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER})
public @interface WebParam {
    String name() default "";

    String partName() default "";

    String targetNamespace() default "";

    WebParam.Mode mode() default WebParam.Mode.IN;

    boolean header() default false;

    public static enum Mode {
        IN,
        OUT,
        INOUT;

        private Mode() {
        }
    }
}

 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值