简体   繁体   English

如何在没有拦截器的情况下将头添加到Soap Fault

[英]How to add header to soap fault without interceptor

I'm trying to find a way to add header to soap fault with out using interceptor. 我正在尝试找到一种方法,可以在不使用拦截器的情况下将标头添加到soap错误。 Is there any alternative solution. 有没有其他解决方案。

Basically I've my soap request as follows. 基本上,我的肥皂要求如下。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sch="http://kp.web.com/schema/" xmlns:sch1="http://kp.web.com/Shared/schema/">
   <soapenv:Header>
      <sch:clientHeader>
         <sch1:consumerId>12</sch1:consumerId>
      </sch:clientHeader>
   </soapenv:Header>
   <soapenv:Body>
      <sch:addRequest>
         <sch:field1>-3</sch:field1>
         <sch:field2>-1</sch:field2>
      </sch:addRequest>
   </soapenv:Body>
</soapenv:Envelope>

Success message. 成功消息。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" >
   <soap:Header>
      <serverHeader xmlns:ns2="http://kp.web.com/schema/" xmlns="http://kp.web.com/Shared/schema/">
         <ns2:consumerId>12</ns2:consumerId>
         <ns2:completionCode>100</ns2:completionCode>
      </serverHeader>
   </soap:Header>
   <soap:Body>
      <addResponse xmlns="http://kp.web.com/schema/" xmlns:ns2="http://kp.web.com/Shared/schema/">
         <result>-4</result>
      </addResponse>
   </soap:Body>
</soap:Envelope>

When fault occurs 故障发生时

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <soap:Fault>
         <faultcode>soap:Server</faultcode>
         <faultstring>Faulted you sent -1 and -1</faultstring>
         <detail>
            <faultResponse xmlns:ns2="http://kp.web.com/schema/" xmlns="http://kp.web.com/Shared/schema/">400</faultResponse>
         </detail>
      </soap:Fault>
   </soap:Body>
</soap:Envelope>

I would expect fault response something like this. 我希望这样的故障响应。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sch="http://kp.web.com/schema/" xmlns:sch1="http://kp.web.com/Shared/schema/">
    <soap:Header>
          <serverHeader>
             <ns2:consumerId>12</ns2:consumerId>
             <ns2:completionCode>100</ns2:completionCode>
          </serverHeader>
   </soap:Header>
   <soap:Body>
      <soap:Fault>
         <faultcode>soap:Server</faultcode>
         <faultstring>Faulted you sent -1 and -1</faultstring>
         <detail>
             <faultResponse xmlns:ns2="http://kp.web.com/schema/" xmlns="http://kp.web.com/Shared/schema/">400</faultResponse>
         </detail>
      </soap:Fault>
   </soap:Body>
</soap:Envelope>

Can I use holder or is there any solution. 我可以使用支架还是有什么解决方案? I can't use interceptor because I need to send the consumer Id back. 我无法使用拦截器,因为我需要将使用者ID发送回去。 In interceptor I will not have request details. 在拦截器中,我将没有请求的详细信息。

You can use SOAP Message Handlers and Handler Chains . 您可以使用SOAP消息处理程序和处理程序链 Another way do it use Filters . 另一种方法是使用Filters I use Handler Chains for modify SOAP header. 我使用处理程序链来修改SOAP标头。

This link might be helpful. 链接可能会有所帮助。

You can still use an interceptor. 您仍然可以使用拦截器。 There are two ways you can get the data you need from the interceptor: 您可以通过两种方式从拦截器获取所需的数据:

1) In you business logic, if you have a WebServiceContext injected in (@Resource), you can set properties on that that you should be able to pick up later from the message. 1)在业务逻辑中,如果在(@Resource)中注入了WebServiceContext,则可以设置属性,以便以后可以从消息中提取。 (or from the message.getExchange().getInMessage()) (或来自message.getExchange()。getInMessage())

2) From the message, you can get the Exchange and then get the inMessage. 2)从消息中,您可以获取Exchange,然后获取inMessage。 From that message you can get the contents that were unmarshalled (inMessage.getContent(List.class)) and passed into your class. 从该消息中,您可以获得解组(inMessage.getContent(List.class))并传递到您的类中的内容。

Hope that helps. 希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM