1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.soap.server.endpoint.interceptor;
18
19 import javax.xml.namespace.QName;
20 import javax.xml.transform.TransformerException;
21
22 import org.springframework.util.Assert;
23 import org.springframework.util.StringUtils;
24 import org.springframework.ws.WebServiceMessage;
25 import org.springframework.ws.server.EndpointInterceptor;
26 import org.springframework.ws.server.endpoint.support.PayloadRootUtils;
27 import org.springframework.xml.transform.TransformerHelper;
28
29
30
31
32
33
34
35
36
37 public class PayloadRootSmartSoapEndpointInterceptor extends DelegatingSmartSoapEndpointInterceptor {
38
39 private TransformerHelper transformerHelper = new TransformerHelper();
40
41 private final String namespaceUri;
42
43 private final String localPart;
44
45 public PayloadRootSmartSoapEndpointInterceptor(EndpointInterceptor delegate,
46 String namespaceUri,
47 String localPart) {
48 super(delegate);
49 Assert.hasLength(namespaceUri, "namespaceUri can not be empty");
50 this.namespaceUri = namespaceUri;
51 this.localPart = localPart;
52 }
53
54 public void setTransformerHelper(TransformerHelper transformerHelper) {
55 this.transformerHelper = transformerHelper;
56 }
57
58 @Override
59 protected boolean shouldIntercept(WebServiceMessage request, Object endpoint) {
60 try {
61 QName payloadRootName = PayloadRootUtils.getPayloadRootQName(request.getPayloadSource(), transformerHelper);
62 if (!namespaceUri.equals(payloadRootName.getNamespaceURI())) {
63 return false;
64 }
65 return !StringUtils.hasLength(localPart) || localPart.equals(payloadRootName.getLocalPart());
66
67 }
68 catch (TransformerException e) {
69 return false;
70 }
71 }
72 }