1 16 17 package org.apache.axis.handlers.soap; 18 19 import org.apache.axis.AxisFault; 20 import org.apache.axis.Constants; 21 import org.apache.axis.MessageContext; 22 import org.apache.axis.Message; 23 import org.apache.axis.description.OperationDesc; 24 import org.apache.axis.components.logger.LogFactory; 25 import org.apache.axis.handlers.BasicHandler; 26 import org.apache.axis.message.SOAPEnvelope; 27 import org.apache.axis.message.SOAPHeaderElement; 28 import org.apache.axis.soap.SOAPConstants; 29 import org.apache.axis.utils.Messages; 30 import org.apache.commons.logging.Log; 31 32 import javax.xml.namespace.QName ; 33 import java.util.ArrayList ; 34 import java.util.Enumeration ; 35 import java.util.Vector ; 36 37 41 public class MustUnderstandChecker extends BasicHandler { 42 43 private static Log log = 44 LogFactory.getLog(MustUnderstandChecker.class.getName()); 45 46 private SOAPService service = null; 47 48 public MustUnderstandChecker(SOAPService service) { 49 this.service = service; 50 } 51 52 public void invoke(MessageContext msgContext) throws AxisFault { 53 if (log.isDebugEnabled()) { 55 log.debug(Messages.getMessage("semanticCheck00")); 56 } 57 58 Message msg = msgContext.getCurrentMessage(); 59 if (msg == null) 60 return; 62 SOAPEnvelope env = msg.getSOAPEnvelope(); 63 Vector headers = null; 64 if (service != null) { 65 ArrayList acts = service.getActors(); 66 headers = env.getHeadersByActor(acts); 67 } else { 68 headers = env.getHeaders(); 69 } 70 71 Vector misunderstoodHeaders = null; 73 Enumeration enumeration = headers.elements(); 74 while (enumeration.hasMoreElements()) { 75 SOAPHeaderElement header = (SOAPHeaderElement) enumeration. 76 nextElement(); 77 78 if(msgContext != null && msgContext.getOperation() != null) { 80 OperationDesc oper = msgContext.getOperation(); 81 if(oper.getParamByQName(header.getQName())!=null) { 82 continue; 83 } 84 } 85 if (header.getMustUnderstand() && !header.isProcessed()) { 86 if (misunderstoodHeaders == null) 87 misunderstoodHeaders = new Vector (); 88 misunderstoodHeaders.addElement(header); 89 } 90 } 91 SOAPConstants soapConstants = msgContext.getSOAPConstants(); 92 95 if (misunderstoodHeaders != null) { 96 AxisFault fault = 97 new AxisFault(soapConstants.getMustunderstandFaultQName(), 98 null, null, 99 null, null, 100 null); 101 StringBuffer whatWasMissUnderstood = new StringBuffer (256); 102 103 if (soapConstants == SOAPConstants.SOAP12_CONSTANTS) { 105 enumeration = misunderstoodHeaders.elements(); 106 while (enumeration.hasMoreElements()) { 107 SOAPHeaderElement badHeader = (SOAPHeaderElement) enumeration. 108 nextElement(); 109 QName badQName = new QName (badHeader.getNamespaceURI(), 110 badHeader.getName()); 111 if (whatWasMissUnderstood.length() != 0) 112 whatWasMissUnderstood.append(", "); 113 whatWasMissUnderstood.append(badQName.toString()); 114 SOAPHeaderElement newHeader = new 115 SOAPHeaderElement(Constants.URI_SOAP12_ENV, 116 Constants.ELEM_NOTUNDERSTOOD); 117 newHeader.addAttribute(null, 118 Constants.ATTR_QNAME, 119 badQName); 120 fault.addHeader(newHeader); 121 } 122 } 123 fault.setFaultString(Messages.getMessage("noUnderstand00", 124 whatWasMissUnderstood.toString())); 125 throw fault; 126 } 127 } 128 } 129 | Popular Tags |