JAX-WS, How do I pass an authentication data in the header?

I'm trying to develop a webservice client using Netbeans 5.5 and JAX-WS 2.0

I can't seem to figure out how to pass authentication parameters in the message header. Is there a simple way to do this? I basically just need to send two string values (userName and password)

Thanks!

WSDL included:

<?xml version="1.0" encoding="UTF-8"?>

<wsdl:definitions targetNamespace="urn:AutoREG"

xmlns:s0="urn:AutoREG" xmlns:xsd="">

<wsdl:types>

<xsd:schema elementFormDefault="qualified" targetNamespace="urn:AutoREG">

<xsd:element name="OpGet" type="s0:GetInputMap"/>

<xsd:complexType name="GetInputMap">

<xsd:sequence>

<xsd:element name="Request_ID" type="xsd:string"/>

</xsd:sequence>

</xsd:complexType>

<xsd:element name="OpGetResponse" type="s0:GetOutputMap"/>

<xsd:complexType name="GetOutputMap">

<xsd:sequence>

<xsd:element name="Assigned_To" type="xsd:string"/>

<xsd:element name="Character" type="xsd:string"/>

<xsd:element name="Decimal" type="xsd:decimal"/>

<xsd:element name="Integer" type="xsd:int"/>

<xsd:element name="Short_Description" type="xsd:string"/>

<xsd:element name="Status" type="s0:StatusType"/>

<xsd:element name="Submitter" type="xsd:string"/>

</xsd:sequence>

</xsd:complexType>

<xsd:simpleType name="StatusType">

<xsd:restriction base="xsd:string">

<xsd:enumeration value="New"/>

<xsd:enumeration value="Assigned"/>

<xsd:enumeration value="Fixed"/>

<xsd:enumeration value="Rejected"/>

<xsd:enumeration value="Closed"/>

</xsd:restriction>

</xsd:simpleType>

<xsd:element name="AuthenticationInfo" type="s0:AuthenticationInfo"/>

<xsd:complexType name="AuthenticationInfo">

<xsd:sequence>

<xsd:element name="userName" type="xsd:string"/>

<xsd:element name="password" type="xsd:string"/>

<xsd:element minOccurs="0" name="authentication" type="xsd:string"/>

<xsd:element minOccurs="0" name="locale" type="xsd:string"/>

<xsd:element minOccurs="0" name="timeZone" type="xsd:string"/>

</xsd:sequence>

</xsd:complexType>

</xsd:schema>

</wsdl:types>

<wsdl:message name="OpGetSoapIn">

<wsdl:part element="s0:OpGet" name="parameters"/>

</wsdl:message>

<wsdl:message name="ARAuthenticate">

<wsdl:part element="s0:AuthenticationInfo" name="parameters"/>

</wsdl:message>

<wsdl:message name="OpGetSoapOut">

<wsdl:part element="s0:OpGetResponse" name="parameters"/>

</wsdl:message>

<wsdl:portType name="AutoREGPortType">

<wsdl:operation name="OpGet">

<wsdl:input message="s0:OpGetSoapIn"/>

<wsdl:output message="s0:OpGetSoapOut"/>

</wsdl:operation>

</wsdl:portType>

<wsdl:binding name="AutoREGSoapBinding" type="s0:AutoREGPortType">

<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>

<wsdl:operation name="OpGet">

<soap:operation soapAction="urn:AutoREG/OpGet" style="document"/>

<wsdl:input>

<soap:header message="s0:ARAuthenticate" part="parameters" use="literal">

</soap:header>

<soap:body use="literal"/>

</wsdl:input>

<wsdl:output>

<soap:body use="literal"/>

</wsdl:output>

</wsdl:operation>

</wsdl:binding>

<wsdl:service name="AutoREGService">

<wsdl:port binding="s0:AutoREGSoapBinding" name="AutoREGSoap">

<soap:address location="http://xxxx/&webService=AutoREG"/>

</wsdl:port>

</wsdl:service>

</wsdl:definitions>

[6159 byte] By [BryanYa] at [2007-10-3 3:44:17]
# 1

OK, so I've done some research and figured out the answer...

In JAX-WS, Username and Password are defined as standard properties on BindingProvider. You can set these properties on RequestContext.

Example:

HelloService service = new HelloService();

Hello proxy = (service.getHelloPort());

((BindingProvider)proxy).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "userfoo");

((BindingProvider)proxy).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "passbar");

BryanYa at 2007-7-14 21:40:27 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...