Loading ...
Sorry, an error occurred while loading the content.

signing soap attachment

Expand Messages
  • GANDHIRAJAN,AYYAPPAN (HP-India,ex2)
    Hi gurus, I hope I am sending this query to the right group. I have been facing a problem with signing soap attachments. My intension is to create an envelope
    Message 1 of 1 , Dec 7, 2003
    • 0 Attachment
      Hi gurus,

      I hope I am sending this query to the right group. I have been facing a
      problem with signing soap attachments.

      My intension is to create an envelope with body element containing
      DataHandler object.
      Then, I need to sign the envelope and pass it as a parameter to
      Call.invoke(env).

      But I have been consistently getting the Null pointer exception while trying
      to create a Document object from the envelope. I know this is something
      related to "serialization of DataHandler". Can you please advise as to what
      could have caused this error?

      I am using following versions
      1) Axis - 1.1RC2
      2) mail.jar 1.3
      3) activation.jar - 1.0.2

      And my classpath is
      "activation.jar;mailapi.jar;mail.jar;xerces_1_4_3.jar;jaxrpc.jar;saaj.jar;co
      mmons-logging.jar;commons-discovery.jar;axis.jar"

      Your help is much appriciated.

      Regards,
      Ayyappan Gandhirajan

      The error description is --

      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.MessageElement.outputImpl(MessageElement.java
      :813)
      at
      org.apache.axis.message.MessageElement.output(MessageElement.java:779
      )
      at
      org.apache.axis.message.MessageElement.outputImpl(MessageElement.java
      :822)
      at
      org.apache.axis.message.MessageElement.output(MessageElement.java:779
      )
      at org.apache.axis.message.SOAPBody.outputImpl(SOAPBody.java:150)
      at
      org.apache.axis.message.SOAPEnvelope.outputImpl(SOAPEnvelope.java:413
      )
      at
      org.apache.axis.message.MessageElement.output(MessageElement.java:779
      )
      at
      org.apache.axis.message.MessageElement.getAsString(MessageElement.jav
      a:702)
      at
      org.apache.axis.message.MessageElement.getAsDocument(MessageElement.j
      ava:681)
      at
      org.apache.axis.message.MessageElement.getAsDOM(MessageElement.java:7
      10)
      at MessageTest.createEnvelope(MessageTest.java:78)
      at MessageTest.main(MessageTest.java:52)



      The source code is as follows:
      public class MessageTest{

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

      //private static DataHandler dh = null;
      public static void main(String[] args) throws Exception{
      MessageTest test = new MessageTest();

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

      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());

      test.createEnvelope(namespace, methodName, dh);
      System.out.println("Success");
      }

      public void createEnvelope(String namespace, String methodName,
      DataHandler dh) 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");

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

      //Body
      System.out.println("Creating envelope.body....");
      SOAPBodyElement sbe = new
      SOAPBodyElement(env.createName(methodName, "m", namespace));
      env.addBodyElement(sbe);
      sbe.addChildElement(new MessageElement(new QName("in0"),
      dh));

      System.out.println("");
      System.out.println("Printing envelope");
      System.out.println("**************ENVELOPE
      STARTS**************");
      XMLUtils.PrettyElementToStream(env.getAsDOM(), System.out);

      System.out.println("**************ENVELOPE
      ENDS**************");
      }
      }
    Your message has been successfully submitted and would be delivered to recipients shortly.