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.handler;
020:
021: import org.apache.axis2.jaxws.core.MessageContext;
022: import org.apache.commons.logging.Log;
023: import org.apache.commons.logging.LogFactory;
024:
025: import java.util.Collection;
026: import java.util.Map;
027: import java.util.Set;
028:
029: /**
030: * @author rott
031: *
032: * BaseMessageContext is the base class for the two handler message contexts:
033: * SoapMessageContext and LogicalMessageContext. It delegates everything up to
034: * the MEPContext, which itself delegates to the requestMC or responseMC, as
035: * appropriate.
036: *
037: */
038: public class BaseMessageContext implements
039: javax.xml.ws.handler.MessageContext {
040: private static final Log log = LogFactory
041: .getLog(BaseMessageContext.class);
042:
043: protected MessageContext messageCtx;
044:
045: /**
046: * @param messageCtx
047: */
048: protected BaseMessageContext(MessageContext messageCtx) {
049: this .messageCtx = messageCtx;
050:
051: // Install an an AttachmentsAdapter between the
052: // jaxws attachment standard properties and the
053: // MessageContext Attachments implementation.
054: AttachmentsAdapter.install(messageCtx);
055: TransportHeadersAdapter.install(messageCtx);
056: }
057:
058: /* (non-Javadoc)
059: * @see java.util.Map#clear()
060: */
061: public void clear() {
062: messageCtx.getMEPContext().clear();
063: }
064:
065: /* (non-Javadoc)
066: * @see java.util.Map#containsKey(java.lang.Object)
067: */
068: public boolean containsKey(Object key) {
069: return messageCtx.getMEPContext().containsKey(key);
070: }
071:
072: /* (non-Javadoc)
073: * @see java.util.Map#containsValue(java.lang.Object)
074: */
075: public boolean containsValue(Object value) {
076: return messageCtx.getMEPContext().containsValue(value);
077: }
078:
079: /* (non-Javadoc)
080: * @see java.util.Map#entrySet()
081: */
082: public Set<java.util.Map.Entry<String, Object>> entrySet() {
083: return messageCtx.getMEPContext().entrySet();
084: }
085:
086: /* (non-Javadoc)
087: * @see java.util.Map#get(java.lang.Object)
088: */
089: public Object get(Object key) {
090: // There are some properties that, in some cases, should not span the message exchange;
091: // that is, they should come from only the current message context. For others properties,
092: // they should span the message exchange, meaning a property could be set on the request
093: // and it will also be available on the response. [JAXWS 2.0, Sec 9.4.1.1, pp. 110-113]
094: Object returnValue = null;
095: if (shouldPropertySpanMEP(key)) {
096: returnValue = messageCtx.getMEPContext().get(key);
097: } else {
098: returnValue = messageCtx.getProperty((String) key);
099: }
100:
101: // For the HTTP_REQUEST_HEADERS and HTTP_RESPONSE_HEADERS, the CTS tests want a null returned
102: // if there are no headers. Since we always put an instance of TransportHeadersAdapter,
103: // which contains the headers, on the message context, return a null if it is empty.
104: if (returnValue != null
105: && (returnValue instanceof TransportHeadersAdapter)) {
106: TransportHeadersAdapter adapter = (TransportHeadersAdapter) returnValue;
107: if (adapter.isEmpty()) {
108: return null;
109: }
110: }
111: return returnValue;
112: }
113:
114: private boolean shouldPropertySpanMEP(Object key) {
115: boolean shouldSpan = true;
116: String keyString = (String) key;
117:
118: // The CTS tests require that HTTP_REQUEST_HEADERS span the request and response contexts
119: // on the service-provider, but do NOT span the request and response context on the
120: // service-requester. So, for an INBOUND flow, do not allow HTTP_REQUEST_HEADERS to
121: // span the request and response contexts. The result is that the service-requester
122: // inbound handler will not see the request headers while processing a response.
123: Boolean outbound = (Boolean) messageCtx.getMEPContext().get(
124: MESSAGE_OUTBOUND_PROPERTY);
125: if (outbound != null && !outbound)
126: if (javax.xml.ws.handler.MessageContext.HTTP_REQUEST_HEADERS
127: .equals(keyString)) {
128: shouldSpan = false;
129: }
130: return shouldSpan;
131: }
132:
133: /* (non-Javadoc)
134: * @see java.util.Map#isEmpty()
135: */
136: public boolean isEmpty() {
137: return messageCtx.getMEPContext().isEmpty();
138: }
139:
140: /* (non-Javadoc)
141: * @see java.util.Map#keySet()
142: */
143: public Set<String> keySet() {
144: return messageCtx.getMEPContext().keySet();
145: }
146:
147: /* (non-Javadoc)
148: * @see java.util.Map#put(java.lang.Object, java.lang.Object)
149: */
150: public Object put(String key, Object value) {
151: return messageCtx.getMEPContext().put(key, value);
152: }
153:
154: /* (non-Javadoc)
155: * @see java.util.Map#putAll(java.util.Map)
156: */
157: public void putAll(Map<? extends String, ? extends Object> t) {
158: messageCtx.getMEPContext().putAll(t);
159: }
160:
161: /* (non-Javadoc)
162: * @see java.util.Map#remove(java.lang.Object)
163: */
164: public Object remove(Object key) {
165: return messageCtx.getMEPContext().remove(key);
166: }
167:
168: /* (non-Javadoc)
169: * @see java.util.Map#size()
170: */
171: public int size() {
172: return messageCtx.getMEPContext().size();
173: }
174:
175: /* (non-Javadoc)
176: * @see java.util.Map#values()
177: */
178: public Collection<Object> values() {
179: return messageCtx.getMEPContext().values();
180: }
181:
182: /* (non-Javadoc)
183: * @see javax.xml.ws.handler.MessageContext#getScope(java.lang.String)
184: */
185: public Scope getScope(String s) {
186: return messageCtx.getMEPContext().getScope(s);
187: }
188:
189: /* (non-Javadoc)
190: * @see javax.xml.ws.handler.MessageContext#setScope(java.lang.String, javax.xml.ws.handler.MessageContext.Scope)
191: */
192: public void setScope(String s, Scope scope) {
193: messageCtx.getMEPContext().setScope(s, scope);
194: }
195:
196: }
|