View Javadoc

1   /*
2    * $Id: UrlEndpointURIBuilder.java 21109 2011-01-26 07:39:00Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.endpoint;
12  
13  import org.mule.api.endpoint.MalformedEndpointException;
14  import org.mule.util.StringUtils;
15  
16  import java.net.URI;
17  import java.util.Properties;
18  
19  /**
20   * <code>UrlEndpointURIBuilder</code> is the default endpointUri strategy suitable for
21   * most connectors
22   */
23  public class UrlEndpointURIBuilder extends AbstractEndpointURIBuilder
24  {
25      @Override
26      protected void setEndpoint(URI uri, Properties props) throws MalformedEndpointException
27      {
28          address = "";
29          if (uri.getHost() != null)
30          {
31              // set the endpointUri to be a proper url if host and port are set
32              this.address = uri.getScheme() + "://" + uri.getHost();
33              if (uri.getPort() != -1)
34              {
35                  address += ":" + uri.getPort();
36              }
37          }
38          if (StringUtils.isNotBlank(uri.getRawPath()))
39          {
40              address += uri.getRawPath();
41          }
42  
43          if (StringUtils.isNotBlank(uri.getRawQuery()))
44          {
45              address += "?" + uri.getRawQuery();
46          }
47      }
48  }