1
2
3
4
5
6
7
8
9
10
11 package org.mule.transport.cxf.support;
12
13 import org.mule.api.endpoint.EndpointNotFoundException;
14
15 import java.io.IOException;
16
17 import org.apache.cxf.endpoint.Endpoint;
18 import org.apache.cxf.service.model.EndpointInfo;
19 import org.apache.cxf.transport.ChainInitiationObserver;
20 import org.apache.cxf.transport.Destination;
21 import org.apache.cxf.transport.DestinationFactory;
22 import org.apache.cxf.transport.MessageObserver;
23
24 public final class CxfUtils
25 {
26
27 public static Endpoint getEndpoint(DestinationFactory df, String uri)
28 throws IOException, EndpointNotFoundException
29 {
30 int idx = uri.indexOf('?');
31 if (idx != -1)
32 {
33 uri = uri.substring(0, idx);
34 }
35
36 EndpointInfo ei = new EndpointInfo();
37 ei.setAddress(uri);
38
39 Destination d = df.getDestination(ei);
40 if (d.getMessageObserver() == null)
41 {
42
43 throw new EndpointNotFoundException(uri);
44 }
45
46 MessageObserver mo = d.getMessageObserver();
47 if (!(mo instanceof ChainInitiationObserver))
48 {
49 throw new EndpointNotFoundException(uri);
50 }
51
52 ChainInitiationObserver co = (ChainInitiationObserver) mo;
53 return co.getEndpoint();
54 }
55
56 }