users@jax-ws.java.net

How do I attach a soap message?

From: <ddelponte_at_wi.rr.com>
Date: Thu, 03 May 2007 12:35:20 -0500

I've generated a web service client in netbeans 5.5 with JAX-WS 2.0.
I've attached a handler to this client. The outgoing message is
intercepted by the handler and I modify the MessageContext object by
adding a SOAPMessage object.

The problem is, my soap is not appearing in the outgoing message. Can
anyone please help? My handler method is listed below:

public boolean handleMessage(SOAPMessageContext messageContext) {
        SOAPFactory sf;
        MessageFactory mf;
        try {
            mf = MessageFactory.newInstance();
            sf = SOAPFactory.newInstance();
            SOAPMessage message = messageContext.getMessage();
            
            // Add soap action to header
            MimeHeaders hd = message.getMimeHeaders();
            hd.addHeader("SOAPAction", "http://blah/blah");
            
            //Create objects for the message parts
            SOAPPart soapPart = message.getSOAPPart();
            SOAPEnvelope envelope = soapPart.getEnvelope();
            if (envelope.getHeader() == null) {
                envelope.addHeader();
            }
            SOAPBody body = envelope.getBody();
            
            // Add FFI info to header
            SOAPHeader header = message.getSOAPHeader();
            Name ffiName = sf.createName("FFI", "", "http://blah.com/");
            SOAPHeaderElement headerElement =
header.addHeaderElement(ffiName);
            
            //Populate the body of the message
            Name bodyName = sf.createName("getPrice", "ns1",
"urn:xmethods-BNPriceCheck");
            SOAPBodyElement bodyElement = body.addBodyElement(bodyName);
            Name name = sf.createName("isbn");
            SOAPElement isbn = bodyElement.addChildElement(name);
            isbn.addTextNode("0596002432");
            
            //Display the request sent
            System.out.println("SOAP Request Sent:");
            messageContext.getMessage().writeTo(System.out);
        } catch (IOException ex) {
            ex.printStackTrace();
        } catch (SOAPException ex) {
            ex.printStackTrace();
        }
        
        return true;
    }


I may be overlooking something simple, but please help if you can.

Thanks,

Dean

----- Original Message -----
Date: Wed, 2 May 2007 12:44:41 -0400
From: Murali Gunasekaran <Murali_Gunasekaran_at_webMethods.com>
Subject: How do I attach soap header?


Dean,
You can try adding handlers programmatically by either,
1. Implementing the HandlerResolver interface and adding your soap
message custom headers via a handler... and setting your handler
resolver to the service instance, or
2. Set a handler chain (list of handlers) with your handler to the
Binding obtained from the port/dispatch

You should be able to use the SAAJ api to add your soap headers in the
handleMessage(SOAPMessageContext) of your soap handler...

Hope it helps,
Murali


-----Original Message-----
From: ddelponte_at_wi.rr.com [mailto:ddelponte_at_wi.rr.com]
Sent: Wednesday, May 02, 2007 12:22 PM
To: users_at_jax-ws.dev.java.net
Subject: Re: RE: How do I attach soap header?

Murali,

Thank you for your help. The problem I'm having is that I need to use
JAX-WS 2.0... not 2.1 so the information in the link is not relative.

The web service to which I am trying to connect is protected by:
1. Custom soap header which must be validated before access to the
service is granted
2. NTLM

I can never get to the web service because I am failing the initial
validation which requires a custom header be in place.


The code generated by Netbeans goes through the following steps:
1. Instantiate the service object
2. Instantiate the port object
    - It is in this step that (I think) it attempts to validate the wsdl
and cannot
      because it is not allowed access to the web service because the
request does
      not contain the proper soap header information.
3. Request is sent to the web service, but intercepted by the handler.
 I wish to add soap headers at this point, but have been unable too.

Does this make sense or is clarification needed?

Thanks again,

Dean

----- Original Message -----
From: Murali Gunasekaran <Murali_Gunasekaran_at_webMethods.com>
Date: Wednesday, May 2, 2007 9:48 am
Subject: RE: How do I attach soap header?
To: users_at_jax-ws.dev.java.net

> Dean,
> Check this article
>
http://weblogs.java.net/blog/kohsuke/archive/2006/11/adding_soap_hea.htm
> l
>
> If portability is not a problem you can try this approach...
>
> Murali
>
> -----Original Message-----
> From: ddelponte_at_wi.rr.com [mailto:ddelponte_at_wi.rr.com]
> Sent: Tuesday, May 01, 2007 5:09 PM
> To: users_at_jax-ws.dev.java.net
> Subject: How do I attach soap header?
>
> Hi everyone,
>
> I'm using Netbeans 5.5 to generate a web service client from a wsdl
> (this is a Swing app). I need to add a custom soap header to the web
> service request. Without this information, my request will be
> rejectedby the web service. How do I do this???? I've found some
> scatteredinformation talking about Handlers, but haven't found any
> good (simple
> :) ) examples to assist me.
>
> Any and all help would be greatly appreciated.
>
> Thanks,
>
> Dean
>
> --------------------------------------------------------------------
> -
> To unsubscribe, e-mail: users-unsubscribe_at_jax-ws.dev.java.net
> For additional commands, e-mail: users-help_at_jax-ws.dev.java.net
>
> --------------------------------------------------------------------
> -
> To unsubscribe, e-mail: users-unsubscribe_at_jax-ws.dev.java.net
> For additional commands, e-mail: users-help_at_jax-ws.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jax-ws.dev.java.net
For additional commands, e-mail: users-help_at_jax-ws.dev.java.net