cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the payload from webservice method getMessageBytesJavaLangStringBoolean

0 Kudos

I want to receive the message payload from the SAP webservice AdapterMessageMonitoringVi using the method getMessageBytesJavaLangStringBoolean. Here the main parts of the coding:

public static void main(String[] args) throws Exception {

 

  AdapterMessageMonitoring adapterMessageMonitoring = new AdapterMessageMonitoring();

  AdapterMessageMonitoringVi port = adapterMessageMonitoring.getBasicPort();

  Map reqContext = ((BindingProvider) port).getRequestContext();

  reqContext.put(BindingProvider.USERNAME_PROPERTY, "***");

  reqContext.put(BindingProvider.PASSWORD_PROPERTY, "***");


  ...

  String msgKey ="a valid messageKey ID"

  byte[] result = port.getMessageBytesJavaLangStringBoolean(msgKey, false);

 

  SAXParser builder = SAXParserFactory.newInstance().newSAXParser();

  parser.parse(new ByteArrayInputStream(result), new MySAPPayloadParser());

  ...

}

Calling the method with a valid messageId I'm always getting the following exception trying to parse the received byteArray:

[Fatal Error] :1:1: Content is not allowed in prolog.

Exception in thread "main" org.xml.sax.SAXParseException: Content is not allowed in prolog.

    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:246)

    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284)

    at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:124)

    at client.WebServiceCaller.byteArrayToDocument(WebServiceCaller.java:61)

    at client.WebServiceCaller.main(WebServiceCaller.java:130)

Checking the received byteArray I found out that I receive in the byteArray a complete SOAP Message incl. BODY and ENVELOP information instead of the message payload content only.

I guess I miss one important step in my coding, but I don't know which ?

Accepted Solutions (1)

Accepted Solutions (1)

engswee
Active Contributor
0 Kudos

Hi Christian

First of all, make sure that the message key is in the following format as described in the blog below

<guid>\<direction>\<node>\<QoS>\<seqNr>\

I've executed the web service in my system using the WS Navigator and received the following response. Note that from the message in the Response element is Base64 encoded as mentioned by the following blog

I used an online decoder and upon decoding, it looks like the content is actually the whole MIME envelope. Therefore, I don't think you can just use a SAX Parser to parse the content, you would have to parse the MIME content to get to the actual payload.

Rgds

Eng Swee

0 Kudos

Indead I have to parse throuh the webservice response. Here my code lines to parse through the response:

...

    byte[] res2 = port.getMessageBytesJavaLangStringBoolean(msgKey, false);

     ByteArrayDataSource content=new ByteArrayDataSource(res2, "multipart/related");
    
     MimeMultipart mmp=new MimeMultipart(content);
   
     for (int i=0; i < mmp.getCount(); i++) {
        BodyPart bp=mmp.getBodyPart(i);
        System.out.println("Index: " + i);
        System.out.println("Content: " + bp.getContent());
        System.out.println("ContentType: " + bp.getContentType());
      
        StreamSource s = (StreamSource) bp.getContent();
        System.out.println(streamSourceToString(s));

...

Answers (0)