1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.soap.support;
18
19 import java.util.regex.Matcher;
20 import java.util.regex.Pattern;
21
22 import org.springframework.util.Assert;
23 import org.springframework.util.StringUtils;
24 import org.springframework.ws.transport.TransportConstants;
25
26
27
28
29
30
31
32 public abstract class SoapUtils {
33
34 private static final Pattern ACTION_PATTERN = Pattern.compile("action\\s*=\\s*([^;]+)");
35
36 private SoapUtils() {
37 }
38
39
40 public static String escapeAction(String soapAction) {
41 if (!StringUtils.hasLength(soapAction)) {
42 soapAction = "\"\"";
43 }
44 if (!soapAction.startsWith("\"")) {
45 soapAction = "\"" + soapAction;
46 }
47 if (!soapAction.endsWith("\"")) {
48 soapAction = soapAction + "\"";
49 }
50 return soapAction;
51 }
52
53
54
55
56
57
58
59 public static String extractActionFromContentType(String contentType) {
60 if (contentType != null) {
61 Matcher matcher = ACTION_PATTERN.matcher(contentType);
62 if (matcher.find() && matcher.groupCount() == 1) {
63 return matcher.group(1).trim();
64 }
65 }
66 return TransportConstants.EMPTY_SOAP_ACTION;
67 }
68
69
70
71
72
73
74
75
76 public static String setActionInContentType(String contentType, String action) {
77 Assert.hasLength(contentType, "'contentType' must not be empty");
78 if (StringUtils.hasText(action)) {
79 Matcher matcher = ACTION_PATTERN.matcher(contentType);
80 if (matcher.find() && matcher.groupCount() == 1) {
81 StringBuffer buffer = new StringBuffer();
82 matcher.appendReplacement(buffer, "action=" + action);
83 matcher.appendTail(buffer);
84 return buffer.toString();
85 }
86 else {
87 return contentType + "; action=" + action;
88 }
89 }
90 else {
91 return contentType;
92 }
93 }
94
95
96 }