Hi all, 

Here is some code that provide client side support for soap:header entry in
the WSDL operation binding.  

Modified files:
  xml-axis/java/src/org/apache/axis/client/Service.java
  xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaStubWriter.java
Added files:
  xml-axis/java/src/org/apache/axis/serviceContext/ServiceContext.java  
  xml-axis/java/src/org/apache/axis/serviceContext/HeaderKey.java
  xml-axis/java/src/org/apache/axis/wsdl/toJava/Headers.java
  xml-axis/java/src/org/apache/axis/wsdl/toJava/Header.java

>From a high level point of view:

1 - WSDL2Java now adds the appropriate setHeader() before call.invoke() as
well as the appropriate updateHeader() following call.invoke()

2 - I have added a ServiceContext class stored in the Service that currently
simply stores a Hashtable of all the service's header.  The key to the hash
is a HeaderKey (which could/should (not sure) be replace by a String if
someone can confirm that the key to a header is the part name...)  I did
create HeaderKey because originaly I was using the combination of the part
and the message to find a Header in the ServiceContext hash.

I believe that this will not make its way into the build before Beta-2
(right?) so I am sending it to get feedback, let me know if my understanding
of soap:header is right and what should be changed may this be the case.

To try it simply have some entry like this in your input operation :
<soap:header required="false" message="tns:tracking" part="tracking"
use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>

--
Sylvain

This message may contain privileged and/or confidential information.  If you
have received this e-mail in error or are not the intended recipient, you
may not use, copy, disseminate or distribute it; do not open any
attachments, delete it immediately from your system and notify the sender
promptly by e-mail that you have done so.  Thank you.
          

Attachment: ServiceContext.java
Description: Binary data

Attachment: HeaderKey.java
Description: Binary data

Attachment: Header.java
Description: Binary data

Attachment: Headers.java
Description: Binary data

Index: xml-axis/java/src/org/apache/axis/client/Service.java
===================================================================
RCS file: /home/cvspublic/xml-axis/java/src/org/apache/axis/client/Service.java,v
retrieving revision 1.49
diff -r1.49 Service.java
60a61,63
> import org.apache.axis.message.SOAPHeaderElement;
> import org.apache.axis.serviceContext.*;
> 
69a73,74
> import javax.xml.soap.*;
> 
115a121
>     private ServiceContext       serviceContext  = new ServiceContext();
674a681,735
>     
>     /**
>      * This method allows a service consumer to set a SOAP Header object defined 
>through 
>      * <b>soap:header</b> operation element.  Every opertaion refering to this 
>soap:header part in their binding 
>      * will send this object as a SOAP Header.  The returned object will overwrite 
>the current Service's ServiceContext 
>      * instance of this part object.
>      * @author Sylvain St-Germain ([EMAIL PROTECTED])
>      * @return void
>      */
>     public void setHeader(String partName, Object header) {      
>       serviceContext.setHeader( new HeaderKey("", partName), header);      
>     }
> 
>     /**
>      * This method is meant to be used by the service consumer to retreive a 
>Service's ServiceContext header object.  
>      * It returns the current object stored for the given part name.  The object is 
>either the one previously set by the 
>      * user before the call to invoke or the object returned by the service provider 
>for that part.
>      * @author Sylvain St-Germain ([EMAIL PROTECTED])
>      * @return Object
>      */    
>     public Object getHeader(String partName) {                
>       return serviceContext.getHeader("", partName);
>     }
> 
>     /**
>      * This method is meant to be used by the BindingStub to set the requested 
>header onto the Call object 
>      * just before the call gets invoked. 
>      * @author Sylvain St-Germain ([EMAIL PROTECTED])
>      * @return SOAPHeaderElement
>      */    
>     public SOAPHeaderElement getHeader(String namespace, String partName) {          
> 
>       return new SOAPHeaderElement(namespace, partName, serviceContext.getHeader("", 
>partName) );
>     }
>     
>     /**
>      * This method is provided with the soap:header part name and the namespace so 
>it can update the 
>      * Header object stored in the Service's ServiceContext using the one retreived 
>in the response
>      * @author Sylvain St-Germain ([EMAIL PROTECTED])
>      * @return void
>      */
>     public void updateHeader(String namespace, String partName) {             
> 
>                       try {      
>                               org.apache.axis.Message              response = 
>getCall().getMessageContext().getResponseMessage();      
>                               org.apache.axis.message.SOAPEnvelope env      = 
>response.getSOAPEnvelope();
>                       
>                               SOAPHeaderElement header = 
>env.getHeaderByName(namespace, partName, true);
>                       
>                               serviceContext.setHeader(new HeaderKey("", partName), 
>header.getObjectValue());
> 
>                       } catch ( Exception e ) {
>                         // TBD : Swallow it... for now...
>                               System.out.println("Header update problem : " + e);    
>       
>                       }
>     }    
Index: xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaStubWriter.java
===================================================================
RCS file: 
/home/cvspublic/xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaStubWriter.java,v
retrieving revision 1.55
diff -r1.55 JavaStubWriter.java
70a71
> import javax.wsdl.extensions.soap.SOAPHeader;
73a75
> import java.util.Enumeration;
231a234,235
>             Headers headers = new Headers();
> 
259a264,266
>               
>                 boolean namespaceFound = false;
>                 
262c269
<                     if (obj instanceof SOAPBody) {
---
>                     if ( !namespaceFound && obj instanceof SOAPBody) {
269c276,281
<                         break;
---
> 
>                         namespaceFound = true;
>                                                     
>                     } else if (obj instanceof SOAPHeader) {
>                       
>                         headers.list.add( new Header((SOAPHeader)obj) );             
>                                                                                      
>         
285c297
<                         operation, parameters, soapAction, namespace, isRPC);
---
>                         operation, headers, parameters, soapAction, namespace, 
>isRPC);
468a481
>             Headers headers,
578a592,599
>         // Set the headers
>         pw.println();
>         Enumeration headersEnum = headers.list.elements();
>         while ( headersEnum.hasMoreElements() ) {
>           Header h = (Header)headersEnum.nextElement();          
>               pw.println("        call.addHeader( call.getService().getHeader( \"" + 
>namespace + "\", \"" + h.getPartName() + "\"));");
>         }                
>         
606a628,636
>         
>         // Update the headers
>         headersEnum = headers.list.elements();
>         while ( headersEnum.hasMoreElements() ) {
>           Header h = (Header)headersEnum.nextElement();          
>               pw.println("        call.getService().updateHeader( \"" + namespace + 
>"\", \"" + h.getPartName() + "\");");
>         }       
>         
>         pw.println();       

Reply via email to