简体   繁体   中英

SOAP: Log Payload Request and Response xml

I want to capture the SOAP request xml and SOAP response xml and dump it in DB as an entire xml format. i use payload for my request and response.

Below is my controller

@PayloadRoot(localPart = "StudentDetailsRequest", namespace = TARGET_NAMESPACE)
public @ResponsePayload StudentDetailsResponse getStudentDetails(@RequestPayload StudentDetailsRequest request) throws Exception
{
    StudentDetailsResponse response = new StudentDetailsResponse();
    response=studentService.execute(request);
    return response;
}

Please help on how to achieve the same

Thanks in advance.

Worked! Below are the steps

public String getResponseXML(StudentDetailsResponse response) throws JAXBException
{
     StringWriter sw = new StringWriter();
    JAXBContext jaxbContext = JAXBContext.newInstance(StudentDetailsResponse.class);
    Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
    jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    jaxbMarshaller.marshal(response,  new StreamResult(sw));
    return sw.toString();
}

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