1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.soap.axiom;
18
19 import java.util.Arrays;
20 import java.util.Iterator;
21 import java.util.List;
22 import javax.xml.namespace.QName;
23
24 import org.apache.axiom.om.OMElement;
25 import org.apache.axiom.om.OMException;
26 import org.apache.axiom.om.OMNamespace;
27 import org.apache.axiom.soap.RolePlayer;
28 import org.apache.axiom.soap.SOAPFactory;
29 import org.apache.axiom.soap.SOAPHeader;
30 import org.apache.axiom.soap.SOAPHeaderBlock;
31 import org.apache.axiom.soap.SOAPProcessingException;
32 import org.springframework.util.ObjectUtils;
33 import org.springframework.ws.soap.SoapHeaderElement;
34 import org.springframework.ws.soap.SoapHeaderException;
35 import org.springframework.ws.soap.soap12.Soap12Header;
36 import org.springframework.xml.namespace.QNameUtils;
37
38
39
40
41
42
43
44 class AxiomSoap12Header extends AxiomSoapHeader implements Soap12Header {
45
46 AxiomSoap12Header(SOAPHeader axiomHeader, SOAPFactory axiomFactory) {
47 super(axiomHeader, axiomFactory);
48 }
49
50 public SoapHeaderElement addNotUnderstoodHeaderElement(QName headerName) {
51 try {
52 SOAPHeaderBlock notUnderstood =
53 getAxiomHeader().addHeaderBlock("NotUnderstood", getAxiomHeader().getNamespace());
54 OMNamespace headerNamespace =
55 notUnderstood.declareNamespace(headerName.getNamespaceURI(), QNameUtils.getPrefix(headerName));
56 notUnderstood.addAttribute("qname", headerNamespace.getPrefix() + ":" + headerName.getLocalPart(), null);
57 return new AxiomSoapHeaderElement(notUnderstood, getAxiomFactory());
58 }
59 catch (SOAPProcessingException ex) {
60 throw new AxiomSoapHeaderException(ex);
61 }
62 }
63
64 public SoapHeaderElement addUpgradeHeaderElement(String[] supportedSoapUris) {
65 try {
66 SOAPHeaderBlock upgrade = getAxiomHeader().addHeaderBlock("Upgrade", getAxiomHeader().getNamespace());
67 for (int i = 0; i < supportedSoapUris.length; i++) {
68 OMElement supportedEnvelope = getAxiomFactory()
69 .createOMElement("SupportedEnvelope", getAxiomHeader().getNamespace(), upgrade);
70 OMNamespace namespace = supportedEnvelope.declareNamespace(supportedSoapUris[i], "");
71 supportedEnvelope.addAttribute("qname", namespace.getPrefix() + ":Envelope", null);
72 }
73 return new AxiomSoapHeaderElement(upgrade, getAxiomFactory());
74 }
75 catch (OMException ex) {
76 throw new AxiomSoapHeaderException(ex);
77 }
78 }
79
80 public Iterator examineHeaderElementsToProcess(final String[] roles, final boolean isUltimateDestination)
81 throws SoapHeaderException {
82 RolePlayer rolePlayer = null;
83 if (!ObjectUtils.isEmpty(roles)) {
84 rolePlayer = new RolePlayer() {
85
86 public List getRoles() {
87 return Arrays.asList(roles);
88 }
89
90 public boolean isUltimateDestination() {
91 return isUltimateDestination;
92 }
93 };
94 }
95 Iterator result = getAxiomHeader().getHeadersToProcess(rolePlayer);
96 return new AxiomSoapHeaderElementIterator(result);
97 }
98 }