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.message.Protocol;
022:
023: import javax.xml.ws.handler.Handler;
024:
025: import java.util.List;
026:
027: public class HandlerInvokerUtils {
028:
029: /**
030: * Invoke Inbound Handlers
031: * @param requestMsgCtx
032: */
033: public static boolean invokeInboundHandlers(
034: MEPContext mepMessageCtx, List<Handler> handlers,
035: HandlerChainProcessor.MEP mep, boolean isOneWay) {
036:
037: String bindingProto = null;
038: if (mep.equals(HandlerChainProcessor.MEP.REQUEST)) // inbound request; must be on the server
039: bindingProto = mepMessageCtx.getEndpointDesc()
040: .getBindingType();
041: else
042: // inbound response; must be on the client
043: bindingProto = mepMessageCtx.getEndpointDesc()
044: .getClientBindingID();
045: Protocol proto = Protocol.getProtocolForBinding(bindingProto);
046:
047: HandlerChainProcessor processor = new HandlerChainProcessor(
048: handlers, proto);
049: // if not one-way, expect a response
050: boolean success = true;
051: try {
052: if (mepMessageCtx.getMessageObject().isFault()) {
053: processor.processFault(mepMessageCtx,
054: HandlerChainProcessor.Direction.IN);
055: } else {
056: success = processor.processChain(mepMessageCtx,
057: HandlerChainProcessor.Direction.IN, mep,
058: !isOneWay);
059: }
060: } catch (RuntimeException re) {
061: /*
062: * handler framework should only throw an exception here if
063: * we are in the client inbound case. Make sure the message
064: * context and message are transformed.
065: */
066: HandlerChainProcessor.convertToFaultMessage(mepMessageCtx,
067: re, proto);
068: // done invoking inbound handlers, be sure to set the access lock flag on the context to true
069: mepMessageCtx.setApplicationAccessLocked(true);
070: return false;
071: }
072:
073: if (!success && mep.equals(HandlerChainProcessor.MEP.REQUEST)) {
074: // uh-oh. We've changed directions on the server inbound handler processing,
075: // This means we're now on an outbound flow, and the endpoint will not
076: // be called. Be sure to mark the context and message as such.
077:
078: // done invoking inbound handlers, be sure to set the access lock flag on the context to true
079: mepMessageCtx.setApplicationAccessLocked(true);
080: return false;
081: }
082: // done invoking inbound handlers, be sure to set the access lock flag on the context to true
083: mepMessageCtx.setApplicationAccessLocked(true);
084: return true;
085:
086: }
087:
088: /**
089: * Invoke OutboundHandlers
090: *
091: * @param msgCtx
092: */
093: public static boolean invokeOutboundHandlers(
094: MEPContext mepMessageCtx, List<Handler> handlers,
095: HandlerChainProcessor.MEP mep, boolean isOneWay) {
096:
097: if (handlers == null)
098: return true;
099:
100: String bindingProto = null;
101: if (mep.equals(HandlerChainProcessor.MEP.REQUEST)) // outbound request; must be on the client
102: bindingProto = mepMessageCtx.getEndpointDesc()
103: .getClientBindingID();
104: else
105: // outbound response; must be on the server
106: bindingProto = mepMessageCtx.getEndpointDesc()
107: .getBindingType();
108: Protocol proto = Protocol.getProtocolForBinding(bindingProto);
109:
110: HandlerChainProcessor processor = new HandlerChainProcessor(
111: handlers, proto);
112: // if not one-way, expect a response
113: boolean success = true;
114: try {
115: if (mepMessageCtx.getMessageObject().isFault()) {
116: processor.processFault(mepMessageCtx,
117: HandlerChainProcessor.Direction.OUT);
118: } else {
119: success = processor.processChain(mepMessageCtx,
120: HandlerChainProcessor.Direction.OUT, mep,
121: !isOneWay);
122: }
123: } catch (RuntimeException re) {
124: /*
125: * handler framework should only throw an exception here if
126: * we are in the server outbound case. Make sure the message
127: * context and message are transformed.
128: */
129: HandlerChainProcessor.convertToFaultMessage(mepMessageCtx,
130: re, proto);
131: return false;
132: }
133:
134: if (!success && mep.equals(HandlerChainProcessor.MEP.REQUEST)) {
135: // uh-oh. We've changed directions on the client outbound handler processing,
136: // This means we're now on an inbound flow, and the service will not
137: // be called. Be sure to mark the context and message as such.
138: return false;
139: }
140: return true;
141:
142: }
143:
144: }
|