1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.server.endpoint.mapping;
18
19 import java.lang.reflect.Method;
20 import javax.xml.namespace.QName;
21 import javax.xml.stream.XMLStreamException;
22 import javax.xml.transform.TransformerException;
23 import javax.xml.transform.TransformerFactory;
24
25 import org.springframework.beans.factory.InitializingBean;
26 import org.springframework.util.Assert;
27 import org.springframework.ws.WebServiceMessage;
28 import org.springframework.ws.context.MessageContext;
29 import org.springframework.ws.server.endpoint.support.PayloadRootUtils;
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 public class SimpleMethodEndpointMapping extends AbstractMethodEndpointMapping implements InitializingBean {
52
53
54 public static final String DEFAULT_METHOD_PREFIX = "handle";
55
56
57 public static final String DEFAULT_METHOD_SUFFIX = "";
58
59 private Object[] endpoints;
60
61 private String methodPrefix = DEFAULT_METHOD_PREFIX;
62
63 private String methodSuffix = DEFAULT_METHOD_SUFFIX;
64
65 private TransformerFactory transformerFactory;
66
67 public Object[] getEndpoints() {
68 return endpoints;
69 }
70
71
72
73
74
75 public void setEndpoints(Object[] endpoints) {
76 this.endpoints = endpoints;
77 }
78
79
80 public String getMethodPrefix() {
81 return methodPrefix;
82 }
83
84
85
86
87
88
89
90 public void setMethodPrefix(String methodPrefix) {
91 this.methodPrefix = methodPrefix;
92 }
93
94
95 public String getMethodSuffix() {
96 return methodSuffix;
97 }
98
99
100
101
102
103
104
105 public void setMethodSuffix(String methodSuffix) {
106 this.methodSuffix = methodSuffix;
107 }
108
109 public final void afterPropertiesSet() throws Exception {
110 Assert.notEmpty(getEndpoints(), "'endpoints' is required");
111 transformerFactory = TransformerFactory.newInstance();
112 for (int i = 0; i < getEndpoints().length; i++) {
113 registerMethods(getEndpoints()[i]);
114 }
115 }
116
117
118 protected String getLookupKeyForMethod(Method method) {
119 String methodName = method.getName();
120 String prefix = getMethodPrefix();
121 String suffix = getMethodSuffix();
122 if (methodName.startsWith(prefix) && methodName.endsWith(suffix)) {
123 return methodName.substring(prefix.length(), methodName.length() - suffix.length());
124 }
125 else {
126 return null;
127 }
128 }
129
130
131 protected String getLookupKeyForMessage(MessageContext messageContext)
132 throws TransformerException, XMLStreamException {
133 WebServiceMessage request = messageContext.getRequest();
134 QName rootQName = PayloadRootUtils.getPayloadRootQName(request.getPayloadSource(), transformerFactory);
135 return rootQName.getLocalPart();
136 }
137 }