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:eu.over9000.cathode.Dispatcher.java
public <ResponseType> Result<ResponseType> performPost(final Class<ResponseType> resultClass, final String path, final HttpEntity payload, final Parameter... parameters) { return performInternal(HttpPost.METHOD_NAME, resultClass, path, payload, parameters); }
From source file:org.trancecode.xproc.step.RequestParser.java
public XProcHttpRequest parseRequest(final XdmNode requestNode, final Processor processor) { final String method = requestNode.getAttributeValue(XProcXmlModel.Attributes.METHOD); if (Strings.isNullOrEmpty(method)) { throw XProcExceptions.xc0006(requestNode); }// www. j a v a 2s. c om request.setHeaders(parseHeaders(requestNode)); request.setEntity(parseMultipart(requestNode, processor)); if (!request.hasEntity()) { request.setEntity(parseBody(requestNode, processor)); } if (request.hasEntity()) { checkCoherenceHeaders(request.getHeaders(), request.getEntity(), requestNode); if (!(StringUtils.equalsIgnoreCase(HttpPut.METHOD_NAME, method) || StringUtils.equalsIgnoreCase(HttpPost.METHOD_NAME, method))) { throw XProcExceptions.xc0005(requestNode); } } final boolean status = Boolean.valueOf(requestNode.getAttributeValue(XProcXmlModel.Attributes.STATUS_ONLY)); final boolean detailed = Boolean.valueOf(requestNode.getAttributeValue(XProcXmlModel.Attributes.DETAILED)); if (status && !detailed) { throw XProcExceptions.xc0004(requestNode); } request.setDetailled(detailed); request.setStatusOnly(status); final String href = requestNode.getAttributeValue(XProcXmlModel.Attributes.HREF); final URI hrefUri = requestNode.getBaseURI().resolve(href); if (hrefUri.getPort() != -1) { request.setHttpHost(new HttpHost(hrefUri.getHost(), hrefUri.getPort(), hrefUri.getScheme())); } else { request.setHttpHost(new HttpHost(hrefUri.getHost())); } final CredentialsProvider credentialsProvider = parseAuthentication(requestNode); request.setCredentials(credentialsProvider); request.setHttpRequest(constructMethod(method, hrefUri)); request.setOverrideContentType( requestNode.getAttributeValue(XProcXmlModel.Attributes.OVERRIDE_CONTENT_TYPE)); return request; }
From source file:com.uploader.Vimeo.java
public VimeoResponse beginUploadVideo(Map<String, String> params) throws IOException { return apiRequest("/me/videos", HttpPost.METHOD_NAME, params, null); }
From source file:ch.cyberduck.core.dropbox.client.DropboxClient.java
/** * Put a file in the user's Dropbox./* ww w . j av a 2 s. co m*/ */ public void put(String to, ContentBody content) throws IOException { HttpClient client = getClient(); HttpPost req = (HttpPost) buildRequest(HttpPost.METHOD_NAME, "/files/" + ROOT + to, true); // this has to be done this way because of how oauth signs params // first we add a "fake" param of file=path of *uploaded* file, THEN we sign that. List<BasicNameValuePair> nvps = new ArrayList<BasicNameValuePair>(); nvps.add(new BasicNameValuePair("file", content.getFilename())); req.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); try { auth.sign(req); } catch (OAuthException e) { IOException failure = new IOException(e.getMessage()); failure.initCause(e); throw failure; } // now we can add the real file multipart and we're good MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); entity.addPart("file", content); // this resets it to the new entity with the real file req.setEntity(entity); this.finish(client.execute(req)); }
From source file:org.elasticsearch.test.rest.client.http.HttpRequestBuilder.java
private HttpUriRequest buildRequest() { if (HttpGetWithEntity.METHOD_NAME.equalsIgnoreCase(method)) { return addOptionalBody(new HttpGetWithEntity(buildUri())); }/*from ww w .j a v a 2 s .c o m*/ if (HttpHead.METHOD_NAME.equalsIgnoreCase(method)) { checkBodyNotSupported(); return new HttpHead(buildUri()); } if (HttpDeleteWithEntity.METHOD_NAME.equalsIgnoreCase(method)) { return addOptionalBody(new HttpDeleteWithEntity(buildUri())); } if (HttpPut.METHOD_NAME.equalsIgnoreCase(method)) { return addOptionalBody(new HttpPut(buildUri())); } if (HttpPost.METHOD_NAME.equalsIgnoreCase(method)) { return addOptionalBody(new HttpPost(buildUri())); } throw new UnsupportedOperationException("method [" + method + "] not supported"); }
From source file:com.blacklocus.jres.request.index.JresUpdateDocument.java
@Override public String getHttpMethod() { return HttpPost.METHOD_NAME; }
From source file:com.linkedin.pinot.common.utils.FileUploadDownloadClient.java
private static HttpUriRequest getAddSchemaRequest(URI uri, String schemaName, File schemaFile) { return getUploadFileRequest(HttpPost.METHOD_NAME, uri, getContentBody(schemaName, schemaFile), null, null, DEFAULT_SOCKET_TIMEOUT_MS); }
From source file:com.seleritycorp.common.base.http.client.HttpRequest.java
private org.apache.http.HttpResponse getHttpResponse() throws HttpException { final HttpRequestBase request; switch (method) { case HttpGet.METHOD_NAME: request = new HttpGet(); break;/*from w ww. j a va 2 s. c o m*/ case HttpPost.METHOD_NAME: request = new HttpPost(); break; default: throw new HttpException("Unknown HTTP method '" + method + "'"); } try { request.setURI(URI.create(uri)); } catch (IllegalArgumentException e) { throw new HttpException("Failed to create URI '" + uri + "'", e); } if (userAgent != null) { request.setHeader(HTTP.USER_AGENT, userAgent); } if (readTimeoutMillis >= 0) { request.setConfig(RequestConfig.custom().setSocketTimeout(readTimeoutMillis) .setConnectTimeout(readTimeoutMillis).setConnectionRequestTimeout(readTimeoutMillis).build()); } if (!data.isEmpty()) { if (request instanceof HttpEntityEnclosingRequestBase) { final HttpEntity entity; ContentType localContentType = contentType; if (localContentType == null) { localContentType = ContentType.create("text/plain", StandardCharsets.UTF_8); } entity = new StringEntity(data, localContentType); HttpEntityEnclosingRequestBase entityRequest = (HttpEntityEnclosingRequestBase) request; entityRequest.setEntity(entity); } else { throw new HttpException( "Request " + request.getMethod() + " does not allow to send data " + "with the request"); } } final HttpClient httpClient; if (uri.startsWith("file://")) { httpClient = this.fileHttpClient; } else { httpClient = this.netHttpClient; } final org.apache.http.HttpResponse response; try { response = httpClient.execute(request); } catch (IOException e) { throw new HttpException("Failed to execute request to '" + uri + "'", e); } return response; }
From source file:com.microsoft.windowsazure.mobileservices.sdk.testapp.test.CustomApiClientTests.java
public void testResponseWithNon2xxStatusShouldThrowException() throws Throwable { final ResultsContainer container = new ResultsContainer(); MobileServiceClient client = null;/*from ww w. j a va 2 s. c om*/ try { client = new MobileServiceClient(appUrl, appKey, getInstrumentation().getTargetContext()); client = client.withFilter(new ServiceFilter() { @Override public ListenableFuture<ServiceFilterResponse> handleRequest(ServiceFilterRequest request, NextServiceFilterCallback nextServiceFilterCallback) { ServiceFilterResponseMock mockResponse = new ServiceFilterResponseMock(); mockResponse.setStatus(new StatusLineMock(418)); // I'm a // teapot // status // code ServiceFilterRequestMock mockRequest = new ServiceFilterRequestMock(mockResponse); return nextServiceFilterCallback.onNext(mockRequest); } }); List<Pair<String, String>> mockHeaders = new ArrayList<Pair<String, String>>(); List<Pair<String, String>> mockParameters = new ArrayList<Pair<String, String>>(); client.invokeApi("myApi", new byte[] { 1, 2, 3, 4 }, HttpPost.METHOD_NAME, mockHeaders, mockParameters) .get(); } catch (Exception exception) { if (exception instanceof ExecutionException) { container.setException((Exception) exception.getCause()); } else { container.setException(exception); } } // Asserts Exception exception = container.getException(); if (!(exception instanceof MobileServiceException)) { fail("Expected Exception MobileServiceException"); } }
From source file:org.apache.zeppelin.notebook.repo.zeppelinhub.rest.HttpProxyClient.java
private HttpAsyncClientBuilder setRedirects(HttpAsyncClientBuilder clientBuilder) { clientBuilder.setRedirectStrategy(new DefaultRedirectStrategy() { /** Redirectable methods. */ private String[] REDIRECT_METHODS = new String[] { HttpGet.METHOD_NAME, HttpPost.METHOD_NAME, HttpPut.METHOD_NAME, HttpDelete.METHOD_NAME, HttpHead.METHOD_NAME }; @Override/*from w w w. ja va 2 s. c o m*/ protected boolean isRedirectable(String method) { for (String m : REDIRECT_METHODS) { if (m.equalsIgnoreCase(method)) { return true; } } return false; } }); return clientBuilder; }