FileDocCategorySizeDatePackage
MustUnderstandChecker.javaAPI DocApache Axis 1.45029Sat Apr 22 18:57:26 BST 2006org.apache.axis.handlers.soap

MustUnderstandChecker

public class MustUnderstandChecker extends org.apache.axis.handlers.BasicHandler
MustUnderstandChecker is used to inject SOAP semantics just before the pivot handler.

Fields Summary
private static Log
log
private SOAPService
service
Constructors Summary
public MustUnderstandChecker(SOAPService service)


       
        this.service = service;
    
Methods Summary
public voidinvoke(org.apache.axis.MessageContext msgContext)

        // Do SOAP semantics here
        if (log.isDebugEnabled()) {
            log.debug(Messages.getMessage("semanticCheck00"));
        }
        
        Message msg = msgContext.getCurrentMessage();
        if (msg == null)
            return;  // nothing to do if there's no message
        
        SOAPEnvelope env = msg.getSOAPEnvelope();
        Vector headers = null;
        if (service != null) {
            ArrayList acts = service.getActors();
            headers = env.getHeadersByActor(acts);
        } else {
            headers = env.getHeaders();
        }
            
        // 1. Check mustUnderstands
        Vector misunderstoodHeaders = null;
        Enumeration enumeration = headers.elements();
        while (enumeration.hasMoreElements()) {
            SOAPHeaderElement header = (SOAPHeaderElement) enumeration.
                    nextElement();
            
            // Ignore header, if it is a parameter to the operation 
            if(msgContext != null && msgContext.getOperation() != null) {
                OperationDesc oper = msgContext.getOperation();
                if(oper.getParamByQName(header.getQName())!=null) {
                    continue;
                }                    
            }
            if (header.getMustUnderstand() && !header.isProcessed()) {
                if (misunderstoodHeaders == null)
                    misunderstoodHeaders = new Vector();
                misunderstoodHeaders.addElement(header);
            }
        }
        SOAPConstants soapConstants = msgContext.getSOAPConstants();
        // !!! we should indicate SOAP1.2 compliance via the
        // MessageContext, not a boolean here....

        if (misunderstoodHeaders != null) {
            AxisFault fault =
                    new AxisFault(soapConstants.getMustunderstandFaultQName(),
                            null, null,
                            null, null,
                            null);
            StringBuffer whatWasMissUnderstood = new StringBuffer(256);

            enumeration = misunderstoodHeaders.elements();
            while (enumeration.hasMoreElements()) {
                SOAPHeaderElement badHeader = (SOAPHeaderElement) enumeration.
                        nextElement();
                QName badQName = new QName(badHeader.getNamespaceURI(),
                        badHeader.getName());
                if (whatWasMissUnderstood.length() != 0)
                    whatWasMissUnderstood.append(", ");
                whatWasMissUnderstood.append(badQName.toString());
                // !!! If SOAP 1.2, insert misunderstood fault headers here
                if ( soapConstants == SOAPConstants.SOAP12_CONSTANTS ) {
                  SOAPHeaderElement newHeader = new
                          SOAPHeaderElement(Constants.URI_SOAP12_ENV,
                                  Constants.ELEM_NOTUNDERSTOOD);
                  newHeader.addAttribute(null,
                          Constants.ATTR_QNAME,
                          badQName);
                  fault.addHeader(newHeader);
                }
            }
            fault.setFaultString(Messages.getMessage("noUnderstand00",
                    whatWasMissUnderstood.toString()));
            throw fault;
        }