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: */package org.apache.cxf.jaxws.handler;
019:
020: import javax.xml.ws.Binding;
021:
022: import org.apache.cxf.message.Exchange;
023: import org.apache.cxf.message.Message;
024: import org.apache.cxf.phase.AbstractPhaseInterceptor;
025:
026: public abstract class AbstractJAXWSHandlerInterceptor<T extends Message>
027: extends AbstractPhaseInterceptor<T> {
028: private Binding binding;
029:
030: protected AbstractJAXWSHandlerInterceptor(Binding b, String phase) {
031: super (phase);
032: binding = b;
033: }
034:
035: protected boolean isOutbound(T message) {
036: return isOutbound(message, message.getExchange());
037: }
038:
039: private boolean isOutbound(T message, Exchange ex) {
040: return message == ex.getOutMessage()
041: || message == ex.getOutFaultMessage();
042: }
043:
044: protected boolean isRequestor(T message) {
045: return Boolean.TRUE.equals(message
046: .containsKey(Message.REQUESTOR_ROLE));
047: }
048:
049: protected HandlerChainInvoker getInvoker(T message) {
050: Exchange ex = message.getExchange();
051: HandlerChainInvoker invoker = ex.get(HandlerChainInvoker.class);
052: if (null == invoker) {
053: invoker = new HandlerChainInvoker(
054: binding.getHandlerChain(), isOutbound(message));
055: ex.put(HandlerChainInvoker.class, invoker);
056: }
057:
058: boolean outbound = isOutbound(message, ex);
059: if (outbound) {
060: invoker.setOutbound();
061: } else {
062: invoker.setInbound();
063: }
064: invoker.setRequestor(isRequestor(message));
065:
066: if (ex.isOneWay()
067: || ((isRequestor(message) && !outbound) || (!isRequestor(message) && outbound))) {
068: invoker.setResponseExpected(false);
069: } else {
070: invoker.setResponseExpected(true);
071: }
072:
073: return invoker;
074: }
075:
076: protected Binding getBinding() {
077: return binding;
078: }
079:
080: public void onCompletion(T message) {
081: getInvoker(message).mepComplete(message);
082: }
083:
084: public boolean isMEPComlete(T message) {
085: HandlerChainInvoker invoker = getInvoker(message);
086:
087: if (invoker.isRequestor()) {
088: //client inbound and client outbound with no response are end of MEP
089: if (invoker.isInbound()) {
090: return true;
091: } else if (!invoker.isResponseExpected()) {
092: return true;
093: }
094: } else {
095: //server outbound and server inbound with no response are end of MEP
096: if (!invoker.isInbound()) {
097: return true;
098: } else if (!invoker.isResponseExpected()) {
099: return true;
100: }
101: }
102:
103: return false;
104: }
105: }
|