Package org.apache.http.client.methods

Examples of org.apache.http.client.methods.HttpOptions


        String r = configClient.replacePath("/setAllowCredentials/false")
            .accept("text/plain").post(null, String.class);
        assertEquals("ok", r);
       
        HttpClient httpclient = HttpClientBuilder.create().build();
        HttpOptions http = new HttpOptions("http://localhost:" + PORT + "/antest/delete");
        // this is the origin we expect to get.
        http.addHeader("Origin", "http://area51.mil:4444");
        http.addHeader(CorsHeaderConstants.HEADER_AC_REQUEST_METHOD, "DELETE");
        HttpResponse response = httpclient.execute(http);
        assertEquals(200, response.getStatusLine().getStatusCode());
        assertOriginResponse(false, new String[]{"http://area51.mil:4444"}, false, response);
        // we could check that the others are also missing.
        if (httpclient instanceof Closeable) {
View Full Code Here


            } else if (method.equals(HTTPConstants.HEAD)) {
                httpRequest = new HttpHead(uri);
            } else if (method.equals(HTTPConstants.TRACE)) {
                httpRequest = new HttpTrace(uri);
            } else if (method.equals(HTTPConstants.OPTIONS)) {
                httpRequest = new HttpOptions(uri);
            } else if (method.equals(HTTPConstants.DELETE)) {
                httpRequest = new HttpDelete(uri);
            } else if (method.equals(HTTPConstants.GET)) {
                httpRequest = new HttpGet(uri);
            } else if (method.equals(HTTPConstants.PATCH)) {
View Full Code Here

                request = new HttpHead(_baseAddress);
            } else if (_httpMethod.equals(HTTP_PUT)) {
                request = new HttpPut(_baseAddress);
                ((HttpPut) request).setEntity(new InputStreamEntity(httpRequest.getBodyBytes(), httpRequest.getBodyBytes().available()));
            } else if (_httpMethod.equals(HTTP_OPTIONS)) {
                request = new HttpOptions(_baseAddress);
            }
            Iterator<Map.Entry<String, List<String>>> entries = httpRequest.getHeaders().entrySet().iterator();
            while (entries.hasNext()) {
                Map.Entry<String, List<String>> entry = entries.next();
                String name = entry.getKey();
View Full Code Here

                httpMethod = new HttpPost(endpointURL);
                ((HttpPost)httpMethod).setEntity(new StringEntity(request, _contentType, "UTF-8"));
            } else if (method.equals(HTTP_DELETE)) {
                httpMethod = new HttpDelete(endpointURL);
            } else if (method.equals(HTTP_OPTIONS)) {
                httpMethod = new HttpOptions(endpointURL);
            } else if (method.equals(HTTP_HEAD)) {
                httpMethod = new HttpHead(endpointURL);
            } else {
                httpMethod = new HttpGet(endpointURL);
            }
View Full Code Here

     *
     * @param url The URL of a resource. Accepts any Object and calls .toString() on it.
     * @return A Response encapsulating the server's reply.
     */
    public static Response options(Object url) {
        ServerDriverHttpUriRequest request = new ServerDriverHttpUriRequest(new HttpOptions(url.toString()));
        return doHttpRequest(request);
    }
View Full Code Here

        driver.addExpectation(
                onRequestTo("/blah2").withMethod(Method.OPTIONS),
                giveResponse(null, null).withStatus(200).withHeader("Allow", "POST, OPTIONS"));
       
        HttpClient client = new DefaultHttpClient();
        HttpOptions options = new HttpOptions(baseUrl + "/blah2");
        HttpResponse response = client.execute(options);
       
        assertThat(response.getStatusLine().getStatusCode(), is(200));
        assertThat(response.getHeaders("Allow")[0].getValue(), equalTo("POST, OPTIONS"));
    }
View Full Code Here

  @Test
  public void unsupportedMethod() throws Exception {
    HttpResponse response = getHttpClient().execute(new HttpHead(getEndpoint()));
    assertEquals(HttpStatusCodes.NOT_IMPLEMENTED.getStatusCode(), response.getStatusLine().getStatusCode());

    response = getHttpClient().execute(new HttpOptions(getEndpoint()));
    assertEquals(HttpStatusCodes.NOT_IMPLEMENTED.getStatusCode(), response.getStatusLine().getStatusCode());
  }
View Full Code Here

   * java.util.Map)
   */
  @Override
  public String[] options ( URL url, Map<String, String> newHeaders ) throws ParseException, RestException, RuntimeRestException, URISyntaxException
  {
    HttpOptions options = new HttpOptions(url.toURI());
    setupMethod(options, newHeaders);
    HttpResponse response = execute(options);
    EntityUtils.consumeQuietly(response.getEntity());
    String allow = null;
    Header[] allHeaders = response.getAllHeaders();
View Full Code Here

                } 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 copyEntity(new HttpPatch(uri), request);
                }
            }
            return new HttpGet(uri);
View Full Code Here

     * @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();
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.http.client.methods.HttpOptions

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.