List of usage examples for org.apache.http.client.methods HttpOptions HttpOptions
public HttpOptions(final String uri)
From source file:com.helger.httpclient.HttpClientHelper.java
@Nonnull public static HttpRequestBase createRequest(@Nonnull final EHttpMethod eHTTPMethod, @Nonnull final ISimpleURL aSimpleURL) { final String sURL = aSimpleURL.getAsStringWithEncodedParameters(); switch (eHTTPMethod) { case DELETE:/*from w w w . j a v a2 s . c om*/ return new HttpDelete(sURL); case GET: return new HttpGet(sURL); case HEAD: return new HttpHead(sURL); case OPTIONS: return new HttpOptions(sURL); case TRACE: return new HttpTrace(sURL); case POST: return new HttpPost(sURL); case PUT: return new HttpPut(sURL); default: throw new IllegalStateException("Unsupported HTTP method: " + eHTTPMethod); } }
From source file:at.bitfire.davdroid.webdav.DavRedirectStrategyTest.java
public void testMissingLocation() throws Exception { HttpContext context = HttpClientContext.create(); HttpUriRequest request = new HttpOptions(TestConstants.roboHydra.resolve("redirect/without-location")); HttpResponse response = httpClient.execute(request, context); assertFalse(strategy.isRedirected(request, response, context)); }
From source file:org.apache.abdera2.common.protocol.RequestHelper.java
public static HttpUriRequest createRequest(String method, String uri, HttpEntity entity, RequestOptions options) {// ww w.j a va2s.co m if (method == null) return null; if (options == null) options = createAtomDefaultRequestOptions().get(); Method m = Method.get(method); Method actual = null; HttpUriRequest httpMethod = null; if (options.isUsePostOverride() && !nopostoveride.contains(m)) { actual = m; m = Method.POST; } if (m == GET) httpMethod = new HttpGet(uri); else if (m == POST) { httpMethod = new HttpPost(uri); if (entity != null) ((HttpPost) httpMethod).setEntity(entity); } else if (m == PUT) { httpMethod = new HttpPut(uri); if (entity != null) ((HttpPut) httpMethod).setEntity(entity); } else if (m == DELETE) httpMethod = new HttpDelete(uri); else if (m == HEAD) httpMethod = new HttpHead(uri); else if (m == OPTIONS) httpMethod = new HttpOptions(uri); else if (m == TRACE) httpMethod = new HttpTrace(uri); // else if (m == PATCH) // httpMethod = new ExtensionRequest(m.name(),uri,entity); else httpMethod = new ExtensionRequest(m.name(), uri, entity); if (actual != null) { httpMethod.addHeader("X-HTTP-Method-Override", actual.name()); } initHeaders(options, httpMethod); HttpParams params = httpMethod.getParams(); if (!options.isUseExpectContinue()) { params.setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false); } else { if (options.getWaitForContinue() > -1) params.setIntParameter(CoreProtocolPNames.WAIT_FOR_CONTINUE, options.getWaitForContinue()); } if (!(httpMethod instanceof HttpEntityEnclosingRequest)) params.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, options.isFollowRedirects()); return httpMethod; }
From source file:org.apache.synapse.samples.framework.clients.BasicHttpClient.java
/** * Make a HTTP OPTIONS request on the specified URL. * * @param url A valid HTTP URL//from w w w. j a v a 2 s. com * @return A HttpResponse object * @throws Exception If an error occurs while making the HTTP call */ public HttpResponse doOptions(String url) throws Exception { CloseableHttpClient client = HttpClientBuilder.create().build(); try { HttpOptions options = new HttpOptions(url); return new HttpResponse(client.execute(options)); } finally { client.close(); } }
From source file:org.hl7.fhir.client.ClientUtils.java
public static <T extends Resource> ResourceRequest<T> issueOptionsRequest(URI optionsUri, String resourceFormat, HttpHost proxy) {/*from w w w . j a v a 2s. com*/ HttpOptions options = new HttpOptions(optionsUri); return issueResourceRequest(resourceFormat, options, proxy); }
From source file:com.rackspacecloud.blueflood.outputs.handlers.HttpOptionsHandlerIntegrationTest.java
@Test public void testHttpMetricsIndexHandlerOptions() throws Exception { // test query .../metrics/search for CORS support HttpOptions httpOptions = new HttpOptions(getQuerySearchURI(tenantId)); HttpResponse response = client.execute(httpOptions); assertCorsResponseHeaders(response, allowedOrigins, allowedHeaders, allowedMethods, allowedMaxAge); }
From source file:org.gradle.internal.resource.transport.http.AlwaysRedirectRedirectStrategy.java
public HttpUriRequest getRedirect(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException { URI uri = this.getLocationURI(request, response, context); String method = request.getRequestLine().getMethod(); if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) { return new HttpHead(uri); } else if (method.equalsIgnoreCase(HttpPost.METHOD_NAME)) { return this.copyEntity(new HttpPost(uri), request); } else if (method.equalsIgnoreCase(HttpPut.METHOD_NAME)) { return this.copyEntity(new HttpPut(uri), request); } else if (method.equalsIgnoreCase(HttpDelete.METHOD_NAME)) { return new HttpDelete(uri); } else if (method.equalsIgnoreCase(HttpTrace.METHOD_NAME)) { return new HttpTrace(uri); } else if (method.equalsIgnoreCase(HttpOptions.METHOD_NAME)) { return new HttpOptions(uri); } else if (method.equalsIgnoreCase(HttpPatch.METHOD_NAME)) { return this.copyEntity(new HttpPatch(uri), request); } else {//from ww w . j a v a 2 s. com return new HttpGet(uri); } }
From source file:at.bitfire.davdroid.webdav.DavRedirectStrategyTest.java
public void testRelativeLocation() throws Exception { HttpContext context = HttpClientContext.create(); HttpUriRequest request = new HttpOptions(TestConstants.roboHydra.resolve("redirect/relative")); HttpResponse response = httpClient.execute(request, context); assertTrue(strategy.isRedirected(request, response, context)); HttpUriRequest redirected = strategy.getRedirect(request, response, context); assertEquals(TestConstants.roboHydra.resolve("/new/location"), redirected.getURI()); }
From source file:org.obm.sync.push.client.commands.Options.java
@Override public OptionsResponse run(AccountInfos ai, OPClient opc, HttpClient hc) throws Exception { HttpOptions request = new HttpOptions( opc.buildUrl(ai.getUrl(), ai.getLogin(), ai.getDevId(), ai.getDevType())); request.setHeaders(new Header[] { new BasicHeader("User-Agent", ai.getUserAgent()), new BasicHeader("Authorization", ai.authValue()) }); synchronized (hc) { try {//from ww w . ja v a2 s. c om HttpResponse response = hc.execute(request); StatusLine statusLine = response.getStatusLine(); int statusCode = statusLine.getStatusCode(); if (statusCode != HttpStatus.SC_OK) { logger.error("method failed:{}\n{}\n", statusLine, response.getEntity()); } Header[] hs = response.getAllHeaders(); for (Header h : hs) { logger.info("resp head[" + h.getName() + "] => " + h.getValue()); } return new OptionsResponse(statusLine, ImmutableSet.copyOf(hs)); } finally { request.releaseConnection(); } } }
From source file:com.aliyun.oss.common.comm.HttpRequestFactory.java
public HttpRequestBase createHttpRequest(ServiceClient.Request request, ExecutionContext context) { String uri = request.getUri(); HttpRequestBase httpRequest;//w ww. j av a2 s . c o m HttpMethod method = request.getMethod(); if (method == HttpMethod.POST) { HttpPost postMethod = new HttpPost(uri); if (request.getContent() != null) { postMethod.setEntity(new RepeatableInputStreamEntity(request)); } httpRequest = postMethod; } else if (method == HttpMethod.PUT) { HttpPut putMethod = new HttpPut(uri); if (request.getContent() != null) { if (request.isUseChunkEncoding()) { putMethod.setEntity(buildChunkedInputStreamEntity(request)); } else { putMethod.setEntity(new RepeatableInputStreamEntity(request)); } } httpRequest = putMethod; } else if (method == HttpMethod.GET) { httpRequest = new HttpGet(uri); } else if (method == HttpMethod.DELETE) { httpRequest = new HttpDelete(uri); } else if (method == HttpMethod.HEAD) { httpRequest = new HttpHead(uri); } else if (method == HttpMethod.OPTIONS) { httpRequest = new HttpOptions(uri); } else { throw new ClientException("Unknown HTTP method name: " + method.toString()); } configureRequestHeaders(request, context, httpRequest); return httpRequest; }