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 public class LocalClientMessageProcessorBuilder extends AbstractOutboundMessageProcessorBuilder
43 {
44 @Override
45 protected void configureMessageProcessor(CxfOutboundMessageProcessor processor)
46 {
47 }
48
49 @Override
50 protected Client createClient() throws CreateException, Exception
51 {
52 String uri = getAddress();
53 int idx = uri.indexOf('?');
54 if (idx != -1)
55 {
56 uri = uri.substring(0, idx);
57 }
58
59
60 idx = uri.indexOf('@');
61 int slashIdx = uri.indexOf("//");
62 if (idx != -1 && slashIdx != -1)
63 {
64 uri = uri.substring(0, slashIdx + 2) + uri.substring(idx + 1);
65 }
66
67 EndpointInfo ei = new EndpointInfo();
68 ei.setAddress(uri);
69
70 DestinationFactoryManager dfm = getBus().getExtension(DestinationFactoryManager.class);
71 DestinationFactory df = dfm.getDestinationFactoryForUri(uri);
72 if (df == null)
73 {
74 throw new Exception("Could not find a destination factory for uri " + uri);
75 }
76
77 Destination dest = df.getDestination(ei);
78 MessageObserver mo = dest.getMessageObserver();
79 if (mo instanceof ChainInitiationObserver)
80 {
81 ChainInitiationObserver cMo = (ChainInitiationObserver) mo;
82 Endpoint cxfEP = cMo.getEndpoint();
83
84 return new ClientImpl(getBus(), cxfEP);
85 }
86 else
87 {
88 throw new Exception("Could not create client! No Server was found directly on the endpoint: "
89 + uri);
90 }
91 }
92
93 }