axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "GANDHIRAJAN,AYYAPPAN (HP-India,ex2)" <ayyappan.gandhira...@hp.com>
Subject Problem with attachment
Date Thu, 04 Dec 2003 07:01:16 GMT
Hi folks,

I have been facing a problem while using soap RPC attachment. Let me
summarize as follows:

1) Create a header
2) Create a body that contains information about an operation. The operation
or method takes javax.activation.DataHandler as an input
3) Create envelope by combining header and body
4) Create a document from the envelope [Later, I will sign this document and
send the signed XML for invoking secured webservices]

I am able to succeed until step3. While I try to create the document object
at step 4, I am getting DataHandler serializer error. The error description
is as follows:

Exception in thread "main" java.lang.NullPointerException
        at
org.apache.axis.encoding.ser.JAFDataHandlerSerializer.serialize(JAFDa
taHandlerSerializer.java:96)
        at
org.apache.axis.encoding.SerializationContextImpl.serializeActual(Ser
ializationContextImpl.java:1247)
        at
org.apache.axis.encoding.SerializationContextImpl.serialize(Serializa
tionContextImpl.java:787)
        at org.apache.axis.message.RPCParam.serialize(RPCParam.java:225)
        at tests.java.com.hp.mesac.security.client.Test.serialize(Unknown
Source
)
        at
tests.java.com.hp.mesac.security.client.Test.getEnvelopeAsDocument(Un
known Source)
        at tests.java.com.hp.mesac.security.client.Test.main(Unknown Source)



The java source code is also given below. can some one help how I can
resolve it?

Thanks in advance.

Regards,
Ayyappan Gandhirajan

----------------------------------------------------------------------------
-------------------------------------------------------------

public class Test1{

    private static String SOAPSECNS =
"http://schemas.xmlsoap.org/soap/security/2000-12";
    private static String SOAPSECprefix = "SOAP-SEC";

	public static void main(String[] args) throws Exception{
		Test1 test = new Test1();

		String namespace = "http://tempuri.org";
		String methodName = "echo";

		System.out.println("File exists - "+new
File("test.txt").exists());
		DataHandler dh = new DataHandler(new
File("test.txt").toURL());
		System.out.println("File Name - "+dh.getName());
		Object[] paramValues = {dh};

		Document doc = test.getEnvelopeAsDocument(namespace,
methodName, paramValues);
		System.out.println("Document - "+doc);
	}

	public Document getEnvelopeAsDocument(String namespace, String
methodName, Object[] paramValues) throws Exception{
		System.out.println("Creating envelope....");
		//envelope
		SOAPEnvelope env = new SOAPEnvelope();
		env.addMapping(new Mapping(SOAPSECNS, SOAPSECprefix));
		env.addAttribute(Constants.URI_SOAP11_ENV, "actor",
"http://tempuri.org");
		env.addAttribute(Constants.URI_SOAP11_ENV, "mustUnderstand",
"1");

		System.out.println("Creating envelope.header....");
		//Header
		SOAPHeaderElement header = new
SOAPHeaderElement(XMLUtils.StringToElement(SOAPSECNS, "Signature", ""));
		env.addHeader(header);

		System.out.println("Creating envelope.body....");
		RPCElement bodyInfo = new RPCElement(namespace, methodName,
paramValues);
		env.addBodyElement(bodyInfo);

		System.out.println("");
		System.out.println("Envelope is ready. ---ENVELOPE
STARTS----");
		System.out.println("Is envelope NULL? - "+(env == null));
		System.out.println(env);
		System.out.println("Envelope is ready. ---ENVELOPE
ENDS----");
		System.out.println("");

		//Get as doc
		System.out.println("Trying to create document....");
		Document doc = getSOAPEnvelopeAsDocument(env);
		System.out.println("Document creation success");
		return doc;
	}

	private Document getSOAPEnvelopeAsDocument(SOAPEnvelope env) throws
Exception{
		MessageContext msgContext = null;

		StringWriter writer = new StringWriter();
		SerializationContext serializeContext = new
SerializationContextImpl(writer, msgContext);
		env.output(serializeContext);
		writer.close();

		Reader reader = new
StringReader(writer.getBuffer().toString());
		Document doc = XMLUtils.newDocument(new
InputSource(reader));
		if (doc == null){
			throw new Exception(Messages.getMessage("noDoc00",
writer.getBuffer().toString()));
		}
		return doc;
	}
}

Mime
View raw message