1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.module.cxf.builder; |
8 | |
|
9 | |
import org.mule.api.lifecycle.CreateException; |
10 | |
import org.mule.module.cxf.CxfOutboundMessageProcessor; |
11 | |
import org.mule.module.cxf.endpoint.CxfEndpointBuilder; |
12 | |
|
13 | |
import org.apache.cxf.endpoint.Client; |
14 | |
import org.apache.cxf.endpoint.ClientImpl; |
15 | |
import org.apache.cxf.endpoint.Endpoint; |
16 | |
import org.apache.cxf.service.model.EndpointInfo; |
17 | |
import org.apache.cxf.transport.ChainInitiationObserver; |
18 | |
import org.apache.cxf.transport.Destination; |
19 | |
import org.apache.cxf.transport.DestinationFactory; |
20 | |
import org.apache.cxf.transport.DestinationFactoryManager; |
21 | |
import org.apache.cxf.transport.MessageObserver; |
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | 0 | public class LocalClientMessageProcessorBuilder extends AbstractOutboundMessageProcessorBuilder |
43 | |
{ |
44 | |
@Override |
45 | |
protected void configureMessageProcessor(CxfOutboundMessageProcessor processor) |
46 | |
{ |
47 | 0 | } |
48 | |
|
49 | |
@Override |
50 | |
protected Client createClient() throws CreateException, Exception |
51 | |
{ |
52 | 0 | String uri = getAddress(); |
53 | 0 | int idx = uri.indexOf('?'); |
54 | 0 | if (idx != -1) |
55 | |
{ |
56 | 0 | uri = uri.substring(0, idx); |
57 | |
} |
58 | |
|
59 | |
|
60 | 0 | idx = uri.indexOf('@'); |
61 | 0 | int slashIdx = uri.indexOf("//"); |
62 | 0 | if (idx != -1 && slashIdx != -1) |
63 | |
{ |
64 | 0 | uri = uri.substring(0, slashIdx + 2) + uri.substring(idx + 1); |
65 | |
} |
66 | |
|
67 | 0 | EndpointInfo ei = new EndpointInfo(); |
68 | 0 | ei.setAddress(uri); |
69 | |
|
70 | 0 | DestinationFactoryManager dfm = getBus().getExtension(DestinationFactoryManager.class); |
71 | 0 | DestinationFactory df = dfm.getDestinationFactoryForUri(uri); |
72 | 0 | if (df == null) |
73 | |
{ |
74 | 0 | throw new Exception("Could not find a destination factory for uri " + uri); |
75 | |
} |
76 | |
|
77 | 0 | Destination dest = df.getDestination(ei); |
78 | 0 | MessageObserver mo = dest.getMessageObserver(); |
79 | 0 | if (mo instanceof ChainInitiationObserver) |
80 | |
{ |
81 | 0 | ChainInitiationObserver cMo = (ChainInitiationObserver) mo; |
82 | 0 | Endpoint cxfEP = cMo.getEndpoint(); |
83 | |
|
84 | 0 | return new ClientImpl(getBus(), cxfEP); |
85 | |
} |
86 | |
else |
87 | |
{ |
88 | 0 | throw new Exception("Could not create client! No Server was found directly on the endpoint: " |
89 | |
+ uri); |
90 | |
} |
91 | |
} |
92 | |
|
93 | |
} |