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.SOAPEnvelope;
022: import org.apache.axiom.soap.SOAPHeaderBlock;
023: import org.apache.axis2.context.MessageContext;
024: import org.apache.axis2.description.AxisDescription;
025: import org.apache.axis2.description.AxisOperation;
026: import org.apache.axis2.description.AxisService;
027: import org.apache.axis2.description.Parameter;
028: import org.apache.axis2.jaxws.description.EndpointDescription;
029: import org.apache.axis2.jaxws.description.OperationDescription;
030: import org.apache.commons.logging.Log;
031: import org.apache.commons.logging.LogFactory;
032:
033: import javax.xml.namespace.QName;
034:
035: import java.util.ArrayList;
036: import java.util.Iterator;
037:
038: /**
039: * Static utility methods used in processing mustUnderstand headers relative to JAXWS.
040: */
041: public class MustUnderstandUtils {
042: private static final Log log = LogFactory
043: .getLog(MustUnderstandUtils.class);
044:
045: /**
046: * Mark all headers for JAXWS SEI method paramaters as understood. Note that per the JAXWS
047: * 2.0 specification, a header is considered understood if it used by as a parameter for
048: * any method on the SEI, not just the method corresponding to the incoming operation.
049: * See Section 10.2.1 item 3.a which specifically says "mapped to method parameters
050: * in the service endpoint interface".
051: *
052: * @param msgContext
053: */
054: public static void markUnderstoodHeaderParameters(
055: MessageContext msgContext) {
056: if (msgContext == null) {
057: return;
058: }
059:
060: SOAPEnvelope envelope = msgContext.getEnvelope();
061: if (envelope.getHeader() == null) {
062: return;
063: }
064:
065: ArrayList understoodHeaderQNames = MustUnderstandUtils
066: .getHeaderParamaterList(msgContext);
067: if (understoodHeaderQNames == null) {
068: return;
069: }
070:
071: // Passing in null will get headers targeted for NEXT and ULTIMATE RECEIVER
072: Iterator headerBlocks = envelope.getHeader()
073: .getHeadersToProcess(null);
074: while (headerBlocks.hasNext()) {
075: SOAPHeaderBlock headerBlock = (SOAPHeaderBlock) headerBlocks
076: .next();
077: QName headerQN = headerBlock.getQName();
078: if (understoodHeaderQNames.contains(headerQN)) {
079: headerBlock.setProcessed();
080: if (log.isDebugEnabled()) {
081: log
082: .debug("Header marked as processed by JAXWS MustUnderstandChecker: "
083: + headerQN);
084: }
085: }
086: }
087: }
088:
089: /**
090: * Return an ArrayList of QNames corresponding to SOAP headers which map to method parameters
091: * for any methods on the corresponding SEI and the SOAP handlers.
092: *
093: * @param msgContext
094: * @return ArrayList of QNames for all header parameters for an SEI and SOAP handlers.
095: * The list may be empty but will not be null.
096: */
097: public static ArrayList getHeaderParamaterList(
098: MessageContext msgContext) {
099: ArrayList returnList = new ArrayList();
100: // Build a list of understood headers for all the operations under the service
101: AxisService axisService = msgContext.getAxisService();
102: if (log.isDebugEnabled()) {
103: log
104: .debug("Building list of understood headers for all operations under "
105: + axisService);
106: }
107: if (axisService != null) {
108: ArrayList understoodHeaders;
109:
110: // examine SEI methods
111: Iterator operationIterator = axisService.getOperations();
112: if (operationIterator != null) {
113: while (operationIterator.hasNext()) {
114: AxisOperation operation = (AxisOperation) operationIterator
115: .next();
116: understoodHeaders = getSEIMethodHeaderParameterList(operation);
117: if (log.isDebugEnabled()) {
118: log.debug("Adding headers from operation "
119: + operation + "; headers = "
120: + understoodHeaders);
121: }
122: if (understoodHeaders != null
123: && !understoodHeaders.isEmpty()) {
124: returnList.addAll(understoodHeaders);
125: }
126: }
127: }
128:
129: // examine handlers
130: understoodHeaders = getHandlersHeaderParameterList(axisService);
131: if (log.isDebugEnabled()) {
132: log
133: .debug("Adding headers from SOAP handlers; headers = "
134: + understoodHeaders);
135: }
136: if (understoodHeaders != null
137: && !understoodHeaders.isEmpty()) {
138: returnList.addAll(understoodHeaders);
139: }
140: }
141: return returnList;
142: }
143:
144: /**
145: * Return an ArrayList of QNames corresponding to SOAP headers which map to method parameters
146: * for a specific operation.
147: *
148: * @param axisOperation
149: * @return ArrayList of header QNames for all header paramters on an operation, or null if none.
150: */
151: public static ArrayList getSEIMethodHeaderParameterList(
152: AxisOperation axisOperation) {
153: return getHeaderParameterList(axisOperation,
154: OperationDescription.HEADER_PARAMETER_QNAMES);
155: }
156:
157: /**
158: * Return an ArrayList of QNames that is a collection of SOAP handlers
159: *
160: * @param axisService
161: * @return ArrayList of header QNames.
162: */
163: public static ArrayList getHandlersHeaderParameterList(
164: AxisService axisService) {
165: return getHeaderParameterList(axisService,
166: EndpointDescription.HANDLER_PARAMETER_QNAMES);
167: }
168:
169: private static ArrayList getHeaderParameterList(
170: AxisDescription axisDescription, String paramName) {
171: Parameter headerQNamesParameter = axisDescription
172: .getParameter(paramName);
173: if (headerQNamesParameter == null) {
174: if (log.isDebugEnabled()) {
175: log.debug("Parameter not on " + axisDescription + "; "
176: + paramName);
177: }
178: return null;
179: }
180:
181: ArrayList understoodHeaderQNames = (ArrayList) headerQNamesParameter
182: .getValue();
183: if (understoodHeaderQNames == null
184: || understoodHeaderQNames.isEmpty()) {
185: if (log.isDebugEnabled()) {
186: log.debug("Parameter value is empty: "
187: + axisDescription + "; " + paramName);
188: }
189: return null;
190: }
191:
192: return understoodHeaderQNames;
193: }
194:
195: }
|