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