View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.endpoint;
8   
9   import org.mule.api.endpoint.MalformedEndpointException;
10  
11  import java.net.URI;
12  import java.util.Properties;
13  
14  /**
15   * <code>SocketEndpointBuilder</code> builds an endpointUri based on host and port
16   * only
17   */
18  public class SocketEndpointURIBuilder extends AbstractEndpointURIBuilder
19  {
20      protected void setEndpoint(URI uri, Properties props) throws MalformedEndpointException
21      {
22          // set the endpointUri to be a proper url if host and port are set
23          if (uri.getPort() == -1)
24          {
25              // try the form tcp://6666
26              try
27              {
28                  int port = Integer.parseInt(uri.getHost());
29                  this.address = uri.getScheme() + "://localhost:" + port;
30              }
31              catch (NumberFormatException e)
32              {
33                  // ignore
34              }
35          }
36  
37          if (address == null)
38          {
39              this.address = uri.getScheme() + "://" + uri.getHost();
40              if (uri.getPort() != -1)
41              {
42                  this.address += ":" + uri.getPort();
43              }
44          }
45      }
46  }