01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.jaxws.handler.logical;
19:
20: import javax.xml.stream.XMLStreamReader;
21: import javax.xml.ws.Binding;
22: import org.apache.cxf.endpoint.Endpoint;
23: import org.apache.cxf.interceptor.Fault;
24: import org.apache.cxf.jaxws.handler.AbstractJAXWSHandlerInterceptor;
25: import org.apache.cxf.jaxws.handler.HandlerChainInvoker;
26: import org.apache.cxf.jaxws.support.ContextPropertiesMapping;
27: import org.apache.cxf.message.Message;
28: import org.apache.cxf.phase.Phase;
29: import org.apache.cxf.phase.PhaseInterceptorChain;
30: import org.apache.cxf.transport.MessageObserver;
31:
32: public class DispatchLogicalHandlerInterceptor<T extends Message>
33: extends AbstractJAXWSHandlerInterceptor<T> {
34:
35: public DispatchLogicalHandlerInterceptor(Binding binding) {
36: super (binding, Phase.PRE_MARSHAL);
37: }
38:
39: public DispatchLogicalHandlerInterceptor(Binding binding,
40: String phase) {
41: super (binding, phase);
42: }
43:
44: public void handleMessage(T message) throws Fault {
45: HandlerChainInvoker invoker = getInvoker(message);
46: if (invoker.getLogicalHandlers().isEmpty()) {
47: return;
48: }
49:
50: LogicalMessageContextImpl lctx = new LogicalMessageContextImpl(
51: message);
52: invoker.setLogicalMessageContext(lctx);
53: boolean requestor = isRequestor(message);
54:
55: ContextPropertiesMapping.mapCxf2Jaxws(message.getExchange(),
56: lctx, requestor);
57:
58: if (!invoker.invokeLogicalHandlers(requestor, lctx)
59: && requestor) {
60: if (isOutbound(message)) {
61: // client side outbound - the request message becomes the
62: // response message
63: message.getInterceptorChain().abort();
64: Endpoint e = message.getExchange().get(Endpoint.class);
65: Message responseMsg = e.getBinding().createMessage();
66:
67: MessageObserver observer = (MessageObserver) message
68: .getExchange().get(MessageObserver.class);
69: if (observer != null) {
70: responseMsg.setContent(XMLStreamReader.class,
71: message.getContent(XMLStreamReader.class));
72:
73: message.getExchange().setInMessage(responseMsg);
74: responseMsg
75: .put(
76: PhaseInterceptorChain.STARTING_AT_INTERCEPTOR_ID,
77: LogicalHandlerInInterceptor.class
78: .getName());
79: observer.onMessage(responseMsg);
80: }
81: } else {
82: //Client side inbound, thus no response expected, do nothing, the close will
83: //be handled by MEPComplete later
84: }
85: }
86:
87: //If this is the inbound and end of MEP, call MEP completion
88: if (!isOutbound(message) && isMEPComlete(message)) {
89: onCompletion(message);
90: }
91: }
92: }
|