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.Iterator;
17 import java.util.List;
18
19 import org.apache.cxf.binding.soap.SoapVersion;
20 import org.apache.cxf.binding.soap.SoapVersionFactory;
21 import org.apache.cxf.endpoint.Endpoint;
22 import org.apache.cxf.interceptor.Interceptor;
23 import org.apache.cxf.message.Message;
24 import org.apache.cxf.phase.PhaseInterceptor;
25 import org.apache.cxf.service.model.EndpointInfo;
26 import org.apache.cxf.transport.ChainInitiationObserver;
27 import org.apache.cxf.transport.Destination;
28 import org.apache.cxf.transport.DestinationFactory;
29 import org.apache.cxf.transport.MessageObserver;
30
31 public final class CxfUtils
32 {
33
34 @SuppressWarnings("unchecked")
35 public static boolean removeInterceptor(List<Interceptor<? extends Message>> inInterceptors, String name)
36 {
37
38 for (Interceptor<?> i : inInterceptors)
39 {
40 if (i instanceof PhaseInterceptor)
41 {
42 PhaseInterceptor<Message> p = (PhaseInterceptor<Message>)i;
43
44 if (p.getId().equals(name))
45 {
46 inInterceptors.remove(p);
47 return true;
48 }
49 }
50 }
51
52 return false;
53 }
54
55
56 public static Endpoint getEndpoint(DestinationFactory df, String uri)
57 throws IOException, EndpointNotFoundException
58 {
59 int idx = uri.indexOf('?');
60 if (idx != -1)
61 {
62 uri = uri.substring(0, idx);
63 }
64
65 EndpointInfo ei = new EndpointInfo();
66 ei.setAddress(uri);
67
68 Destination d = df.getDestination(ei);
69 if (d.getMessageObserver() == null)
70 {
71
72 throw new EndpointNotFoundException(uri);
73 }
74
75 MessageObserver mo = d.getMessageObserver();
76 if (!(mo instanceof ChainInitiationObserver))
77 {
78 throw new EndpointNotFoundException(uri);
79 }
80
81 ChainInitiationObserver co = (ChainInitiationObserver) mo;
82 return co.getEndpoint();
83 }
84
85 public static String getBindingIdForSoapVersion(String version)
86 {
87 Iterator<SoapVersion> soapVersions = SoapVersionFactory.getInstance().getVersions();
88 while(soapVersions.hasNext())
89 {
90 SoapVersion soapVersion = soapVersions.next();
91 if(Double.toString(soapVersion.getVersion()).equals(version))
92 {
93 return soapVersion.getBindingId();
94 }
95 }
96 throw new IllegalArgumentException("Invalid Soap version " + version);
97 }
98
99 public static String mapUnsupportedSchemas(String url)
100 {
101
102 if(url != null)
103 {
104 url = url.replace("servlet://", "http://");
105 url = url.replace("jetty://", "http://");
106 url = url.replace("jetty-ssl://", "https://");
107 }
108 return url;
109 }
110
111 }