Заголовки ответа веб-службы Soap с пружинной загрузкой - PullRequest
0 голосов
/ 09 апреля 2019

Я разрабатываю мыльный веб-сервис с весенней загрузкой.В заголовке запроса передается заголовок идентификатора сообщения, и в ответе требуется, чтобы в заголовке ответа было то же значение.Однако я не могу найти способ добавить раздел заголовка к ответному сообщению.

Я прочитал перехватчики сообщений, но в моем случае он не будет работать, так как значения заголовков являются переменными.

Пожалуйста, помогите.Заранее спасибо!

<!-- MY REQUEST -->
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://mynamespace.com/">
   <soapenv:Header>
      <ns:HeaderRequest>
         <messageID>1234testID</messageID>
      </ns:HeaderRequest>
   <soapenv:Header>
   <soapenv:Body>
    <!-- Request body content -->
   </soapenv:Body>
</soapenv:Envelope>

<!-- EXPECTED RESPONSE -->
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://mynamespace.com/">
    <soapenv:Header>
        <ns:HeaderReply>
            <messageID>1234testID</messageID>
            <statusCode>200</statusCode>
            <statusDescription>Success</statusDescription>
        </ns:HeaderReply>
    </soapenv:Header>
    <soapenv:Body>
        <!-- The response body -->
    </soapenv:Body>
</soapenv:Envelope>

<!-- CURRENT RESPONSE -->
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://mynamespace.com/">
    <soapenv:Header />
    <soapenv:Body>
        <!-- The response body -->
    </soapenv:Body>
</soapenv:Envelope>

// My web config 
@EnableWs
@Configuration
public class WebConfig extends WsConfigurerAdapter {

    @Bean
    public ServletRegistrationBean<MessageDispatcherServlet> messageDispatcherServlet(
            ApplicationContext applicationContext) {
        MessageDispatcherServlet servlet = new MessageDispatcherServlet();
        servlet.setApplicationContext(applicationContext);

        return new ServletRegistrationBean<MessageDispatcherServlet>(servlet, "/ws/*");
    }

    @Bean(name = "services")
    public Wsdl11Definition defaultWsdl11Definition() {
        SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition();
        wsdl11Definition.setWsdl(new ClassPathResource("/mywsdl.wsdl"));

        return wsdl11Definition;
    }

    @Bean
    public Jaxb2Marshaller jaxb2Marshaller() {
        Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
        marshaller.setContextPath("com.ws.objects");
        return marshaller;
    }

    @Bean
    public WebServiceTemplate webServiceTemplate() throws Exception {
        WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
        webServiceTemplate.setMessageFactory(getMessageFactory());
        webServiceTemplate.setMarshaller(jaxb2Marshaller());
        webServiceTemplate.setUnmarshaller(jaxb2Marshaller());
        webServiceTemplate.setDefaultUri("http://localhost:8080/ws");
        webServiceTemplate.setMessageSender(getMessageSender());
        return webServiceTemplate;
    }

    @Bean
    public SaajSoapMessageFactory getMessageFactory() {
        return new SaajSoapMessageFactory();
    }

    @Bean
    public HttpComponentsMessageSender getMessageSender() {
        return new HttpComponentsMessageSender();
    }

}


// My endpoint
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "getInput")
    @ResponsePayload
    public JAXBElement<GetResponse> validationRequest(@RequestPayload Element body, MessageContext context) 
    {
        JAXBElement<GetResponse> result =factory.createGetResponse(new GetResponse());
        return result;
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...