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:com.uploader.Vimeo.java
public String addTextTrack(String videoEndPoint, File file, boolean active, String type, String language, String name) throws IOException, VimeoException { VimeoResponse response = null;// ww w . ja v a 2 s. c om Map<String, String> params = new HashMap<String, String>(); params.put("active", active ? "true" : "false"); params.put("type", type); params.put("language", language); params.put("name", name); VimeoResponse addVideoRespose = apiRequest(new StringBuffer(videoEndPoint).append("/texttracks").toString(), HttpPost.METHOD_NAME, params, null); try { if (addVideoRespose.getStatusCode() == 201) { String textTrackUploadLink = addVideoRespose.getJson().getString("link"); response = apiRequest(textTrackUploadLink, HttpPut.METHOD_NAME, null, file); if (response.getStatusCode() == 200) { return addVideoRespose.getJson().getString("uri"); } } } catch (Exception e) { System.out.println("Err in getStatusCode"); } throw new VimeoException( new StringBuffer("HTTP Status Code: ").append(response.getStatusCode()).toString()); }
From source file:io.cloudslang.content.services.WSManRemoteShellService.java
/** * Configures the HttpClientInputs object with the most common http parameters. * * @param httpClientInputs//from w w w.j a va 2 s .com * @param url * @param wsManRequestInputs * @return the configured HttpClientInputs object. * @throws MalformedURLException */ private static HttpClientInputs setCommonHttpInputs(HttpClientInputs httpClientInputs, URL url, WSManRequestInputs wsManRequestInputs) throws MalformedURLException { httpClientInputs.setUrl(url.toString()); httpClientInputs.setUsername(wsManRequestInputs.getUsername()); httpClientInputs.setPassword(wsManRequestInputs.getPassword()); httpClientInputs.setAuthType(wsManRequestInputs.getAuthType()); httpClientInputs.setKerberosConfFile(wsManRequestInputs.getKerberosConfFile()); httpClientInputs.setKerberosLoginConfFile(wsManRequestInputs.getKerberosLoginConfFile()); httpClientInputs.setKerberosSkipPortCheck(wsManRequestInputs.getKerberosSkipPortForLookup()); httpClientInputs.setTrustAllRoots(wsManRequestInputs.getTrustAllRoots()); httpClientInputs.setX509HostnameVerifier(wsManRequestInputs.getX509HostnameVerifier()); httpClientInputs.setProxyHost(wsManRequestInputs.getProxyHost()); httpClientInputs.setProxyPort(wsManRequestInputs.getProxyPort()); httpClientInputs.setProxyUsername(wsManRequestInputs.getProxyUsername()); httpClientInputs.setProxyPassword(wsManRequestInputs.getProxyPassword()); httpClientInputs.setKeystore(wsManRequestInputs.getKeystore()); httpClientInputs.setKeystorePassword(wsManRequestInputs.getKeystorePassword()); httpClientInputs.setTrustKeystore(wsManRequestInputs.getTrustKeystore()); httpClientInputs.setTrustPassword(wsManRequestInputs.getTrustPassword()); String headers = httpClientInputs.getHeaders(); if (StringUtils.isEmpty(headers)) { httpClientInputs.setHeaders(CONTENT_TYPE_HEADER); } else { httpClientInputs.setHeaders(headers + NEW_LINE_SEPARATOR + CONTENT_TYPE_HEADER); } httpClientInputs.setMethod(HttpPost.METHOD_NAME); return httpClientInputs; }
From source file:com.microsoft.windowsazure.mobileservices.sdk.testapp.test.CustomApiClientTests.java
public void testInvokeGenericWithNullClassShouldThrowException() throws Throwable { // Container to store callback's results and do the asserts. final ResultsContainer container = new ResultsContainer(); MobileServiceClient client = null;/*from www . ja va 2 s. c om*/ try { client = new MobileServiceClient(appUrl, appKey, getInstrumentation().getTargetContext()); client.invokeApi("myApi", new Object(), HttpPost.METHOD_NAME, null, null).get(); } catch (Exception exception) { container.setException(exception); } // Asserts Exception exception = container.getException(); if (!(exception instanceof IllegalArgumentException)) { fail("Expected Exception IllegalArgumentException"); } }
From source file:org.jboss.as.test.integration.security.perimeter.WebConsoleSecurityTestCase.java
@Test public void testPost() throws Exception { getConnection().setRequestMethod(HttpPost.METHOD_NAME); getConnection().connect();// w ww . j av a2s. c o m assertEquals(HttpURLConnection.HTTP_UNAUTHORIZED, getConnection().getResponseCode()); }
From source file:org.elasticsearch.client.RequestConverters.java
static Request updateAliases(IndicesAliasesRequest indicesAliasesRequest) throws IOException { Request request = new Request(HttpPost.METHOD_NAME, "/_aliases"); Params parameters = new Params(request); parameters.withTimeout(indicesAliasesRequest.timeout()); parameters.withMasterTimeout(indicesAliasesRequest.masterNodeTimeout()); request.setEntity(createEntity(indicesAliasesRequest, REQUEST_BODY_CONTENT_TYPE)); return request; }
From source file:com.azure.webapi.MobileServiceClient.java
/** * Invokes a custom API using POST HTTP method * //from w w w. ja v a 2 s .c o m * @param apiName * The API name * @param body * The object to send as the request body * @param clazz * The API result class * @param callback * The callback to invoke after the API execution */ public <E> void invokeApi(String apiName, Object body, Class<E> clazz, ApiOperationCallback<E> callback) { invokeApi(apiName, body, HttpPost.METHOD_NAME, null, clazz, callback); }
From source file:ch.cyberduck.core.dropbox.client.AbstractHttpDropboxClient.java
/** * @param method//from w ww. ja va2 s. c o m * @param path * @param params * @param content * @return */ protected HttpUriRequest buildRequest(String method, String path, String[] params, boolean content) { if (method.equals(HttpGet.METHOD_NAME)) { return new HttpGet(this.getUrl(path, params, content)); } else if (method.equals(HttpPost.METHOD_NAME)) { HttpPost post = new HttpPost(this.getUrl(path, params, content)); if (params != null && params.length > 2) { List<BasicNameValuePair> form = new ArrayList<BasicNameValuePair>(); for (int i = 0; i < params.length; i += 2) { if (params[i + 1] != null) { form.add(new BasicNameValuePair("" + params[i], "" + params[i + 1])); } } try { post.setEntity(new UrlEncodedFormEntity(form, HTTP.UTF_8)); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } } return post; } throw new IllegalArgumentException(method); }
From source file:com.microsoft.windowsazure.mobileservices.sdk.testapp.test.CustomApiClientTests.java
public void testInvokeTypedSingleObject() throws Throwable { // Container to store callback's results and do the asserts. final ResultsContainer container = new ResultsContainer(); final PersonTestObject p = new PersonTestObject("john", "doe", 30); MobileServiceClient client = null;//from w w w . j a v a 2s .c o m try { client = new MobileServiceClient(appUrl, appKey, getInstrumentation().getTargetContext()); client = client.withFilter(new EchoFilter()); PersonTestObject result = client .invokeApi("myApi", p, HttpPost.METHOD_NAME, null, PersonTestObject.class).get(); if (result == null) { container.setException(new Exception("Expected one person result")); } else { container.setPerson(result); } } catch (Exception exception) { container.setException(exception); } // Asserts Exception exception = container.getException(); if (exception != null) { fail(exception.getMessage()); } else { assertEquals(p.getFirstName(), container.getPerson().getFirstName()); assertEquals(p.getLastName(), container.getPerson().getLastName()); assertEquals(p.getAge(), container.getPerson().getAge()); } }
From source file:org.elasticsearch.client.Request.java
static Request bulk(BulkRequest bulkRequest) throws IOException { Params parameters = Params.builder(); parameters.withTimeout(bulkRequest.timeout()); parameters.withRefreshPolicy(bulkRequest.getRefreshPolicy()); // Bulk API only supports newline delimited JSON or Smile. Before executing // the bulk, we need to check that all requests have the same content-type // and this content-type is supported by the Bulk API. XContentType bulkContentType = null; for (int i = 0; i < bulkRequest.numberOfActions(); i++) { DocWriteRequest<?> request = bulkRequest.requests().get(i); DocWriteRequest.OpType opType = request.opType(); if (opType == DocWriteRequest.OpType.INDEX || opType == DocWriteRequest.OpType.CREATE) { bulkContentType = enforceSameContentType((IndexRequest) request, bulkContentType); } else if (opType == DocWriteRequest.OpType.UPDATE) { UpdateRequest updateRequest = (UpdateRequest) request; if (updateRequest.doc() != null) { bulkContentType = enforceSameContentType(updateRequest.doc(), bulkContentType); }//from w w w. j a va 2 s . c o m if (updateRequest.upsertRequest() != null) { bulkContentType = enforceSameContentType(updateRequest.upsertRequest(), bulkContentType); } } } if (bulkContentType == null) { bulkContentType = XContentType.JSON; } byte separator = bulkContentType.xContent().streamSeparator(); ContentType requestContentType = ContentType.create(bulkContentType.mediaType()); ByteArrayOutputStream content = new ByteArrayOutputStream(); for (DocWriteRequest<?> request : bulkRequest.requests()) { DocWriteRequest.OpType opType = request.opType(); try (XContentBuilder metadata = XContentBuilder.builder(bulkContentType.xContent())) { metadata.startObject(); { metadata.startObject(opType.getLowercase()); if (Strings.hasLength(request.index())) { metadata.field("_index", request.index()); } if (Strings.hasLength(request.type())) { metadata.field("_type", request.type()); } if (Strings.hasLength(request.id())) { metadata.field("_id", request.id()); } if (Strings.hasLength(request.routing())) { metadata.field("_routing", request.routing()); } if (Strings.hasLength(request.parent())) { metadata.field("_parent", request.parent()); } if (request.version() != Versions.MATCH_ANY) { metadata.field("_version", request.version()); } VersionType versionType = request.versionType(); if (versionType != VersionType.INTERNAL) { if (versionType == VersionType.EXTERNAL) { metadata.field("_version_type", "external"); } else if (versionType == VersionType.EXTERNAL_GTE) { metadata.field("_version_type", "external_gte"); } else if (versionType == VersionType.FORCE) { metadata.field("_version_type", "force"); } } if (opType == DocWriteRequest.OpType.INDEX || opType == DocWriteRequest.OpType.CREATE) { IndexRequest indexRequest = (IndexRequest) request; if (Strings.hasLength(indexRequest.getPipeline())) { metadata.field("pipeline", indexRequest.getPipeline()); } } else if (opType == DocWriteRequest.OpType.UPDATE) { UpdateRequest updateRequest = (UpdateRequest) request; if (updateRequest.retryOnConflict() > 0) { metadata.field("_retry_on_conflict", updateRequest.retryOnConflict()); } if (updateRequest.fetchSource() != null) { metadata.field("_source", updateRequest.fetchSource()); } } metadata.endObject(); } metadata.endObject(); BytesRef metadataSource = metadata.bytes().toBytesRef(); content.write(metadataSource.bytes, metadataSource.offset, metadataSource.length); content.write(separator); } BytesRef source = null; if (opType == DocWriteRequest.OpType.INDEX || opType == DocWriteRequest.OpType.CREATE) { IndexRequest indexRequest = (IndexRequest) request; BytesReference indexSource = indexRequest.source(); XContentType indexXContentType = indexRequest.getContentType(); try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, indexSource, indexXContentType)) { try (XContentBuilder builder = XContentBuilder.builder(bulkContentType.xContent())) { builder.copyCurrentStructure(parser); source = builder.bytes().toBytesRef(); } } } else if (opType == DocWriteRequest.OpType.UPDATE) { source = XContentHelper.toXContent((UpdateRequest) request, bulkContentType, false).toBytesRef(); } if (source != null) { content.write(source.bytes, source.offset, source.length); content.write(separator); } } HttpEntity entity = new ByteArrayEntity(content.toByteArray(), 0, content.size(), requestContentType); return new Request(HttpPost.METHOD_NAME, "/_bulk", parameters.getParams(), entity); }