001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.servicemix.cxfbc.interceptors;
018
019
020 import javax.jbi.messaging.MessageExchange;
021 import javax.xml.namespace.QName;
022
023 import org.apache.cxf.interceptor.Fault;
024 import org.apache.cxf.message.Message;
025 import org.apache.cxf.phase.AbstractPhaseInterceptor;
026 import org.apache.cxf.phase.Phase;
027 import org.apache.cxf.ws.addressing.AddressingPropertiesImpl;
028 import org.apache.cxf.ws.addressing.AttributedURIType;
029 import org.apache.cxf.ws.addressing.ContextUtils;
030 import org.apache.servicemix.cxfbc.CxfBcConsumer;
031 import org.apache.servicemix.jbi.resolver.URIResolver;
032
033
034 public class JbiAddressingInterceptor extends AbstractPhaseInterceptor<Message> {
035
036
037
038 public JbiAddressingInterceptor() {
039 super(Phase.INVOKE);
040 getBefore().add(CxfBcConsumer.JbiInvokerInterceptor.class.getName());
041 }
042
043 public void handleMessage(Message message) throws Fault {
044
045 final AddressingPropertiesImpl maps = ContextUtils.retrieveMAPs(message, false, false);
046 if (null == maps) {
047 return;
048 }
049 AttributedURIType action = maps.getAction();
050 if (action != null) {
051 String value = action.getValue();
052
053 if (value != null && value.endsWith(JbiConstants.JBI_SUFFIX)) {
054 value = value.substring(0, value.indexOf(JbiConstants.JBI_SUFFIX) - 1);
055 String[] parts = URIResolver.split3(value);
056 MessageExchange exchange = message.getContent(MessageExchange.class);
057 exchange.setOperation(new QName(parts[0], parts[2]));
058 exchange.setInterfaceName(new QName(parts[0], parts[1]));
059 }
060 }
061
062 AttributedURIType to = maps.getTo();
063 if (to != null) {
064 String toAddress = to.getValue();
065 if (toAddress != null && toAddress.endsWith(JbiConstants.JBI_SUFFIX)) {
066 toAddress = toAddress.substring(0, toAddress.indexOf(JbiConstants.JBI_SUFFIX) - 1);
067 String[] parts = URIResolver.split3(toAddress);
068 MessageExchange exchange = message.getContent(MessageExchange.class);
069 exchange.setService(new QName(parts[0], parts[1]));
070 }
071 }
072
073 }
074
075
076 }