I’m rewriting a Web service in Java (originally .NET).
I’m having an issue where the returned SOAP envelope returned is not coming
back with an XML Declaration <?xml version="1.0" encoding="UTF-8"?>
Normally this would not be an issue but the .NET client to the Web Service
is lame and it expects that XML Declaration. Because there is no
declaration, the client code crashes. Because the .NET client can’t change,
there’s no simple fix there.
Is there any way to tell CXF to include the XML Declaration when the Web
Service gets called?
I tried creating a JAX-WS Handler which included the following section of
code, and this code gets printed out in System.out correctly, but somehow
the XML declaration never makes it to TCPMON.
public boolean handleMessage(SOAPMessageContext soapMessageContext)
{
Boolean outboundProperty = (Boolean) soapMessageContext
.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
SOAPMessage message = soapMessageContext.getMessage();
if (outboundProperty.booleanValue())
{
try
{
message.setProperty(SOAPMessage.WRITE_XML_DECLARATION, "true");
soapMessageContext.setMessage(message);
soapMessageContext.getMessage().writeTo(System.out);
}
catch (Exception e)
{
}
}
return true;
}
Below is the TCPMON logs of what is being requested and returned:
REQUEST
POST /SpmlProvisioningService/SPMLHandler.asmx HTTP/1.1
Content-Type: text/xml; charset=UTF-8
User-Agent: SPMLClient
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
SOAPAction: SPMLLookupRequest
Host: localhost:1111
Content-Length: 364
Expect: 100-continue
Connection: Keep-Alive
<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body><spml:lookupRequest
returnData="everything" requestID="984"
xmlns:spml="urn:oasis:names:tc:SPML:2:0"><psoID ID="11223344" targetID="123"
eaHIDBadgeID="123"
/></spml:lookupRequest></SOAP-ENV:Body></SOAP-ENV:Envelope>
RESPONSE
HTTP/1.1 100 Continue
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/xml;charset=UTF-8
Content-Length: 442
Date: Fri, 06 Aug 2010 13:03:36 GMT
<!-- NOTE NO XML DECLARATION -->
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><SPMLLookupRequestResult
xmlns="urn:oasis:names:tc:SPML:2:0"><?xml version="1.0"
encoding="UTF-8"?><lookupResponse status="success"
xmlns="urn:oasis:names:tc:SPML:2:0"><pso><psoID
ID="1122334455"
/></pso></lookupResponse></SPMLLookupRequestResult></soap:Body></soap:Envelope>
Thanks,
James
--
View this message in context:
http://cxf.547215.n5.nabble.com/XML-Declaration-not-being-added-in-SOAP-Response-tp2266979p2266979.html
Sent from the cxf-user mailing list archive at Nabble.com.