List of usage examples for org.apache.http.client.methods HttpPost METHOD_NAME
String METHOD_NAME
To view the source code for org.apache.http.client.methods HttpPost METHOD_NAME.
Click Source Link
From source file:org.apache.metamodel.elasticsearch.rest.ElasticSearchRestClient.java
private static Request refresh(final String indexName) { return new Request(HttpPost.METHOD_NAME, "/" + indexName + "/_refresh", Collections.emptyMap(), null); }
From source file:com.twitter.hbc.core.HttpConstants.java
public static HttpUriRequest constructRequest(String host, Endpoint endpoint, Authentication auth) { String url = host + endpoint.getURI(); if (endpoint.getHttpMethod().equalsIgnoreCase(HttpGet.METHOD_NAME)) { HttpGet get = new HttpGet(url); if (auth != null) auth.signRequest(get, null); return get; } else if (endpoint.getHttpMethod().equalsIgnoreCase(HttpPost.METHOD_NAME)) { HttpPost post = new HttpPost(url); post.setEntity(new StringEntity(endpoint.getPostParamString(), Constants.DEFAULT_CHARSET)); post.setHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded"); if (auth != null) auth.signRequest(post, endpoint.getPostParamString()); return post; } else {// w w w. j a v a2s . com throw new IllegalArgumentException("Bad http method: " + endpoint.getHttpMethod()); } }
From source file:org.gradle.internal.resource.transport.http.AlwaysRedirectRedirectStrategy.java
public HttpUriRequest getRedirect(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException { URI uri = this.getLocationURI(request, response, context); String method = request.getRequestLine().getMethod(); if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) { return new HttpHead(uri); } else if (method.equalsIgnoreCase(HttpPost.METHOD_NAME)) { return this.copyEntity(new HttpPost(uri), request); } else if (method.equalsIgnoreCase(HttpPut.METHOD_NAME)) { return this.copyEntity(new HttpPut(uri), request); } else if (method.equalsIgnoreCase(HttpDelete.METHOD_NAME)) { return new HttpDelete(uri); } else if (method.equalsIgnoreCase(HttpTrace.METHOD_NAME)) { return new HttpTrace(uri); } else if (method.equalsIgnoreCase(HttpOptions.METHOD_NAME)) { return new HttpOptions(uri); } else if (method.equalsIgnoreCase(HttpPatch.METHOD_NAME)) { return this.copyEntity(new HttpPatch(uri), request); } else {/*from www .j a v a 2s .c o m*/ return new HttpGet(uri); } }
From source file:com.trickl.crawler.robot.http.SimpleHttpPostTask.java
@Override public Protocol getProtocol() { HttpProtocol protocol = new HttpProtocol(); protocol.setMethod(HttpPost.METHOD_NAME); protocol.setHeaderData(headerData);//w w w . j ava 2 s . c om protocol.setPostData(postData); return protocol; }
From source file:com.openx.oauth.redirect.OpenXRedirectStrategy.java
/** * Custom redirect logic//from w w w. j a v a 2s. c o m * @param request * @param response * @param context * @return if the handler should redirect or not */ @Override public boolean isRedirected(final HttpRequest request, final HttpResponse response, final HttpContext context) { if (response == null) { throw new IllegalArgumentException("HTTP response may not be null"); } int statusCode = response.getStatusLine().getStatusCode(); String method = request.getRequestLine().getMethod(); Header locationHeader = response.getFirstHeader("location"); switch (statusCode) { case HttpStatus.SC_MOVED_TEMPORARILY: if (method.equalsIgnoreCase(HttpPost.METHOD_NAME)) { return locationHeader != null; } else { return (method.equalsIgnoreCase(HttpGet.METHOD_NAME) || method.equalsIgnoreCase(HttpHead.METHOD_NAME)) && locationHeader != null; } case HttpStatus.SC_MOVED_PERMANENTLY: case HttpStatus.SC_TEMPORARY_REDIRECT: return method.equalsIgnoreCase(HttpGet.METHOD_NAME) || method.equalsIgnoreCase(HttpHead.METHOD_NAME); case HttpStatus.SC_SEE_OTHER: return true; default: return false; } }
From source file:ch.cyberduck.core.dropbox.client.DropboxClient.java
/** * Copy a file from one path to another, with root being either "sandbox" or "dropbox". *//*from w w w .j ava 2 s.c o m*/ public void copy(String from_path, String to_path) throws IOException { String[] params = { "root", ROOT, "from_path", from_path, "to_path", to_path }; HttpResponse response = request(this.buildRequest(HttpPost.METHOD_NAME, "/fileops/copy", params)); this.finish(response); }
From source file:org.camunda.connect.httpclient.HttpRequestTest.java
@Test public void setHttpMethod() { HttpRequest request = connector.createRequest().get(); assertThat(request.getMethod()).isEqualTo(HttpGet.METHOD_NAME); request = connector.createRequest().post(); assertThat(request.getMethod()).isEqualTo(HttpPost.METHOD_NAME); request = connector.createRequest().put(); assertThat(request.getMethod()).isEqualTo(HttpPut.METHOD_NAME); request = connector.createRequest().delete(); assertThat(request.getMethod()).isEqualTo(HttpDelete.METHOD_NAME); request = connector.createRequest().patch(); assertThat(request.getMethod()).isEqualTo(HttpPatch.METHOD_NAME); request = connector.createRequest().head(); assertThat(request.getMethod()).isEqualTo(HttpHead.METHOD_NAME); request = connector.createRequest().options(); assertThat(request.getMethod()).isEqualTo(HttpOptions.METHOD_NAME); request = connector.createRequest().trace(); assertThat(request.getMethod()).isEqualTo(HttpTrace.METHOD_NAME); }
From source file:ch.cyberduck.core.dropbox.client.DropboxClient.java
/** * Create a folder at the given path./*w w w .ja v a 2s .c om*/ */ public void create(String path) throws IOException { String[] params = { "root", ROOT, "path", path }; HttpResponse response = request(this.buildRequest(HttpPost.METHOD_NAME, "/fileops/create_folder", params)); this.finish(response); }
From source file:org.elasticsearch.test.rest.yaml.restspec.ClientYamlSuiteRestApi.java
/** * Returns the supported http methods given the rest parameters provided *//*from w ww.j a va 2 s. co m*/ public List<String> getSupportedMethods(Set<String> restParams) { //we try to avoid hardcoded mappings but the index api is the exception if ("index".equals(name) || "create".equals(name)) { List<String> indexMethods = new ArrayList<>(); for (String method : methods) { if (restParams.contains("id")) { //PUT when the id is provided if (HttpPut.METHOD_NAME.equals(method)) { indexMethods.add(method); } } else { //POST without id if (HttpPost.METHOD_NAME.equals(method)) { indexMethods.add(method); } } } return indexMethods; } return methods; }
From source file:org.jolokia.client.request.J4pRequestHandler.java
/** * Get the HttpRequest for executing the given single request * * @param pRequest request to convert//w w w .j a va 2 s. c om * @param pPreferredMethod HTTP method preferred * @param pProcessingOptions optional map of processiong options * @return the request used with HttpClient to obtain the result. */ public HttpUriRequest getHttpRequest(J4pRequest pRequest, String pPreferredMethod, Map<J4pQueryParameter, String> pProcessingOptions) throws UnsupportedEncodingException, URISyntaxException { String method = pPreferredMethod; if (method == null) { method = pRequest.getPreferredHttpMethod(); } if (method == null) { method = doUseProxy(pRequest) ? HttpPost.METHOD_NAME : HttpGet.METHOD_NAME; } String queryParams = prepareQueryParameters(pProcessingOptions); // GET request if (method.equals(HttpGet.METHOD_NAME)) { if (doUseProxy(pRequest)) { throw new IllegalArgumentException("Proxy mode can only be used with POST requests"); } List<String> parts = pRequest.getRequestParts(); // If parts == null the request decides, that POST *must* be used if (parts != null) { String base = prepareBaseUrl(j4pServerUrl); StringBuilder requestPath = new StringBuilder(base); requestPath.append(pRequest.getType().getValue()); for (String p : parts) { requestPath.append("/"); requestPath.append(escape(p)); } return new HttpGet(createRequestURI(requestPath.toString(), queryParams)); } } // We are using a post method as fallback JSONObject requestContent = getJsonRequestContent(pRequest); HttpPost postReq = new HttpPost(createRequestURI(j4pServerUrl.getPath(), queryParams)); postReq.setEntity(new StringEntity(requestContent.toJSONString(), "utf-8")); return postReq; }