0

I am converting Python code to Java. The code is SOAP 1.5 client code which communicates with a SOAP server endpoint.

What doesn't make sense is that the Python code sends the XML request and gets the accepted response from the server. With the Java code however, the response is a fault stating "Request is not well formed".

Below I am showing the XML requests, the one which is sent in Python and the other in Java. How can the Java one sent by Java return a fault, but the Python is fine / accepted. They are both valid requests. Or perhaps I am missing something obvious.

Request in Python :

<SOAP-ENV:Envelope
    xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope"
    xmlns:wsa="http://www.w3.org/2005/08/addressing"
    xmlns:cs="urn://Ocpp/Cp/2012/06/">
    <SOAP-ENV:Header>
        <cs:chargeBoxIdentity>Test</cs:chargeBoxIdentity>
        <wsa:MessageID>Fake OCPP571322528896</wsa:MessageID>
        <wsa:Action>/ChangeConfiguration</wsa:Action>
    </SOAP-ENV:Header>
    <SOAP-ENV:Body>
        <cs:changeConfigurationRequest>
            <cs:key>LaMa_ConnectionRate</cs:key>
            <cs:value>5120</cs:value>
        </cs:changeConfigurationRequest>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Request in Java :

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SOAP-ENV:Envelope
    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:cs="urn://Ocpp/Cp/2012/06/"
    xmlns:wsa="http://www.w3.org/2005/08/addressing">
    <SOAP-ENV:Header>
        <cs:chargeBoxIdentity>Test</cs:chargeBoxIdentity>
        <wsa:Action>/ChangeConfiguration</wsa:Action>
        <wsa:MessageID>Fake OCPP571322528896</wsa:MessageID>
    </SOAP-ENV:Header>
    <SOAP-ENV:Body>
        <cs:changeConfigurationRequest>
            <cs:key>LaMa_ConnectionRate</cs:key>
            <cs:value>5120</cs:value>
        </cs:changeConfigurationRequest>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Fault response to Java :

<?xml version="1.0" encoding="UTF-8"?><env:Envelope 
xmlns:env="http://www.w3.org/2003/05/soap-envelope">
  <env:Header/>
  <env:Body>
    <env:Fault>
      <env:Code>
        <env:Value>env:Sender</env:Value>
      </env:Code>
      <env:Reason>
        <env:Text xml:lang="en-US">XML Request is not well formed!</env:Text>
      </env:Reason>
    </env:Fault>
  </env:Body>
</env:Envelope>

Update :

My Java code should be sending "http://www.w3.org/2003/05/soap-envelope" for "SOAP-ENV", as shown below in my code. However it somehow sends "http://schemas.xmlsoap.org/soap/envelope/" instead. I don't understand why.

// SOAP Envelope
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("SOAP-ENV", "http://www.w3.org/2003/05/soap-envelope");
Engineer999
  • 3,683
  • 6
  • 33
  • 71
  • 1
    Well, obviously the Java request has the ` – John Gordon Oct 17 '19 at 15:54
  • Also, it is possible that invisible Byte Order Mark (BOM) is causing a problem. – Yitzhak Khabinsky Oct 17 '19 at 16:12
  • Thanks for replies. Does the order in which elements appear also matter? For example, xmlns:wsa and xmlns:cs ? – Engineer999 Oct 17 '19 at 16:15
  • `xmlns:wsa="..."` and `xmlns:cs="..."` are attributes (namespace declarations). From an XML point of view it does not matter in which order they appear. – mzjn Oct 17 '19 at 16:27
  • I think you should look into the fact that the value of `xmlns:SOAP-ENV` is different in the two requests (as pointed out by John Gordon). That could be significant. See https://stackoverflow.com/q/403980/407651. – mzjn Oct 17 '19 at 16:38
  • @mzjn It should be using "http://www.w3.org/2003/05/soap-envelope" for SOAP-ENV , the same as in the Python code, but somehow it sends "http://schemas.xmlsoap.org/soap/envelope/" instead. Please see my edit. Thanks – Engineer999 Oct 17 '19 at 20:26

0 Answers0