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.logical;
019:
020: import javax.xml.stream.XMLStreamReader;
021: import javax.xml.ws.Binding;
022:
023: import org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor;
024: import org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor;
025: import org.apache.cxf.endpoint.Endpoint;
026: import org.apache.cxf.interceptor.InterceptorChain;
027: import org.apache.cxf.interceptor.OutgoingChainInterceptor;
028: import org.apache.cxf.jaxws.handler.AbstractJAXWSHandlerInterceptor;
029: import org.apache.cxf.jaxws.handler.HandlerChainInvoker;
030: import org.apache.cxf.jaxws.handler.soap.SOAPHandlerInterceptor;
031: import org.apache.cxf.jaxws.support.ContextPropertiesMapping;
032: import org.apache.cxf.message.Message;
033: import org.apache.cxf.phase.Phase;
034: import org.apache.cxf.staxutils.StaxUtils;
035: import org.apache.cxf.staxutils.W3CDOMStreamWriter;
036:
037: public class LogicalHandlerInInterceptor<T extends Message> extends
038: AbstractJAXWSHandlerInterceptor<T> {
039:
040: public LogicalHandlerInInterceptor(Binding binding) {
041: super (binding, Phase.PRE_PROTOCOL);
042: addAfter(MustUnderstandInterceptor.class.getName());
043: addAfter(SAAJOutInterceptor.class.getName());
044: addAfter(SOAPHandlerInterceptor.class.getName());
045: }
046:
047: public void handleMessage(T message) {
048: HandlerChainInvoker invoker = getInvoker(message);
049: if (invoker.getLogicalHandlers().isEmpty()) {
050: return;
051: }
052:
053: LogicalMessageContextImpl lctx = new LogicalMessageContextImpl(
054: message);
055: invoker.setLogicalMessageContext(lctx);
056: boolean requestor = isRequestor(message);
057:
058: ContextPropertiesMapping.mapCxf2Jaxws(message.getExchange(),
059: lctx, requestor);
060: if (!invoker.invokeLogicalHandlers(requestor, lctx)) {
061: if (!requestor) {
062: //server side
063: handleAbort(message, null);
064: } else {
065: //Client side inbound, thus no response expected, do nothing, the close will
066: //be handled by MEPComplete later
067: }
068: }
069:
070: //If this is the inbound and end of MEP, call MEP completion
071: if (!isOutbound(message) && isMEPComlete(message)) {
072: onCompletion(message);
073: }
074: }
075:
076: private void handleAbort(T message, W3CDOMStreamWriter writer) {
077: message.getInterceptorChain().abort();
078:
079: if (!message.getExchange().isOneWay()) {
080: //server side inbound
081: Endpoint e = message.getExchange().get(Endpoint.class);
082: Message responseMsg = e.getBinding().createMessage();
083:
084: message.getExchange().setOutMessage(responseMsg);
085: XMLStreamReader reader = message
086: .getContent(XMLStreamReader.class);
087: if (reader == null && writer != null) {
088: reader = StaxUtils.createXMLStreamReader(writer
089: .getDocument());
090: }
091:
092: InterceptorChain chain = OutgoingChainInterceptor
093: .getOutInterceptorChain(message.getExchange());
094: responseMsg.setInterceptorChain(chain);
095: responseMsg.put("LogicalHandlerInterceptor.INREADER",
096: reader);
097:
098: chain.doIntercept(responseMsg);
099: }
100: }
101:
102: public void handleFault(T message) {
103: // TODO
104: }
105: }
|