猿问

EndPoint 类中的 Spring WS SOAP 响应头修改

我是 Spring WS 的新手,正在实施一项服务。为此,我使用 EndPoint 类并且可以成功接收请求并发送响应。


SOAP 请求消息包含我成功提取的 SOAP 标头中的重要信息。有些信息也必须在 SOAP 响应头中发送,但我无法编辑或修改 SOAP 响应头。


我需要帮助来了解创建 SOAP 响应标头和 SOAP 响应消息的最佳方法和最佳实践。


您可以在下面找到我的 EndPoint 类:


 @Endpoint

public class EndpointAccountInformationInquiry {


    private static final String TARGET_NAMESPACE = "http://www.sample.com/inquiry/GetAccountInformation";


    @Autowired

    private ServiceAccountInformation service;


    @PayloadRoot(localPart = "GetAccountInformationRq", namespace = TARGET_NAMESPACE)

    public @ResponsePayload GetAccountInformationRs handleRequest(@RequestPayload GetAccountInformationRq request, MessageContext messageContext) throws JAXBException, TransformerException {


        /*****************************************************************

         * Parse the request header and body

         * Also create response body and header

         *****************************************************************/

        SaajSoapMessage soapRequest = (SaajSoapMessage) messageContext.getRequest();

        SoapHeader soapRequestHeader = soapRequest.getSoapHeader();


        SaajSoapMessage soapResponse = (SaajSoapMessage) messageContext.getResponse();

        SoapHeader soapResponseHeader = soapResponse.getSoapHeader();        


        TransformerFactory transformerFactory = TransformerFactory.newInstance();

        Transformer transformer = transformerFactory.newTransformer();


        MyHeaderClassRq myHeaderClassRq = null;

        JAXBContext jaxbContext = JAXBContext.newInstance(MyHeaderClassRq.class);

        Iterator<SoapHeaderElement> itr = soapRequestHeader.examineAllHeaderElements();

        while (itr.hasNext()) {

            SoapHeaderElement ele = itr.next();


            myHeaderClassRq = (MyHeaderClassRq)jaxbContext.createUnmarshaller().unmarshal(ele.getSource());

            transformer.transform(ele.getSource(), soapResponseHeader.getResult());

        }



交互式爱情
浏览 356回答 1
1回答
随时随地看视频慕课网APP

相关分类

Java
我要回答