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