List of usage examples for org.apache.http.client.utils URIBuilder setScheme
public URIBuilder setScheme(final String scheme)
From source file:org.wso2.carbon.analytics.api.internal.client.AnalyticsAPIHttpClient.java
@SuppressWarnings("unchecked") public void putRecords(String username, List<Record> records, boolean securityEnabled) throws AnalyticsServiceException { URIBuilder builder = new URIBuilder(); builder.setScheme(protocol).setHost(hostname).setPort(port) .setPath(AnalyticsAPIConstants.RECORD_PROCESSOR_SERVICE_URI) .addParameter(AnalyticsAPIConstants.OPERATION, AnalyticsAPIConstants.PUT_RECORD_OPERATION) .addParameter(AnalyticsAPIConstants.ENABLE_SECURITY_PARAM, String.valueOf(securityEnabled)); if (securityEnabled) { builder.addParameter(AnalyticsAPIConstants.USERNAME_PARAM, username); }//from w ww. j a v a 2 s .c o m try { HttpPost postMethod = new HttpPost(builder.build().toString()); postMethod.addHeader(AnalyticsAPIConstants.SESSION_ID, sessionId); postMethod.setEntity(new ByteArrayEntity(GenericUtils.serializeObject(records))); HttpResponse httpResponse = httpClient.execute(postMethod); if (httpResponse.getStatusLine().getStatusCode() != HttpServletResponse.SC_OK) { String response = getResponseString(httpResponse); throw new AnalyticsServiceException("Unable to put the records. " + response); } else { Object recordIdsObj = GenericUtils.deserializeObject(httpResponse.getEntity().getContent()); EntityUtils.consumeQuietly(httpResponse.getEntity()); if (recordIdsObj != null && recordIdsObj instanceof List) { List<String> recordIds = (List<String>) recordIdsObj; int index = 0; for (Record record : records) { record.setId(recordIds.get(index)); index++; } } else { throw new AnalyticsServiceException(getUnexpectedResponseReturnedErrorMsg("putting the records", null, "list of strings", recordIdsObj)); } } } 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 void deleteRecords(int tenantId, String username, String tableName, long timeFrom, long timeTo, boolean securityEnabled) throws AnalyticsServiceException { URIBuilder builder = new URIBuilder(); builder.setScheme(protocol).setHost(hostname).setPort(port) .setPath(AnalyticsAPIConstants.RECORD_PROCESSOR_SERVICE_URI) .addParameter(AnalyticsAPIConstants.OPERATION, AnalyticsAPIConstants.DELETE_RECORDS_RANGE_OPERATION) .addParameter(AnalyticsAPIConstants.TABLE_NAME_PARAM, tableName) .addParameter(AnalyticsAPIConstants.TIME_FROM_PARAM, String.valueOf(timeFrom)) .addParameter(AnalyticsAPIConstants.TIME_TO_PARAM, String.valueOf(timeTo)) .addParameter(AnalyticsAPIConstants.ENABLE_SECURITY_PARAM, String.valueOf(securityEnabled)); if (!securityEnabled) { builder.addParameter(AnalyticsAPIConstants.TENANT_ID_PARAM, String.valueOf(tenantId)); } else {/*from www.j a v a2 s.com*/ builder.addParameter(AnalyticsAPIConstants.USERNAME_PARAM, username); } try { HttpDelete deleteMethod = new HttpDelete(builder.build().toString()); deleteMethod.addHeader(AnalyticsAPIConstants.SESSION_ID, sessionId); HttpResponse httpResponse = httpClient.execute(deleteMethod); String response = getResponseString(httpResponse); if (httpResponse.getStatusLine().getStatusCode() != HttpServletResponse.SC_OK) { throw new AnalyticsServiceException("Unable to delete the record count for the table - " + tableName + ", time from : " + timeFrom + " , timeTo : " + timeTo + " for tenant id : " + tenantId + ". " + 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
public void deleteRecords(int tenantId, String username, String tableName, List<String> recordIds, boolean securityEnabled) throws AnalyticsServiceException { URIBuilder builder = new URIBuilder(); builder.setScheme(protocol).setHost(hostname).setPort(port) .setPath(AnalyticsAPIConstants.RECORD_PROCESSOR_SERVICE_URI) .addParameter(AnalyticsAPIConstants.OPERATION, AnalyticsAPIConstants.DELETE_RECORDS_IDS_OPERATION) .addParameter(AnalyticsAPIConstants.TABLE_NAME_PARAM, tableName) .addParameter(AnalyticsAPIConstants.RECORD_IDS_PARAM, gson.toJson(recordIds)) .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 a2 s . co m*/ builder.addParameter(AnalyticsAPIConstants.USERNAME_PARAM, username); } try { HttpDelete deleteMethod = new HttpDelete(builder.build().toString()); deleteMethod.addHeader(AnalyticsAPIConstants.SESSION_ID, sessionId); HttpResponse httpResponse = httpClient.execute(deleteMethod); String response = getResponseString(httpResponse); if (httpResponse.getStatusLine().getStatusCode() != HttpServletResponse.SC_OK) { throw new AnalyticsServiceException("Unable to delete the record count for the table - " + tableName + ", records - " + recordIds + " for tenant id : " + tenantId + ". " + 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
public void clearIndices(int tenantId, String username, String tableName, boolean securityEnabled) throws AnalyticsServiceException { URIBuilder builder = new URIBuilder(); builder.setScheme(protocol).setHost(hostname).setPort(port) .setPath(AnalyticsAPIConstants.INDEX_PROCESSOR_SERVICE_URI) .addParameter(AnalyticsAPIConstants.OPERATION, AnalyticsAPIConstants.DELETE_INDICES_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 {// ww w. ja v a 2 s .c o m builder.addParameter(AnalyticsAPIConstants.USERNAME_PARAM, username); } try { HttpDelete deleteMethod = new HttpDelete(builder.build().toString()); deleteMethod.addHeader(AnalyticsAPIConstants.SESSION_ID, sessionId); HttpResponse httpResponse = httpClient.execute(deleteMethod); if (httpResponse.getStatusLine().getStatusCode() != HttpServletResponse.SC_OK) { String response = getResponseString(httpResponse); throw new AnalyticsServiceException("Unable to get the index for table - " + tableName + " for tenant id : " + tenantId + ". " + response); } else { EntityUtils.consume(httpResponse.getEntity()); } } 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<SearchResultEntry> search(int tenantId, String username, String tableName, String query, int start, int count, boolean securityEnabled) throws AnalyticsServiceException { URIBuilder builder = new URIBuilder(); builder.setScheme(protocol).setHost(hostname).setPort(port) .setPath(AnalyticsAPIConstants.SEARCH_PROCESSOR_SERVICE_URI) .addParameter(AnalyticsAPIConstants.OPERATION, AnalyticsAPIConstants.SEARCH_OPERATION) .addParameter(AnalyticsAPIConstants.TABLE_NAME_PARAM, tableName) .addParameter(AnalyticsAPIConstants.QUERY, query) .addParameter(AnalyticsAPIConstants.START_PARAM, String.valueOf(start)) .addParameter(AnalyticsAPIConstants.COUNT_PARAM, String.valueOf(count)) .addParameter(AnalyticsAPIConstants.ENABLE_SECURITY_PARAM, String.valueOf(securityEnabled)); if (!securityEnabled) { builder.addParameter(AnalyticsAPIConstants.TENANT_ID_PARAM, String.valueOf(tenantId)); } else {/*from w ww . j a v a2 s . c om*/ 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 search the table - " + tableName + " for tenant id : " + tenantId + " with query : " + query + ". " + response); } else { Object searchResultObj = GenericUtils.deserializeObject(httpResponse.getEntity().getContent()); EntityUtils.consumeQuietly(httpResponse.getEntity()); if (searchResultObj != null && searchResultObj instanceof List) { return (List<SearchResultEntry>) searchResultObj; } else { throw new AnalyticsServiceException(getUnexpectedResponseReturnedErrorMsg("searching the table", tableName, "List of Search Result Entry objects", searchResultObj)); } } } 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 int searchCount(int tenantId, String username, String tableName, String query, boolean securityEnabled) throws AnalyticsServiceException { URIBuilder builder = new URIBuilder(); builder.setScheme(protocol).setHost(hostname).setPort(port) .setPath(AnalyticsAPIConstants.SEARCH_PROCESSOR_SERVICE_URI) .addParameter(AnalyticsAPIConstants.OPERATION, AnalyticsAPIConstants.SEARCH_COUNT_OPERATION) .addParameter(AnalyticsAPIConstants.TABLE_NAME_PARAM, tableName) .addParameter(AnalyticsAPIConstants.QUERY, query) .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 a va 2 s. c o 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 search the table - " + tableName + " for tenant id : " + tenantId + " with query : " + query + ". " + response); } else { if (response.startsWith(AnalyticsAPIConstants.SEARCH_COUNT)) { String[] responseElements = response.split(AnalyticsAPIConstants.SEPARATOR); if (responseElements.length == 2) { return Integer.parseInt(responseElements[1]); } else { throw new AnalyticsServiceException("Invalid response returned, cannot find search count" + " message. Response:" + response); } } else { throw new AnalyticsServiceException( "Invalid response returned, search count 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
public void waitForIndexing(int tenantId, String username, String tableName, long maxWait, boolean securityEnabled) throws AnalyticsServiceException { URIBuilder builder = new URIBuilder(); builder.setScheme(protocol).setHost(hostname).setPort(port) .setPath(AnalyticsAPIConstants.INDEX_PROCESSOR_SERVICE_URI); try {//from w w w. j a va2 s . c om HttpPost postMethod = new HttpPost(builder.build().toString()); postMethod.addHeader(AnalyticsAPIConstants.SESSION_ID, sessionId); List<NameValuePair> params = new ArrayList<>(); params.add(new BasicNameValuePair(AnalyticsAPIConstants.OPERATION, AnalyticsAPIConstants.WAIT_FOR_INDEXING_OPERATION)); params.add(new BasicNameValuePair(AnalyticsAPIConstants.MAX_WAIT_PARAM, String.valueOf(maxWait))); params.add(new BasicNameValuePair(AnalyticsAPIConstants.TABLE_NAME_PARAM, tableName)); params.add(new BasicNameValuePair(AnalyticsAPIConstants.TENANT_ID_PARAM, String.valueOf(tenantId))); params.add(new BasicNameValuePair(AnalyticsAPIConstants.USERNAME_PARAM, username)); params.add(new BasicNameValuePair(AnalyticsAPIConstants.ENABLE_SECURITY_PARAM, String.valueOf(securityEnabled))); postMethod.setEntity(new UrlEncodedFormEntity(params)); HttpResponse httpResponse = httpClient.execute(postMethod); String response = getResponseString(httpResponse); if (httpResponse.getStatusLine().getStatusCode() != HttpServletResponse.SC_OK) { throw new AnalyticsServiceException( "Unable to configure max wait: " + maxWait + " for indexing. " + 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
public void destroy() throws AnalyticsServiceException { URIBuilder builder = new URIBuilder(); builder.setScheme(protocol).setHost(hostname).setPort(port) .setPath(AnalyticsAPIConstants.ANALYTICS_SERVICE_PROCESSOR_URI); try {//from ww w . jav a 2 s .c o m HttpPost postMethod = new HttpPost(builder.build().toString()); postMethod.addHeader(AnalyticsAPIConstants.SESSION_ID, sessionId); List<NameValuePair> params = new ArrayList<>(); params.add(new BasicNameValuePair(AnalyticsAPIConstants.OPERATION, AnalyticsAPIConstants.DESTROY_OPERATION)); postMethod.setEntity(new UrlEncodedFormEntity(params)); HttpResponse httpResponse = httpClient.execute(postMethod); String response = getResponseString(httpResponse); if (httpResponse.getStatusLine().getStatusCode() != HttpServletResponse.SC_OK) { throw new AnalyticsServiceException("Unable to destroy the process . " + 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
public AnalyticsDataResponse getRecordGroup(int tenantId, String username, String tableName, int numPartitionsHint, List<String> columns, long timeFrom, long timeTo, int recordsFrom, int recordsCount, boolean securityEnabled) 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.GET_RANGE_RECORD_GROUP_OPERATION) .addParameter(AnalyticsAPIConstants.TABLE_NAME_PARAM, tableName) .addParameter(AnalyticsAPIConstants.PARTITIONER_NO_PARAM, String.valueOf(numPartitionsHint)) .addParameter(AnalyticsAPIConstants.COLUMNS_PARAM, new Gson().toJson(columns)) .addParameter(AnalyticsAPIConstants.TIME_FROM_PARAM, String.valueOf(timeFrom)) .addParameter(AnalyticsAPIConstants.TIME_TO_PARAM, String.valueOf(timeTo)) .addParameter(AnalyticsAPIConstants.RECORD_FROM_PARAM, String.valueOf(recordsFrom)) .addParameter(AnalyticsAPIConstants.COUNT_PARAM, String.valueOf(recordsCount)) .addParameter(AnalyticsAPIConstants.ENABLE_SECURITY_PARAM, String.valueOf(securityEnabled)); if (!securityEnabled) { builder.addParameter(AnalyticsAPIConstants.TENANT_ID_PARAM, String.valueOf(tenantId)); } else {/* w w w.ja va2s . c o 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); 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 AnalyticsDataResponse getWithKeyValues(int tenantId, String username, String tableName, int numPartitionsHint, List<String> columns, List<Map<String, Object>> valuesBatch, boolean securityEnabled) 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.GET_RECORDS_WITH_KEY_VALUES_OPERATION) .addParameter(AnalyticsAPIConstants.TABLE_NAME_PARAM, tableName) .addParameter(AnalyticsAPIConstants.PARTITIONER_NO_PARAM, String.valueOf(numPartitionsHint)) .addParameter(AnalyticsAPIConstants.COLUMNS_PARAM, new Gson().toJson(columns)) .addParameter(AnalyticsAPIConstants.KEY_VALUE_PARAM, new Gson().toJson(valuesBatch)) .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 v a 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); if (httpResponse.getStatusLine().getStatusCode() != HttpServletResponse.SC_OK) { String response = getResponseString(httpResponse); throw new AnalyticsServiceException("Unable to get with key values . " + 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 " + "with key values", tableName, "Analytics Data Response object consist of" + " array of remote record group", analyticsDataResponseObj)); } } else { throw new AnalyticsServiceAuthenticationException( getUnexpectedResponseReturnedErrorMsg("getting " + "with key value", 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); } }