简体   繁体   中英

How to print SOAP XML response

I am using below system properties:

System.setProperty("com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump", "true");
                System.setProperty("com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.dump", "true");
                System.setProperty("com.sun.xml.ws.transport.http.HttpAdapter.dump", "true");
                System.setProperty("com.sun.xml.internal.ws.transport.http.HttpAdapter.dump", "true");

This is printing:

---[HTTP response - https://XXXXXXXXXXXXXXXXX/v1.0?wsdl - 200]---

null: HTTP/1.1 200 OK

Connection: Keep-Alive

Content-Language: en-US

Content-Type: text/xml; charset=utf-8

Date: Tue, 09 Jan 2018 12:23:42 GMT

Keep-Alive: timeout=30, max=100

Transfer-Encoding: chunked

X-Frame-Options: SAMEORIGIN

X-Powered-By: Servlet/3.0

<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><sch:InquiryResponse xmlns:sch="http://XXXXXXXXXX/1.0"><sch:InquiryResponseHeader><sch:ClientID>XXXX</sch:ClientID><sch:ProductCode>PCS</sch:ProductCode><sch:SuccessCode>0</sch:SuccessCode><sch:Date>XX-XX-XXXX</sch:Date><sch:Time>17:53:28</sch:Time></sch:InquiryResponseHeader><sch:InquiryRequestInfo><sch:InquiryPurpose>05</sch:InquiryPurpose><sch:FirstName>Ajay</sch:FirstName><sch:LastName>XXXX</sch:LastName><sch:AddrLine1>XXXX</sch:AddrLine1><sch:State>MH</sch:State><sch:Postal>411014</sch:Postal><sch:DOB>1987-06-21</sch:DOB><sch:Id>XXXX</sch:Id><sch:MobilePhone>XXXX</sch:MobilePhone></sch:InquiryRequestInfo><sch:ReportData><sch:Error><sch:ErrorCode>E0021</sch:ErrorCode><sch:ErrorMsg>User ID does not exist for the given customer.</sch:ErrorMsg></sch:Error></sch:ReportData></sch:InquiryResponse></soapenv:Body></soapenv:Envelope>

How can I get XML data from above printing data?

I want to store that XML in a variable for further use.

Thanks.

MessageHandler:

Utilizing the extensible Handler framework provided by JAX-WS Specification and the better Message abstraction in RI, we introduced a new handler called MessageHandler to extend your Web Service applications. MessageHandler is similar to SOAPHandler, except that implementations of it gets access to MessageHandlerContext (an extension of MessageContext). Through MessageHandlerContext one can access the Message and process it using the Message API. As I put in the title of the blog, this handler lets you work on Message, which provides efficient ways to access/process the message not just a DOM based message. The programming model of the handlers is same and the Message handlers can be mixed with standard Logical and SOAP handlers. I have added a sample in JAX-WS RI 2.1.3 showing the use of MessageHandler to log messages and here is a snippet from the sample:

        public class LoggingHandler implements MessageHandler<MessageHandlerContext> {
public boolean handleMessage(MessageHandlerContext mhc) {
    Message m = mhc.getMessage().copy();
    XMLStreamWriter writer = XMLStreamWriterFactory.create(System.out);
    try {
        m.writeTo(writer);
    } catch (XMLStreamException e) {
        e.printStackTrace();
        return false;
    }
    return true;
}

public boolean handleFault(MessageHandlerContext mhc) {
    ..... 
    return true;
}

public void close(MessageContext messageContext) {    }

public Set getHeaders() {
    return null;
}

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM