01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.servicemix.cxfbc.interceptors;
18:
19: import javax.jbi.messaging.MessageExchange;
20: import javax.xml.namespace.QName;
21:
22: import org.apache.cxf.interceptor.Fault;
23: import org.apache.cxf.message.Message;
24: import org.apache.cxf.phase.AbstractPhaseInterceptor;
25: import org.apache.cxf.phase.Phase;
26: import org.apache.cxf.ws.addressing.AddressingPropertiesImpl;
27: import org.apache.cxf.ws.addressing.AttributedURIType;
28: import org.apache.cxf.ws.addressing.ContextUtils;
29: import org.apache.servicemix.cxfbc.CxfBcConsumer;
30: import org.apache.servicemix.jbi.resolver.URIResolver;
31:
32: public class JbiAddressingInterceptor extends
33: AbstractPhaseInterceptor<Message> {
34:
35: public JbiAddressingInterceptor() {
36: super (Phase.INVOKE);
37: getBefore().add(
38: CxfBcConsumer.JbiInvokerInterceptor.class.getName());
39: }
40:
41: public void handleMessage(Message message) throws Fault {
42:
43: final AddressingPropertiesImpl maps = ContextUtils
44: .retrieveMAPs(message, false, false);
45: if (null == maps) {
46: return;
47: }
48: AttributedURIType action = maps.getAction();
49: if (action != null) {
50: String value = action.getValue();
51:
52: if (value != null
53: && value.endsWith(JbiConstants.JBI_SUFFIX)) {
54: value = value.substring(0, value
55: .indexOf(JbiConstants.JBI_SUFFIX) - 1);
56: String[] parts = URIResolver.split3(value);
57: MessageExchange exchange = message
58: .getContent(MessageExchange.class);
59: exchange.setOperation(new QName(parts[0], parts[2]));
60: exchange
61: .setInterfaceName(new QName(parts[0], parts[1]));
62: }
63: }
64:
65: AttributedURIType to = maps.getTo();
66: if (to != null) {
67: String toAddress = to.getValue();
68: if (toAddress != null
69: && toAddress.endsWith(JbiConstants.JBI_SUFFIX)) {
70: toAddress = toAddress.substring(0, toAddress
71: .indexOf(JbiConstants.JBI_SUFFIX) - 1);
72: String[] parts = URIResolver.split3(toAddress);
73: MessageExchange exchange = message
74: .getContent(MessageExchange.class);
75: exchange.setService(new QName(parts[0], parts[1]));
76: }
77: }
78:
79: }
80:
81: }
|