Adding SOAP headers【转】
来源:互联网 发布:拼多多是什么软件 编辑:程序博客网 时间:2024/06/16 05:32
Adding SOAP headers in the JAX-WS RI is easier in 2.1 EA3
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 toWSBindingProvider 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 onHeaders 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 onHeaders, please let us know!
We are also talking about adding a switch to wsimport so that you won't have to downcast.
- Java Web Services and XML
- Login orregister to post comments
- Printer-friendly version
- kohsuke's blog
- 10760 reads
- Adding SOAP headers【转】
- Adding SOAP headers in the JAX-WS
- SOAP headers
- Adding SVN Information to File Headers Revisited
- Adding headers and footers to RecyclerView.
- CXF-使用interceptor处理Soap Headers
- Build Secure Web Services With SOAP Headers and Extensions
- Using implicit SOAP headers with JAX-WS web services
- 一个简单的基于SOAP headers的WebService式身份验证
- Adding A System Call(转)
- How to pass SOAP headers into python SUDS that are not defined in WSDL file
- iText - Adding PDF bookmark and anchor (转)
- soap浅谈(转)
- 浅谈 SOAP(转)
- SOAP
- SOAP
- SOAP
- SOAP
- Ubuntu 10.10下Android源码编译环境的搭建
- zoj 1889 ones (同余定理)
- 滤波电容的选择
- 量子物理史话 第三章 火流星
- windows 7 下让 Delphi 2010 开发的程序具备UAC管理员权限
- Adding SOAP headers【转】
- c#多线实例
- 解决弹出的窗口window.open会被浏览器阻止的问题
- Ubuntu 10.04 下pdf显示乱码的解决方法
- php函数前面加&符号的意思是函数的引用
- 网络协议的三要素
- 资治通鉴,卷八十五,晋惠帝也有明白的时候
- 黑马程序员—学习笔记之SQL数据分组、限制结果集行数
- fatjar导出的jar文件双击执行时提示could not find the main class
Comments
Adding SOAP headers in the
by rdelaplante - 2010-11-09 09:15
This 2006 example of the Headers.create(jaxbContext, myJaxbObject) assumes the reader already has a reference to a jaxbContext. From what I've read it can be as easy as JAXBContext.newInstance(myJaxbObject) or JAXBContext.newInstance("jaxb.objects.package"), however in 2010 the Headers.create method takes a JAXBRIContext, not a JAXBContext. JAXBRIContext has the same newInstance methods, but there is only one newInstance method signature that returns a JAXBRIContext needed by Headers.create. It looks very long and complicated, and I don't know how to fill it in. In 2010 is there an easy way for developers to add a JAXB object graph into a JAXWS SOAP header? Thanks.
<p> </p> <p><strong>com.sun.xml.bind.api.JAXBRIContext ...
by Erkam - 2011-07-15 05:36
com.sun.xml.bind.api.JAXBRIContext extends javax.xml.bind.JAXBContext, so you can cast it.
Be careful not to mix namespaces, there are homonymous classes with "internal" in the FQCN that should not be used. For example,com.sun.xml.internal.bind.api.JAXBRIContext
Does this solution works with JAX-WS RI 2.1.1?
by nehalshah50 - 2010-03-31 12:30
I tried using your solution and I am getting following error?java.lang.ClassCastException: $Proxy135
I need to add SOAP headers and I can't find solution. I tried using the Handler and that doesn't work either. For some reason it doesn't invoke the handler I wrote. Is it because of JAX-WS version I m using?
Try this
by sanju_dear - 2010-03-31 17:23
I have spent a lot of time searching for a quick and neat solution for the same problem but could not find anything. But the following article was useful:http://soalogic.blogspot.com/It worked for me, but.....
by jonathanvila - 2010-02-25 05:51
Hello Kohsuke.I've tried your code and is working for me, but I need to add some attributes to the headers created..... as follows :
< User Type="company" > myusersname < /User >
How can I do that ?
Adding an attribute to a soap header
by devfactor - 2010-04-09 21:32
Hello, I am very new to this, so pardon me if I didn't understand your question correctly. The following works for me inside a message handler.
Hope this helps. I have just create variables of type javax.xml.soap.Name for this exercise. But this is usually generated by xmlbeans or whatever tools you may be using. Since I am new to this stuff, I really have no idea if a message handler is the appropriate place to insert soap headers, etc. I hope someone else can clarify that. BTW, how to add formatted code in my comments? Sorry for editing the message so many times. :( I hope you did not receive an email for each time I modified this message.public boolean handleMessage(SOAPMessageContext messageContext) {
SOAPMessage msg = messageContext.getMessage();
SOAPHeader header = msg.getSOAPHeader();
// get the part
SOAPPart soapPart = msg.getSOAPPart();
// get the envelope from the part
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
// add a header to the envelope
header = soapEnvelope.addHeader();
// add a namespace declaration. headers MUST be "namespace-qualified"
header.addNamespaceDeclaration("hehe", "http://www.hehe.org");
// now add the child element User
SOAPElement soapElement = header.addChildElement(UserName);
// then add an attribute to the child element
soapElement.addAttribute(TypeName, "company");
// and finally add the value
soapElement.addTextNode("myusername");
}
Name UserName = new Name() {
public String getLocalName() {return "LocalNameUser";}
public String getQualifiedName() {return "User";}
public String getPrefix() {return "hehe";}
public String getURI() {return "http://www.hehe.org";}
};
Name TypeName = new Name() {
public String getLocalName() {return "LocalNameType";}
public String getQualifiedName() {return "Type";}
public String getPrefix() {return "hehe";}
public String getURI() {return "http://www.hehe.org";}
};
How are SOAP headers accessed in a Web service operation?
by pshrosbree - 2009-10-08 02:46
I have a client application that sets up some SOAP headers to specify a message ID and a callback URL, calls the Web service operation, and the Web service operation is supposed to callback asynchronously on the SOAP header provided URL. I can cheat, by creating a singleton map that maps MessageIDs to URLs, which is populated by the handler chain, and the operation can access this map, but this is not scalable, and it is nasty. The best would be if there were a way to access the SOAP headers inside the operation. In the operation I have access to the WebServiceContext, and so the MessageContext, and so the HTTP Request headers, but I can’t see how to access the SOAP headers. Is there a portable to do this in Metro 1.4?To answer my own
by pshrosbree - 2009-10-08 06:27
To answer my own question: UseHeaderList headers = (HeaderList) messageContext.get(JAXWSProperties.INBOUND_HEADER_LIST_PROPERTY);
How to set header in Web service response?
by contactasmi - 2009-09-24 03:45
How to set the Header in response with different attribute values in it? followinn sets that in body of the response instead of header.? ABCHeader header = new ABCHeader(); header = this.setJDCHeader(header); response.setHeader(header);contactasmi wrote:How to set
by GYoga2025 - 2011-03-24 14:51
The following link solved my issue. simple and clear. Using jaxb context messed up my namespace in the headers.
http://javadb.com/using-a-message-handler-to-alter-the-soap-header-in-a-...