xml-soap-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Greg Symons" <gsym...@researchfed.com>
Subject RE: Correct way to add Apache SOAP Header ?
Date Tue, 11 Jun 2002 20:02:43 GMT
The problem you're having here is in the way you are using the Header
object. What you're doing will actually create this for the header:

<soap:Header Version Identification="SKARABEEPRO" Major="0" Minor="0"
Build="0" Revision="0"/>

What you should be doing is creating a org.w3c.dom.Node object and
adding it to the header entries using setHeaderEntries on your Header
object. Also, by passing in the empty string as your namespace prefix,
I'm guessing weird things are gonna happen with the namespace
declarations... unless that was deleted so you could post:)




 __________________________________
|                                  \
|  Greg Symons                     /
|  Systems Analyst                 \
|  Research Federal Credit Union   /
|  (586) 264-8710 x1234            \
|__________________________________/ 
-----Original Message-----
From: Tom Leuntjens [mailto:Tom.Leuntjens@korfina.be] 
Sent: Tuesday, June 11, 2002 8:57 AM
To: soap-user@xml.apache.org
Subject: RE: Correct way to add Apache SOAP Header ?


The problem is that I need to compose this little piece header ... and
add it to the call (I think) ..
 
  <soap:Header>    <Version Identification="SKARABEEPRO" Major="0"
Minor="0" Build="0" Revision="0" xmlns="XXX" />  </soap:Header>  
I' don't really see how I need to do this with APACHE SOAP API
 
Code so far .....
 
import java.io.*;
import java.util.*;
import java.net.*;
import org.w3c.dom.*;
import org.apache.soap.util.xml.*;
import org.apache.soap.*;
import org.apache.soap.encoding.*;
import org.apache.soap.encoding.soapenc.*;
import org.apache.soap.rpc.*;
import org.apache.soap.transport.http.SOAPHTTPConnection;
 
public class testClient {
 
            public static void main(String[] args) throws Exception {
 
                        URL url = new URL
("http://xxx/dataswitch23.asmx");
                        String SOAPAction = "http://xxx/core23/Ping";
                        SOAPMappingRegistry smr = new
SOAPMappingRegistry();
                        StringDeserializer sd = new StringDeserializer
();
                        smr.mapTypes (Constants.NS_URI_SOAP_ENC, new
QName ("", "Result"), null, null, sd);
 
 
                        // create the transport and set parameters
                        SOAPHTTPConnection st = new
SOAPHTTPConnection();
                        st.setUserName("xxxx");
                        st.setPassword("xxx");
 
                        // create the header
                        Header myHeader = new Header();
                        myHeader.declareNamespace("", " XXX ");
                        myHeader.setAttribute(new QName("",
"Identification"), "SKARABEEPRO");
                        myHeader.setAttribute(new QName("", "Major"),
"0");
                        myHeader.setAttribute(new QName("", "Minor"),
"0");
                        myHeader.setAttribute(new QName("", "Revision"),
"0");
                        myHeader.setAttribute(new QName("", "Build"),
"0");
 
/*
 
System.out.println("\n------------------------------------------------\n
");
                        System.out.println(myHeader.toString());
*/
 
 
                        // build the call.
                        Call call = new Call ();
                        call.setSOAPTransport(st);
                        call.setSOAPMappingRegistry (smr);
                        call.setTargetObjectURI
("http://xxx/service/dataswitch23.asmx");
                        call.setMethodName("Ping");
                        call.setEncodingStyleURI
("Constants.NS_URI_SOAP_ENC");
                        call.setHeader(myHeader);
 
 
/*
 
System.out.println("\n------------------------------------------------\n
");
                        System.out.println(call.toString());
 
System.out.println("\n------------------------------------------------\n
");
*/
 
                        Response resp = null;
                        try {
                          resp = call.invoke (url, SOAPAction);
                        }
                        catch (SOAPException e) {
                                    System.err.println("Caught
SOAPException (" + e.getFaultCode () + "): " + e.getMessage ());
                                    return;
                        }
 
                        // check response
                        if (resp != null && !resp.generatedFault()) {
                           Parameter ret = resp.getReturnValue();
                          Object value = ret.getValue();
 
                          System.out.println ("Answer--> " + value);
                        }
                        else {
                                    Fault fault = resp.getFault ();
                                    System.err.println ("Generated
fault: ");
                                    System.out.println (" Fault Code = "
+ fault.getFaultCode());
                                    System.out.println (" Fault String =
" + fault.getFaultString());
                        }
            }
}
 
 
the error I keep getting ...
Server did not find required Version SOAP header in the message
 
 
 
-----Original Message-----
From: Wimmer, Matthias [mailto:matthias.wimmer@scr.siemens.com] 
Sent: Tuesday, June 11, 2002 2:42 PM
To: 'soap-user@xml.apache.org'
Subject: RE: Correct way to add Apache SOAP Header ?
 
Tom:
 
What is your problem? Doesn't it work? So below you will find an example
I found:
 
        Element emailElem = doc.createElementNS(
"http://any.namespace.com",  "EMail");
        emailElem.appendChild( ... );
        SOAPEnvelope reqEnv = new SOAPEnvelope();
        reqEnv.addHeader( new SOAPHeader(emailElem ));
        reqEnv.addBodyElement( ... );
        
        // Invoke the web service
        Call call = new Call( url );
        SOAPEnvelope respEnv = call.invoke(reqEnv);
I hope it works like this.
 
best regards
Matthias Wimmer
-----Original Message-----
From: Tom Leuntjens [mailto:Tom.Leuntjens@korfina.be]
Sent: Tuesday, June 11, 2002 7:01 AM
To: soap-user@xml.apache.org
Subject: Correct way to add Apache SOAP Header ?
Hi, 
So far im creating the call and i get this :
System.Web.Services.Protocols.SoapHeaderException: Server did not find
required Version SOAP header in the message. 
So I have been trying to add the header like this but to no avail .. 
 
 
// create the headerHeader myHeader = new
Header();myHeader.declareNamespace("Version", "");
myHeader.setAttribute(new QName("", "Identification"), "SKARABEEPRO");
myHeader.setAttribute(new QName("", "Major"),
"0");myHeader.setAttribute(new QName("", "Minor"),
"0");myHeader.setAttribute(new QName("", "Revision"),
"0");myHeader.setAttribute(new QName("", "Build"), "0"); //add the
header to the call ...call.setHeader(myHeader);
Can somebody can give me some more info on how to do this ? What is the
correct way to add the header (details below)? Don't seem to find any
info about it ... 
Any help is appreciated ..
Thanx
Regards,
Tom

The service requires this call: 
<?xml version="1.0" encoding="utf-8"?><soap:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">  <soap:Header>
<Version Identification="SKARABEEPRO" Major="0" Minor="0" Build="0"
Revision="0" xmlns="leftthisouttopost" />  </soap:Header>  <soap:Body>
<Ping xmlns="leftthisouttopost" />  </soap:Body></soap:Envelope>
The toString() of the call (for my code at the time that doesn't work)
gives this : 
[Header=[Attributes={ Build="0" Revision="0" xmlns:Version=""
Identification="SKARABEEPRO" Minor="0" Major="0"}] [HeaderEntries={}]]
[methodName=Ping] [targetObjectURI=leftthisouttopostonforum]
[encodingStyleURI=Constants.NS_URI_SOAP_ENC] [SOAPContext=[Parts={}]]
[Params={}] 

Mime
View raw message