简体   繁体   English

Spring WS Endpoint提取SOAP信息

[英]Spring WS Endpoint extract SOAP info

After reading doc on the Spring web site, still confused about how to extract information from a SOAP request. 在Spring网站上阅读了文档之后,仍然对如何从SOAP请求中提取信息感到困惑。 For example, the SOAP request sent to server is like: 例如,发送到服务器的SOAP请求类似于:

<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:user="http://www.mysite.com/user/schemas">
   <soapenv:Header/>
   <soapenv:Body>
      <user:UserRequest>
         <!--You may enter the following 4 items in any order-->
         <user:Key>key</user:Key>
         <user:UserName>username</user:UserName>
         <user:RequesterName>reqname</user:RequesterName>
         <user:RequesterPassword>repw</user:RequesterPassword>
      </user:UserRequest>
   </soapenv:Body>
</soapenv:Envelope>

On my server side I create an Endpoint like: 在服务器端,我创建一个端点,如下所示:

@Endpoint
public class UserEndpoint {

    private static final String NAMESPACE_URI = "http://www.mysite.com/user/schemas";

@PayloadRoot(namespace = NAMESPACE_URI, localPart = "UserRequest")
    public void handleGetUserRequest() {
//Extract here...
    }   
}

How should I write extraction code here? 我应该如何在此处编写提取代码?

I would suggest having a look at the Spring WS samples for code ideas, depending on what else you are using in your application. 我建议看看Spring WS示例中的代码思想,这取决于您在应用程序中使用的其他内容。 For example: the HolidayEndpoint source code . 例如:HolidayEndpoint 源代码

@Endpoint("myEndpoint")
public class MyEndpoint {

    /**
     * Spring-WS Endpoint 
     * @param submitSomethingRequest 
     * @param header
     * @return SubmitSomethingResponse
     */
    @PayloadRoot(namespace="http://my.namespace.org/spec/1.0.1", localPart="submitSomethingRequest")
    @ResponsePayload
    public SubmitSomethingResponse submitSomethingRequest(@RequestPayload SubmitSomethingRequest submitSomethingRequest, **SoapHeader header**) {
        LOG.info("Received SOAP HEADER: " + header);
        if(header != null) {
            Iterator<SoapHeaderElement> hdrs = header.examineAllHeaderElements();
            while(hdrs.hasNext()) {
                SoapHeaderElement hdrEle = hdrs.next();
                System.out.prinltn(hdrEle.getName().getPrefix() + ":" + hdrEle.getName().getLocalPart());
                 ... //Do something here to parse DOM and extract headers you care about
            }
        }
...

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

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