List of usage examples for org.apache.http.params CoreProtocolPNames USE_EXPECT_CONTINUE
String USE_EXPECT_CONTINUE
To view the source code for org.apache.http.params CoreProtocolPNames USE_EXPECT_CONTINUE.
Click Source Link
From source file:com.sangupta.jerry.http.WebRequest.java
/** * Set the request to use expect continue. * /*from w w w . j a v a 2 s .c o m*/ * @return this very {@link WebRequest} */ public WebRequest useExpectContinue() { return config(CoreProtocolPNames.USE_EXPECT_CONTINUE, true); }
From source file:com.expertiseandroid.lib.sociallib.connectors.TwitterConnector.java
private ReadableResponse signedPostRequest(String request, List<NameValuePair> bodyParams) throws OAuthMessageSignerException, OAuthExpectationFailedException, OAuthCommunicationException, ClientProtocolException, IOException { HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(request); post.setEntity(new UrlEncodedFormEntity(bodyParams, HTTP.UTF_8)); post.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false); httpOauthConsumer.sign(post);//from w w w .ja v a2 s . c o m HttpResponse response = client.execute(post); return new HttpResponseWrapper(response); }
From source file:com.expertiseandroid.lib.sociallib.utils.Utils.java
/** * Sends a signed POST request using the Signpost library * @param request the request's URL//w ww . j a v a 2 s . co m * @param entity the message's contents * @param consumer the Signpost consumer object * @param contentType the message's content type * @return the response * @throws OAuthMessageSignerException * @throws OAuthExpectationFailedException * @throws OAuthCommunicationException * @throws ClientProtocolException * @throws IOException */ public static ReadableResponse signedPostRequest(String request, String entity, CommonsHttpOAuthConsumer consumer, String contentType) throws OAuthMessageSignerException, OAuthExpectationFailedException, OAuthCommunicationException, ClientProtocolException, IOException { HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(request); post.setEntity(new StringEntity(entity)); post.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false); consumer.sign(post); post.addHeader("Content-Type", contentType); HttpResponse response = client.execute(post); return new HttpResponseWrapper(response); }
From source file:com.expertiseandroid.lib.sociallib.utils.Utils.java
/** * Sends a signed PUT request using the Signpost library * @param request the request's URL//from w w w. ja v a 2s.com * @param entity the message's contents * @param consumer the Signpost consumer object * @param contentType the message's content type * @return the response * @throws OAuthMessageSignerException * @throws OAuthExpectationFailedException * @throws OAuthCommunicationException * @throws ClientProtocolException * @throws IOException */ public static ReadableResponse signedPutRequest(String request, String entity, CommonsHttpOAuthConsumer consumer, String contentType) throws OAuthMessageSignerException, OAuthExpectationFailedException, OAuthCommunicationException, ClientProtocolException, IOException { HttpClient client = new DefaultHttpClient(); HttpPut put = new HttpPut(request); put.setEntity(new StringEntity(entity)); put.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false); consumer.sign(put); put.addHeader("Content-Type", contentType); HttpResponse response = client.execute(put); return new HttpResponseWrapper(response); }
From source file:com.android.unit_tests.TestHttpService.java
/** * This test case executes a series of simple POST requests that do not * meet the target server expectations. *//* w w w .jav a 2 s . co m*/ @LargeTest public void testHttpPostsWithExpectationVerification() throws Exception { int reqNo = 3; // Initialize the server-side request handler this.server.registerHandler("*", new HttpRequestHandler() { public void handle(final HttpRequest request, final HttpResponse response, final HttpContext context) throws HttpException, IOException { StringEntity outgoing = new StringEntity("No content"); response.setEntity(outgoing); } }); this.server.setExpectationVerifier(new HttpExpectationVerifier() { public void verify(final HttpRequest request, final HttpResponse response, final HttpContext context) throws HttpException { Header someheader = request.getFirstHeader("Secret"); if (someheader != null) { int secretNumber; try { secretNumber = Integer.parseInt(someheader.getValue()); } catch (NumberFormatException ex) { response.setStatusCode(HttpStatus.SC_BAD_REQUEST); return; } if (secretNumber < 2) { response.setStatusCode(HttpStatus.SC_EXPECTATION_FAILED); ByteArrayEntity outgoing = new ByteArrayEntity( EncodingUtils.getAsciiBytes("Wrong secret number")); response.setEntity(outgoing); } } } }); this.server.start(); // Activate 'expect: continue' handshake this.client.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, true); DefaultHttpClientConnection conn = new DefaultHttpClientConnection(); HttpHost host = new HttpHost("localhost", this.server.getPort()); try { for (int r = 0; r < reqNo; r++) { if (!conn.isOpen()) { Socket socket = new Socket(host.getHostName(), host.getPort()); conn.bind(socket, this.client.getParams()); } BasicHttpEntityEnclosingRequest post = new BasicHttpEntityEnclosingRequest("POST", "/"); post.addHeader("Secret", Integer.toString(r)); ByteArrayEntity outgoing = new ByteArrayEntity(EncodingUtils.getAsciiBytes("No content")); post.setEntity(outgoing); HttpResponse response = this.client.execute(post, host, conn); HttpEntity entity = response.getEntity(); assertNotNull(entity); entity.consumeContent(); if (r < 2) { assertEquals(HttpStatus.SC_EXPECTATION_FAILED, response.getStatusLine().getStatusCode()); } else { assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode()); } if (!this.client.keepAlive(response)) { conn.close(); } } //Verify the connection metrics HttpConnectionMetrics cm = conn.getMetrics(); assertEquals(reqNo, cm.getRequestCount()); assertEquals(reqNo, cm.getResponseCount()); } finally { conn.close(); this.server.shutdown(); } }
From source file:com.flipzu.flipzu.FlipInterface.java
public FlipUser getUser(String username, String token) throws IOException { String data = "username=" + username + "&access_token=" + token; String url = WSServer + "/api/get_user.xml"; debug.logV(TAG, "getUser for username " + username); DefaultHttpClient hc = new DefaultHttpClient(); ResponseHandler<String> res = new ResponseHandler<String>() { public String handleResponse(final HttpResponse response) throws HttpResponseException, IOException { StatusLine statusLine = response.getStatusLine(); if (statusLine.getStatusCode() >= 300) { throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase()); }// w w w . j ava 2s .c o m HttpEntity entity = response.getEntity(); return entity == null ? null : EntityUtils.toString(entity, "UTF-8"); } }; HttpPost postMethod = new HttpPost(url); postMethod.getParams().setParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, Boolean.FALSE); if (data != null) { StringEntity tmp = null; try { tmp = new StringEntity(data, "UTF-8"); } catch (UnsupportedEncodingException e) { debug.logE(TAG, "getUser ERROR", e.getCause()); return null; } postMethod.setEntity(tmp); } String response = hc.execute(postMethod, res); SAXParserFactory spf = SAXParserFactory.newInstance(); try { SAXParser sp = spf.newSAXParser(); XMLReader xr = sp.getXMLReader(); UserHandler myUserHandler = new UserHandler(); xr.setContentHandler(myUserHandler); InputSource inputSource = new InputSource(); inputSource.setEncoding("UTF-8"); inputSource.setCharacterStream(new StringReader(response)); xr.parse(inputSource); FlipUser parsedData = myUserHandler.getParsedData(); return parsedData; } catch (ParserConfigurationException e) { return null; } catch (SAXException e) { return null; } }
From source file:com.flipzu.flipzu.FlipInterface.java
private List<BroadcastDataSet> sendRequest(String url, String data) throws IOException { DefaultHttpClient hc = new DefaultHttpClient(); ResponseHandler<String> res = new ResponseHandler<String>() { public String handleResponse(final HttpResponse response) throws HttpResponseException, IOException { StatusLine statusLine = response.getStatusLine(); if (statusLine.getStatusCode() >= 300) { throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase()); }/*from w w w . j a v a 2 s . c o m*/ HttpEntity entity = response.getEntity(); return entity == null ? null : EntityUtils.toString(entity, "UTF-8"); } }; HttpPost postMethod = new HttpPost(url); postMethod.getParams().setParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, Boolean.FALSE); if (data != null) { StringEntity tmp = null; try { tmp = new StringEntity(data, "UTF-8"); } catch (UnsupportedEncodingException e) { debug.logE(TAG, "sendRequest ERROR", e.getCause()); return null; } postMethod.setEntity(tmp); } String response = hc.execute(postMethod, res); SAXParserFactory spf = SAXParserFactory.newInstance(); try { SAXParser sp = spf.newSAXParser(); XMLReader xr = sp.getXMLReader(); TimelineHandler myTimelineHandler = new TimelineHandler(); xr.setContentHandler(myTimelineHandler); InputSource inputSource = new InputSource(); inputSource.setEncoding("UTF-8"); inputSource.setCharacterStream(new StringReader(response)); xr.parse(inputSource); List<BroadcastDataSet> parsedDataSet = myTimelineHandler.getParsedData(); return parsedDataSet; } catch (ParserConfigurationException e) { return null; } catch (SAXException e) { return null; } }
From source file:com.expertiseandroid.lib.sociallib.utils.Utils.java
private static void setParams(HttpEntityEnclosingRequestBase req) { req.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false); }
From source file:com.flipzu.flipzu.FlipInterface.java
private JSONArray sendJson(String url, String data) throws IOException { DefaultHttpClient hc = new DefaultHttpClient(); ResponseHandler<String> res = new ResponseHandler<String>() { public String handleResponse(final HttpResponse response) throws HttpResponseException, IOException { StatusLine statusLine = response.getStatusLine(); if (statusLine.getStatusCode() >= 300) { throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase()); }/*from w w w . java 2 s .c o m*/ HttpEntity entity = response.getEntity(); return entity == null ? null : EntityUtils.toString(entity, "UTF-8"); } }; HttpPost postMethod = new HttpPost(url); postMethod.getParams().setParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, Boolean.FALSE); if (data != null) { StringEntity tmp = null; try { tmp = new StringEntity(data, "UTF-8"); } catch (UnsupportedEncodingException e) { debug.logE(TAG, "sendJson ERROR", e.getCause()); return null; } postMethod.setEntity(tmp); } String response = hc.execute(postMethod, res); JSONTokener tokener = new JSONTokener(response); JSONArray jobj = null; try { jobj = new JSONArray(tokener); } catch (JSONException e) { debug.logE(TAG, "sendJson got exception " + response, e.getCause()); return null; } debug.logV(TAG, "sendJson got " + jobj); return jobj; }