1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.soap.saaj;
18
19 import java.util.ArrayList;
20 import java.util.Iterator;
21 import java.util.List;
22 import javax.xml.namespace.QName;
23 import javax.xml.soap.SOAPConstants;
24 import javax.xml.soap.SOAPException;
25 import javax.xml.soap.SOAPHeader;
26 import javax.xml.soap.SOAPHeaderElement;
27
28 import org.springframework.util.ObjectUtils;
29 import org.springframework.util.StringUtils;
30 import org.springframework.ws.soap.SoapHeaderElement;
31 import org.springframework.ws.soap.SoapHeaderException;
32 import org.springframework.ws.soap.soap12.Soap12Header;
33
34
35
36
37
38
39
40 class SaajSoap12Header extends SaajSoapHeader implements Soap12Header {
41
42 SaajSoap12Header(SOAPHeader header) {
43 super(header);
44 }
45
46 public SoapHeaderElement addNotUnderstoodHeaderElement(QName headerName) {
47 try {
48 SOAPHeaderElement headerElement =
49 getImplementation().addNotUnderstoodHeaderElement(getSaajHeader(), headerName);
50 return new SaajSoapHeaderElement(headerElement);
51 }
52 catch (SOAPException ex) {
53 throw new SaajSoapHeaderException(ex);
54 }
55 }
56
57 public SoapHeaderElement addUpgradeHeaderElement(String[] supportedSoapUris) {
58 try {
59 SOAPHeaderElement headerElement =
60 getImplementation().addUpgradeHeaderElement(getSaajHeader(), supportedSoapUris);
61 return new SaajSoapHeaderElement(headerElement);
62 }
63 catch (SOAPException ex) {
64 throw new SaajSoapHeaderException(ex);
65 }
66 }
67
68 public Iterator<SoapHeaderElement> examineHeaderElementsToProcess(String[] roles, boolean isUltimateDestination)
69 throws SoapHeaderException {
70 List<SOAPHeaderElement> result = new ArrayList<SOAPHeaderElement>();
71 Iterator<SOAPHeaderElement> iterator = getImplementation().examineAllHeaderElements(getSaajHeader());
72 while (iterator.hasNext()) {
73 SOAPHeaderElement saajHeaderElement = iterator.next();
74 String headerRole = saajHeaderElement.getRole();
75 if (shouldProcess(headerRole, roles, isUltimateDestination)) {
76 result.add(saajHeaderElement);
77 }
78 }
79 return new SaajSoapHeaderElementIterator(result.iterator());
80
81 }
82
83 private boolean shouldProcess(String headerRole, String[] roles, boolean isUltimateDestination) {
84 if (!StringUtils.hasLength(headerRole)) {
85 return true;
86 }
87 if (SOAPConstants.URI_SOAP_1_2_ROLE_NEXT.equals(headerRole)) {
88 return true;
89 }
90 if (SOAPConstants.URI_SOAP_1_2_ROLE_ULTIMATE_RECEIVER.equals(headerRole)) {
91 return isUltimateDestination;
92 }
93 if (SOAPConstants.URI_SOAP_1_2_ROLE_NONE.equals(headerRole)) {
94 return false;
95 }
96 if (!ObjectUtils.isEmpty(roles)) {
97 for (String role : roles) {
98 if (role.equals(headerRole)) {
99 return true;
100 }
101 }
102 }
103 return false;
104 }
105 }