Example usage for org.apache.http.client.utils URIBuilder setScheme

List of usage examples for org.apache.http.client.utils URIBuilder setScheme

Introduction

In this page you can find the example usage for org.apache.http.client.utils URIBuilder setScheme.

Prototype

public URIBuilder setScheme(final String scheme) 

Source Link

Document

Sets URI scheme.

Usage

From source file:org.wso2.carbon.analytics.api.internal.client.AnalyticsAPIHttpClient.java

public String getRecordStoreNameByTable(int tenantId, String username, String tableName,
        boolean securityEnabled) {
    URIBuilder builder = new URIBuilder();
    builder.setScheme(protocol).setHost(hostname).setPort(port)
            .setPath(AnalyticsAPIConstants.ANALYTIC_RECORD_STORE_PROCESSOR_SERVICE_URI)
            .addParameter(AnalyticsAPIConstants.OPERATION,
                    AnalyticsAPIConstants.GET_RECORD_STORE_OF_TABLE_OPERATION)
            .addParameter(AnalyticsAPIConstants.TABLE_NAME_PARAM, tableName)
            .addParameter(AnalyticsAPIConstants.ENABLE_SECURITY_PARAM, String.valueOf(securityEnabled));
    if (!securityEnabled) {
        builder.addParameter(AnalyticsAPIConstants.TENANT_ID_PARAM, String.valueOf(tenantId));
    } else {/*from ww w  . j  a  va 2  s .co  m*/
        builder.addParameter(AnalyticsAPIConstants.USERNAME_PARAM, username);
    }
    try {
        HttpGet getMethod = new HttpGet(builder.build().toString());
        getMethod.addHeader(AnalyticsAPIConstants.SESSION_ID, sessionId);
        HttpResponse httpResponse = httpClient.execute(getMethod);
        String response = getResponseString(httpResponse);
        if (httpResponse.getStatusLine().getStatusCode() != HttpServletResponse.SC_OK) {
            throw new AnalyticsServiceException(
                    "Unable to get the record store for the table : " + tableName + " ." + response);
        } else {
            if (response.startsWith(AnalyticsAPIConstants.RECORD_STORE_NAME)) {
                String[] reponseElements = response.split(AnalyticsAPIConstants.SEPARATOR);
                if (reponseElements.length == 2) {
                    return reponseElements[1].trim();
                } else {
                    throw new AnalyticsServiceException(
                            "Invalid response returned, cannot find record store name" + " message. Response:"
                                    + response);
                }
            } else {
                throw new AnalyticsServiceException(
                        "Invalid response returned, record store name message not found!" + response);
            }
        }
    } catch (URISyntaxException e) {
        throw new AnalyticsServiceAuthenticationException("Malformed URL provided. " + e.getMessage(), e);
    } catch (IOException e) {
        throw new AnalyticsServiceAuthenticationException(
                "Error while connecting to the remote service. " + e.getMessage(), e);
    }
}

From source file:org.wso2.carbon.analytics.api.internal.client.AnalyticsAPIHttpClient.java

@SuppressWarnings("unchecked")
public List<String> listRecordStoreNames() {
    URIBuilder builder = new URIBuilder();
    builder.setScheme(protocol).setHost(hostname).setPort(port)
            .setPath(AnalyticsAPIConstants.ANALYTIC_RECORD_STORE_PROCESSOR_SERVICE_URI)
            .addParameter(AnalyticsAPIConstants.OPERATION, AnalyticsAPIConstants.LIST_RECORD_STORES_OPERATION);
    try {/*  ww w .j  a va2  s  .com*/
        HttpGet getMethod = new HttpGet(builder.build().toString());
        getMethod.addHeader(AnalyticsAPIConstants.SESSION_ID, sessionId);
        HttpResponse httpResponse = httpClient.execute(getMethod);
        if (httpResponse.getStatusLine().getStatusCode() != HttpServletResponse.SC_OK) {
            String response = getResponseString(httpResponse);
            throw new AnalyticsServiceException("Unable to list the record stores." + response);
        } else {
            Object listOfRecordStores = GenericUtils.deserializeObject(httpResponse.getEntity().getContent());
            EntityUtils.consumeQuietly(httpResponse.getEntity());
            if (listOfRecordStores != null && listOfRecordStores instanceof List) {
                return (List<String>) listOfRecordStores;
            } else {
                throw new AnalyticsServiceException(getUnexpectedResponseReturnedErrorMsg(
                        "getting list of record stores", null, "list of record store", listOfRecordStores));
            }
        }
    } catch (URISyntaxException e) {
        throw new AnalyticsServiceAuthenticationException("Malformed URL provided. " + e.getMessage(), e);
    } catch (IOException e) {
        throw new AnalyticsServiceAuthenticationException(
                "Error while connecting to the remote service. " + e.getMessage(), e);
    }
}

From source file:org.wso2.carbon.analytics.api.internal.client.AnalyticsAPIHttpClient.java

public AnalyticsDataResponse getRecordGroup(int tenantId, String username, String tableName,
        int numPartitionsHint, List<String> columns, List<String> ids, boolean securityEnabled)
        throws AnalyticsServiceException {
    URIBuilder builder = new URIBuilder();
    Gson gson = new Gson();
    builder.setScheme(protocol).setHost(hostname).setPort(port)
            .setPath(AnalyticsAPIConstants.ANALYTIC_RECORD_READ_PROCESSOR_SERVICE_URI)
            .addParameter(AnalyticsAPIConstants.OPERATION, AnalyticsAPIConstants.GET_IDS_RECORD_GROUP_OPERATION)
            .addParameter(AnalyticsAPIConstants.TABLE_NAME_PARAM, tableName)
            .addParameter(AnalyticsAPIConstants.PARTITIONER_NO_PARAM, String.valueOf(numPartitionsHint))
            .addParameter(AnalyticsAPIConstants.COLUMNS_PARAM, gson.toJson(columns))
            .addParameter(AnalyticsAPIConstants.RECORD_IDS_PARAM, gson.toJson(ids))
            .addParameter(AnalyticsAPIConstants.ENABLE_SECURITY_PARAM, String.valueOf(securityEnabled));
    if (!securityEnabled) {
        builder.addParameter(AnalyticsAPIConstants.TENANT_ID_PARAM, String.valueOf(tenantId));
    } else {//  w  ww .ja  v a 2 s . com
        builder.addParameter(AnalyticsAPIConstants.USERNAME_PARAM, username);
    }
    try {
        HttpGet getMethod = new HttpGet(builder.build().toString());
        getMethod.addHeader(AnalyticsAPIConstants.SESSION_ID, sessionId);
        HttpResponse httpResponse = httpClient.execute(getMethod);
        if (httpResponse.getStatusLine().getStatusCode() != HttpServletResponse.SC_OK) {
            String response = getResponseString(httpResponse);
            throw new AnalyticsServiceException("Unable to destroy the process . " + response);
        } else {
            Object analyticsDataResponseObj = GenericUtils
                    .deserializeObject(httpResponse.getEntity().getContent());
            EntityUtils.consumeQuietly(httpResponse.getEntity());
            if (analyticsDataResponseObj != null && analyticsDataResponseObj instanceof AnalyticsDataResponse) {
                AnalyticsDataResponse analyticsDataResponse = (AnalyticsDataResponse) analyticsDataResponseObj;
                if (analyticsDataResponse.getRecordGroups() instanceof RemoteRecordGroup[]) {
                    return analyticsDataResponse;
                } else {
                    throw new AnalyticsServiceAuthenticationException(getUnexpectedResponseReturnedErrorMsg(
                            "getting " + "the record group", tableName,
                            "Analytics Data Response object consist of" + " array of remote record group",
                            analyticsDataResponseObj));
                }
            } else {
                throw new AnalyticsServiceAuthenticationException(
                        getUnexpectedResponseReturnedErrorMsg("getting " + "the record group", tableName,
                                "Analytics Data Response object", analyticsDataResponseObj));
            }
        }
    } catch (URISyntaxException e) {
        throw new AnalyticsServiceAuthenticationException("Malformed URL provided. " + e.getMessage(), e);
    } catch (IOException e) {
        throw new AnalyticsServiceAuthenticationException(
                "Error while connecting to the remote service. " + e.getMessage(), e);
    }
}

From source file:org.wso2.carbon.analytics.api.internal.client.AnalyticsAPIHttpClient.java

public AnalyticsIterator<Record> readRecords(String recordStoreName, RecordGroup recordGroup)
        throws AnalyticsServiceException {
    URIBuilder builder = new URIBuilder();
    builder.setScheme(protocol).setHost(hostname).setPort(port)
            .setPath(AnalyticsAPIConstants.ANALYTIC_RECORD_READ_PROCESSOR_SERVICE_URI)
            .addParameter(AnalyticsAPIConstants.OPERATION, AnalyticsAPIConstants.READ_RECORD_OPERATION)
            .addParameter(AnalyticsAPIConstants.RECORD_STORE_NAME_PARAM, recordStoreName);
    try {//from   w  w w .  j av  a  2  s .c  om
        HttpPost postMethod = new HttpPost(builder.build().toString());
        postMethod.addHeader(AnalyticsAPIConstants.SESSION_ID, sessionId);
        postMethod.setEntity(new ByteArrayEntity(GenericUtils.serializeObject(recordGroup)));
        HttpResponse httpResponse = httpClient.execute(postMethod);
        if (httpResponse.getStatusLine().getStatusCode() != HttpServletResponse.SC_OK) {
            String response = getResponseString(httpResponse);
            throw new AnalyticsServiceException("Unable to read the record group. " + response);
        }
        return new RemoteRecordIterator(httpResponse.getEntity().getContent());
    } catch (URISyntaxException e) {
        throw new AnalyticsServiceAuthenticationException("Malformed URL provided. " + e.getMessage(), e);
    } catch (IOException e) {
        throw new AnalyticsServiceAuthenticationException(
                "Error while connecting to the remote service. " + e.getMessage(), e);
    }
}

From source file:org.wso2.carbon.analytics.api.internal.client.AnalyticsAPIHttpClient.java

public boolean isPaginationSupported(String recordStoreName) {
    URIBuilder builder = new URIBuilder();
    builder.setScheme(this.protocol).setHost(hostname).setPort(port)
            .setPath(AnalyticsAPIConstants.MANAGEMENT_SERVICE_URI)
            .setParameter(AnalyticsAPIConstants.OPERATION,
                    AnalyticsAPIConstants.IS_PAGINATION_SUPPORTED_OPERATION)
            .addParameter(AnalyticsAPIConstants.RECORD_STORE_NAME_PARAM, recordStoreName);
    try {//from w w w .j av  a  2s  . c  o  m
        HttpGet getMethod = new HttpGet(builder.build().toString());
        getMethod.addHeader(AnalyticsAPIConstants.SESSION_ID, sessionId);
        HttpResponse httpResponse = httpClient.execute(getMethod);
        String response = getResponseString(httpResponse);
        if (httpResponse.getStatusLine().getStatusCode() != HttpServletResponse.SC_OK) {
            throw new AnalyticsServiceException("Error while checking the pagination support. " + response);
        }
        if (response.startsWith(AnalyticsAPIConstants.PAGINATION_SUPPORT)) {
            String[] reponseElements = response.split(AnalyticsAPIConstants.SEPARATOR);
            if (reponseElements.length == 2) {
                return Boolean.parseBoolean(reponseElements[1]);
            } else {
                throw new AnalyticsServiceAuthenticationException("Invalid response returned, cannot find "
                        + "pagination support element. Response:" + response);
            }
        } else {
            throw new AnalyticsServiceAuthenticationException(
                    "Invalid response returned, no pagination support found!" + response);
        }
    } catch (URISyntaxException e) {
        throw new AnalyticsServiceException(
                "Malformed URL provided for pagination support checking. " + e.getMessage(), e);
    } catch (IOException e) {
        throw new AnalyticsServiceException("Error while connecting to the remote service. " + e.getMessage(),
                e);
    }
}

From source file:org.wso2.carbon.analytics.api.internal.client.AnalyticsAPIHttpClient.java

public boolean isRecordCountSupported(String recordStoreName) {
    URIBuilder builder = new URIBuilder();
    builder.setScheme(this.protocol).setHost(hostname).setPort(port)
            .setPath(AnalyticsAPIConstants.MANAGEMENT_SERVICE_URI)
            .setParameter(AnalyticsAPIConstants.OPERATION,
                    AnalyticsAPIConstants.IS_RECORD_COUNT_SUPPORTED_OPERATION)
            .addParameter(AnalyticsAPIConstants.RECORD_STORE_NAME_PARAM, recordStoreName);
    try {/*from  w w  w  . j a v  a  2  s.  c  o  m*/
        HttpGet getMethod = new HttpGet(builder.build().toString());
        getMethod.addHeader(AnalyticsAPIConstants.SESSION_ID, sessionId);
        HttpResponse httpResponse = httpClient.execute(getMethod);
        String response = getResponseString(httpResponse);
        if (httpResponse.getStatusLine().getStatusCode() != HttpServletResponse.SC_OK) {
            throw new AnalyticsServiceException("Error while checking the record count support. " + response);
        }
        if (response.startsWith(AnalyticsAPIConstants.RECORD_COUNT_SUPPORT)) {
            String[] reponseElements = response.split(AnalyticsAPIConstants.SEPARATOR);
            if (reponseElements.length == 2) {
                return Boolean.parseBoolean(reponseElements[1]);
            } else {
                throw new AnalyticsServiceAuthenticationException("Invalid response returned, cannot find "
                        + "record count support element. Response:" + response);
            }
        } else {
            throw new AnalyticsServiceAuthenticationException(
                    "Invalid response returned, no record count support found!" + response);
        }
    } catch (URISyntaxException e) {
        throw new AnalyticsServiceException(
                "Malformed URL provided for record count support checking. " + e.getMessage(), e);
    } catch (IOException e) {
        throw new AnalyticsServiceException("Error while connecting to the remote service. " + e.getMessage(),
                e);
    }
}

From source file:org.wso2.carbon.analytics.api.internal.client.AnalyticsAPIHttpClient.java

@SuppressWarnings("unchecked")
public List<SearchResultEntry> drillDownSearch(int tenantId, String username,
        AnalyticsDrillDownRequest drillDownRequest, boolean securityEnabled) {
    URIBuilder builder = new URIBuilder();
    builder.setScheme(protocol).setHost(hostname).setPort(port)
            .setPath(AnalyticsAPIConstants.SEARCH_PROCESSOR_SERVICE_URI)
            .addParameter(AnalyticsAPIConstants.OPERATION, AnalyticsAPIConstants.DRILL_DOWN_SEARCH_OPERATION)
            .addParameter(AnalyticsAPIConstants.ENABLE_SECURITY_PARAM, String.valueOf(securityEnabled));
    if (!securityEnabled) {
        builder.addParameter(AnalyticsAPIConstants.TENANT_ID_PARAM, String.valueOf(tenantId));
    } else {//from w w w.  j  av  a 2 s  . c  o  m
        builder.addParameter(AnalyticsAPIConstants.USERNAME_PARAM, username);
    }
    try {
        HttpPost postMethod = new HttpPost(builder.build().toString());
        postMethod.addHeader(AnalyticsAPIConstants.SESSION_ID, sessionId);
        postMethod.setEntity(new ByteArrayEntity(GenericUtils.serializeObject(drillDownRequest)));
        HttpResponse httpResponse = httpClient.execute(postMethod);
        if (httpResponse.getStatusLine().getStatusCode() != HttpServletResponse.SC_OK) {
            String response = getResponseString(httpResponse);
            throw new AnalyticsServiceException("Unable to process the DrillDown Request. " + response);
        } else {
            Object searchResultListObj = GenericUtils.deserializeObject(httpResponse.getEntity().getContent());
            EntityUtils.consumeQuietly(httpResponse.getEntity());
            if (searchResultListObj != null && searchResultListObj instanceof List) {
                return (List<SearchResultEntry>) searchResultListObj;
            } else {
                throw new AnalyticsServiceException(getUnexpectedResponseReturnedErrorMsg(
                        "preforming drill down search", drillDownRequest.getTableName(),
                        "list of search result entry", searchResultListObj));
            }
        }

    } catch (URISyntaxException e) {
        throw new AnalyticsServiceException("Malformed URL provided. " + e.getMessage(), e);
    } catch (IOException e) {
        throw new AnalyticsServiceException("Error while connecting to the remote service. " + e.getMessage(),
                e);
    }
}

From source file:org.wso2.carbon.analytics.api.internal.client.AnalyticsAPIHttpClient.java

public int drillDownSearchCount(int tenantId, String username, AnalyticsDrillDownRequest drillDownRequest,
        boolean securityEnabled) {
    URIBuilder builder = new URIBuilder();
    builder.setScheme(protocol).setHost(hostname).setPort(port)
            .setPath(AnalyticsAPIConstants.SEARCH_PROCESSOR_SERVICE_URI)
            .addParameter(AnalyticsAPIConstants.OPERATION,
                    AnalyticsAPIConstants.DRILL_DOWN_SEARCH_COUNT_OPERATION)
            .addParameter(AnalyticsAPIConstants.ENABLE_SECURITY_PARAM, String.valueOf(securityEnabled));
    if (!securityEnabled) {
        builder.addParameter(AnalyticsAPIConstants.TENANT_ID_PARAM, String.valueOf(tenantId));
    } else {/* w  ww.  ja  va2 s  .co m*/
        builder.addParameter(AnalyticsAPIConstants.USERNAME_PARAM, username);
    }
    try {
        HttpPost postMethod = new HttpPost(builder.build().toString());
        postMethod.addHeader(AnalyticsAPIConstants.SESSION_ID, sessionId);
        postMethod.setEntity(new ByteArrayEntity(GenericUtils.serializeObject(drillDownRequest)));
        HttpResponse httpResponse = httpClient.execute(postMethod);
        if (httpResponse.getStatusLine().getStatusCode() != HttpServletResponse.SC_OK) {
            String response = getResponseString(httpResponse);
            throw new AnalyticsServiceException("Unable to process the drillDown request. " + response);
        } else {
            Object searchCountObj = GenericUtils.deserializeObject(httpResponse.getEntity().getContent());
            EntityUtils.consumeQuietly(httpResponse.getEntity());
            if (searchCountObj != null && searchCountObj instanceof Integer) {
                return (Integer) searchCountObj;
            } else {
                throw new AnalyticsServiceException(
                        getUnexpectedResponseReturnedErrorMsg("preforming drill down search count",
                                drillDownRequest.getTableName(), "number of search result", searchCountObj));
            }
        }
    } catch (URISyntaxException e) {
        throw new AnalyticsServiceException("Malformed URL provided. " + e.getMessage(), e);
    } catch (IOException e) {
        throw new AnalyticsServiceException("Error while connecting to the remote service. " + e.getMessage(),
                e);
    }
}

From source file:org.wso2.carbon.analytics.api.internal.client.AnalyticsAPIHttpClient.java

public SubCategories drillDownCategories(int tenantId, String username,
        CategoryDrillDownRequest drillDownRequest, boolean securityEnabled) {
    URIBuilder builder = new URIBuilder();
    builder.setScheme(protocol).setHost(hostname).setPort(port)
            .setPath(AnalyticsAPIConstants.SEARCH_PROCESSOR_SERVICE_URI)
            .addParameter(AnalyticsAPIConstants.OPERATION,
                    AnalyticsAPIConstants.DRILL_DOWN_SEARCH_CATEGORY_OPERATION)
            .addParameter(AnalyticsAPIConstants.ENABLE_SECURITY_PARAM, String.valueOf(securityEnabled));
    if (!securityEnabled) {
        builder.addParameter(AnalyticsAPIConstants.TENANT_ID_PARAM, String.valueOf(tenantId));
    } else {/*w ww .j av  a 2s .  c  o  m*/
        builder.addParameter(AnalyticsAPIConstants.USERNAME_PARAM, username);
    }
    try {
        HttpPost postMethod = new HttpPost(builder.build().toString());
        postMethod.addHeader(AnalyticsAPIConstants.SESSION_ID, sessionId);
        postMethod.setEntity(new ByteArrayEntity(GenericUtils.serializeObject(drillDownRequest)));
        HttpResponse httpResponse = httpClient.execute(postMethod);
        if (httpResponse.getStatusLine().getStatusCode() != HttpServletResponse.SC_OK) {
            String response = getResponseString(httpResponse);
            throw new AnalyticsServiceException("Unable to read the Category drilldown object. " + response);
        } else {
            Object drillDownCategoriesObj = GenericUtils
                    .deserializeObject(httpResponse.getEntity().getContent());
            EntityUtils.consumeQuietly(httpResponse.getEntity());
            if (drillDownCategoriesObj != null && drillDownCategoriesObj instanceof SubCategories) {
                return (SubCategories) drillDownCategoriesObj;
            } else {
                throw new AnalyticsServiceException(getUnexpectedResponseReturnedErrorMsg(
                        "preforming drill down" + " search for categories", drillDownRequest.getTableName(),
                        "object of sub categories", drillDownCategoriesObj));
            }
        }
    } catch (URISyntaxException e) {
        throw new AnalyticsServiceException("Malformed URL provided. " + e.getMessage(), e);
    } catch (IOException e) {
        throw new AnalyticsServiceException("Error while connecting to the remote service. " + e.getMessage(),
                e);
    }
}

From source file:org.wso2.carbon.analytics.api.internal.client.AnalyticsAPIHttpClient.java

@SuppressWarnings("unchecked")
public List<AnalyticsDrillDownRange> drillDownRangeCount(int tenantId, String username,
        AnalyticsDrillDownRequest drillDownRequest, boolean securityEnabled) {
    URIBuilder builder = new URIBuilder();
    builder.setScheme(protocol).setHost(hostname).setPort(port)
            .setPath(AnalyticsAPIConstants.SEARCH_PROCESSOR_SERVICE_URI)
            .addParameter(AnalyticsAPIConstants.OPERATION,
                    AnalyticsAPIConstants.DRILL_DOWN_SEARCH_RANGE_COUNT_OPERATION)
            .addParameter(AnalyticsAPIConstants.ENABLE_SECURITY_PARAM, String.valueOf(securityEnabled));
    if (!securityEnabled) {
        builder.addParameter(AnalyticsAPIConstants.TENANT_ID_PARAM, String.valueOf(tenantId));
    } else {//  ww  w.jav  a 2  s .co m
        builder.addParameter(AnalyticsAPIConstants.USERNAME_PARAM, username);
    }
    try {
        HttpPost postMethod = new HttpPost(builder.build().toString());
        postMethod.addHeader(AnalyticsAPIConstants.SESSION_ID, sessionId);
        postMethod.setEntity(new ByteArrayEntity(GenericUtils.serializeObject(drillDownRequest)));
        HttpResponse httpResponse = httpClient.execute(postMethod);
        if (httpResponse.getStatusLine().getStatusCode() != HttpServletResponse.SC_OK) {
            String response = getResponseString(httpResponse);
            throw new AnalyticsServiceException("Unable to read the Analytics drilldown object. " + response);
        } else {
            Object listOfReangeObj = GenericUtils.deserializeObject(httpResponse.getEntity().getContent());
            EntityUtils.consumeQuietly(httpResponse.getEntity());
            if (listOfReangeObj != null && listOfReangeObj instanceof List) {
                return (List<AnalyticsDrillDownRange>) listOfReangeObj;
            } else {
                throw new AnalyticsServiceException(getUnexpectedResponseReturnedErrorMsg(
                        "preforming drill down range count", drillDownRequest.getTableName(),
                        "list of analytics drill down ranges", listOfReangeObj));
            }
        }
    } catch (URISyntaxException e) {
        throw new AnalyticsServiceException("Malformed URL provided. " + e.getMessage(), e);
    } catch (IOException e) {
        throw new AnalyticsServiceException("Error while connecting to the remote service. " + e.getMessage(),
                e);
    }
}