The Source for Java Technology Collaboration
User: Password:



Rama Pulavarthi

Rama Pulavarthi's Blog

Using Addressing With JAX-WS Clients without WSDL

Posted by ramapulavarthi on January 21, 2007 at 01:54 AM | Comments (3)


Addressing can be enabled on client by having a wsdl with <wsaw:UsingAddressing/> in the wsdl definitions or enabling AddressingFeature while creating the client proxy. In EA3, Although Addressing is enabled, for it to work the clients (esp. Dispatch) have to be created with wsdl, otherwise Addressing headers are not sent automatically by the JAX-WS Runtime.

The reason was wsa:Action header which is mandatory comes from wsdl either it be explicitly specified or implicitly computed using wsdl:operation's definition. All other addressing headers can be computed without WSDL or assume default values. The same wsa:Action header is used as SOAPAction http header.

JAX-WS API provides way to set SOAPAction header in the message context. Using this mechanism, Recently I made a fix to use Addressing runtime. Now for Addressing to work, WSDL is no more needed. All you need to do is set BindingProvider.SOAPACTION_URI_PROPERTY property. An example below shows its usage.

Service service = Service.create(SERVICE_QNAME);
service.addPort(PORT_QNAME, SOAPBinding.SOAP11HTTP_BINDING, "http://localhost:8080/service/example");
Dispatch<Source> dispatch = service.createDispatch(PORT_QNAME, Source.class,
Service.Mode.PAYLOAD, new AddressingFeature());
dispatch.getRequestContext().put(BindingProvider.SOAPACTION_USE_PROPERTY, true);
dispatch.getRequestContext().put(BindingProvider.SOAPACTION_URI_PROPERTY,"http://example.com/action/dothis");
dispatch.invoke(requestSrc);

If you set these properties, JAXWS Runtime  takes care of sending all the addressing headers in the SOAP Message.
These are the messages with Addressing disabled(default)/enabled with the dispatch client.

Addressing not enabled:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
  <S:Body>
    <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
      <S:Body>
<addNumbers xmlns="http://example.com/">
  <number1>10</number1>
  <number2>10</number2>
</addNumbers>
</S:Body>
    </S:Envelope>
  </S:Body>
</S:Envelope>

Addressing enabled:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
  <S:Header>
    <To xmlns="http://www.w3.org/2005/08/addressing">http://localhost:8080/service/example</To>
    <Action xmlns="http://www.w3.org/2005/08/addressing">http://example.com/action/dothis</Action>
    <ReplyTo xmlns="http://www.w3.org/2005/08/addressing">
    <Address>http://www.w3.org/2005/08/addressing/anonymous</Address>
</ReplyTo>
    <MessageID xmlns="http://www.w3.org/2005/08/addressing">uuid:45c2f4eb-48ea-4
be4-8376-05535313ef9f</MessageID>
  </S:Header>
  <S:Body>
    <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
      <S:Body>
<addNumbers xmlns="http://example.com/">
  <number1>10</number1>
  <number2>10</number2>
</addNumbers>
</S:Body>
    </S:Envelope>
  </S:Body>
</S:Envelope>
 
Hope this makes it easy to use Addressing with Dispatch.

Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment

  • Hello Rama.

    I tried to follow your instructions but had some Problems.
    First, I did not find anything like AddressingFeature class in WS2.1 EA3. What release do I have to use to get to the result?
    Then I tried to use the tag in the WSDL and regenerate the webservice client artifacts - without the desired result. The generates are the same (using jaxws 2.0 from netbeans 5.5). Replacing netbeans' jaxws with the 2.1 EA3 classes also does'nt produce the expected results (generates some realy weird stuff that does not compile).

    Following your example, how do I use the dispatcher, when the webservice resource is injected through a @WebServiceReference annotation?

    Is there any way to set the Addressing feature using annotations?

    With kind regards,
    Alexander.

    Posted by: sahlix on January 31, 2007 at 11:40 PM

  • Rama,

    Also, how can you change the ReplyTo and other fields in the WS-Addressing headers?

    For example, my client has a Web Service Endpoint up and the server is to generate callbacks to this endpoint. I would like to use the ReplyTo Field to specify the url of the callback interface.

    Can you offer any guidance?

    Posted by: ronak2121 on July 20, 2007 at 02:32 PM

  • Good example.

    But is there any way to specify use version 2004/08 instead of default?
    This version is specified in AddressingVersion.MEMBER.

    How to do this?

    Posted by: exgorth on October 04, 2007 at 04:57 AM



Only logged in users may post comments. Login Here.


Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds