gpt4 book ai didi

java - 如何从 Spring Web 服务中删除 Soap 消息中的 body 元素

转载 作者:行者123 更新时间:2023-12-01 14:44:55 25 4
gpt4 key购买 nike

我有以下拦截器,可以修改 SOAP 响应的 header 。我还想清除 SOAP 响应的正文,但我找不到任何有关执行此操作或解决方法的文档。有建议吗?

  public class LisResponseInterceptor extends EndpointInterceptorAdapter {

@Override
public boolean handleResponse(MessageContext messageContext, Object endpoint) {
return true;
}

@Override
public boolean handleRequest(MessageContext messageContext, Object endpoint) {
return true;
}

@Override
public boolean handleFault(MessageContext messageContext, Object endpoint) {

SoapMessage response = (SoapMessage) messageContext.getResponse();
SoapHeader header = response.getSoapHeader();
header.addHeaderElement(new QName("ims","imsx_syncRequestHeaderInfo"));

SoapBody body = response.getSoapBody();

// clear body

return true;
}
}

最佳答案

已修复

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
<imsx_syncRequestHeaderInfo xmlns="ims"/>
</SOAP-ENV:Header>
<SOAP-ENV:Body/>
</SOAP-ENV:Envelope>


public class LisResponseInterceptor extends EndpointInterceptorAdapter {

@Override
public boolean handleResponse(MessageContext messageContext, Object endpoint) {
return true;
}

@Override
public boolean handleRequest(MessageContext messageContext, Object endpoint) {
return true;
}

@Override
public boolean handleFault(MessageContext messageContext, Object endpoint) {

SoapMessage response = (SoapMessage) messageContext.getResponse();
SoapHeader header = response.getSoapHeader();
header.addHeaderElement(new QName("ims","imsx_syncRequestHeaderInfo"));

SoapBody body = response.getSoapBody();

Transformer identityTransform = null;

try {
identityTransform = TransformerFactory.newInstance().newTransformer();
} catch (TransformerConfigurationException e) {
e.printStackTrace();
} catch (TransformerFactoryConfigurationError e) {
e.printStackTrace();
}

try {
identityTransform.transform(new DOMSource(null), body.getPayloadResult());
} catch (TransformerException e) {
e.printStackTrace();
}

return true;
}
}

关于java - 如何从 Spring Web 服务中删除 Soap 消息中的 body 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15530911/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com