View Javadoc

1   /*
2    * $Id: CxfUtils.java 11549 2008-04-09 05:12:30Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
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              // TODO is this the right Mule exception?
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  }