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  import org.mule.util.StringUtils;
11  
12  import java.net.URI;
13  import java.util.Properties;
14  
15  /**
16   * <code>UrlEndpointURIBuilder</code> is the default endpointUri strategy suitable for
17   * most connectors
18   */
19  public class UrlEndpointURIBuilder extends AbstractEndpointURIBuilder
20  {
21      @Override
22      protected void setEndpoint(URI uri, Properties props) throws MalformedEndpointException
23      {
24          address = "";
25          if (uri.getHost() != null)
26          {
27              // set the endpointUri to be a proper url if host and port are set
28              this.address = uri.getScheme() + "://" + uri.getHost();
29              if (uri.getPort() != -1)
30              {
31                  address += ":" + uri.getPort();
32              }
33          }
34          if (StringUtils.isNotBlank(uri.getRawPath()))
35          {
36              address += uri.getRawPath();
37          }
38  
39          if (StringUtils.isNotBlank(uri.getRawQuery()))
40          {
41              address += "?" + uri.getRawQuery();
42          }
43      }
44  }