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