1 16 package org.apache.axis.message; 17 18 import org.apache.axis.AxisFault; 19 import org.apache.axis.Constants; 20 import org.apache.axis.encoding.DeserializationContext; 21 import org.apache.axis.encoding.SerializationContext; 22 import org.apache.axis.soap.SOAPConstants; 23 import org.apache.axis.utils.Messages; 24 import org.w3c.dom.Element ; 25 import org.w3c.dom.NamedNodeMap ; 26 import org.xml.sax.Attributes ; 27 28 import javax.xml.namespace.QName ; 29 import javax.xml.soap.Name ; 30 import javax.xml.soap.SOAPElement ; 31 import javax.xml.soap.SOAPException ; 32 33 40 public class SOAPHeaderElement extends MessageElement 41 implements javax.xml.soap.SOAPHeaderElement 42 { 43 44 protected boolean processed = false; 45 46 protected String actor = "http://schemas.xmlsoap.org/soap/actor/next"; 47 protected boolean mustUnderstand = false; 48 protected boolean relay = false; 49 50 public SOAPHeaderElement(String namespace, String localPart) 51 { 52 super(namespace, localPart); 53 } 54 55 public SOAPHeaderElement(Name name) 56 { 57 super(name); 58 } 59 60 public SOAPHeaderElement(QName qname) 61 { 62 super(qname); 63 } 64 65 public SOAPHeaderElement(String namespace, String localPart, 66 Object value) 67 { 68 super(namespace, localPart, value); 69 } 70 71 public SOAPHeaderElement(QName qname, Object value) 72 { 73 super(qname, value); 74 } 75 76 public SOAPHeaderElement(Element elem) 77 { 78 super(elem); 79 80 SOAPConstants soapConstants = getSOAPConstants(); 83 84 String val = elem.getAttributeNS(soapConstants.getEnvelopeURI(), 85 Constants.ATTR_MUST_UNDERSTAND); 86 87 try { 88 setMustUnderstandFromString(val, (soapConstants == 89 SOAPConstants.SOAP12_CONSTANTS)); 90 } catch (AxisFault axisFault) { 91 log.error(axisFault); 93 } 94 95 QName roleQName = soapConstants.getRoleAttributeQName(); 96 actor = elem.getAttributeNS(roleQName.getNamespaceURI(), 97 roleQName.getLocalPart()); 98 102 if (soapConstants == SOAPConstants.SOAP12_CONSTANTS) { 103 String relayVal = elem.getAttributeNS(soapConstants.getEnvelopeURI(), 104 Constants.ATTR_RELAY); 105 relay = ((relayVal != null) && (relayVal.equals("true") || relayVal.equals("1"))) ? true : false; 106 } 107 } 108 109 public void setParentElement(SOAPElement parent) throws SOAPException 110 { 111 if(parent == null) { 112 throw new IllegalArgumentException (Messages.getMessage("nullParent00")); 113 } 114 if (parent instanceof SOAPEnvelope) { 116 log.warn(Messages.getMessage("bodyHeaderParent")); 117 parent = ((SOAPEnvelope)parent).getHeader(); 118 } 119 if (!(parent instanceof SOAPHeader)) { 120 throw new IllegalArgumentException (Messages.getMessage("illegalArgumentException00")); 121 } 122 123 super.setParentElement(parent); 124 } 125 126 public SOAPHeaderElement(String namespace, 127 String localPart, 128 String prefix, 129 Attributes attributes, 130 DeserializationContext context) 131 throws AxisFault 132 { 133 super(namespace, localPart, prefix, attributes, context); 134 135 SOAPConstants soapConstants = getSOAPConstants(); 136 137 String val = attributes.getValue(soapConstants.getEnvelopeURI(), 139 Constants.ATTR_MUST_UNDERSTAND); 140 141 setMustUnderstandFromString(val, (soapConstants == 142 SOAPConstants.SOAP12_CONSTANTS)); 143 144 QName roleQName = soapConstants.getRoleAttributeQName(); 145 actor = attributes.getValue(roleQName.getNamespaceURI(), 146 roleQName.getLocalPart()); 147 151 if (soapConstants == SOAPConstants.SOAP12_CONSTANTS) { 152 String relayVal = attributes.getValue(soapConstants.getEnvelopeURI(), 153 Constants.ATTR_RELAY); 154 relay = ((relayVal != null) && (relayVal.equals("true") || relayVal.equals("1"))) ? true : false; 155 } 156 157 processed = false; 158 alreadySerialized = true; 159 } 160 161 private void setMustUnderstandFromString(String val, boolean isSOAP12) 162 throws AxisFault { 163 if (val != null && val.length() > 0) { 164 if ("0".equals(val)) { 165 mustUnderstand = false; 166 } else if ("1".equals(val)) { 167 mustUnderstand = true; 168 } else if (isSOAP12) { 169 if ("true".equalsIgnoreCase(val)) { 170 mustUnderstand = true; 171 } else if ("false".equalsIgnoreCase(val)) { 172 mustUnderstand = false; 173 } else { 174 throw new AxisFault( 175 Messages.getMessage("badMUVal", 176 val, 177 new QName (namespaceURI, 178 name).toString())); 179 } 180 } else { 181 throw new AxisFault( 182 Messages.getMessage("badMUVal", 183 val, 184 new QName (namespaceURI, 185 name).toString())); 186 } 187 } 188 } 189 190 public boolean getMustUnderstand() { return( mustUnderstand ); } 191 public void setMustUnderstand(boolean b) { 192 mustUnderstand = b ; 193 } 194 195 public String getActor() { return( actor ); } 196 public void setActor(String a) { 197 actor = a ; 198 } 199 200 public String getRole() { return( actor ); } 201 public void setRole(String a) { 202 actor = a ; 203 } 204 205 public boolean getRelay() { 206 return relay; 207 } 208 public void setRelay(boolean relay) { 209 this.relay = relay; 210 } 211 212 public void setProcessed(boolean value) { 213 processed = value ; 214 } 215 216 public boolean isProcessed() { 217 return( processed ); 218 } 219 220 boolean alreadySerialized = false; 221 222 224 protected void outputImpl(SerializationContext context) throws Exception { 225 if (!alreadySerialized) { 226 SOAPConstants soapVer = getSOAPConstants(); 227 QName roleQName = soapVer.getRoleAttributeQName(); 228 229 if (actor != null) { 230 setAttribute(roleQName.getNamespaceURI(), 231 roleQName.getLocalPart(), actor); 232 } 233 234 String val; 235 if (context.getMessageContext() != null && context.getMessageContext().getSOAPConstants() == SOAPConstants.SOAP12_CONSTANTS) 236 val = mustUnderstand ? "true" : "false"; 237 else 238 val = mustUnderstand ? "1" : "0"; 239 240 setAttribute(soapVer.getEnvelopeURI(), 241 Constants.ATTR_MUST_UNDERSTAND, 242 val); 243 244 if (soapVer == SOAPConstants.SOAP12_CONSTANTS && relay) { 245 setAttribute(soapVer.getEnvelopeURI(), Constants.ATTR_RELAY, 246 "true"); 247 } 248 } 249 250 super.outputImpl(context); 251 } 252 253 public NamedNodeMap getAttributes() { 254 makeAttributesEditable(); 255 SOAPConstants soapConstants = getSOAPConstants(); 256 String mustUnderstand = attributes.getValue(soapConstants.getEnvelopeURI(), 257 Constants.ATTR_MUST_UNDERSTAND); 258 QName roleQName = soapConstants.getRoleAttributeQName(); 259 String actor = attributes.getValue(roleQName.getNamespaceURI(),roleQName.getLocalPart()); 260 261 if(mustUnderstand == null){ 262 if (soapConstants == SOAPConstants.SOAP12_CONSTANTS) { 263 setAttributeNS(soapConstants.getEnvelopeURI(), 264 Constants.ATTR_MUST_UNDERSTAND,"false"); 265 } else { 266 setAttributeNS(soapConstants.getEnvelopeURI(), 267 Constants.ATTR_MUST_UNDERSTAND,"0"); 268 } 269 } 270 if(actor == null){ 271 setAttributeNS(roleQName.getNamespaceURI(), 272 roleQName.getLocalPart(), this.actor); 273 } 274 return super.getAttributes(); 275 } 276 277 private SOAPConstants getSOAPConstants() { 278 SOAPConstants soapConstants = null; 279 if (context != null) { 280 return context.getSOAPConstants(); 281 } 282 if (getNamespaceURI() != null && 283 getNamespaceURI().equals(SOAPConstants.SOAP12_CONSTANTS.getEnvelopeURI())) { 284 soapConstants = SOAPConstants.SOAP12_CONSTANTS; 285 } 286 if (soapConstants == null && getEnvelope() != null) { 287 soapConstants = getEnvelope().getSOAPConstants(); 288 } 289 if (soapConstants == null) { 290 soapConstants = SOAPConstants.SOAP11_CONSTANTS; 291 } 292 return soapConstants; 293 } 294 } 295 | Popular Tags |