Package org.apache.http.client.entity

Examples of org.apache.http.client.entity.UrlEncodedFormEntity


      List<NameValuePair> nvps = new ArrayList<NameValuePair>();
      nvps.add(new BasicNameValuePair("j_username", user));
      nvps.add(new BasicNameValuePair("j_password", pass));

      httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));

      response = httpclient.execute(httpost);


      int statusCode = response.getStatusLine().getStatusCode();
View Full Code Here


         List<NameValuePair> nvps = new ArrayList<NameValuePair>();
         nvps.add(new BasicNameValuePair("j_username", user));
         nvps.add(new BasicNameValuePair("j_password", pass));

         httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));

         response = httpclient.execute(httpost);
         entity = response.getEntity();
         if (entity != null)
            EntityUtils.consume(entity);
View Full Code Here

            postParameters.add(new BasicNameValuePair(key, value));
        }

        Debug.logInfo("SagePay PostParameters - " + postParameters, module);

        HttpEntity postEntity = new UrlEncodedFormEntity(postParameters);
        httpPost.setEntity(postEntity);
        return httpPost;
    }
View Full Code Here

        List <NameValuePair> nvps = new ArrayList <NameValuePair>();
        nvps.add(new BasicNameValuePair("IDToken1", "username"));
        nvps.add(new BasicNameValuePair("IDToken2", "password"));

        httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));

        response = httpclient.execute(httpost);
        entity = response.getEntity();

        System.out.println("Login form get: " + response.getStatusLine());
View Full Code Here

                    String storeDir = basePath + "/node-" + node.getId();
                    params.add(new BasicNameValuePair("dir", storeDir));
                    params.add(new BasicNameValuePair("store", storeName));
                    if(pushVersion > 0)
                        params.add(new BasicNameValuePair("pushVersion", Long.toString(pushVersion)));
                    post.setEntity(new UrlEncodedFormEntity(params));

                    logger.info("Invoking fetch for node " + node.getId() + " for " + storeDir);

                    HttpResponse httpResponse = null;
                    try {
                        httpResponse = httpClient.execute(post);
                        int responseCode = httpResponse.getStatusLine().getStatusCode();
                        InputStream is = httpResponse.getEntity().getContent();
                        String response = VoldemortIOUtils.toString(is, 30000);

                        if(responseCode != HttpURLConnection.HTTP_OK)
                            throw new VoldemortException("Fetch request on node "
                                                         + node.getId()
                                                         + " ("
                                                         + url
                                                         + ") failed: "
                                                         + httpResponse.getStatusLine()
                                                                       .getReasonPhrase());
                        logger.info("Fetch succeeded on node " + node.getId());
                        return response.trim();
                    } finally {
                        VoldemortIOUtils.closeQuietly(httpResponse);
                    }
                }
            }));
        }

        // wait for all operations to complete successfully
        TreeMap<Integer, String> results = Maps.newTreeMap();
        HashMap<Integer, Exception> exceptions = Maps.newHashMap();

        for(int nodeId = 0; nodeId < cluster.getNumberOfNodes(); nodeId++) {
            Future<String> val = fetchDirs.get(nodeId);
            try {
                results.put(nodeId, val.get());
            } catch(Exception e) {
                exceptions.put(nodeId, new VoldemortException(e));
            }
        }

        if(!exceptions.isEmpty()) {

            if(deleteFailedFetch) {
                // Delete data from successful nodes
                for(int successfulNodeId: results.keySet()) {
                    HttpResponse httpResponse = null;
                    try {
                        String url = cluster.getNodeById(successfulNodeId).getHttpUrl() + "/"
                                     + readOnlyMgmtPath;
                        HttpPost post = new HttpPost(url);

                        List<NameValuePair> params = new ArrayList<NameValuePair>();
                        params.add(new BasicNameValuePair("operation", "failed-fetch"));
                        params.add(new BasicNameValuePair("dir", results.get(successfulNodeId)));
                        params.add(new BasicNameValuePair("store", storeName));
                        post.setEntity(new UrlEncodedFormEntity(params));

                        logger.info("Deleting fetched data from node " + successfulNodeId);

                        httpResponse = httpClient.execute(post);
                        int responseCode = httpResponse.getStatusLine().getStatusCode();
View Full Code Here

                params.add(new BasicNameValuePair("operation", "swap"));
                String dir = fetchFiles.get(node.getId());
                logger.info("Attempting swap for node " + node.getId() + " dir = " + dir);
                params.add(new BasicNameValuePair("dir", dir));
                params.add(new BasicNameValuePair("store", storeName));
                post.setEntity(new UrlEncodedFormEntity(params));

                httpResponse = httpClient.execute(post);
                int responseCode = httpResponse.getStatusLine().getStatusCode();
                String previousDir = VoldemortIOUtils.toString(httpResponse.getEntity()
                                                                           .getContent(), 30000);

                if(responseCode != HttpURLConnection.HTTP_OK)
                    throw new VoldemortException("Swap request on node " + node.getId() + " ("
                                                 + url + ") failed: "
                                                 + httpResponse.getStatusLine().getReasonPhrase());
                logger.info("Swap succeeded on node " + node.getId());
                previousDirs.put(node.getId(), previousDir);
            } catch(Exception e) {
                exceptions.put(node.getId(), e);
                logger.error("Exception thrown during swap operation on node " + node.getId()
                             + ": ", e);
            } finally {
                VoldemortIOUtils.closeQuietly(httpResponse, node.toString());
            }
        }

        if(!exceptions.isEmpty()) {
            if(rollbackFailedSwap) {
                // Rollback data on successful nodes
                for(int successfulNodeId: previousDirs.keySet()) {
                    HttpResponse httpResponse = null;
                    try {
                        String url = cluster.getNodeById(successfulNodeId).getHttpUrl() + "/"
                                     + readOnlyMgmtPath;
                        HttpPost post = new HttpPost(url);

                        List<NameValuePair> params = new ArrayList<NameValuePair>();
                        params.add(new BasicNameValuePair("operation", "rollback"));
                        params.add(new BasicNameValuePair("store", storeName));
                        params.add(new BasicNameValuePair("pushVersion",
                                                          Long.toString(ReadOnlyUtils.getVersionId(new File(previousDirs.get(successfulNodeId))))));
                        post.setEntity(new UrlEncodedFormEntity(params));

                        logger.info("Rolling back data on successful node " + successfulNodeId);

                        httpResponse = httpClient.execute(post);
                        int responseCode = httpResponse.getStatusLine().getStatusCode();
View Full Code Here

                List<NameValuePair> params = new ArrayList<NameValuePair>();
                params.add(new BasicNameValuePair("operation", "rollback"));
                params.add(new BasicNameValuePair("store", storeName));
                params.add(new BasicNameValuePair("pushVersion", Long.toString(pushVersion)));
                post.setEntity(new UrlEncodedFormEntity(params));

                httpResponse = httpClient.execute(post);
                int responseCode = httpResponse.getStatusLine().getStatusCode();
                String response = httpResponse.getStatusLine().getReasonPhrase();
                if(responseCode == 200) {
View Full Code Here

  public byte[] post(String relativeUrl, TokenHolder tokenHolder, HttpParameters oauthParams,
    List<? extends NameValuePair> parameters) {
    HttpPost post = new HttpPost(baseUrl + relativeUrl);
    if (parameters != null) {
      try {
        post.setEntity(new UrlEncodedFormEntity(parameters, "UTF-8"));
      } catch (UnsupportedEncodingException e) {
        throw new IllegalArgumentException("Invalid URL encoding", e);
      }
    }
    return doRequest(post, tokenHolder, oauthParams);
View Full Code Here

          for (String key : postMap.keySet()) {
            String value = postMap.get(key);
            value = value==null ? "" : value;
            list.add(new BasicNameValuePair(key, value));
          }
          httppost.setEntity(new UrlEncodedFormEntity(list, request.getCharset()));
        }
        Map<String, String> headerMap = request.getHeaderMap();
        for(String key: headerMap.keySet()){
          httppost.addHeader(key, headerMap.get(key));
        }
View Full Code Here

            BasicNameValuePair clientPair = new BasicNameValuePair("clientUUID", _clientId);
            dataList.add(clientPair);
        }

        if (dataList.size() > 0) {
            UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(dataList);
            urlEncodedFormEntity.setContentEncoding(HTTP.UTF_8);
            post.setEntity(urlEncodedFormEntity);
        }

        HttpClient client = new DefaultHttpClient();
        HttpConnectionParams.setConnectionTimeout(client.getParams(), _timeout);
View Full Code Here

TOP

Related Classes of org.apache.http.client.entity.UrlEncodedFormEntity

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.