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