7 Replies Latest reply on Mar 19, 2010 5:27 PM by oberiko

    how to set headers in JAX-WS

      Hi All,

      My web service has a method which accepts two parameters one xmlstring and the other is header
      class which has two instance variables username and password.

      when i used wsconsume on my wsdl to generate client side artifacts,it has generated one the method with one parameter.

      Is there any way so that i can pass header object to my web service?

      Any help would be appreciated.

      Thanks in Advance.

      Thanks,
      Pavan.

        • 1. Re: how to set headers in JAX-WS
          camateusno

          Hi friend,
          i have the same problem and i think that the jbossws do it a bad parse to some documents WSDL.

          If you know something thereon, i thank you very much, for several days working on it...

          • 2. Re: how to set headers in JAX-WS
            asoldano

            Just tried to be sure, this is working for me. Could you please post both your wsdl contract and the server implementation (if it is done with JBossWS)? Which version of JBossWS are you using?

            • 3. Re: how to set headers in JAX-WS

              Hi Alessio,

              This is the wsdl

              <?xml version="1.0" encoding="utf-8" ?>
               <wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://McAfeeAsap.com" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://McAfeeAsap.com" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
               <wsdl:types>
               <s:schema elementFormDefault="qualified" targetNamespace="http://McAfeeAsap.com">
               <s:element name="ProcessOrder">
               <s:complexType>
               <s:sequence>
               <s:element minOccurs="0" maxOccurs="1" name="sOrderXML" type="s:string" />
               </s:sequence>
               </s:complexType>
               </s:element>
               <s:element name="ProcessOrderResponse">
               <s:complexType>
               <s:sequence>
               <s:element minOccurs="0" maxOccurs="1" name="ProcessOrderResult" type="s:string" />
               </s:sequence>
               </s:complexType>
               </s:element>
               <s:element name="AuthHeader" type="tns:AuthHeader" />
               <s:complexType name="AuthHeader">
               <s:sequence>
               <s:element minOccurs="0" maxOccurs="1" name="sToken" type="s:string" />
               </s:sequence>
               <s:anyAttribute />
               </s:complexType>
               </s:schema>
               </wsdl:types>
               <wsdl:message name="ProcessOrderSoapIn">
               <wsdl:part name="parameters" element="tns:ProcessOrder" />
               </wsdl:message>
               <wsdl:message name="ProcessOrderSoapOut">
               <wsdl:part name="parameters" element="tns:ProcessOrderResponse" />
               </wsdl:message>
               <wsdl:message name="ProcessOrderAuthHeader">
               <wsdl:part name="AuthHeader" element="tns:AuthHeader" />
               </wsdl:message>
               <wsdl:portType name="McAfee_x0020_Order_x0020_ProcessingSoap">
               <wsdl:operation name="ProcessOrder">
               <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">McAfee Order Processing</wsdl:documentation>
               <wsdl:input message="tns:ProcessOrderSoapIn" />
               <wsdl:output message="tns:ProcessOrderSoapOut" />
               </wsdl:operation>
               </wsdl:portType>
               <wsdl:binding name="McAfee_x0020_Order_x0020_ProcessingSoap" type="tns:McAfee_x0020_Order_x0020_ProcessingSoap">
               <soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
               <wsdl:operation name="ProcessOrder">
               <soap:operation soapAction="http://McAfeeAsap.com/ProcessOrder" style="document" />
               <wsdl:input>
               <soap:body use="literal" />
               <soap:header message="tns:ProcessOrderAuthHeader" part="AuthHeader" use="literal" />
               </wsdl:input>
               <wsdl:output>
               <soap:body use="literal" />
               </wsdl:output>
               </wsdl:operation>
               </wsdl:binding>
               <wsdl:binding name="McAfee_x0020_Order_x0020_ProcessingSoap12" type="tns:McAfee_x0020_Order_x0020_ProcessingSoap">
               <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
               <wsdl:operation name="ProcessOrder">
               <soap12:operation soapAction="http://McAfeeAsap.com/ProcessOrder" style="document" />
               <wsdl:input>
               <soap12:body use="literal" />
               <soap12:header message="tns:ProcessOrderAuthHeader" part="AuthHeader" use="literal" />
               </wsdl:input>
               <wsdl:output>
               <soap12:body use="literal" />
               </wsdl:output>
               </wsdl:operation>
               </wsdl:binding>
               <wsdl:service name="McAfee_x0020_Order_x0020_Processing">
               <wsdl:port name="McAfee_x0020_Order_x0020_ProcessingSoap" binding="tns:McAfee_x0020_Order_x0020_ProcessingSoap">
               <soap:address location="http://testdrive.mcafeeasap.com/ws/mop/mop.asmx" />
               </wsdl:port>
               <wsdl:port name="McAfee_x0020_Order_x0020_ProcessingSoap12" binding="tns:McAfee_x0020_Order_x0020_ProcessingSoap12">
               <soap12:address location="http://testdrive.mcafeeasap.com/ws/mop/mop.asmx" />
               </wsdl:port>
               </wsdl:service>
               </wsdl:definitions>


              and on the server side i don't have the implementation,it is third party service we are using.

              But i knew there is a method processOrder which takes two parameters one is xmlstring and the other is authheader object.

              The Jboss server i am using is Jboss 4.2.1 GA and jbossws is 1.2.1GA.

              Please let me know if you have any suggestions?

              Thanks,
              Pavan

              • 4. Re: how to set headers in JAX-WS
                asoldano

                I think your issue is due to the way the wsdl:message is defined; I would have expected you to have a binding/operation/input block specifying the two part names, instead you have two different messages for the soap header and the soap body. Take a look at the PingService.wsdl of the webparam samples in the binary distribution for an example.

                • 5. Re: how to set headers in JAX-WS

                  Hi Alessio,

                  Thanks for the reply.

                  But this wsdl is third party vendor where i cannot change.

                  Actually i am migrating the webservice which talks to third party vendor webservice from Weblogic to jboss.

                  In weblogic it is creating the method with two parameters but in jboss it is not.

                  Is there any way we can send header parameter with out editing WSDL?

                  Thanks
                  Pavan

                  • 6. Re: how to set headers in JAX-WS
                    asoldano

                    I investigated this a bit further... first of all, the reason why you don't get the parameter corresponding to the soap header is that the JAX-WS specs say that only the wsdl:part from the abstract portion of the contract (i.e. the wsdl:portType section) are mapped to Java method parameters.
                    I see three possible solutions to this, unfortunately they're all not so easy / for beginners:
                    - manually modify the wsdl before consuming it, in order to let wsconsume generate the soap header parameter too
                    - create a SOAPHandler and mess with SAAJ to manually add the header when sending the message
                    - leverage SunRI tool (wsimport), which starting from v. 2.1.3 has a new option -XadditionalHeaders that map additional headers in wsdl:binding section as method parameters.

                    • 7. Re: how to set headers in JAX-WS
                      oberiko

                      Sorry to drag up an old message like this, but I don't see a newer one on the same topic.

                      Are the three solutions presented still the only way of handling  authenication via headers within the operation.  For example, a WSDL I'm trying to build a client for has the following:

                      {code:xml}

                      <?xml version="1.0" encoding="utf-8"?>
                      <wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://ws.myWebService.net" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://ws.myWebService.net" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
                        <wsdl:types>
                          <s:schema elementFormDefault="qualified" targetNamespace="http://ws.myWebService.net">
                            <s:element name="myOperation">
                              <s:complexType>
                                <s:sequence>
                                  <s:element minOccurs="1" maxOccurs="1" name="isSecureMode" type="s:boolean" />
                                </s:sequence>
                              </s:complexType>
                            </s:element>
                            <s:element name="myOperationResponse">
                              <s:complexType>
                                <s:sequence>
                                  <s:element minOccurs="0" maxOccurs="1" name="myOperationResult" type="s:string" />
                                </s:sequence>
                              </s:complexType>
                            </s:element>
                            <s:element name="AuthenticationXML" type="tns:AuthenticationXML" />
                            <s:complexType name="AuthenticationXML">
                              <s:sequence>
                                <s:element minOccurs="0" maxOccurs="1" name="User" type="s:string" />
                                <s:element minOccurs="0" maxOccurs="1" name="Password" type="s:string" />
                              </s:sequence>
                              <s:anyAttribute />
                            </s:complexType>
                          </s:schema>
                        </wsdl:types>
                        <wsdl:message name="myOperationSoapIn">
                          <wsdl:part name="parameters" element="tns:myOperation" />
                        </wsdl:message>
                        <wsdl:message name="myOperationSoapOut">
                          <wsdl:part name="parameters" element="tns:myOperationResponse" />
                        </wsdl:message>
                        <wsdl:message name="myOperationAuthenticationXML">
                          <wsdl:part name="AuthenticationXML" element="tns:AuthenticationXML" />
                        </wsdl:message>
                        <wsdl:message name="SendDataAuthenticationXML">
                          <wsdl:part name="AuthenticationXML" element="tns:AuthenticationXML" />
                        </wsdl:message>
                      <wsdl:portType name="myPort">
                        <wsdl:operation name="myOperation">
                         <wsdl:input message="tns:myOperationSoapIn" />
                         <wsdl:output message="tns:myOperationSoapOut" />
                        </wsdl:operation>
                        </wsdl:portType>
                        <wsdl:binding name="myPort12" type="tns:myPort">
                          <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
                          <wsdl:operation name="myOperation">
                            <soap12:operation soapAction="myWebService:myOperation" style="document" />
                            <wsdl:input>
                              <soap12:body use="literal" />
                              <soap12:header message="tns:myOperationAuthenticationXML" part="AuthenticationXML" use="literal" />
                            </wsdl:input>
                            <wsdl:output>
                              <soap12:body use="literal" />
                            </wsdl:output>
                          </wsdl:operation>
                        </wsdl:binding>
                        <wsdl:service name="myWebServiceWS">
                          <wsdl:port name="myPort11" binding="tns:myPort11">
                            <soap:address location="https://devws.myWebService.myDomain.net/myWebServicews/myWebServicews.asmx" />
                          </wsdl:port>
                          <wsdl:port name="myPort12" binding="tns:myPort12">
                            <soap12:address location="https://devws.myWebService.myDomain.net/myWebServicews/myWebServicews.asmx" />
                          </wsdl:port>
                        </wsdl:service>
                      </wsdl:definitions>

                      {code}

                      With WsConsume, I don't get the option to add Authentication elements to my methods and setting the binding properties does nothing.