Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send SOAP request header in Java?

I have a WSDL file (the web-service has written by .NET) and i can generate the java web-service client proxy classes and codes in IntelliJ IDEA 7.0.4 by its tool. the web-service has a soap request header , but i can't see any property or method in auto generated Java proxy classes and codes to set the request header. (but when i use Visual Studio 2008 to generate the proxy classes for C#, an object is created in web-service proxy class as the header so i can set fill it simply)

what should i do in Java?

like image 685
losingsleeep Avatar asked Nov 05 '22 07:11

losingsleeep


2 Answers

I'm not sure what IntelliJ uses to generate proxy classes. AXIS maybe?

I do know that if you want to do this with CXF, when you are defining your client, the best way is to create a class that implement SoapInterceptor and then set it as an outbound Interceptor.

public void handleMessage(SoapMessage message) throws Fault {
           message.getHeaders().add(QName.valueOf("foo"), "bar");
   }

Ultimately though, it's going to be hard for you to figure out the right way to handle this if you don't know the library your IDE is using.

like image 138
jcalvert Avatar answered Nov 09 '22 02:11

jcalvert


All the classes for a complete web service client can be created by wsimport tool included in jdk.

http://download.oracle.com/javase/6/docs/technotes/tools/share/wsimport.html

You only need to specify the wsdl address.

like image 37
elias Avatar answered Nov 09 '22 04:11

elias