Example usage for java.net URISyntaxException printStackTrace

List of usage examples for java.net URISyntaxException printStackTrace

Introduction

In this page you can find the example usage for java.net URISyntaxException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:org.dasein.cloud.aws.AWSCloud.java

private String buildEc2AuthString(String method, String serviceUrl, Map<String, String> parameters)
        throws InternalException {
    StringBuilder authString = new StringBuilder();
    TreeSet<String> sortedKeys;
    URI endpoint;//from  w  ww . j av  a  2 s .co  m
    String tmp;

    authString.append(method);
    authString.append("\n");
    try {
        endpoint = new URI(serviceUrl);
    } catch (URISyntaxException e) {
        logger.error(e);
        e.printStackTrace();
        throw new InternalException(e);
    }
    authString.append(endpoint.getHost().toLowerCase());
    authString.append("\n");
    tmp = endpoint.getPath();
    if (tmp == null || tmp.length() == 0) {
        tmp = "/";
    }
    authString.append(encode(tmp, true));
    authString.append("\n");
    sortedKeys = new TreeSet<String>();
    sortedKeys.addAll(parameters.keySet());
    boolean first = true;
    for (String key : sortedKeys) {
        String value = parameters.get(key);

        if (!first) {
            authString.append("&");
        } else {
            first = false;
        }
        authString.append(encode(key, false));
        authString.append("=");
        if (value == null) {
            value = "";
        }
        authString.append(encode(value, false));
    }
    return authString.toString();
}

From source file:org.mobicents.servlet.restcomm.telephony.CallManager.java

private Notification notification(final int log, final int error, final String message) {
    String version = configuration.subset("runtime-settings").getString("api-version");
    Sid accountId = null;//  ww  w. j  a  v  a  2  s .  c  o m
    // Sid callSid = new Sid("CA00000000000000000000000000000000");
    if (createCallRequest != null) {
        accountId = createCallRequest.accountId();
    } else if (switchProxyRequest != null) {
        accountId = switchProxyRequest.getSid();
    } else {
        accountId = new Sid("ACae6e420f425248d6a26948c17a9e2acf");
    }

    final Notification.Builder builder = Notification.builder();
    final Sid sid = Sid.generate(Sid.Type.NOTIFICATION);
    builder.setSid(sid);
    builder.setAccountSid(accountId);
    // builder.setCallSid(callSid);
    builder.setApiVersion(version);
    builder.setLog(log);
    builder.setErrorCode(error);
    final String base = configuration.subset("runtime-settings").getString("error-dictionary-uri");
    StringBuilder buffer = new StringBuilder();
    buffer.append(base);
    if (!base.endsWith("/")) {
        buffer.append("/");
    }
    buffer.append(error).append(".html");
    final URI info = URI.create(buffer.toString());
    builder.setMoreInfo(info);
    builder.setMessageText(message);
    final DateTime now = DateTime.now();
    builder.setMessageDate(now);
    try {
        builder.setRequestUrl(new URI(""));
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }

    builder.setRequestMethod("");
    builder.setRequestVariables("");
    buffer = new StringBuilder();
    buffer.append("/").append(version).append("/Accounts/");
    buffer.append(accountId.toString()).append("/Notifications/");
    buffer.append(sid.toString());
    final URI uri = URI.create(buffer.toString());
    builder.setUri(uri);
    return builder.build();
}

From source file:com.marketplace.io.Sender.java

/**
 * Perform a simple HTTP Post request//from  w  w  w  .j  a  va2 s.com
 * 
 * @param data
 *            information that needs to be sent
 * @param url
 *            the location to send the information to
 * @return the response returned by Rails app
 * @throws ConnectivityException
 *             thrown if there was a problem connecting with the database
 */
public byte[] doBasicHttpPost(String data, String url) throws ConnectivityException {
    byte[] response = null;
    HttpResponse httpResponse = null;
    StringEntity stringEntity = null;

    try {
        httpPost = new HttpPost();
        httpPost.setURI(new URI(url));
        httpPost.addHeader("Content-Type", "application/json");
    } catch (URISyntaxException e) {
        throw new ConnectivityException("Error occured while setting URL");
    }

    try {
        stringEntity = new StringEntity(data, "UTF-8");

        if (stringEntity != null) {
            httpPost.setEntity(stringEntity);
            httpResponse = httpClient.execute(httpPost);

            HttpEntity entity = httpResponse.getEntity();
            if (entity != null) {
                InputStream contentStream = entity.getContent();
                response = IOUtils.toByteArray(contentStream);
                contentStream.close();
            }
        }
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        throw new ConnectivityException("Error occured in Client Protocol");
    } catch (IOException e) {
        e.printStackTrace();
    }

    return response;
}

From source file:com.zoffcc.applications.aagtl.HTMLDownloader.java

public String get_reader_stream(String url, List<NameValuePair> values, ByteArrayOutputStream data,
        Boolean need_login) {//from  www  .  ja  v a 2s  .c om

    if ((need_login) && (!this.logged_in)) {
        System.out.println("--2--- LOGIN START -----");
        this.logged_in = login();
        System.out.println("--2--- LOGIN END   -----");
    }

    if ((values == null) && (data == null)) {
        return null;
    } else if (data == null) {
        String websiteData = null;
        URI uri = null;
        DefaultHttpClient client = new DefaultHttpClient();

        // insert cookies from cookie_jar
        client.setCookieStore(cookie_jar);

        try {
            uri = new URI(url);
        } catch (URISyntaxException e) {
            e.printStackTrace();
            return null;
        }

        HttpPost method = new HttpPost(uri);
        method.addHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)");
        method.addHeader("Pragma", "no-cache");
        method.addHeader("Content-Type", "application/x-www-form-urlencoded");

        HttpEntity entity = null;
        try {
            entity = new UrlEncodedFormEntity(values, HTTP.UTF_8);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return null;
        }

        method.addHeader(entity.getContentType());
        method.setEntity(entity);

        try {
            HttpResponse res2 = client.execute(method);
            // System.out.println("login response ->" +
            // String.valueOf(res2.getStatusLine()));
            InputStream data2 = res2.getEntity().getContent();
            websiteData = generateString(data2);

        } catch (ClientProtocolException e) {
            // e.printStackTrace();
            return null;
        } catch (IOException e) {
            // e.printStackTrace();
            return null;
        }

        client.getConnectionManager().shutdown();

        return websiteData;

    } else {
        try {
            // url Header textdata
            InputStream i = this.doPost2(url, values, data);
            return this.convertStreamToString(i);
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
}

From source file:com.marketplace.io.Sender.java

/**
 * Perform a complex HTTP Put (send files over the network)
 * /*from   ww w  . j  a  v a2  s . co m*/
 * @param data
 *            file that needs to be sent
 * @param mimeType
 *            the content type of file
 * @param filename
 *            the name of file
 * @param url
 *            the location to send the file to
 * @throws ConnectivityException
 *             thrown if there was a problem connecting with the database
 */
public void doComplexHttpPut(byte[] data, String mimeType, String filename, String url)
        throws ConnectivityException {
    HttpResponse httpResponse = null;

    try {
        httpPut = new HttpPut();
        httpPut.setURI(new URI(url));
        httpPut.addHeader("content_type", "image/jpeg");
    } catch (URISyntaxException e) {
        throw new ConnectivityException("Error occured while setting URL");
    }

    ContentBody contentBody = new ByteArrayBody(data, mimeType, filename);

    MultipartEntity multipartEntity = new MultipartEntity();
    multipartEntity.addPart("image", contentBody);

    httpPut.setEntity(multipartEntity);

    try {
        httpResponse = httpClient.execute(httpPut);
        HttpEntity entity = httpResponse.getEntity();

        if (entity != null) {
            entity.getContent().close();
        }

    } catch (ClientProtocolException e) {
        throw new ConnectivityException("Error occured in Client Protocol");
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.marketplace.io.Sender.java

/**
 * Perform a complex HTTP Post (send files over the network)
 * /*from w w  w.  j  a v a  2s.  com*/
 * @param data
 *            file that needs to be sent
 * @param mimeType
 *            the content type of file
 * @param filename
 *            the name of file
 * @param url
 *            the location to send the file to
 * @throws ConnectivityException
 *             thrown if there was a problem connecting with the database
 */
public void doComplexHttpPost(byte[] data, String mimeType, String filename, String url)
        throws ConnectivityException {
    HttpResponse httpResponse = null;

    try {
        httpPost = new HttpPost();
        httpPost.setURI(new URI(url));
        httpPost.addHeader("content_type", "image/jpeg");
    } catch (URISyntaxException e) {
        throw new ConnectivityException("Error occured while setting URL");
    }

    ContentBody contentBody = new ByteArrayBody(data, mimeType, filename);

    MultipartEntity multipartEntity = new MultipartEntity();
    multipartEntity.addPart("image", contentBody);

    httpPost.setEntity(multipartEntity);

    try {
        httpResponse = httpClient.execute(httpPost);
        HttpEntity entity = httpResponse.getEntity();

        if (entity != null) {
            entity.getContent().close();
        }

    } catch (ClientProtocolException e) {
        throw new ConnectivityException("Error occured in Client Protocol");
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.witness.ssc.xfer.utils.PublishingUtils.java

public Thread videoUploadToVideoBin(final Activity activity, final Handler handler,
        final String video_absolutepath, final String title, final String description,
        final String emailAddress, final long sdrecord_id) {

    Log.d(TAG, "doPOSTtoVideoBin starting");

    // Make the progress bar view visible.
    ((SSCXferActivity) activity).startedUploading();
    final Resources res = activity.getResources();

    Thread t = new Thread(new Runnable() {
        public void run() {
            // Do background task.

            boolean failed = false;

            HttpClient client = new DefaultHttpClient();

            if (useProxy) {
                HttpHost proxy = new HttpHost(PROXY_HOST, PROXY_PORT_HTTP);
                client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
            }//from  ww  w .j  a v a 2s.c  o m

            client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);

            URI url = null;
            try {
                url = new URI(res.getString(R.string.http_videobin_org_add));
            } catch (URISyntaxException e) {
                // Ours is a fixed URL, so not likely to get here.
                e.printStackTrace();
                return;

            }
            HttpPost post = new HttpPost(url);
            CustomMultiPartEntity entity = new CustomMultiPartEntity(HttpMultipartMode.BROWSER_COMPATIBLE,
                    new ProgressListener() {
                        int lastPercent = 0;

                        @Override
                        public void transferred(long num) {

                            percentUploaded = (int) (((float) num) / ((float) totalLength) * 99f);
                            //Log.d(TAG, "percent uploaded: " + percentUploaded + " - " + num + " / " + totalLength);
                            if (lastPercent != percentUploaded) {
                                ((SSCXferActivity) activity).showProgress("uploading...", percentUploaded);
                                lastPercent = percentUploaded;
                            }
                        }

                    });

            File file = new File(video_absolutepath);
            entity.addPart(res.getString(R.string.video_bin_API_videofile), new FileBody(file));

            try {
                entity.addPart(res.getString(R.string.video_bin_API_api),
                        new StringBody("1", "text/plain", Charset.forName("UTF-8")));

                // title
                entity.addPart(res.getString(R.string.video_bin_API_title),
                        new StringBody(title, "text/plain", Charset.forName("UTF-8")));

                // description
                entity.addPart(res.getString(R.string.video_bin_API_description),
                        new StringBody(description, "text/plain", Charset.forName("UTF-8")));

            } catch (IllegalCharsetNameException e) {
                // error
                e.printStackTrace();
                failed = true;

            } catch (UnsupportedCharsetException e) {
                // error
                e.printStackTrace();
                return;
            } catch (UnsupportedEncodingException e) {
                // error
                e.printStackTrace();
                failed = true;
            }

            post.setEntity(entity);

            totalLength = entity.getContentLength();

            // Here we go!
            String response = null;
            try {
                response = EntityUtils.toString(client.execute(post).getEntity(), "UTF-8");
            } catch (ParseException e) {
                // error
                e.printStackTrace();
                failed = true;
            } catch (ClientProtocolException e) {
                // error
                e.printStackTrace();
                failed = true;
            } catch (IOException e) {
                // error
                e.printStackTrace();
                failed = true;
            }

            client.getConnectionManager().shutdown();

            if (failed) {
                // Use the handler to execute a Runnable on the
                // main thread in order to have access to the
                // UI elements.
                handler.postDelayed(new Runnable() {
                    public void run() {
                        // Update UI

                        // Indicate back to calling activity the result!
                        // update uploadInProgress state also.

                        ((SSCXferActivity) activity).finishedUploading(false);

                        ((SSCXferActivity) activity)
                                .createNotification(res.getString(R.string.upload_to_videobin_org_failed_));
                    }
                }, 0);

                return;
            }

            Log.d(TAG, " video bin got back " + response);

            // XXX Convert to preference for auto-email on videobin post
            // XXX ADD EMAIL NOTIF to all other upload methods
            // stuck on YES here, if email is defined.

            if (emailAddress != null && response != null) {

                // EmailSender through IR controlled gmail system.
                SSLEmailSender sender = new SSLEmailSender(
                        activity.getString(R.string.automatic_email_username),
                        activity.getString(R.string.automatic_email_password)); // consider
                // this
                // public
                // knowledge.
                try {
                    sender.sendMail(activity.getString(R.string.vidiom_automatic_email), // subject.getText().toString(),
                            activity.getString(R.string.url_of_hosted_video_is_) + " " + response, // body.getText().toString(),
                            activity.getString(R.string.automatic_email_from), // from.getText().toString(),
                            emailAddress // to.getText().toString()
                    );
                } catch (Exception e) {
                    Log.e(TAG, e.getMessage(), e);
                }
            }

            // Log record of this URL in POSTs table
            dbutils.creatHostDetailRecordwithNewVideoUploaded(sdrecord_id,
                    res.getString(R.string.http_videobin_org_add), response, "");

            // Use the handler to execute a Runnable on the
            // main thread in order to have access to the
            // UI elements.
            handler.postDelayed(new Runnable() {
                public void run() {
                    // Update UI

                    // Indicate back to calling activity the result!
                    // update uploadInProgress state also.

                    ((SSCXferActivity) activity).finishedUploading(true);
                    ((SSCXferActivity) activity)
                            .createNotification(res.getString(R.string.upload_to_videobin_org_succeeded_));

                }
            }, 0);
        }
    });

    t.start();

    return t;

}

From source file:com.zoffcc.applications.aagtl.HTMLDownloader.java

public boolean login() {
    // System.out.println("--L--- LOGIN START -----");

    String login_url = "https://www.geocaching.com/login/default.aspx";

    DefaultHttpClient client2 = null;//from  ww w  .  jav a  2 s.com
    HttpHost proxy = null;

    if (CacheDownloader.DEBUG2_) {
        // NEVER enable this on a production release!!!!!!!!!!
        // NEVER enable this on a production release!!!!!!!!!!
        trust_Every_ssl_cert();

        SchemeRegistry schemeRegistry = new SchemeRegistry();
        schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
        schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443));

        HttpParams params = new BasicHttpParams();
        params.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 30);
        params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(30));
        params.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false);

        proxy = new HttpHost("192.168.0.1", 8888);
        params.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);

        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);

        ClientConnectionManager cm = new SingleClientConnManager(params, schemeRegistry);
        client2 = new DefaultHttpClient(cm, params);
        // NEVER enable this on a production release!!!!!!!!!!
        // NEVER enable this on a production release!!!!!!!!!!
    } else {
        HttpParams httpParameters = new BasicHttpParams();
        int timeoutConnection = 10000;
        HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
        int timeoutSocket = 10000;
        HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);

        client2 = new DefaultHttpClient(httpParameters);
    }

    if (CacheDownloader.DEBUG2_) {
        client2.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    }

    // read first page to check for login
    // read first page to check for login
    // read first page to check for login

    String websiteData2 = null;
    URI uri2 = null;
    try {
        uri2 = new URI(login_url);
    } catch (URISyntaxException e) {
        e.printStackTrace();
        return false;
    }

    client2.setCookieStore(cookie_jar);

    HttpGet method2 = new HttpGet(uri2);

    method2.addHeader("User-Agent",
            "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.10) Gecko/20071115 Firefox/2.0.0.10");
    method2.addHeader("Pragma", "no-cache");
    method2.addHeader("Accept-Language", "en");

    HttpResponse res = null;
    try {
        res = client2.execute(method2);
    } catch (ClientProtocolException e1) {
        e1.printStackTrace();
        return false;
    } catch (IOException e1) {
        e1.printStackTrace();
        return false;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }

    InputStream data = null;
    try {
        data = res.getEntity().getContent();
    } catch (IllegalStateException e1) {
        e1.printStackTrace();
        return false;
    } catch (IOException e1) {
        e1.printStackTrace();
        return false;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }

    websiteData2 = generateString(data);

    if (CacheDownloader.DEBUG_)
        System.out.println("111 cookies=" + dumpCookieStore(client2.getCookieStore()));
    cookie_jar = client2.getCookieStore();

    // on every page
    final Matcher matcherLogged2In = patternLogged2In.matcher(websiteData2);
    if (matcherLogged2In.find()) {
        if (CacheDownloader.DEBUG_)
            System.out.println("login: -> already logged in (1)");
        return true;
    }

    // after login
    final Matcher matcherLoggedIn = patternLoggedIn.matcher(websiteData2);
    if (matcherLoggedIn.find()) {
        if (CacheDownloader.DEBUG_)
            System.out.println("login: -> already logged in (2)");
        return true;
    }
    // read first page to check for login
    // read first page to check for login
    // read first page to check for login

    // ok post login data as formdata
    // ok post login data as formdata
    // ok post login data as formdata
    // ok post login data as formdata
    HttpPost method = new HttpPost(uri2);

    method.addHeader("User-Agent", "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0) Firefox/7.0");
    method.addHeader("Pragma", "no-cache");
    method.addHeader("Content-Type", "application/x-www-form-urlencoded");
    method.addHeader("Accept-Language", "en");

    List<NameValuePair> loginInfo = new ArrayList<NameValuePair>();

    loginInfo.add(new BasicNameValuePair("__EVENTTARGET", ""));
    loginInfo.add(new BasicNameValuePair("__EVENTARGUMENT", ""));

    String[] viewstates = getViewstates(websiteData2);
    if (CacheDownloader.DEBUG_)
        System.out.println("vs==" + viewstates[0]);
    putViewstates(loginInfo, viewstates);

    loginInfo.add(new BasicNameValuePair("ctl00$ContentBody$tbUsername",
            this.main_aagtl.global_settings.options_username));
    loginInfo.add(new BasicNameValuePair("ctl00$ContentBody$tbPassword",
            this.main_aagtl.global_settings.options_password));
    loginInfo.add(new BasicNameValuePair("ctl00$ContentBody$btnSignIn", "Login"));
    loginInfo.add(new BasicNameValuePair("ctl00$ContentBody$cbRememberMe", "on"));

    //for (int i = 0; i < loginInfo.size(); i++)
    //{
    //   System.out.println("x*X " + loginInfo.get(i).getName() + " " + loginInfo.get(i).getValue());
    //}

    // set cookies
    client2.setCookieStore(cookie_jar);

    HttpEntity entity = null;
    try {
        entity = new UrlEncodedFormEntity(loginInfo, HTTP.UTF_8);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        return false;
    }

    //      try
    //      {
    //         System.out.println("1 " + entity.toString());
    //         InputStream in2 = entity.getContent();
    //         InputStreamReader ir2 = new InputStreamReader(in2, "utf-8");
    //         BufferedReader r = new BufferedReader(ir2);
    //         System.out.println("line=" + r.readLine());
    //      }
    //      catch (Exception e2)
    //      {
    //         e2.printStackTrace();
    //      }

    method.setEntity(entity);

    HttpResponse res2 = null;
    try {
        res2 = client2.execute(method);
        if (CacheDownloader.DEBUG_)
            System.out.println("login response ->" + String.valueOf(res2.getStatusLine()));
    } catch (ClientProtocolException e) {
        e.printStackTrace();
        return false;
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }

    //      for (int x = 0; x < res2.getAllHeaders().length; x++)
    //      {
    //         System.out.println("## n=" + res2.getAllHeaders()[x].getName());
    //         System.out.println("## v=" + res2.getAllHeaders()[x].getValue());
    //      }

    InputStream data2 = null;
    try {
        data2 = res2.getEntity().getContent();
    } catch (IllegalStateException e1) {
        e1.printStackTrace();
        return false;
    } catch (IOException e1) {
        e1.printStackTrace();
        return false;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }

    websiteData2 = generateString(data2);

    if (CacheDownloader.DEBUG_)
        System.out.println("2222 cookies=" + dumpCookieStore(client2.getCookieStore()));
    cookie_jar = client2.getCookieStore();

    String[] viewstates2 = getViewstates(websiteData2);
    if (CacheDownloader.DEBUG_)
        System.out.println("vs==" + viewstates2[0]);

    //      System.out.println("******");
    //      System.out.println("******");
    //      System.out.println("******");
    //      System.out.println(websiteData2);
    //      System.out.println("******");
    //      System.out.println("******");
    //      System.out.println("******");

    return true;

}

From source file:org.apache.ambari.server.upgrade.UpgradeCatalog210.java

protected void updateHdfsConfigs() throws AmbariException {
    AmbariManagementController ambariManagementController = injector
            .getInstance(AmbariManagementController.class);
    Clusters clusters = ambariManagementController.getClusters();

    if (clusters != null) {
        Map<String, Cluster> clusterMap = clusters.getClusters();
        Map<String, String> prop = new HashMap<String, String>();
        String content = null;/*from ww w.j  a v  a 2s  .  c  o m*/

        if (clusterMap != null && !clusterMap.isEmpty()) {
            for (final Cluster cluster : clusterMap.values()) {
                /***
                 * Append -Dorg.mortbay.jetty.Request.maxFormContentSize=-1 to HADOOP_NAMENODE_OPTS from hadoop-env.sh
                 */
                content = null;
                if (cluster.getDesiredConfigByType("hadoop-env") != null) {
                    content = cluster.getDesiredConfigByType("hadoop-env").getProperties().get("content");
                }

                if (content != null) {
                    content += "\nexport HADOOP_NAMENODE_OPTS=\"${HADOOP_NAMENODE_OPTS} -Dorg.mortbay.jetty.Request.maxFormContentSize=-1\"";

                    prop.put("content", content);
                    updateConfigurationPropertiesForCluster(cluster, "hadoop-env", prop, true, false);
                }
                /***
                 * Update dfs.namenode.rpc-address set hostname instead of localhost
                 */
                if (cluster.getDesiredConfigByType(HDFS_SITE_CONFIG) != null
                        && !cluster.getHosts("HDFS", "NAMENODE").isEmpty()) {

                    URI nameNodeRpc = null;
                    String hostName = cluster.getHosts("HDFS", "NAMENODE").iterator().next();
                    // Try to generate dfs.namenode.rpc-address
                    if (cluster.getDesiredConfigByType("core-site").getProperties() != null && cluster
                            .getDesiredConfigByType("core-site").getProperties().get("fs.defaultFS") != null) {
                        try {
                            if (isNNHAEnabled(cluster)) {
                                // NN HA enabled
                                // Remove dfs.namenode.rpc-address property
                                Set<String> removePropertiesSet = new HashSet<>();
                                removePropertiesSet.add("dfs.namenode.rpc-address");
                                removeConfigurationPropertiesFromCluster(cluster, HDFS_SITE_CONFIG,
                                        removePropertiesSet);
                            } else {
                                // NN HA disabled
                                nameNodeRpc = new URI(cluster.getDesiredConfigByType("core-site")
                                        .getProperties().get("fs.defaultFS"));
                                Map<String, String> hdfsProp = new HashMap<String, String>();
                                hdfsProp.put("dfs.namenode.rpc-address",
                                        hostName + ":" + nameNodeRpc.getPort());
                                updateConfigurationPropertiesForCluster(cluster, HDFS_SITE_CONFIG, hdfsProp,
                                        false, false);
                            }
                        } catch (URISyntaxException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
    }
}