SOAP:记录有效负载请求和响应xml

时间:2015-07-13 05:27:50

标签: java web-services soap payload

我想捕获SOAP请求xml和SOAP响应xml,并将其作为整个xml格式转储到DB中。我使用有效载荷来处理我的请求和响应。

以下是我的控制器

public class Route implements Serializable{

@DatabaseField(id = true, canBeNull = false, columnName = "id")
private long id;

@DatabaseField(columnName = "parent", foreign = true)
private Route parent;

@ForeignCollectionField
private ForeignCollection<Route> childRoutes;

}

请帮助我们了解如何实现相同的目标

提前致谢。

1 个答案:

答案 0 :(得分:0)

工作!以下是步骤

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();
}