All-
I am trying to add a header to my SOAP request and not having any success. I
have actually modified the samples.addressbook.GetAddress java file. But
whenever I execute the client, I get back a NullPointerException from the
server. The server diagnostics I have added indicate that the header did not
get sent as part of the request - i.e. when it extracts the header, it is
null. I know how to solve the NullPointerException - i.e. check the value of
header before referencing it. However, that does not solve the overall big
picture - why isn't the header being sent as part of my SOAP message. I am
not sure what I am doing wrong. Any help would be greatly appreciated.
Client code:
Call call = new Call();
call.setSOAPMappingRegistry(smr);
call.setTargetObjectURI("urn:AddressFetcher");
call.setMethodName("getAddressFromName");
call.setEncodingStyleURI(encodingStyleURI);
Vector params = new Vector();
params.addElement(new Parameter("nameToLookup", String.class,
nameToLookup, null));
call.setParams(params);
// ********CHANGES
// Create header
Header header = new Header();
// Add attribute to header
QName attributeName = new QName("urn:xml-soap-address-demo",
"SOAP-SEC");
header.setAttribute(attributeName, "test");
// Add header to Call object.
call.setHeader(header);
// Invoke the call.
Response resp;
try
{
resp = call.invoke(url, "");
}
...
On the server-side, I have written my own Provider that extends
RPCJavaProvider and actually builds the envelope and attempts to extract the
header. The code is as follows.
package samples.addressbook;
import java.util.Enumeration;
import java.util.Vector;
import org.apache.soap.Envelope;
import org.apache.soap.Header;
import org.apache.soap.rpc.Call;
import org.apache.soap.rpc.SOAPContext;
import org.apache.soap.SOAPException;
import org.apache.soap.server.DeploymentDescriptor;
public class SecureProvider extends
org.apache.soap.providers.RPCJavaProvider
{
public void locate(DeploymentDescriptor dd,Envelope env, Call call,
String methodName,
String targetObjectURI, SOAPContext reqContext) throws SOAPException
{
super.locate(dd, env, call, methodName, targetObjectURI,
reqContext);
// set protected data member to call's envelope
System.out.println("Building envelope.");
envelope = call.buildEnvelope();
System.out.println("finished building envelope.");
}
public void invoke(SOAPContext req, SOAPContext res) throws
SOAPException
{
System.err.println("Getting header out of envelope = " + envelope);
Header header = envelope.getHeader(); // this returns null and I
then get a NullPointerException
Vector headerEntries = header.getHeaderEntries();
for (Enumeration enum = headerEntries.elements();
enum.hasMoreElements();)
{
System.err.println("Header Entry: " + enum.nextElement());
}
super.invoke(req, res);
}
}
-----Original Message-----
From: David B. Bitton [mailto:[EMAIL PROTECTED]]
Sent: Thursday, March 21, 2002 9:35 PM
To: [EMAIL PROTECTED]
Subject: java.io.InputStream
I have the potential to send XML files in excess of 400MB via SOAP. I
noticed that java.io.InputStream can be used as a parameter for my method.
If I do not specify literalxml encoding in the envelope, can I bring the XML
in through as a stream, and have my method start chomping on the data before
the end of the envelope?
--
David B. Bitton
[EMAIL PROTECTED]
www.codenoevil.com
Code Made Fresh Daily�