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.transform.TransformerException;
22 import javax.xml.transform.TransformerFactory;
23
24 import org.springframework.beans.factory.InitializingBean;
25 import org.springframework.util.Assert;
26 import org.springframework.ws.WebServiceMessage;
27 import org.springframework.ws.context.MessageContext;
28 import org.springframework.ws.server.endpoint.support.PayloadRootUtils;
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 public class SimpleMethodEndpointMapping extends AbstractMethodEndpointMapping<String> implements InitializingBean {
51
52
53 public static final String DEFAULT_METHOD_PREFIX = "handle";
54
55
56 public static final String DEFAULT_METHOD_SUFFIX = "";
57
58 private Object[] endpoints;
59
60 private String methodPrefix = DEFAULT_METHOD_PREFIX;
61
62 private String methodSuffix = DEFAULT_METHOD_SUFFIX;
63
64 private TransformerFactory transformerFactory;
65
66 public Object[] getEndpoints() {
67 return endpoints;
68 }
69
70
71
72
73
74 public void setEndpoints(Object[] endpoints) {
75 this.endpoints = endpoints;
76 }
77
78
79 public String getMethodPrefix() {
80 return methodPrefix;
81 }
82
83
84
85
86
87
88
89 public void setMethodPrefix(String methodPrefix) {
90 this.methodPrefix = methodPrefix;
91 }
92
93
94 public String getMethodSuffix() {
95 return methodSuffix;
96 }
97
98
99
100
101
102
103
104 public void setMethodSuffix(String methodSuffix) {
105 this.methodSuffix = methodSuffix;
106 }
107
108 public final void afterPropertiesSet() throws Exception {
109 Assert.notEmpty(getEndpoints(), "'endpoints' is required");
110 transformerFactory = TransformerFactory.newInstance();
111 for (int i = 0; i < getEndpoints().length; i++) {
112 registerMethods(getEndpoints()[i]);
113 }
114 }
115
116
117 @Override
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 @Override
132 protected String getLookupKeyForMessage(MessageContext messageContext)
133 throws TransformerException {
134 WebServiceMessage request = messageContext.getRequest();
135 QName rootQName = PayloadRootUtils.getPayloadRootQName(request.getPayloadSource(), transformerFactory);
136 return rootQName.getLocalPart();
137 }
138 }