Apache CXF: 如何为 Web 请求增加定制的 HTTP header?
来源:互联网 发布:极简欧洲史 知乎 编辑:程序博客网 时间:2024/06/01 07:41
转自:http://simpleframework.net/blog/v/57763.html
HTTP协议中,HTTP 头部字段是请求和响应消息头的组成部分。它们定义HTTP事务的操作参数,携带有客户端浏览器、请求压面、服务器以及其他更多的信息。
下面是使用CXF(v2.4.0)为Web服务增加HTTP headers的示例:
/*** @author Singaram Subramanian**/ /* Create a ClientProxyFactoryBean reference and assign it an instance of JaxWsProxyFactoryBean, a factory for creating JAX-WS proxies.This class provides access to the internal properties used to set-up proxies. Using it provides more control than the standard JAX-WS APIs. */ ClientProxyFactoryBean factory = new JaxWsProxyFactoryBean();factory.setServiceClass(singz.ws.cxf.sample.SampleServiceInterface.class); // Set the web service endpoint URL herefactory.setAddress("http://xxx.xxx.com/services/SampleService/v1"); SampleServiceInterface serviceClient = (SampleServiceInterface) factory.create(); // Get the underlying Client object from the proxy object of service interfaceClient proxy = ClientProxy.getClient(serviceClient); // Creating HTTP headersMap<String, List<String>> headers = new HashMap<String, List<String>>();headers.put("XXX-SOA-SERVICE-NAME", Arrays.asList("SampleService"));headers.put("XXX-SOA-APP-NAME", Arrays.asList("SampleServiceAppv1")); // Add HTTP headers to the web service requestproxy.getRequestContext().put(Message.PROTOCOL_HEADERS, headers); // If you want to log the SOAP XML of outgoing requests and// incoming responses at client side, you can leave this uncommented. It'll be helpful in debugging.proxy.getOutInterceptors().add(new LoggingOutInterceptor());proxy.getInInterceptors().add(new LoggingInInterceptor());
如果所用的 CXF 版本下于 2.4.0,使用MultivaluedMap,将发现定制的 Http headers会被或略,而在 CXF 论坛已发现一Bug请求认为这是一个问题:定制的Http headers 会遗失,若 CXF 拦截器不使用 MultivaluedMap(https://issues.apache.org/jira/browse/CXF-3408)。
【原文】http://java.dzone.com/articles/apache-cxf-how-add-custom-http
- Apache CXF: 如何为 Web 请求增加定制的 HTTP header?
- 常用的http请求header
- http请求的header body
- 一个http请求的响应报文即response,头部即header,可以任意增加属性吗,即自定义header?
- Java用org.apache.http.client的HttpClient发送Post请求 可获取返回Header
- Java--org.apache.http.client的HttpClient发送Post请求,获取返回Header
- Java用org.apache.http.client的HttpClient发送Post请求 可获取返回Header
- Java用org.apache.http.client的HttpClient发送Post请求 可获取返回Header
- 如何在 SOAP 接口调用的 Http header 中增加字段
- 为ListView增加Header
- 为ListView增加Header
- [转]客户端HTTP请求的Header信息
- http请求协议header的使用
- HTTP请求的header头解析
- HTTP请求的header头解析
- Python发送带header的http请求
- HTTP请求的header头解析
- 为你详细解读HTTP请求头(header)的具体含意
- hud 1016 prime ring problem
- 如何通过批处理来执行JAVA应用程序
- sphinx sphinxse 扩展系统列(Matchestotal、Matchesfound、Querymsec),显示匹配总行数、查询时间等
- python3.2 实现在同一行打印,实现进度条效果
- 应用程序设置成服务程序
- Apache CXF: 如何为 Web 请求增加定制的 HTTP header?
- 连续数的公倍数 为什么1小时有60分钟,而不是100分钟呢?这是历史上的习惯导致。事实上,它是1至6的每个数字的倍数。即1,2,3,4,5,6都是可以除尽60。
- 移植FFMPEG到VS2008系列之二
- struts配置的result绝对路径和相对路径
- ofstream和ifstream详细用法
- js实现C#的Server.Encode和Server.Decode
- 数组指针和指针数组的区别
- 使用 sp_executesql和execute
- sql查询当天的记录