List of usage examples for org.apache.http.client.fluent Request Post
public static Request Post(final String uri)
From source file:org.talend.components.dataprep.connection.DataPrepConnectionHandler.java
public HttpResponse logout() throws IOException { HttpResponse response;/*from w ww .j a v a 2 s . c om*/ try { if (urlConnection != null) { closeUrlConnection(); } } finally { Request request = Request.Post(url + "/logout?client-app=STUDIO").addHeader(authorisationHeader); response = request.execute().returnResponse(); if (returnStatusCode(response) != HttpServletResponse.SC_OK && authorisationHeader != null) { LOGGER.error(messages.getMessage("error.logoutFailed", extractResponseInformationAndConsumeResponse(response))); } } return response; }
From source file:io.coala.capability.online.FluentHCOnlineCapability.java
/** * @param method/*from w w w.j a va 2s.c om*/ * @param uri * @return */ @SuppressWarnings("rawtypes") public static Request getFluentRequest(final HttpMethod method, final URI uri, final Map.Entry... formData) { final Request request; switch (method) { case GET: request = Request.Get(toFormDataURI(uri, formData)); break; case HEAD: request = Request.Head(toFormDataURI(uri, formData)); break; case POST: request = Request.Post(uri); break; case PUT: request = Request.Put(uri); break; case DELETE: request = Request.Delete(toFormDataURI(uri, formData)); break; case OPTIONS: request = Request.Options(toFormDataURI(uri, formData)); break; case TRACE: request = Request.Trace(toFormDataURI(uri, formData)); break; default: throw new IllegalStateException("UNSUPPORTED: " + method); } return request.useExpectContinue().version(HttpVersion.HTTP_1_1); }
From source file:org.apache.james.jmap.methods.integration.cucumber.UploadStepdefs.java
@When("^\"([^\"]*)\" upload a too big content$") public void userUploadTooBigContent(String username) throws Throwable { AccessToken accessToken = userStepdefs.tokenByUser.get(username); Request request = Request.Post(uploadUri).bodyStream( new BufferedInputStream(new ZeroedInputStream(_10M), _10M), org.apache.http.entity.ContentType.DEFAULT_BINARY); if (accessToken != null) { request.addHeader("Authorization", accessToken.serialize()); }//from ww w . java 2 s .co m response = request.execute().returnResponse(); }
From source file:com.qwazr.search.index.IndexSingleClient.java
@Override public IndexStatus createUpdateIndex(String schema_name, String index_name) { UBuilder uriBuilder = new UBuilder("/indexes/", schema_name, "/", index_name); Request request = Request.Post(uriBuilder.build()); return commonServiceRequest(request, null, null, IndexStatus.class, 200); }
From source file:com.cognifide.aet.worker.drivers.HttpRequestBuilderImpl.java
private Request createRawRequest(String url, String methodName) { Request rawRequest;//from w ww . j ava2s. c om switch (HttpMethod.valueOf(methodName)) { case POST: rawRequest = Request.Post(url); break; case GET: default: rawRequest = Request.Get(url); break; } return rawRequest; }
From source file:org.restheart.test.integration.JsonPathConditionsCheckerIT.java
@Test public void testPostDataDotNotation() throws Exception { Response resp;/*from w ww. j a v a 2s . c om*/ // *** test post valid data with dot notation final String VALID_USER_DN = getResourceFile("data/jsonpath-testuser-dotnot.json"); resp = adminExecutor.execute(Request.Post(collectionTmpUri).bodyString(VALID_USER_DN, halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check post valid data with dot notation", resp, HttpStatus.SC_CREATED); }
From source file:org.schedulesdirect.api.json.DefaultJsonRequest.java
private Request initRequest() { Request r = null;//from ww w . j a va 2 s . c o m switch (action) { case GET: r = Request.Get(baseUrl); break; case PUT: r = Request.Put(baseUrl); break; case POST: r = Request.Post(baseUrl); break; case DELETE: r = Request.Delete(baseUrl); break; case OPTIONS: r = Request.Options(baseUrl); break; case HEAD: r = Request.Head(baseUrl); break; } return r.userAgent(userAgent); }
From source file:conversandroid.pandora.PandoraConnection.java
/** * Sends the user message to the chatbot and returns the chatbot response * It is a simplification and adaptation to Android of the method with the same name in the * Pandorabots Java API: https://github.com/pandorabots/pb-java * @param input text for conversation//from w ww . j av a 2 s.c o m * @return text of bot's response * @throws PandoraException when the connection is not succesful */ public String talk(String input) throws PandoraException { String responses = ""; input = input.replace(" ", "%20"); URI uri = null; try { uri = new URI("https://" + host + "/talk/" + appId + "/" + botName + "?input=" + input + "&user_key=" + userKey); Log.d(LOGTAG, "Request to pandorabot: Botname=" + botName + ", input=\"" + input + "\"" + " uri=" + uri); } catch (URISyntaxException e) { Log.e(LOGTAG, e.getMessage()); throw new PandoraException(PandoraErrorCode.IDORHOST); } int SDK_INT = android.os.Build.VERSION.SDK_INT; if (SDK_INT > 8) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); //Why the strictmode: http://stackoverflow.com/questions/25093546/android-os-networkonmainthreadexception-at-android-os-strictmodeandroidblockgua try { Content content = Request.Post(uri).execute().returnContent(); String response = content.asString(); JSONObject jObj = new JSONObject(response); JSONArray jArray = jObj.getJSONArray("responses"); for (int i = 0; i < jArray.length(); i++) { responses += jArray.getString(i).trim(); } } catch (JSONException e) { Log.e(LOGTAG, e.getMessage()); throw new PandoraException(PandoraErrorCode.PARSE); } catch (IOException e) { Log.e(LOGTAG, e.getMessage()); throw new PandoraException(PandoraErrorCode.CONNECTION); } catch (Exception e) { throw new PandoraException(PandoraErrorCode.IDORHOST); } } if (responses.toLowerCase().contains("match failed")) { Log.e(LOGTAG, "Match failed"); throw new PandoraException(PandoraErrorCode.NOMATCH); } Log.d(LOGTAG, "Bot response:" + responses); return responses; }
From source file:org.apache.james.jmap.methods.integration.cucumber.SetMailboxesMethodStepdefs.java
@When("^renaming mailbox \"([^\"]*)\" to \"([^\"]*)\"") public void renamingMailbox(String actualMailboxName, String newMailboxName) throws Throwable { String username = userStepdefs.lastConnectedUser; Mailbox mailbox = mainStepdefs.jmapServer.serverProbe().getMailbox("#private", userStepdefs.lastConnectedUser, actualMailboxName); String mailboxId = mailbox.getMailboxId().serialize(); String requestBody = "[" + " [ \"setMailboxes\"," + " {" + " \"update\": {" + " \"" + mailboxId + "\" : {" + " \"name\" : \"" + newMailboxName + "\"" + " }" + " }" + " }," + " \"#0\"" + " ]" + "]"; Request.Post(mainStepdefs.baseUri().setPath("/jmap").build()) .addHeader("Authorization", userStepdefs.tokenByUser.get(username).serialize()) .bodyString(requestBody, ContentType.APPLICATION_JSON).execute().discardContent(); }
From source file:org.metaservice.core.AbstractDispatcher.java
protected void sendDataByLoad(URI metadata, Collection<Statement> generatedStatements, Set<Statement> loadedStatements) throws MetaserviceException { StringWriter stringWriter = new StringWriter(); try {/* w w w . java 2s .c o m*/ NTriplesWriter nTriplesWriter = new NTriplesWriter(stringWriter); Repository inferenceRepository = createTempRepository(true); RepositoryConnection inferenceRepositoryConnection = inferenceRepository.getConnection(); LOGGER.debug("Start inference..."); inferenceRepositoryConnection.add(loadedStatements); inferenceRepositoryConnection.add(generatedStatements); LOGGER.debug("Finished inference"); List<Statement> filteredStatements = getGeneratedStatements(inferenceRepositoryConnection, loadedStatements); nTriplesWriter.startRDF(); for (Statement statement : filteredStatements) { nTriplesWriter.handleStatement(statement); } nTriplesWriter.endRDF(); inferenceRepositoryConnection.close(); inferenceRepository.shutDown(); Executor executor = Executor.newInstance(HttpClientBuilder.create() .setConnectionManager(new BasicHttpClientConnectionManager()).build()); executor.execute(Request.Post(config.getSparqlEndpoint() + "?context-uri=" + metadata.toString()) .bodyStream(new ByteArrayInputStream(stringWriter.getBuffer().toString().getBytes("UTF-8")), ContentType.create("text/plain", Charset.forName("UTF-8")))); } catch (RDFHandlerException | IOException | RepositoryException e) { throw new MetaserviceException(e); } }