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.interceptor;
19:
20: import java.util.Set;
21:
22: import org.apache.cxf.binding.Binding;
23: import org.apache.cxf.endpoint.Endpoint;
24: import org.apache.cxf.helpers.CastUtils;
25: import org.apache.cxf.message.Exchange;
26: import org.apache.cxf.message.Message;
27: import org.apache.cxf.phase.AbstractPhaseInterceptor;
28: import org.apache.cxf.service.Service;
29: import org.apache.cxf.transport.MultipleEndpointObserver;
30:
31: public abstract class AbstractEndpointSelectionInterceptor extends
32: AbstractPhaseInterceptor<Message> {
33:
34: /**
35: * @deprecated
36: */
37: public AbstractEndpointSelectionInterceptor() {
38: super (null);
39: }
40:
41: public AbstractEndpointSelectionInterceptor(String phase) {
42: super (phase);
43: }
44:
45: public AbstractEndpointSelectionInterceptor(String id, String phase) {
46: super (id, phase);
47: }
48:
49: public void handleMessage(Message message) throws Fault {
50: Exchange ex = message.getExchange();
51: Set<Endpoint> endpoints = CastUtils.cast((Set) ex
52: .get(MultipleEndpointObserver.ENDPOINTS));
53:
54: Endpoint ep = selectEndpoint(message, endpoints);
55:
56: if (ep == null) {
57: return;
58: }
59:
60: ex.put(Endpoint.class, ep);
61: ex.put(Binding.class, ep.getBinding());
62: ex.put(Service.class, ep.getService());
63:
64: InterceptorChain chain = message.getInterceptorChain();
65: chain.add(ep.getInInterceptors());
66: chain.add(ep.getBinding().getInInterceptors());
67: chain.add(ep.getService().getInInterceptors());
68:
69: chain.setFaultObserver(ep.getOutFaultObserver());
70: }
71:
72: /**
73: * Select an Endpoint which will be used for the rest of the inocation.
74: *
75: * @param message
76: * @param eps
77: * @return
78: */
79: protected abstract Endpoint selectEndpoint(Message message,
80: Set<Endpoint> eps);
81: }
|