List of usage examples for org.apache.http.client.fluent Request Post
public static Request Post(final String uri)
From source file:com.movilizer.mds.webservice.services.UploadFileService.java
private CompletableFuture<UploadResponse> upload(HttpEntity entity, Integer connectionTimeoutInMillis) { CompletableFuture<UploadResponse> future = new CompletableFuture<>(); try {//from w w w. j ava 2 s . co m Async.newInstance().execute( Request.Post(documentUploadAddress.toURI()) .addHeader(USER_AGENT_HEADER_KEY, DefaultValues.USER_AGENT) .connectTimeout(connectionTimeoutInMillis).body(entity), new ResponseHandlerAdapter<UploadResponse>(future) { @Override public UploadResponse convertHttpResponse(HttpResponse httpResponse) { logger.info(Messages.UPLOAD_COMPLETE); int statusCode = httpResponse.getStatusLine().getStatusCode(); String errorMessage = httpResponse.getStatusLine().getReasonPhrase(); if (statusCode == POSSIBLE_BAD_CREDENTIALS) { errorMessage = errorMessage + Messages.FAILED_FILE_UPLOAD_CREDENTIALS; } return new UploadResponse(statusCode, errorMessage); } }); } catch (URISyntaxException e) { if (logger.isErrorEnabled()) { logger.error(String.format(Messages.UPLOAD_ERROR, e.getMessage())); } future.completeExceptionally(new MovilizerWebServiceException(e)); } return future; }
From source file:com.twosigma.beaker.NamespaceClient.java
public Object evaluate(String filter) throws ClientProtocolException, IOException { Form form = Form.form().add("filter", filter).add("session", this.session); String reply = Request.Post(ctrlUrlBase + "/evaluate").addHeader("Authorization", auth) .bodyForm(form.build()).execute().returnContent().asString(); Object r;// w w w . j av a 2 s. co m try { JsonNode n = objectMapper.get().readTree(reply); r = objectSerializerProvider.get().deserialize(n, objectMapper.get()); if (r == null) r = deserializeObject(reply); } catch (Exception e) { r = null; } return r; }
From source file:org.mule.module.http.functional.proxy.HttpProxyTemplateTestCase.java
@Test public void proxyBody() throws Exception { handlerExtender = new EchoRequestHandlerExtender() { @Override//from w w w . j a v a 2 s . c o m protected String selectRequestPartToReturn(org.eclipse.jetty.server.Request baseRequest) { return body; } }; Response response = Request.Post(getProxyUrl("test")).bodyString("Some Text", ContentType.DEFAULT_TEXT) .connectTimeout(RECEIVE_TIMEOUT).execute(); HttpResponse httpResponse = response.returnResponse(); assertThat(httpResponse.getStatusLine().getStatusCode(), is(200)); assertThat(IOUtils.toString(httpResponse.getEntity().getContent()), is("Some Text")); }
From source file:org.restheart.test.integration.GetAggreationIT.java
private void createMetadataAndTestData(String aggregationsMetadata) throws Exception { // get the collection etag String etag = getEtag(collectionTmpUri); // post some data String[] data = new String[] { "{\"name\":\"a\",\"age\":10}", "{\"name\":\"a\",\"age\":20}", "{\"name\":\"a\",\"age\":30}", "{\"name\":\"b\",\"age\":40}", "{\"name\":\"b\",\"age\":50}", "{\"name\":\"b\",\"age\":60}", "{\"obj\":{\"name\":\"x\",\"age\":10}}", "{\"obj\":{\"name\":\"x\",\"age\":20}}", "{\"obj\":{\"name\":\"y\",\"age\":10}}", "{\"obj\":{\"name\":\"y\",\"age\":20}}" }; for (String datum : data) { Response resp = adminExecutor.execute(Request.Post(collectionTmpUri).bodyString(datum, halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check aggregation create test data", resp, HttpStatus.SC_CREATED); }/*from www .j ava 2 s. c o m*/ Response resp = adminExecutor .execute(Request.Patch(collectionTmpUri).bodyString(aggregationsMetadata, halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE) .addHeader(Headers.IF_MATCH_STRING, etag)); check("check update collection with aggregations metadata", resp, HttpStatus.SC_OK); }
From source file:com.kurento.kmf.orion.OrionConnector.java
/** * Sends a request to Orion/*from w ww .j a va 2 s. com*/ * * @param ctxElement * The context element * @param path * the path from the context broker that determines which * "operation"will be executed * @param responseClazz * The class expected for the response * @return The object representing the JSON answer from Orion * @throws OrionConnectorException * if a communication exception happens, either when contacting * the context broker at the given address, or obtaining the * answer from it. */ private <E, T> T sendRequestToOrion(E ctxElement, String path, Class<T> responseClazz) { String jsonEntity = gson.toJson(ctxElement); log.debug("Send request to Orion: {}", jsonEntity); Request req = Request.Post(orionAddr.toString() + path).addHeader("Accept", APPLICATION_JSON.getMimeType()) .bodyString(jsonEntity, APPLICATION_JSON).connectTimeout(5000).socketTimeout(5000); Response response; try { response = req.execute(); } catch (IOException e) { throw new OrionConnectorException("Could not execute HTTP request", e); } HttpResponse httpResponse = checkResponse(response); T ctxResp = getOrionObjFromResponse(httpResponse, responseClazz); log.debug("Send to Orion response: {}", httpResponse); return ctxResp; }
From source file:com.qwazr.search.index.IndexSingleClient.java
@Override public LinkedHashMap<String, AnalyzerDefinition> setAnalyzers(String schema_name, String index_name, LinkedHashMap<String, AnalyzerDefinition> analyzers) { UBuilder uriBuilder = new UBuilder("/indexes/", schema_name, "/", index_name, "/analyzers"); Request request = Request.Post(uriBuilder.build()); return commonServiceRequest(request, analyzers, null, AnalyzerDefinition.MapStringAnalyzerTypeRef, 200); }
From source file:org.obm.sync.push.client.WBXMLOPClient.java
private Request buildRequest(String namespace, Document doc, String cmd, String policyKey, boolean multipart) throws WBXmlException, IOException { ByteArrayEntity requestEntity = getRequestEntity(namespace, doc); Request request = Request.Post(buildUrl(ai.getUrl(), ai.getLogin(), ai.getDevId(), ai.getDevType(), cmd)) .addHeader(new BasicHeader("Content-Type", requestEntity.getContentType().getValue())) .addHeader(new BasicHeader("Authorization", ai.authValue())) .addHeader(new BasicHeader("User-Agent", ai.getUserAgent())) .addHeader(new BasicHeader("Ms-Asprotocolversion", protocolVersion.asSpecificationValue())) .addHeader(new BasicHeader("Accept", "*/*")).addHeader(new BasicHeader("Accept-Language", "fr-fr")) .addHeader(new BasicHeader("Connection", "keep-alive")).body(requestEntity); if (multipart) { request.addHeader(new BasicHeader("MS-ASAcceptMultiPart", "T")); request.addHeader(new BasicHeader("Accept-Encoding", "gzip")); }// w w w . j a v a2 s . c o m if (policyKey != null) { request.addHeader(new BasicHeader("X-MS-PolicyKey", policyKey)); } return request; }
From source file:org.mule.test.construct.FlowRefTestCase.java
@Test public void nonBlockingFlowRefToSyncFlow() throws Exception { Response response = Request .Post(String.format("http://localhost:%s/%s", port.getNumber(), "nonBlockingFlowRefToSyncFlow")) .connectTimeout(RECEIVE_TIMEOUT).bodyString(TEST_MESSAGE, ContentType.TEXT_PLAIN).execute(); HttpResponse httpResponse = response.returnResponse(); assertThat(httpResponse.getStatusLine().getStatusCode(), is(200)); assertThat(IOUtils.toString(httpResponse.getEntity().getContent()), is(TEST_MESSAGE)); SensingNullRequestResponseMessageProcessor flow1RequestResponseProcessor = muleContext.getRegistry() .lookupObject(TO_SYNC_FLOW1_SENSING_PROCESSOR_NAME); SensingNullRequestResponseMessageProcessor flow2RequestResponseProcessor = muleContext.getRegistry() .lookupObject(TO_SYNC_FLOW2_SENSING_PROCESSOR_NAME); assertThat(flow1RequestResponseProcessor.requestThread, equalTo(flow1RequestResponseProcessor.responseThread)); assertThat(flow2RequestResponseProcessor.requestThread, equalTo(flow2RequestResponseProcessor.responseThread)); }
From source file:org.metaservice.frontend.rest.SparqlEndpointResource.java
@Deprecated private @NotNull InputStream querySparql(@NotNull String mimeType, @NotNull String query) throws URISyntaxException, IOException { System.err.println(query);//w w w . jav a 2 s. c om URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setScheme("http").setHost("graph.metaservice.org").setPort(8080).setPath("/bigdata/sparql"); return Request.Post(uriBuilder.build()).bodyForm(Form.form().add("query", query).build()) .connectTimeout(1000).socketTimeout(60000).setHeader("Accept", mimeType).execute().returnContent() .asStream(); }
From source file:com.twosigma.beaker.NamespaceClient.java
public Object evaluateCode(String evaluator, String code) throws ClientProtocolException, IOException { Form form = Form.form().add("evaluator", evaluator).add("code", code).add("session", this.session); String reply = Request.Post(ctrlUrlBase + "/evaluateCode").addHeader("Authorization", auth) .bodyForm(form.build()).execute().returnContent().asString(); Object r;// ww w. j a v a 2 s .c o m try { JsonNode n = objectMapper.get().readTree(reply); r = objectSerializerProvider.get().deserialize(n, objectMapper.get()); if (r == null) r = deserializeObject(reply); } catch (Exception e) { r = null; } return r; }