Hi,

I am trying to fill in the soap header of the soap message using WSIF. When I view the 
generated SOAP message it doesn't contain the header element set using the WSIF API. I 
am not sure if my problem is not using the API correctly or missing jar libraries (I 
have the xercesImpl.jar, xmlParserAPIs.jar, mail.jar, activation.jar, wsif.jar, 
qname.jar, commons-logging-api.jar and axis.jar)

I am running in a Websphere environment and so got a lot of these jars from this 
environment. Looking through the code there were references to some axis classes and 
so I added axis.jar onto the class path. Before I did this I did not receive any 
ClassNotFoundExceptions.

I am not sure if I am setting up the element correctly. That is the only thing I can 
think of for not being able to generate the soap header. makeHeaders() sets up the 
headers programatically using the DOM and makeHeaderAlternate() sets up the dom by 
parsing a string.

Any help would be appreciated.
Tx
Jonathan

I am using the following code:
WSIFOperation operation = port.createOperation(operationName, inputName, outputName);
WSIFMessage headers = new WSIFDefaultMessage(); // or use -> operation.getContext();
Element el = makeHeaders(); // or makeHeadersAlternate()
List list = new Vector();
list.add(header);
headers.setObjectPart( WSIFConstants.CONTEXT_REQUEST_SOAP_HEADERS, list );
operation.setContext( headers );     

// Invoke the operation
// Get back success status of invocation, however
//  soap header is not set in the sent request.

private List makeHeaders(){
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);        
      DocumentBuilder builder = factory.newDocumentBuilder();   
      Document doc = builder.newDocument();
        // create the <SOAP-ENV:Header> element
      Element header = 
doc.createElementNS("http://schemas.xmlsoap.org/soap/envelope/";, "SOAP-ENV:Header");
      // create the <my:Content> element
      Element headerContent = doc.createElementNS("http://my.org/uri/";, "my:Content"); 
      header.appendChild(headerContent);
      // insert the text in the content node
      headerContent.appendChild(doc.createTextNode("Content Text"));
      Attr nsAttr = doc.createAttributeNS("http://www.w3.org/2000/xmlns/";, "xmlns:my");
      nsAttr.setValue("http://my.org/uri/";);
      headerContent.setAttributeNodeNS(nsAttr); 
        return header;
}

private Element makeHeaderAlternate() {
        Document doc = null;
        try {
                 DocumentBuilderFactory factory = 
                DocumentBuilderFactory.newInstance();
                factory.setNamespaceAware(true);        
                         DocumentBuilder builder = 
                factory.newDocumentBuilder();
                String s = "<SOAP-ENV:Header 
xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\";>" +
                             " <my:content xmlns:my=\"http://my.com/uri/\";>Content 
Text</my:content></SOAP-ENV:Header>";        
                doc = builder.parse(new ByteArrayInputStream(s.getBytes()) );
        } catch(Exception e ){ /*failed*/ }
        return (Element)doc.getFirstChild();
        }



Reply via email to