List of usage examples for org.apache.http.client.methods HttpOptions HttpOptions
public HttpOptions(final String uri)
From source file:org.dasein.cloud.opsource.OpSourceMethod.java
protected AbstractHttpMessage getMethod(String httpMethod, String urlStr) { AbstractHttpMessage method = null;/* www . jav a 2 s . c o m*/ if (httpMethod.equals("GET")) { method = new HttpGet(urlStr); } else if (httpMethod.equals("POST")) { method = new HttpPost(urlStr); } else if (httpMethod.equals("PUT")) { method = new HttpPut(urlStr); } else if (httpMethod.equals("DELETE")) { method = new HttpDelete(urlStr); } else if (httpMethod.equals("HEAD")) { method = new HttpHead(urlStr); } else if (httpMethod.equals("OPTIONS")) { method = new HttpOptions(urlStr); } else if (httpMethod.equals("HEAD")) { method = new HttpTrace(urlStr); } else { return null; } return method; }
From source file:com.iflytek.android.framework.volley.toolbox.HttpClientStack.java
/** * Creates the appropriate subclass of HttpUriRequest for passed in request. */// w w w . j av a 2 s. 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()); VolleyLog.d("1:" + request.getBodyContentType()); 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.bedework.util.http.HttpUtil.java
/** Specify the next method by name. * * @param name of the method/* www . j a va 2 s .co m*/ * @param uri target * @return method object or null for unknown */ public static HttpRequestBase findMethod(final String name, final URI uri) { final String nm = name.toUpperCase(); if ("PUT".equals(nm)) { return new HttpPut(uri); } if ("GET".equals(nm)) { return new HttpGet(uri); } if ("DELETE".equals(nm)) { return new HttpDelete(uri); } if ("POST".equals(nm)) { return new HttpPost(uri); } if ("PROPFIND".equals(nm)) { return new HttpPropfind(uri); } if ("MKCALENDAR".equals(nm)) { return new HttpMkcalendar(uri); } if ("MKCOL".equals(nm)) { return new HttpMkcol(uri); } if ("OPTIONS".equals(nm)) { return new HttpOptions(uri); } if ("REPORT".equals(nm)) { return new HttpReport(uri); } if ("HEAD".equals(nm)) { return new HttpHead(uri); } return null; }
From source file:com.volley.toolbox.HttpClientStack.java
/** * httprequest?httprequest?httpurlrequest * Creates the appropriate subclass of HttpUriRequest for passed in request. *///from www . 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()); // body? -? 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:com.androidex.volley.toolbox.HttpClientStack.java
/** * Creates the appropriate subclass of HttpUriRequest for passed in request. *///from w w w . j a v a2 s . com @SuppressWarnings("deprecation") /* protected */static HttpUriRequest createHttpRequest(Request<?> request, Map<String, String> additionalHeaders) throws AuthFailureError, IOException { 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()); 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()); setEntityIfNonEmptyBody(patchRequest, request); return patchRequest; } default: throw new IllegalStateException("Unknown request method."); } }
From source file:com.mobillium.paparasdk.sdk.sampleapp.webservice.PaparaHttpClientStack.java
/** * Creates the appropriate subclass of HttpUriRequest for passed in request. *///from w w w . j av a2 s . c o 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: OwnHttpDelete deleteRequest = new OwnHttpDelete(request.getUrl()); deleteRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(deleteRequest, request); return deleteRequest; case Method.POST: { HttpPost postRequest = new HttpPost(request.getUrl()); postRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(postRequest, request); return postRequest; } case Method.PUT: { OwnHttpPut deletepOwnHttpPut = new OwnHttpPut(request.getUrl()); deletepOwnHttpPut.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(deletepOwnHttpPut, request); // HttpPut putRequest = new HttpPut(request.getUrl()); // putRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); // setEntityIfNonEmptyBody(putRequest, request); return deletepOwnHttpPut; } 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:com.farru.android.volley.toolbox.HttpClientStack.java
/** * Creates the appropriate subclass of HttpUriRequest for passed in request. *///from w w w . jav a2 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.codehaus.httpcache4j.resolver.HTTPClientResponseResolver.java
/** * Determines the HttpClient's request method from the HTTPMethod enum. * * @param method the HTTPCache enum that determines * @param requestURI the request URI.//from w ww . jav a 2 s . c o m * @return a new HttpMethod subclass. */ protected HttpUriRequest getMethod(HTTPMethod method, URI requestURI) { if (DELETE.equals(method)) { return new HttpDelete(requestURI); } else if (GET.equals(method)) { return new HttpGet(requestURI); } else if (HEAD.equals(method)) { return new HttpHead(requestURI); } else if (OPTIONS.equals(method)) { return new HttpOptions(requestURI); } else if (POST.equals(method)) { return new HttpPost(requestURI); } else if (PUT.equals(method)) { return new HttpPut(requestURI); } else if (TRACE.equals(method)) { return new HttpTrace(requestURI); } else { throw new IllegalArgumentException("Cannot handle method: " + method); } }
From source file:com.foundationdb.http.CrossOriginITBase.java
@Test public void preFlightDisallowedMethod() throws Exception { URI uri = new URI("http", null /*preflight requires no auth*/, "localhost", port, entityEndpoint(), null, null);//from ww w.j a va 2 s . c o m HttpUriRequest request = new HttpOptions(uri); request.setHeader("Origin", ORIGIN); request.setHeader("Access-Control-Request-Method", "DELETE"); response = client.execute(request); assertEquals("status", HttpStatus.SC_OK, response.getStatusLine().getStatusCode()); assertEquals("Allow-Origin", null, headerValue(response, HEADER_ALLOW_ORIGIN)); }
From source file:org.jboss.pnc.auth.keycloakutil.util.HttpUtil.java
public static HeadersBodyStatus doRequest(String type, String url, HeadersBody request) throws IOException { HttpRequestBase req;/*w ww .j a va 2s. co m*/ switch (type) { case "get": req = new HttpGet(url); break; case "post": req = new HttpPost(url); break; case "put": req = new HttpPut(url); break; case "delete": req = new HttpDelete(url); break; case "options": req = new HttpOptions(url); break; case "head": req = new HttpHead(url); break; default: throw new RuntimeException("Method not supported: " + type); } addHeaders(req, request.getHeaders()); if (request.getBody() != null) { if (req instanceof HttpEntityEnclosingRequestBase == false) { throw new RuntimeException("Request type does not support body: " + type); } ((HttpEntityEnclosingRequestBase) req).setEntity(new InputStreamEntity(request.getBody())); } HttpResponse res = getHttpClient().execute(req); InputStream responseStream = null; if (res.getEntity() != null) { responseStream = res.getEntity().getContent(); } else { responseStream = new InputStream() { @Override public int read() throws IOException { return -1; } }; } Headers headers = new Headers(); HeaderIterator it = res.headerIterator(); while (it.hasNext()) { org.apache.http.Header header = it.nextHeader(); headers.add(header.getName(), header.getValue()); } return new HeadersBodyStatus(res.getStatusLine().toString(), headers, responseStream); }