List of usage examples for org.apache.http.client.methods HttpOptions HttpOptions
public HttpOptions(final String uri)
From source file:org.camunda.connect.httpclient.impl.AbstractHttpConnector.java
@SuppressWarnings("unchecked") protected <T extends HttpRequestBase> T createHttpRequestBase(Q request) { String url = request.getUrl(); if (url != null && !url.trim().isEmpty()) { String method = request.getMethod(); if (HttpGet.METHOD_NAME.equals(method)) { return (T) new HttpGet(url); } else if (HttpPost.METHOD_NAME.equals(method)) { return (T) new HttpPost(url); } else if (HttpPut.METHOD_NAME.equals(method)) { return (T) new HttpPut(url); } else if (HttpDelete.METHOD_NAME.equals(method)) { return (T) new HttpDelete(url); } else if (HttpPatch.METHOD_NAME.equals(method)) { return (T) new HttpPatch(url); } else if (HttpHead.METHOD_NAME.equals(method)) { return (T) new HttpHead(url); } else if (HttpOptions.METHOD_NAME.equals(method)) { return (T) new HttpOptions(url); } else if (HttpTrace.METHOD_NAME.equals(method)) { return (T) new HttpTrace(url); } else {//from w ww . ja v a2 s . c o m throw LOG.unknownHttpMethod(method); } } else { throw LOG.requestUrlRequired(); } }
From source file:org.craftercms.deployer.impl.processors.HttpMethodCallProcessor.java
protected HttpUriRequest createRequest() { if (method.equalsIgnoreCase("get")) { return new HttpGet(url); } else if (method.equalsIgnoreCase("post")) { return new HttpPost(url); } else if (method.equalsIgnoreCase("put")) { return new HttpPut(url); } else if (method.equalsIgnoreCase("delete")) { return new HttpDelete(url); } else if (method.equalsIgnoreCase("head")) { return new HttpHead(url); } else if (method.equalsIgnoreCase("options")) { return new HttpOptions(url); } else if (method.equalsIgnoreCase("trace")) { return new HttpTrace(url); } else {//from w w w . j a v a 2 s . co m throw new DeploymentException("HTTP method '" + method + " not recognized"); } }
From source file:cn.bidaround.ytcore.util.HttpClientStack.java
/** * Creates the appropriate subclass of HttpUriRequest for passed in request. *//*ww w .j a va2 s .c om*/ @SuppressWarnings("deprecation") /* protected */ static HttpUriRequest createHttpRequest(Request<?> request, Map<String, String> additionalHeaders) throws AuthFailureError { switch (request.getMethod()) { case Method.DEPRECATED_GET_OR_POST: { // This is the deprecated way that needs to be handled for backwards compatibility. // If the request's post body is null, then the assumption is that the request is // GET. Otherwise, it is assumed that the request is a POST. byte[] postBody = request.getPostBody(); if (postBody != null) { HttpPost postRequest = new HttpPost(request.getUrl()); postRequest.addHeader(HEADER_CONTENT_TYPE, request.getPostBodyContentType()); HttpEntity entity; entity = new ByteArrayEntity(postBody); postRequest.setEntity(entity); return postRequest; } else { return new HttpGet(request.getUrl()); } } case Method.GET: return new HttpGet(request.getUrl()); case Method.DELETE: return new HttpDelete(request.getUrl()); case Method.POST: { HttpPost postRequest = new HttpPost(request.getUrl()); postRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(postRequest, request); return postRequest; } case Method.PUT: { HttpPut putRequest = new HttpPut(request.getUrl()); putRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(putRequest, request); return putRequest; } case Method.HEAD: return new HttpHead(request.getUrl()); case Method.OPTIONS: return new HttpOptions(request.getUrl()); case Method.TRACE: return new HttpTrace(request.getUrl()); case Method.PATCH: { HttpPatch patchRequest = new HttpPatch(request.getUrl()); patchRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(patchRequest, request); return patchRequest; } default: throw new IllegalStateException("Unknown request method."); } }
From source file:org.apache.marmotta.client.clients.ResourceClient.java
/** * Test whether the resource with the provided URI exists. * <p/>//from w w w. ja v a2 s. c o m * Uses an OPTIONS call to the resource web service to determine whether the resource exists or not * * @param uri * @return * @throws IOException */ public boolean existsResource(String uri) throws IOException { HttpClient httpClient = HTTPUtil.createClient(config); HttpOptions options = new HttpOptions(getServiceUrl(uri)); try { HttpResponse response = httpClient.execute(options); if (response.containsHeader("Access-Control-Allow-Methods") && response.getFirstHeader("Access-Control-Allow-Methods").getValue().equals("POST")) { return false; } else if (response.containsHeader("Access-Control-Allow-Methods") && response.getFirstHeader("Access-Control-Allow-Methods").getValue().contains("GET")) { return true; } else { log.warn("OPTIONS response did not contain a access-control-allow-methods header"); return false; } } catch (UnsupportedEncodingException e) { log.error("could not encode URI parameter", e); return false; } finally { options.releaseConnection(); } }
From source file:com.logsniffer.event.publisher.http.HttpPublisher.java
@Override public void publish(final Event event) throws PublishException { VelocityContext vCtx = velocityRenderer.getContext(event); String eventUrl = velocityRenderer.render(url, vCtx); HttpRequestBase request = null;// ww w . j av a2 s.c om switch (method) { case GET: request = new HttpGet(eventUrl); break; case POST: request = new HttpPost(eventUrl); addBody((HttpPost) request, vCtx); break; case PUT: request = new HttpPut(eventUrl); addBody((HttpPut) request, vCtx); break; case DELETE: request = new HttpDelete(eventUrl); break; case HEAD: request = new HttpHead(eventUrl); break; case OPTIONS: request = new HttpOptions(eventUrl); break; case PATCH: request = new HttpPatch(eventUrl); break; case TRACE: request = new HttpTrace(eventUrl); break; } httpAddons(request, event); try { logger.debug("Publishing event {} via HTTP '{}'", event.getId(), request); HttpResponse response = httpClient.execute(request, httpContext); if (response.getStatusLine().getStatusCode() >= 200 && response.getStatusLine().getStatusCode() < 300) { logger.debug("Published event {} successfuly via HTTP '{}' with status: {}", event.getId(), request, response.getStatusLine().getStatusCode()); } else { logger.warn("Failed to publish event {} via HTTP '{}' due to status: {} - {}", event.getId(), request, response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase()); throw new PublishException("Got errornuous HTTP status for pubslihed event: " + response.getStatusLine().getStatusCode()); } } catch (Exception e) { throw new PublishException("Failed to publish event " + event.getId() + " via HTTP", e); } }
From source file:cn.com.xxutils.volley.toolbox.HttpClientStack.java
/** * Creates the appropriate subclass of HttpUriRequest for passed in request. *//*from w w w. ja va2 s .co m*/ @SuppressWarnings("deprecation") /* protected */ static HttpUriRequest createHttpRequest(Request<?> request, Map<String, String> additionalHeaders) throws AuthFailureError { switch (request.getMethod()) { case Request.Method.DEPRECATED_GET_OR_POST: { // This is the deprecated way that needs to be handled for backwards compatibility. // If the request's post body is null, then the assumption is that the request is // GET. Otherwise, it is assumed that the request is a POST. byte[] postBody = request.getPostBody(); if (postBody != null) { HttpPost postRequest = new HttpPost(request.getUrl()); postRequest.addHeader(HEADER_CONTENT_TYPE, request.getPostBodyContentType()); HttpEntity entity; entity = new ByteArrayEntity(postBody); postRequest.setEntity(entity); return postRequest; } else { return new HttpGet(request.getUrl()); } } case Request.Method.GET: return new HttpGet(request.getUrl()); case Request.Method.DELETE: return new HttpDelete(request.getUrl()); case Request.Method.POST: { HttpPost postRequest = new HttpPost(request.getUrl()); postRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(postRequest, request); return postRequest; } case Request.Method.PUT: { HttpPut putRequest = new HttpPut(request.getUrl()); putRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(putRequest, request); return putRequest; } case Request.Method.HEAD: return new HttpHead(request.getUrl()); case Request.Method.OPTIONS: return new HttpOptions(request.getUrl()); case Request.Method.TRACE: return new HttpTrace(request.getUrl()); case Request.Method.PATCH: { HttpPatch patchRequest = new HttpPatch(request.getUrl()); patchRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(patchRequest, request); return patchRequest; } default: throw new IllegalStateException("Unknown request method."); } }
From source file:uk.co.visalia.brightpearl.apiclient.http.httpclient4.HttpClient4Client.java
private HttpRequestBase createBaseRequest(Method method, String url, String body) { if (method == Method.GET) { return new HttpGet(url); } else if (method == Method.POST) { HttpPost post = new HttpPost(url); addBody(post, body);/*from w ww. ja va 2s .c om*/ return post; } else if (method == Method.PUT) { HttpPut put = new HttpPut(url); addBody(put, body); return put; } else if (method == Method.DELETE) { return new HttpDelete(url); } else if (method == Method.OPTIONS) { return new HttpOptions(url); } throw new IllegalArgumentException("HTTP method " + method + " is not supported by this client"); }
From source file:org.apache.ambari.server.controller.internal.AppCookieManager.java
/** * Returns hadoop.auth cookie, doing needed SPNego authentication * //from w w w.j a v a 2 s.c o m * @param endpoint * the URL of the Hadoop service * @param refresh * flag indicating wehther to refresh the cookie, if * <code>true</code>, we do a new SPNego authentication and refresh * the cookie even if the cookie already exists in local cache * @return hadoop.auth cookie value * @throws IOException * in case of problem getting hadoop.auth cookie */ public String getAppCookie(String endpoint, boolean refresh) throws IOException { HttpUriRequest outboundRequest = new HttpGet(endpoint); URI uri = outboundRequest.getURI(); String scheme = uri.getScheme(); String host = uri.getHost(); int port = uri.getPort(); String path = uri.getPath(); if (!refresh) { String appCookie = endpointCookieMap.get(endpoint); if (appCookie != null) { return appCookie; } } clearAppCookie(endpoint); DefaultHttpClient client = new DefaultHttpClient(); SPNegoSchemeFactory spNegoSF = new SPNegoSchemeFactory(/* stripPort */true); // spNegoSF.setSpengoGenerator(new BouncySpnegoTokenGenerator()); client.getAuthSchemes().register(AuthPolicy.SPNEGO, spNegoSF); client.getCredentialsProvider().setCredentials(new AuthScope(/* host */null, /* port */-1, /* realm */null), EMPTY_JAAS_CREDENTIALS); String hadoopAuthCookie = null; HttpResponse httpResponse = null; try { HttpHost httpHost = new HttpHost(host, port, scheme); HttpRequest httpRequest = new HttpOptions(path); httpResponse = client.execute(httpHost, httpRequest); Header[] headers = httpResponse.getHeaders(SET_COOKIE); hadoopAuthCookie = getHadoopAuthCookieValue(headers); if (hadoopAuthCookie == null) { LOG.error("SPNego authentication failed, can not get hadoop.auth cookie for URL: " + endpoint); throw new IOException("SPNego authentication failed, can not get hadoop.auth cookie"); } } finally { if (httpResponse != null) { HttpEntity entity = httpResponse.getEntity(); if (entity != null) { entity.getContent().close(); } } } hadoopAuthCookie = HADOOP_AUTH_EQ + quote(hadoopAuthCookie); setAppCookie(endpoint, hadoopAuthCookie); if (LOG.isInfoEnabled()) { LOG.info("Successful SPNego authentication to URL:" + uri.toString()); } return hadoopAuthCookie; }
From source file:com.selene.volley.stack.HttpClientStack.java
/** * Creates the appropriate subclass of HttpUriRequest for passed in request. *///from w w w.j a v a2s . co m @SuppressWarnings("deprecation") /* protected */ static HttpUriRequest createHttpRequest(Request<?> request, Map<String, String> additionalHeaders) throws AuthFailureError { switch (request.getMethod()) { case Method.DEPRECATED_GET_OR_POST: // This is the deprecated way that needs to be handled for backwards // compatibility. // If the request's post body is null, then the assumption is that // the request is // GET. Otherwise, it is assumed that the request is a POST. byte[] postBody = request.getPostBody(); if (postBody != null) { HttpPost postRequest = new HttpPost(request.getUrl()); postRequest.addHeader(HEADER_CONTENT_TYPE, request.getPostBodyContentType()); HttpEntity entity; entity = new ByteArrayEntity(postBody); postRequest.setEntity(entity); return postRequest; } else { return new HttpGet(request.getUrl()); } case Method.GET: return new HttpGet(request.getUrl()); case Method.DELETE: return new HttpDelete(request.getUrl()); case Method.POST: { HttpPost postRequest = new HttpPost(request.getUrl()); postRequest.addHeader(HTTP.CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(postRequest, request); return postRequest; } case Method.PUT: { HttpPut putRequest = new HttpPut(request.getUrl()); putRequest.addHeader(HTTP.CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(putRequest, request); return putRequest; } case Method.HEAD: return new HttpHead(request.getUrl()); case Method.OPTIONS: return new HttpOptions(request.getUrl()); case Method.TRACE: return new HttpTrace(request.getUrl()); case Method.PATCH: { HttpPatch patchRequest = new HttpPatch(request.getUrl()); patchRequest.addHeader(HTTP.CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(patchRequest, request); return patchRequest; } default: throw new IllegalStateException("Unknown request method."); } }
From source file:com.iframe.source.publics.http.volley.toolbox.HttpClientStack.java
/** * Creates the appropriate subclass of HttpUriRequest for passed in request. *//* ww w . j av a2s. c om*/ @SuppressWarnings("deprecation") /* protected */static HttpUriRequest createHttpRequest(Request<?> request, Map<String, String> additionalHeaders) throws AuthFailureError { switch (request.getMethod()) { case Method.DEPRECATED_GET_OR_POST: { // This is the deprecated way that needs to be handled for backwards compatibility. // If the request's post body is null, then the assumption is that the request is // GET. Otherwise, it is assumed that the request is a POST. byte[] postBody = request.getPostBody(); if (postBody != null) { HttpPost postRequest = new HttpPost(request.getUrl()); postRequest.addHeader(HEADER_CONTENT_TYPE, request.getPostBodyContentType()); HttpEntity entity; entity = new ByteArrayEntity(postBody); postRequest.setEntity(entity); return postRequest; } else { return new HttpGet(request.getUrl()); } } case Method.GET: return new HttpGet(request.getUrl()); case Method.DELETE: return new HttpDelete(request.getUrl()); case Method.POST: { HttpPost postRequest = new HttpPost(request.getUrl()); postRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(postRequest, request); return postRequest; } case Method.PUT: { HttpPut putRequest = new HttpPut(request.getUrl()); putRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(putRequest, request); return putRequest; } case Method.HEAD: return new HttpHead(request.getUrl()); case Method.OPTIONS: return new HttpOptions(request.getUrl()); case Method.TRACE: return new HttpTrace(request.getUrl()); case Method.PATCH: { HttpPatch patchRequest = new HttpPatch(request.getUrl()); patchRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(patchRequest, request); return patchRequest; } default: throw new IllegalStateException("Unknown request method."); } }