List of usage examples for org.apache.http.client.entity UrlEncodedFormEntity UrlEncodedFormEntity
public UrlEncodedFormEntity(final Iterable<? extends NameValuePair> parameters, final Charset charset)
From source file:org.wso2.carbon.governance.registry.extensions.utils.APIUtils.java
/** * This method will authenticate the user name and password mentioned in life cycle against APIM. * * @param httpContext//from w w w. j a v a 2 s. c o m * @param apimEndpoint * @param apimUsername * @param apimPassword */ public static void authenticateAPIM(HttpContext httpContext, String apimEndpoint, String apimUsername, String apimPassword) throws GovernanceException { String loginEP = apimEndpoint + Constants.APIM_LOGIN_ENDPOINT; try { // create a post request to addAPI. HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(loginEP); // Request parameters and other properties. List<NameValuePair> params = new ArrayList<NameValuePair>(Constants.APIM_PARAMETER_COUNT); params.add(new BasicNameValuePair(API_ACTION, API_LOGIN_ACTION)); params.add(new BasicNameValuePair(API_USERNAME, apimUsername)); params.add(new BasicNameValuePair(API_PASSWORD, apimPassword)); httppost.setEntity(new UrlEncodedFormEntity(params, Constants.UTF_8_ENCODE)); HttpResponse response = httpclient.execute(httppost, httpContext); HttpEntity entity = response.getEntity(); String responseString = EntityUtils.toString(entity, Constants.UTF_8_ENCODE); if (response.getStatusLine().getStatusCode() != Constants.SUCCESS_RESPONSE_CODE) { throw new RegistryException(" Authentication with APIM failed: HTTP error code : " + response.getStatusLine().getStatusCode()); } Gson gson = new Gson(); ResponseAPIM responseAPIM = gson.fromJson(responseString, ResponseAPIM.class); if (responseAPIM.getError().equalsIgnoreCase("true")) { throw new GovernanceException( "Error occurred in validating the user. Please check the credentials"); } } catch (Exception e) { throw new GovernanceException("Authentication failed with API Manager. Please check the credentials", e); } }
From source file:org.dataconservancy.ui.it.support.ListCollectionsRequest.java
public HttpPost asHttpPost() { HttpPost post = null;/* ww w . j a va 2s . com*/ try { post = new HttpPost(urlConfig.getListCollectionsUrl().toURI()); } catch (URISyntaxException e) { throw new RuntimeException(e.getMessage(), e); } List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair(STRIPES_EVENT, "List Collections")); HttpEntity entity = null; try { entity = new UrlEncodedFormEntity(params, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e.getMessage(), e); } post.setEntity(entity); return post; }
From source file:org.dataconservancy.ui.it.support.ListProjectActivityRequest.java
public HttpPost asHttpPost(String projectId) { HttpPost post = null;//from w w w .j a v a 2s .co m try { post = new HttpPost(urlConfig.getListProjectCollectionsUrl().toURI()); } catch (URISyntaxException e) { throw new RuntimeException(e.getMessage(), e); } List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("currentProjectId", projectId)); params.add(new BasicNameValuePair(STRIPES_EVENT, "List Project Activity")); HttpEntity entity = null; try { entity = new UrlEncodedFormEntity(params, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e.getMessage(), e); } post.setEntity(entity); return post; }
From source file:securitytools.veracode.http.request.GetBuildListRequest.java
public GetBuildListRequest(String applicationId) { super("/api/4.0/getbuildlist.do"); if (applicationId == null) { throw new IllegalArgumentException("Application id cannot be null."); }//from www . ja v a 2 s .c om List<NameValuePair> formparams = new ArrayList<NameValuePair>(); formparams.add(new BasicNameValuePair("app_id", applicationId)); setEntity(new UrlEncodedFormEntity(formparams, Consts.UTF_8)); }
From source file:com.kingja.springmvc.util.HttpRequestUtils.java
/** * ??HttpWeb/*from w ww. j av a2 s. c o m*/ * * @param path Web? * @param map Http? * @param encode ?? * @return Web? */ public String sendHttpClientPost(String path, Map<String, String> map, String encode) { List<NameValuePair> list = new ArrayList<NameValuePair>(); if (map != null && !map.isEmpty()) { for (Map.Entry<String, String> entry : map.entrySet()) { //?Map?BasicNameValuePair? list.add(new BasicNameValuePair(entry.getKey(), entry.getValue())); } } try { // ???HttpEntity UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list, encode); //HttpPost? HttpPost httpPost = new HttpPost(path); //?Form httpPost.setEntity(entity); //HttpAndroidHttpClient CloseableHttpClient httpclient = HttpClients.createDefault(); //?? HttpResponse httpResponse = httpclient.execute(httpPost); //??200?? if (httpResponse.getStatusLine().getStatusCode() == 200) { //HttpEntity?? InputStream inputStream = httpResponse.getEntity().getContent(); return changeInputStream(inputStream, encode); } } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return ""; }
From source file:org.dataconservancy.ui.it.support.ApproveRegistrationRequest.java
public HttpPost asHttpPost() { HttpPost form = new HttpPost(config.getAdminRegistrationUrl().toString()); List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("userIdsToApprove", emailAddress)); params.add(new BasicNameValuePair(STRIPES_EVENT, "submit")); UrlEncodedFormEntity entity = null;/* w ww .j a v a 2 s. c o m*/ try { entity = new UrlEncodedFormEntity(params, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } form.setEntity(entity); return form; }
From source file:com.subgraph.vega.impl.scanner.requests.PostParameterRequestBuilder.java
private HttpEntity createParameterEntity(List<NameValuePair> parameters) { try {//ww w . j a v a 2 s. c om return new UrlEncodedFormEntity(parameters, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException("Failed to encode form parameters.", e); } }
From source file:org.dataconservancy.ui.it.support.ListProjectCollectionsRequest.java
public HttpPost asHttpPost(String projectId) { HttpPost post = null;//from www . jav a2 s .c om try { post = new HttpPost(urlConfig.getListProjectCollectionsUrl().toURI()); } catch (URISyntaxException e) { throw new RuntimeException(e.getMessage(), e); } List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("currentProjectId", projectId)); params.add(new BasicNameValuePair(STRIPES_EVENT, "List Project Collections")); HttpEntity entity = null; try { entity = new UrlEncodedFormEntity(params, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e.getMessage(), e); } post.setEntity(entity); return post; }
From source file:com.coroptis.coidi.rp.services.impl.HttpTranportServiceImpl.java
@Override public Map<String, String> doPost(final String url, final Map<String, String> map) { Preconditions.checkNotNull(url, "URL"); try {/*from w w w.ja v a2s . c om*/ HttpPost post = new HttpPost(url); post.getParams().setBooleanParameter(AllClientPNames.HANDLE_REDIRECTS, false); post.setEntity(new UrlEncodedFormEntity(httpService.toList(map), "UTF-8")); HttpResponse httpResponse = httpService.getHttpClient().execute(post); String resp = EntityUtils.toString(httpResponse.getEntity()); if (HttpServletResponse.SC_OK == httpResponse.getStatusLine().getStatusCode()) { logger.debug("HTTP status code '{}' response: {}", httpResponse.getStatusLine().getStatusCode(), resp); return httpService.convertToMap(resp); } else { logger.error("HTTP status code '{}' invalid response: {}", httpResponse.getStatusLine().getStatusCode(), resp); throw new CoidiException( "Unable to process response code '" + httpResponse.getStatusLine().getStatusCode() + "'"); } } catch (ParseException e) { logger.error(e.getMessage(), e); throw new CoidiException(e.getMessage(), e); } catch (IOException e) { logger.error(e.getMessage(), e); throw new CoidiException(e.getMessage(), e); } }
From source file:com.appassit.http.ApiRequestFactory.java
/** * POSTHttpEntity/*from w w w. j a va2s. c o m*/ * * @param params * ? * @throws UnsupportedEncodingException * ???UTF8?? */ private static HttpEntity getPostRequestEntity(ArrayList<BasicNameValuePair> params) throws UnsupportedEncodingException { if (params == null || params.isEmpty()) return null; return new UrlEncodedFormEntity(params, HTTP.UTF_8); }