Adding SOAP headers in the JAX-WS
2008-09-03 15:55
501 查看
One of the additions in the JAX-WS RI 2.1 EA3 is a simple way to add SOAP headers for your request.
The official "portable" way of doing this is that you creaate a SOAPHandler
and mess with SAAJ. This works, but Vivek though it's just too much
work for such a simple thing one day, and we all agreed. So we quickly
put together a better way to do this. Here's how to do this:
When you create a proxy or dispatch object, they implement BindingProvider interface. When you use the JAX-WS RI, you can downcast to WSBindingProvider which defines a few more methods provided only by the JAX-WS RI.
This interface lets you set an arbitrary number of Header
object, each representing a SOAP header. You can implement it on your
own if you want, but most likely you'd use one of the factory methods
defined on Headers class to create one.
Once set, it will take effect on all the successive methods. If you'd like to see more factory methods on Headers, please let us know!
We are also talking about adding a switch to wsimport so that you won't have to downcast.
<转自http://weblogs.java.net/blog/kohsuke/archive/2006/11/adding_soap_hea.html>
The official "portable" way of doing this is that you creaate a SOAPHandler
and mess with SAAJ. This works, but Vivek though it's just too much
work for such a simple thing one day, and we all agreed. So we quickly
put together a better way to do this. Here's how to do this:
When you create a proxy or dispatch object, they implement BindingProvider interface. When you use the JAX-WS RI, you can downcast to WSBindingProvider which defines a few more methods provided only by the JAX-WS RI.
This interface lets you set an arbitrary number of Header
object, each representing a SOAP header. You can implement it on your
own if you want, but most likely you'd use one of the factory methods
defined on Headers class to create one.
import com.sun.xml.ws.developer.WSBindingProvider; HelloPort port = helloService.getHelloPort(); // or something like that... WSBindingProvider bp = (WSBindingProvider)port; bp.setOutboundHeader( // simple string value as a header, like <simpleHeader>stringValue</simpleHeader> Headers.create(new QName("simpleHeader"),"stringValue"), // create a header from JAXB object Headers.create(jaxbContext,myJaxbObject) );
Once set, it will take effect on all the successive methods. If you'd like to see more factory methods on Headers, please let us know!
We are also talking about adding a switch to wsimport so that you won't have to downcast.
<转自http://weblogs.java.net/blog/kohsuke/archive/2006/11/adding_soap_hea.html>
相关文章推荐
- Agile PLM --- JAX-WS 2.2 API is required, but an older version was found in the JDK
- JAX-WS 2.2 API is required, but an older version was found in the JDK.
- Using implicit SOAP headers with JAX-WS web services
- 关于用JAX-WS调用webservice异常:Server did not recognize the value of HTTP Header SOAPAction: .
- A Smple JAX-WS Service in the CXF Distribution
- JAX-WS - Soap详解
- JAX-WS创建和处理SOAP消息
- JAX-WS创建和JavaAPI发送和处理SOAP消息实例
- WebService(二)—JDK内置JAX-WS实现SOAP WebService
- JAX-WS中SOAPBinding的3种方式
- JWS ,JAX-WS ,JAX-RS,REST,Restlet,SOAP 相关概念
- CXF JaxWsProxyFactoryBean调用SOAP服务出现异常信息
- CXF系列之JAX-WS:SOAP服务
- MapReduce报错:Error: java.io.IOException: Initialization of all the collectors failed. Error in last collector was :interface javax.xml.soap.Text
- Adding SOAP headers【转】
- Adding the Test API in The ASP.NET Web API Help Page
- java.lang.NullPointerException: Expected timestamp in the Flume event headers, but it was null
- A little bit about Handlers in JAX-WS
- JAVA采用CXF框架开发基于JAX-WS(SOAP)规范的WebService服务器端
- javax.xml.ws.WebServiceException: WSDL Metadata not available to create the proxy, either Service in