List of usage examples for org.apache.http.client.utils URIBuilder addParameter
public URIBuilder addParameter(final String param, final String value)
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 www . ja 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 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); } }
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 {// w ww.j a v a 2s. 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); 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
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 w w.j av 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
@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 a v a2s .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 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 w w. ja v a 2s.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 {/*ww w . j ava 2s . c om*/ 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 {/*from w ww . j a va 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); } }
From source file:org.wso2.carbon.analytics.api.internal.client.AnalyticsAPIHttpClient.java
public AnalyticsIterator<Record> searchWithAggregates(int tenantId, String username, AggregateRequest aggregateRequest, boolean securityEnabled) { URIBuilder builder = new URIBuilder(); builder.setScheme(protocol).setHost(hostname).setPort(port) .setPath(AnalyticsAPIConstants.SEARCH_PROCESSOR_SERVICE_URI) .addParameter(AnalyticsAPIConstants.OPERATION, AnalyticsAPIConstants.SEARCH_WITH_AGGREGATES_OPERATION) .addParameter(AnalyticsAPIConstants.ENABLE_SECURITY_PARAM, String.valueOf(securityEnabled)) .addParameter(AnalyticsAPIConstants.GROUP_BY_FIELD_PARAM, aggregateRequest.getGroupByField()) .addParameter(AnalyticsAPIConstants.QUERY, aggregateRequest.getQuery()) .addParameter(AnalyticsAPIConstants.AGGREGATING_FIELDS, gson.toJson(aggregateRequest.getFields())) .addParameter(AnalyticsAPIConstants.TABLE_NAME_PARAM, aggregateRequest.getTableName()) .addParameter(AnalyticsAPIConstants.AGGREGATE_LEVEL, String.valueOf(aggregateRequest.getAggregateLevel())) .addParameter(AnalyticsAPIConstants.AGGREGATE_PARENT_PATH, gson.toJson(aggregateRequest.getParentPath())); if (!securityEnabled) { builder.addParameter(AnalyticsAPIConstants.TENANT_ID_PARAM, String.valueOf(tenantId)); } else {//from w w w.j av a 2s . 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("Error while searching with aggregates. " + response); } else { return new RemoteRecordIterator(httpResponse.getEntity().getContent()); } } 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.identity.application.authentication.framework.handler.request.impl.PostAuthnMissingClaimHandler.java
private PostAuthnHandlerFlowStatus handlePostAuthenticationForMissingClaimsRequest(HttpServletRequest request, HttpServletResponse response, AuthenticationContext context) throws PostAuthenticationFailedException { String[] missingClaims = FrameworkUtils.getMissingClaims(context); if (StringUtils.isNotBlank(missingClaims[0])) { if (log.isDebugEnabled()) { log.debug("Mandatory claims missing for the application : " + missingClaims[0]); }//from w w w.j a v a 2s . c o m try { // If there are read only claims marked as mandatory and they are missing, we cannot proceed further. // We have to end the flow and show an error message to user. ClaimManager claimManager = getUserRealm(context.getTenantDomain()).getClaimManager(); Map<String, String> missingClaimMap = FrameworkUtils.getMissingClaimsMap(context); for (Map.Entry<String, String> missingClaim : missingClaimMap.entrySet()) { Claim claimObj = claimManager.getClaim(missingClaim.getValue()); if (claimObj != null && claimObj.isReadOnly()) { throw new PostAuthenticationFailedException("One or more read-only claim is missing in the " + "requested claim set. Please contact your administrator for more information about " + "this issue.", "One or more read-only claim is missing in the requested claim set"); } } URIBuilder uriBuilder = new URIBuilder( ConfigurationFacade.getInstance().getAuthenticationEndpointMissingClaimsURL()); uriBuilder.addParameter(FrameworkConstants.MISSING_CLAIMS, missingClaims[0]); uriBuilder.addParameter(FrameworkConstants.SESSION_DATA_KEY, context.getContextIdentifier()); uriBuilder.addParameter(FrameworkConstants.REQUEST_PARAM_SP, context.getSequenceConfig().getApplicationConfig().getApplicationName()); response.sendRedirect(uriBuilder.build().toString()); context.setProperty(POST_AUTHENTICATION_REDIRECTION_TRIGGERED, true); if (log.isDebugEnabled()) { log.debug("Redirecting to outside to pick mandatory claims"); } } catch (IOException e) { throw new PostAuthenticationFailedException("Error while handling missing mandatory claims", "Error " + "while redirecting to request claims page", e); } catch (URISyntaxException e) { throw new PostAuthenticationFailedException("Error while handling missing mandatory claims", "Error while building redirect URI", e); } catch (org.wso2.carbon.user.api.UserStoreException e) { throw new PostAuthenticationFailedException("Error while handling missing mandatory claims", "Error while retrieving claim from claim URI.", e); } return PostAuthnHandlerFlowStatus.INCOMPLETE; } else { return PostAuthnHandlerFlowStatus.SUCCESS_COMPLETED; } }
From source file:org.wso2.identity.scenarios.commons.HTTPCommonClient.java
/** * Send GET request for a given URL with the request query parameters. * * @param url Request URL./*from www .j a v a 2s . c o m*/ * @param params Request query parameters. * @param headers Request headers. * @return HttpResponse containing the response. * @throws IOException If error occurs while sending the request. * @throws URISyntaxException If error occurs while constructing the request URL. */ public HttpResponse sendGetRequest(String url, Map<String, String> params, Header[] headers) throws IOException, URISyntaxException { URIBuilder uriBuilder = new URIBuilder(url); if (params != null && !params.isEmpty()) { for (Map.Entry<String, String> entry : params.entrySet()) { uriBuilder.addParameter(entry.getKey(), entry.getValue()); } } HttpGet getRequest = new HttpGet(uriBuilder.build()); if (headers != null) { getRequest.setHeaders(headers); } return this.client.execute(getRequest); }