1
2
3
4
5
6
7
8
9
10
11 package org.mule.module.cxf.support;
12
13 import org.mule.api.endpoint.EndpointNotFoundException;
14
15 import java.io.IOException;
16 import java.util.List;
17
18 import org.apache.cxf.endpoint.Endpoint;
19 import org.apache.cxf.interceptor.Interceptor;
20 import org.apache.cxf.message.Message;
21 import org.apache.cxf.phase.PhaseInterceptor;
22 import org.apache.cxf.service.model.EndpointInfo;
23 import org.apache.cxf.transport.ChainInitiationObserver;
24 import org.apache.cxf.transport.Destination;
25 import org.apache.cxf.transport.DestinationFactory;
26 import org.apache.cxf.transport.MessageObserver;
27
28 public final class CxfUtils
29 {
30
31 @SuppressWarnings("unchecked")
32 public static void removeInterceptor(List<Interceptor<? extends Message>> inInterceptors, String name) {
33
34 for (Interceptor<?> i : inInterceptors) {
35 if (i instanceof PhaseInterceptor) {
36 PhaseInterceptor<Message> p = (PhaseInterceptor<Message>)i;
37
38 if (p.getId().equals(name)) {
39 inInterceptors.remove(p);
40 return;
41 }
42 }
43 }
44 }
45
46 public static Endpoint getEndpoint(DestinationFactory df, String uri)
47 throws IOException, EndpointNotFoundException
48 {
49 int idx = uri.indexOf('?');
50 if (idx != -1)
51 {
52 uri = uri.substring(0, idx);
53 }
54
55 EndpointInfo ei = new EndpointInfo();
56 ei.setAddress(uri);
57
58 Destination d = df.getDestination(ei);
59 if (d.getMessageObserver() == null)
60 {
61
62 throw new EndpointNotFoundException(uri);
63 }
64
65 MessageObserver mo = d.getMessageObserver();
66 if (!(mo instanceof ChainInitiationObserver))
67 {
68 throw new EndpointNotFoundException(uri);
69 }
70
71 ChainInitiationObserver co = (ChainInitiationObserver) mo;
72 return co.getEndpoint();
73 }
74
75 }