Error during parsing of SOAP header when calling PI service

4.2k views Asked by At

I have to call a Webservice with SOAP. I have made a client in Java that produces the following SOAPMessage:

<?xml version="1.0" encoding="utf-8" ?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:abc="http://company.com/SAMPLE/ABC">
    <SOAP-ENV:Header />
    <SOAP-ENV:Body>
        <abc:genXX>
            <ServiceRequestID>111</ServiceRequestID>
            <Code>328630962</Code>
        </abc:genXX>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

That call produces Error during parsing of SOAP when I call it inside my application:

<SOAP:Header>
</SOAP:Header>
<SOAP:Body>
    <SOAP:Fault xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
        <faultcode>SOAP:Client</faultcode>
        <faultstring>Error during parsing of SOAP header</faultstring>
        <faultactor>http://sap.com/xi/XI/Message/30</faultactor>
        <detail>
            <SAP:Error SOAP:mustUnderstand="1"
                xmlns:SAP="http://sap.com/xi/XI/Message/30">
                <SAP:Category>XIProtocol</SAP:Category>
                <SAP:Code area="PARSER" />
                <SAP:P1 />
                <SAP:P2 />
                <SAP:P3 />
                <SAP:P4 />
                <SAP:AdditionalText />
                <SAP:Stack>System error in parser
                </SAP:Stack>
            </SAP:Error>
        </detail>
    </SOAP:Fault>
</SOAP:Body>
</SOAP:Envelope>

But when I call it with the same computer with SOAP UI the webservice responds well. The client in my application is made this way:

public void callWebservice(String serviceRequestID, String code) {
    try {
            // Create SOAP Connection
            SOAPConnectionFactory soapConnectionFactory =
               SOAPConnectionFactory.newInstance();
            SOAPConnection soapConnection = soapConnectionFactory.createConnection();
            
            // Send SOAP Message to SOAP Server
            URLEndpoint url = new URLEndpoint ("http://company.com:50000/");
            SOAPMessage soapResponse =  soapConnection.call(
               createSOAPRequest(serviceRequestID, code), url);

           
            {...}

            soapConnection.close();
        } catch (Exception e) {
           //
        }

private SOAPMessage createSOAPRequest(String serviceRequestID, 
    String code) throws SOAPException{
        MessageFactory messageFactory = MessageFactory.newInstance();
        SOAPMessage soapMessage = messageFactory.createMessage();
        
        SOAPPart soapPart = soapMessage.getSOAPPart();

        String serverURI = "http://company.com/SAMPLE/ABC";

        // SOAP Envelope
        SOAPEnvelope envelope = soapPart.getEnvelope();
        envelope.addNamespaceDeclaration("abc", serverURI);

        // SOAP Body
        SOAPBody soapBody = envelope.getBody();
        SOAPElement soapBodyElem = soapBody.addChildElement("genXXX", "abc");
        SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("ServiceRequestID");
        SOAPElement soapBodyElem2 = soapBodyElem.addChildElement("Code");
        
        soapBodyElem1.addTextNode(serviceRequestID);
        soapBodyElem2.addTextNode(code);

        MimeHeaders headers = soapMessage.getMimeHeaders();
        headers.addHeader("SOAPAction", serverURI );
        
        String loginPassword = "USER:PASSWORD";
        headers.addHeader("Authorization", "Basic " + new  
          String(Base64.encodeBase64(loginPassword.getBytes())));
        
        soapMessage.saveChanges();

        return soapMessage;
    }
    
  }

I have checked header and authentication and it is right. If I change the user or password the Webservice responds with an error 401 Unauthorized so I think the header is sent as expected.

Do you have any clue on what's causing the error inside my application?

2

There are 2 answers

0
Pesse On

A couple of years late to the party, but because I ran into pretty much the same issue today, here's the solution:

In order to communicate via SOAP 1.1 protocol as Richard L suggested, change your "SOAPAction" header to "http://sap.com/xi/WebService/soap1.1"

        MimeHeaders headers = soapMessage.getMimeHeaders();
        headers.addHeader("SOAPAction", "http://sap.com/xi/WebService/soap1.1");

That did the trick for me.

0
Richard L On

You are calling a web service in SAP PI (SAP Process Integration). I work as a PI developer and it is possible to use a SAP proprietary protocol over SOAP called XI protocal that is useful in SAP-SAP scenarios. If this service should be accessed by a non SAP system it should probably be changed to regular SOAP 1.1 protocol. Talk to the PI team.