001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.axis2.jaxws.dispatchers;
020:
021: import org.apache.axiom.soap.SOAP11Constants;
022: import org.apache.axiom.soap.SOAP12Constants;
023: import org.apache.axiom.soap.SOAPConstants;
024: import org.apache.axiom.soap.SOAPEnvelope;
025: import org.apache.axiom.soap.SOAPHeaderBlock;
026: import org.apache.axis2.AxisFault;
027: import org.apache.axis2.context.MessageContext;
028: import org.apache.axis2.description.AxisOperation;
029: import org.apache.axis2.description.AxisService;
030: import org.apache.axis2.engine.AbstractDispatcher;
031: import org.apache.axis2.engine.Handler.InvocationResponse;
032: import org.apache.axis2.i18n.Messages;
033: import org.apache.commons.logging.Log;
034: import org.apache.commons.logging.LogFactory;
035:
036: import javax.xml.namespace.QName;
037:
038: import java.util.ArrayList;
039: import java.util.Iterator;
040:
041: /**
042: * Do JAXWS MustUnderstand header processing per the JAXWS 2.0 specification. This checks for
043: * a specific compliance situation where a non-existant operation with mustUnderstood headers
044: * that are not understood must throw a mustUnderstandFault rather than an invalid EPR exception.
045: *
046: * Note that this handler should be inserted in the inbound dispather chains so that the
047: * Dispatcher checkPostConditions does not throw the invalid EPR fault if the operation is null.
048: */
049: public class MustUnderstandValidationDispatcher extends
050: AbstractDispatcher {
051: private static final Log log = LogFactory
052: .getLog(MustUnderstandValidationDispatcher.class);
053:
054: /* (non-Javadoc)
055: * @see org.apache.axis2.engine.AbstractDispatcher#findOperation(org.apache.axis2.description.AxisService, org.apache.axis2.context.MessageContext)
056: */
057: @Override
058: public AxisOperation findOperation(AxisService service,
059: MessageContext messageContext) throws AxisFault {
060: return null;
061: }
062:
063: /* (non-Javadoc)
064: * @see org.apache.axis2.engine.AbstractDispatcher#findService(org.apache.axis2.context.MessageContext)
065: */
066: @Override
067: public AxisService findService(MessageContext messageContext)
068: throws AxisFault {
069: return null;
070: }
071:
072: /* (non-Javadoc)
073: * @see org.apache.axis2.engine.AbstractDispatcher#initDispatcher()
074: */
075: @Override
076: public void initDispatcher() {
077: }
078:
079: public InvocationResponse invoke(MessageContext msgctx)
080: throws AxisFault {
081: AxisService axisService = msgctx.getAxisService();
082: AxisOperation axisOperation = msgctx.getAxisOperation();
083:
084: if (log.isDebugEnabled()) {
085: log
086: .debug("JAXWS MustUnderstandValidationDispatcher.invoke on AxisService "
087: + axisService
088: + "; AxisOperation "
089: + axisOperation);
090: }
091: // REVIEW: This will only check do the mustUnderstand checking if the operation is null
092: // That is because JAXWS compliance requires we throw a mustUnderstand fault even if the operation is
093: // invalid. If the operation is valid, then further mustUnderstand processing will be done
094: // by the JAXWS MustUnderstandChecker handler.
095: if (axisService != null && axisOperation == null) {
096: checkMustUnderstand(msgctx);
097: }
098: return InvocationResponse.CONTINUE;
099: }
100:
101: private boolean checkMustUnderstand(MessageContext msgContext)
102: throws AxisFault {
103: boolean checksPass = true;
104:
105: SOAPEnvelope envelope = msgContext.getEnvelope();
106: if (envelope.getHeader() == null) {
107: return checksPass;
108: }
109:
110: // First mark all the headers JAXWS would understand to make sure we don't throw
111: // a mustUnderstand fault inappropriately for those.
112: MustUnderstandUtils.markUnderstoodHeaderParameters(msgContext);
113:
114: // Now check all the headers and throw the mustUnderstandFault if any not understood.
115: // REVIEW: Note that QoSes that would run after the dispatch phase will not have marked
116: // their headers yet.
117:
118: Iterator headerBlocks = envelope.getHeader()
119: .getHeadersToProcess(null);
120: while (headerBlocks.hasNext()) {
121: SOAPHeaderBlock headerBlock = (SOAPHeaderBlock) headerBlocks
122: .next();
123: if (headerBlock.isProcessed()
124: || !headerBlock.getMustUnderstand()) {
125: continue;
126: }
127:
128: QName faultQName = headerBlock.getVersion()
129: .getMustUnderstandFaultCode();
130: throw new AxisFault(Messages.getMessage(
131: "mustunderstandfailed", headerBlock.getNamespace()
132: .getNamespaceURI(), headerBlock
133: .getLocalName()), faultQName);
134: }
135: return checksPass;
136: }
137:
138: }
|