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:org.apache.abdera2.common.protocol.RequestHelper.java
public static HttpUriRequest createRequest(String method, String uri, HttpEntity entity, RequestOptions options) {//from w w w . j a v a2 s. co m if (method == null) return null; if (options == null) options = createAtomDefaultRequestOptions().get(); Method m = Method.get(method); Method actual = null; HttpUriRequest httpMethod = null; if (options.isUsePostOverride() && !nopostoveride.contains(m)) { actual = m; m = Method.POST; } if (m == GET) httpMethod = new HttpGet(uri); else if (m == POST) { httpMethod = new HttpPost(uri); if (entity != null) ((HttpPost) httpMethod).setEntity(entity); } else if (m == PUT) { httpMethod = new HttpPut(uri); if (entity != null) ((HttpPut) httpMethod).setEntity(entity); } else if (m == DELETE) httpMethod = new HttpDelete(uri); else if (m == HEAD) httpMethod = new HttpHead(uri); else if (m == OPTIONS) httpMethod = new HttpOptions(uri); else if (m == TRACE) httpMethod = new HttpTrace(uri); // else if (m == PATCH) // httpMethod = new ExtensionRequest(m.name(),uri,entity); else httpMethod = new ExtensionRequest(m.name(), uri, entity); if (actual != null) { httpMethod.addHeader("X-HTTP-Method-Override", actual.name()); } initHeaders(options, httpMethod); HttpParams params = httpMethod.getParams(); if (!options.isUseExpectContinue()) { params.setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false); } else { if (options.getWaitForContinue() > -1) params.setIntParameter(CoreProtocolPNames.WAIT_FOR_CONTINUE, options.getWaitForContinue()); } if (!(httpMethod instanceof HttpEntityEnclosingRequest)) params.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, options.isFollowRedirects()); return httpMethod; }
From source file:com.ibm.sbt.service.basic.ProxyEndpointService.java
@Override protected DefaultHttpClient getClient(HttpServletRequest request, int timeout) { DefaultHttpClient httpClient = super.getClient(request, timeout); if (endpoint != null) { if (endpoint.isForceTrustSSLCertificate() && requestURI != null) { httpClient = SSLUtil.wrapHttpClient(httpClient); }//from w ww . j a va2s . co m if (endpoint.isForceDisableExpectedContinue()) { httpClient.getParams().setParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false); } String httpProxy = getHttpProxy(endpoint); if (StringUtil.isNotEmpty(httpProxy)) { httpClient = ProxyDebugUtil.wrapHttpClient(httpClient, httpProxy); } } return httpClient; }
From source file:org.sonatype.nexus.testsuite.deploy.nexus168.Nexus168SnapshotToReleaseIT.java
@Test public void deployUsingRest() throws Exception { Gav gav = new Gav(this.getTestId(), "uploadWithGav", "1.0.0-SNAPSHOT", null, "xml", 0, new Date().getTime(), "Simple Test Artifact", false, null, false, null); // file to deploy File fileToDeploy = this.getTestFile(gav.getArtifactId() + "." + gav.getExtension()); // the Restlet Client does not support multipart forms: http://restlet.tigris.org/issues/show_bug.cgi?id=71 // url to upload to String uploadURL = this.getBaseNexusUrl() + "service/local/artifact/maven/content"; // the method we are calling HttpPost filePost = new HttpPost(uploadURL); filePost.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, true); int status = getDeployUtils().deployUsingGavWithRest(uploadURL, TEST_RELEASE_REPO, gav, fileToDeploy); if (status != HttpStatus.SC_BAD_REQUEST) { Assert.fail("Snapshot repositories do not allow manual file upload: " + status); }/*from ww w . j a va 2 s . c o m*/ boolean fileWasUploaded = true; try { // download it downloadArtifact(gav, "./target/downloaded-jars"); } catch (FileNotFoundException e) { fileWasUploaded = false; } Assert.assertFalse("The file was uploaded and it should not have been.", fileWasUploaded); }
From source file:org.nuxeo.scim.server.tests.ScimServerTest.java
protected static ClientConfig createHttpBasicClientConfig(final String userName, final String password) { final HttpParams params = new BasicHttpParams(); DefaultHttpClient.setDefaultHttpParams(params); params.setBooleanParameter(CoreConnectionPNames.SO_REUSEADDR, true); params.setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, true); params.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, true); final SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); final PoolingClientConnectionManager mgr = new PoolingClientConnectionManager(schemeRegistry); mgr.setMaxTotal(200);//from w w w.java2s . c o m mgr.setDefaultMaxPerRoute(20); final DefaultHttpClient httpClient = new DefaultHttpClient(mgr, params); final Credentials credentials = new UsernamePasswordCredentials(userName, password); httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, credentials); httpClient.addRequestInterceptor(new PreemptiveAuthInterceptor(), 0); ClientConfig clientConfig = new ApacheHttpClientConfig(httpClient); clientConfig.setBypassHostnameVerification(true); return clientConfig; }
From source file:org.jclouds.http.apachehc.ApacheHCUtils.java
public HttpUriRequest convertToApacheRequest(HttpRequest request) { HttpUriRequest apacheRequest;//from w w w.ja v a2 s.co m if (request.getMethod().equals(HttpMethod.HEAD)) { apacheRequest = new HttpHead(request.getEndpoint()); } else if (request.getMethod().equals(HttpMethod.GET)) { apacheRequest = new HttpGet(request.getEndpoint()); } else if (request.getMethod().equals(HttpMethod.DELETE)) { apacheRequest = new HttpDelete(request.getEndpoint()); } else if (request.getMethod().equals(HttpMethod.PUT)) { apacheRequest = new HttpPut(request.getEndpoint()); apacheRequest.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, true); } else if (request.getMethod().equals(HttpMethod.POST)) { apacheRequest = new HttpPost(request.getEndpoint()); } else { final String method = request.getMethod(); if (request.getPayload() != null) apacheRequest = new HttpEntityEnclosingRequestBase() { @Override public String getMethod() { return method; } }; else apacheRequest = new HttpRequestBase() { @Override public String getMethod() { return method; } }; HttpRequestBase.class.cast(apacheRequest).setURI(request.getEndpoint()); } Payload payload = request.getPayload(); // Since we may remove headers, ensure they are added to the apache // request after this block if (apacheRequest instanceof HttpEntityEnclosingRequest) { if (payload != null) { addEntityForContent(HttpEntityEnclosingRequest.class.cast(apacheRequest), payload); } } else { apacheRequest.addHeader(HttpHeaders.CONTENT_LENGTH, "0"); } for (Map.Entry<String, String> entry : request.getHeaders().entries()) { String header = entry.getKey(); // apache automatically tries to add content length header if (!header.equals(HttpHeaders.CONTENT_LENGTH)) apacheRequest.addHeader(header, entry.getValue()); } apacheRequest.addHeader(HttpHeaders.USER_AGENT, USER_AGENT); return apacheRequest; }
From source file:de.unidue.inf.is.ezdl.dlservices.library.manager.referencesystems.connotea.ConnoteaUtils.java
/** send a POST Request and return the response as string */ String sendPostRequest(String url, String bodytext) throws Exception { String sresponse;//from w ww.java2 s . c o m HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(url); // set authentication header httppost.addHeader("Authorization", authHeader); // very important. otherwise there comes a invalid request error httppost.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false); StringEntity body = new StringEntity(bodytext); body.setContentType("application/x-www-form-urlencoded"); httppost.setEntity(body); HttpResponse response = httpclient.execute(httppost); // check status code. if (response.getStatusLine().getStatusCode() == HttpURLConnection.HTTP_OK || response.getStatusLine().getStatusCode() == HttpURLConnection.HTTP_CREATED || response.getStatusLine().getStatusCode() == HttpURLConnection.HTTP_NOT_FOUND) { // Not found too. no exception should be thrown. HttpEntity entity = response.getEntity(); sresponse = readResponseStream(entity.getContent()); httpclient.getConnectionManager().shutdown(); } else { HttpEntity entity = response.getEntity(); sresponse = readResponseStream(entity.getContent()); String httpcode = Integer.toString(response.getStatusLine().getStatusCode()); httpclient.getConnectionManager().shutdown(); throw new ReferenceSystemException(httpcode, "Connotea Error", RDFUtils.parseError(sresponse)); } return sresponse; }
From source file:org.sonatype.nexus.testsuite.deploy.nexus176.Nexus176DeployToInvalidRepoIT.java
@Test public void deploywithGavUsingRest() throws Exception { Gav gav = new Gav(this.getTestId(), "uploadWithGav", "1.0.0", null, "xml", 0, new Date().getTime(), "Simple Test Artifact", false, null, false, null); // file to deploy File fileToDeploy = this.getTestFile(gav.getArtifactId() + "." + gav.getExtension()); // the Restlet Client does not support multipart forms: http://restlet.tigris.org/issues/show_bug.cgi?id=71 // url to upload to String uploadURL = this.getBaseNexusUrl() + "service/local/artifact/maven/content"; // the method we are calling HttpPost filePost = new HttpPost(uploadURL); filePost.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, true); int status = getDeployUtils().deployUsingGavWithRest(uploadURL, TEST_RELEASE_REPO, gav, fileToDeploy); if (status != HttpStatus.SC_NOT_FOUND) { Assert.fail("Upload attempt should have returned a 400, it returned: " + status); }//from w w w . ja v a 2s . com boolean fileWasUploaded = true; try { // download it downloadArtifact(gav, "./target/downloaded-jars"); } catch (FileNotFoundException e) { fileWasUploaded = false; } Assert.assertFalse("The file was uploaded and it should not have been.", fileWasUploaded); }
From source file:net.anymeta.AnyMetaAPI.java
/** * Execute the given API call onto the anymeta instance, with arguments. * * @param method The method, e.g. "anymeta.user.info" * @param args Arguments to give to the call. * @return A JSONObject or JSONArray with the response. * @throws AnyMetaException//w ww . j a v a 2 s . co m */ public Object doMethod(String method, Map<String, Object> args) throws AnyMetaException { List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("method", method)); params.add(new BasicNameValuePair("format", "json")); convertParameters((Object) args, params, null); String url = this.entrypoint; OAuthConsumer consumer = new CommonsHttpOAuthConsumer(this.ckey, this.csec, SignatureMethod.PLAINTEXT); consumer.setTokenWithSecret(this.tkey, this.tsec); HttpPost request = new HttpPost(url); request.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false); // set up httppost try { UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "UTF-8"); request.setEntity(entity); } catch (UnsupportedEncodingException e) { throw new AnyMetaException(e.getMessage()); } try { consumer.sign(request); } catch (OAuthMessageSignerException e) { throw new AnyMetaException(e.getMessage()); } catch (OAuthExpectationFailedException e) { throw new AnyMetaException(e.getMessage()); } DefaultHttpClient client = new DefaultHttpClient(); ResponseHandler<String> handler = new BasicResponseHandler(); String response = ""; try { response = client.execute(request, handler); } catch (IOException e) { throw new AnyMetaException(e.getMessage()); } if (response.equalsIgnoreCase("null") || response.equalsIgnoreCase("false")) { return null; } if (!response.startsWith("[") && !response.startsWith("{")) { response = "{\"result\": " + response + "}"; } // System.out.println(response); Object o; try { o = new JSONObject(response); } catch (JSONException e) { try { o = new JSONArray(response); } catch (JSONException e2) { throw new AnyMetaException(e.getMessage() + ": response=" + response); } } if (o instanceof JSONObject && ((JSONObject) o).has("err")) { // handle error try { JSONObject err = ((JSONObject) o).getJSONObject("err").getJSONObject("-attrib-"); throw new AnyMetaException(err.getString("code") + ": " + err.getString("msg")); } catch (JSONException e) { throw new AnyMetaException("Unexpected response in API error: response=" + response); } } return o; }
From source file:org.apache.droids.protocol.http.DroidsHttpClient.java
@Override protected HttpParams createHttpParams() { HttpParams params = new BasicHttpParams(); params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); params.setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, HTTP.DEFAULT_CONTENT_CHARSET); params.setParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false); params.setParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false); params.setIntParameter(CoreConnectionPNames.MAX_HEADER_COUNT, 256); params.setIntParameter(CoreConnectionPNames.MAX_LINE_LENGTH, 5 * 1024); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 20000); params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 20000); params.setParameter(CoreConnectionPNames.TCP_NODELAY, false); //params.setLongParameter(MAX_BODY_LENGTH, 512 * 1024); return params; }
From source file:org.apache.abdera2.common.protocol.BasicClient.java
protected void initDefaultParameters(HttpParams params) { params.setParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, Boolean.TRUE); params.setParameter(ClientPNames.MAX_REDIRECTS, DEFAULT_MAX_REDIRECTS); params.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY); }