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.wudaosoft.net.httpclient.ParameterRequestBuilder.java
public static HttpUriRequest build(RequestBuilder builder) { final HttpRequestBase result; URI uriNotNull = builder.getUri() != null ? builder.getUri() : URI.create("/"); Charset charset = builder.getCharset(); charset = charset != null ? charset : HTTP.DEF_CONTENT_CHARSET; String method = builder.getMethod(); List<NameValuePair> parameters = builder.getParameters(); HttpEntity entityCopy = builder.getEntity(); if (parameters != null && !parameters.isEmpty()) { if (entityCopy == null && (HttpPost.METHOD_NAME.equalsIgnoreCase(method) || HttpPut.METHOD_NAME.equalsIgnoreCase(method) || HttpPatch.METHOD_NAME.equalsIgnoreCase(method))) { entityCopy = new UrlEncodedFormEntity(parameters, charset); } else {/* w w w . j a v a 2s. c o m*/ try { uriNotNull = new URIBuilder(uriNotNull).setCharset(charset).addParameters(parameters).build(); } catch (final URISyntaxException ex) { // should never happen } } } if (entityCopy == null) { result = new InternalRequest(method); } else { final InternalEntityEclosingRequest request = new InternalEntityEclosingRequest(method); request.setEntity(entityCopy); result = request; } result.setProtocolVersion(builder.getVersion()); result.setURI(uriNotNull); // if (builder.headergroup != null) { // result.setHeaders(builder.headergroup.getAllHeaders()); // } result.setConfig(builder.getConfig()); return result; }
From source file:com.twitter.hbc.core.HttpConstants.java
public static boolean checkHttpMethod(String httpMethod) { if (httpMethod.equalsIgnoreCase(HttpGet.METHOD_NAME)) { return true; } else if (httpMethod.equalsIgnoreCase(HttpPost.METHOD_NAME)) { return true; }//from w w w.java2 s .c om return false; }
From source file:org.jolokia.client.request.J4pVersionIntegrationTest.java
@Test public void versionPostRequest() throws J4pException { for (J4pTargetConfig cfg : new J4pTargetConfig[] { null, getTargetProxyConfig() }) { J4pVersionRequest req = new J4pVersionRequest(cfg); req.setPreferredHttpMethod(HttpPost.METHOD_NAME); J4pVersionResponse resp = (J4pVersionResponse) j4pClient.execute(req); verifyResponse(resp);/* w w w. j ava 2 s.c o m*/ } }
From source file:org.camunda.connect.httpclient.soap.impl.SoapHttpRequestImpl.java
@Override public SoapHttpRequest method(String method) { // only allow post request if (!HttpPost.METHOD_NAME.equals(method)) { throw LOG.invalidRequestMethod(method); }/* w ww .java 2 s .co m*/ super.method(method); return this; }
From source file:org.fcrepo.camel.HttpMethodsTest.java
@Test public void testMethods() { assertEquals(HttpMethods.DELETE.toString(), HttpDelete.METHOD_NAME); assertEquals(HttpMethods.GET.toString(), HttpGet.METHOD_NAME); assertEquals(HttpMethods.HEAD.toString(), HttpHead.METHOD_NAME); assertEquals(HttpMethods.OPTIONS.toString(), HttpOptions.METHOD_NAME); assertEquals(HttpMethods.PATCH.toString(), HttpPatch.METHOD_NAME); assertEquals(HttpMethods.POST.toString(), HttpPost.METHOD_NAME); assertEquals(HttpMethods.PUT.toString(), HttpPut.METHOD_NAME); }
From source file:org.jolokia.client.request.J4pReadIntegrationTest.java
@Test public void nameTest() throws MalformedObjectNameException, J4pException { checkNames(HttpGet.METHOD_NAME, itSetup.getStrangeNames(), itSetup.getEscapedNames()); checkNames(HttpPost.METHOD_NAME, itSetup.getStrangeNames(), itSetup.getEscapedNames()); }
From source file:com.github.opengarageapp.GarageToggleService.java
@Override protected HttpsURLConnection getRequestFromIntent(String baseString, Intent intent) throws ClientProtocolException, IOException { HttpsURLConnection urlConnection = null; URL url = null;//from ww w .ja va 2 s .c o m if (intent.getAction().equals(INTENT_TOGGLE1)) { url = new URL(baseString + "/doorCommand?door=1&command=Toggle"); urlConnection = (HttpsURLConnection) url.openConnection(); } else if (intent.getAction().equals(INTENT_CLOSE1)) { url = new URL(baseString + "/doorCommand?door=1&command=Toggle"); urlConnection = (HttpsURLConnection) url.openConnection(); } else { throw new IllegalArgumentException("Invalid action passed: " + intent.getAction()); } urlConnection.setRequestMethod(HttpPost.METHOD_NAME); setupConnectionProperties(urlConnection); //urlConnection.setSSLSocketFactory(GarageSSLSocketFactory.getSSLSocketFactory(application)); return urlConnection; }
From source file:com.blacklocus.jres.request.JresRawRequestTest.java
@Test public void test() { String index = "JresRawRequestTest_test".toLowerCase(); String type = "test"; jres.quest(new JresIndexDocument(index, type, new Document("big"))); jres.quest(new JresIndexDocument(index, type, new Document("small"))); jres.quest(new JresRefresh(index)); List<Document> hits = jres.quest(new JresRawRequest<JresSearchReply>(HttpPost.METHOD_NAME, JresPaths.slashedPath(index) + "_search", "{\"query\":{\"match_all\":{}}}", JresSearchReply.class)) .getHitsAsType(Document.class); Assert.assertEquals(2, hits.size()); hits = jres//from w w w.j a va 2 s.co m .quest(new JresRawRequest<JresSearchReply>(HttpPost.METHOD_NAME, JresPaths.slashedPath(index) + "_search", JresRawRequestTest.class.getResource("raw query.json"), JresSearchReply.class)) .getHitsAsType(Document.class); Assert.assertEquals(1, hits.size()); Assert.assertEquals("small", hits.get(0).compass); // Imagine this is much more complicated and we just want to insert values in a few key places. JresSearchBody searchBody = Jres.load(JresRawRequestTest.class.getResource("raw query base.json"), JresSearchBody.class); searchBody.getQuery(JresBoolQuery.class).should(new JresMatchQuery("compass", "big")); hits = jres.quest(new JresSearch(index, type, searchBody)).getHitsAsType(Document.class); Assert.assertEquals(1, hits.size()); Assert.assertEquals("big", hits.get(0).compass); }
From source file:io.wcm.caravan.io.http.impl.RequestUtil.java
/** * @param urlPrefix URL prefix/*from w w w . j ava 2 s. co m*/ * @param request Requset * @return HTTP client request object */ public static HttpUriRequest buildHttpRequest(String urlPrefix, Request request) { String url = urlPrefix + request.url(); // http method HttpUriRequest httpRequest; String method = StringUtils.upperCase(request.method()); switch (method) { case HttpGet.METHOD_NAME: httpRequest = new HttpGet(url); break; case HttpPost.METHOD_NAME: httpRequest = new HttpPost(url); break; case HttpPut.METHOD_NAME: httpRequest = new HttpPut(url); break; case HttpDelete.METHOD_NAME: httpRequest = new HttpDelete(url); break; default: throw new IllegalArgumentException("Unsupported HTTP method type: " + request.method()); } // headers for (Entry<String, Collection<String>> entry : request.headers().entrySet()) { Streams.of(entry.getValue()).forEach(value -> httpRequest.addHeader(entry.getKey(), value)); } // body if ((httpRequest instanceof HttpEntityEnclosingRequest) && request.body() != null) { HttpEntityEnclosingRequest entityHttpRequest = (HttpEntityEnclosingRequest) httpRequest; if (request.charset() != null) { entityHttpRequest.setEntity( new StringEntity(new String(request.body(), request.charset()), request.charset())); } else { entityHttpRequest.setEntity(new ByteArrayEntity(request.body())); } } return httpRequest; }
From source file:cn.wanghaomiao.seimi.http.hc.SeimiRedirectStrategy.java
@Override public HttpUriRequest getRedirect(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException { URI uri = getLocationURI(request, response, context); String method = request.getRequestLine().getMethod(); if (HttpPost.METHOD_NAME.equalsIgnoreCase(method)) { try {// www .j a v a 2 s .com HttpRequestWrapper httpRequestWrapper = (HttpRequestWrapper) request; httpRequestWrapper.setURI(uri); httpRequestWrapper.removeHeaders("Content-Length"); return httpRequestWrapper; } catch (Exception e) { logger.error("HttpRequestWrapper"); } return new HttpPost(uri); } else { return new HttpGet(uri); } }