Coverage Report - org.mule.endpoint.UserInfoEndpointURIBuilder
 
Classes in this File Line Coverage Branch Coverage Complexity
UserInfoEndpointURIBuilder
0%
0/24
0%
0/18
11
 
 1  
 /*
 2  
  * $Id: UserInfoEndpointURIBuilder.java 19191 2010-08-25 21:05:23Z tcarlson $
 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  
 
 15  
 import java.net.URI;
 16  
 import java.util.Properties;
 17  
 
 18  
 /**
 19  
  * <code>UserInfoEndpointBuilder</code> builds an endpoint with the userinfo and
 20  
  * host details. This endpoint builder is used where endpoints as of the form :
 21  
  * xxx://ross:secret@host:1000
 22  
  */
 23  0
 public class UserInfoEndpointURIBuilder extends AbstractEndpointURIBuilder
 24  
 {
 25  
     //TODO THis endpoint builder is redundant I think. We should be able to use the URL endpoint builder.
 26  
     //It depends on where deriving classes can work with the URL endpoint builder, but there are a lot of similarities
 27  
     protected void setEndpoint(URI uri, Properties props) throws MalformedEndpointException
 28  
     {
 29  
         // Added by Lajos 2006-12-14 per Ross
 30  0
         if (uri.getHost() == null)
 31  
         {
 32  0
             if (props.getProperty("address") == null)
 33  
             {
 34  0
                 throw new MalformedEndpointException(uri.toString());
 35  
             }
 36  
             else
 37  
             {
 38  0
                 return;
 39  
             }
 40  
         }
 41  
 
 42  
         // Check and handle '@' symbols in the user info
 43  0
         address = uri.getHost();
 44  0
         int a = address.indexOf(".");
 45  0
         int b = (a == -1 ? -1 : address.indexOf(".", a + 1));
 46  0
         if (b > -1)
 47  
         {
 48  0
             address = address.substring(a + 1);
 49  
         }
 50  
 
 51  0
         if (uri.getPort() != -1)
 52  
         {
 53  
             // set the endpointUri to be a proper url if host and port are set
 54  0
             this.address += ":" + uri.getPort();
 55  
         }
 56  
 
 57  0
         if (userInfo != null)
 58  
         {
 59  0
             int x = userInfo.indexOf(":");
 60  0
             if (x > -1)
 61  
             {
 62  0
                 String user = userInfo.substring(0, x);
 63  0
                 if (user.indexOf("@") > -1)
 64  
                 {
 65  0
                     address = user;
 66  
                 }
 67  
                 else
 68  
                 {
 69  0
                     address = user + "@" + address;
 70  
                 }
 71  0
             }
 72  
             else
 73  
             {
 74  0
                 if (userInfo.indexOf("@") > -1)
 75  
                 {
 76  0
                     address = userInfo;
 77  
                 }
 78  
                 else
 79  
                 {
 80  0
                     address = userInfo + "@" + address;
 81  
                 }
 82  
             }
 83  
         }
 84  0
     }
 85  
 }