Package org.apache.commons.httpclient.methods

Examples of org.apache.commons.httpclient.methods.OptionsMethod


        } else if (strMethod.equals("DELETE")) {
            return new CustomMethod("DELETE", uri);
        } else if (strMethod.equals("HEAD")) {
            return new HeadMethod(uri);
        } else if (strMethod.equals("OPTIONS")) {
            return new OptionsMethod(uri);
        } else {
            return new CustomMethod(strMethod, uri);
        }
    }
View Full Code Here


    protected void doOptions(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException {
        ProxyDetails proxyDetails = createProxyDetails(httpServletRequest, httpServletResponse);
        if (!proxyDetails.isValid()) {
            noMappingFound(httpServletRequest, httpServletResponse);
        } else {
            OptionsMethod optionsMethodProxyRequest = new OptionsMethod(proxyDetails.getStringProxyURL());
            setProxyRequestHeaders(proxyDetails, httpServletRequest, optionsMethodProxyRequest);
            executeProxyRequest(proxyDetails, optionsMethodProxyRequest, httpServletRequest, httpServletResponse);
        }
    }
View Full Code Here

      String domain = username.substring(0, username.indexOf("\\"));
      client.getState().setCredentials(authScope, new NTCredentials(domainUser, password, host, domain));
    }

    boolean authenticated = false;
    OptionsMethod authTest = new OptionsMethod(server + "/exchange");
    try {
      authenticated = (client.executeMethod(authTest) < 400);
    } finally {
      try {
        InputStream stream = authTest.getResponseBodyAsStream();
        byte[] buf = new byte[65536];
        try {
          if (session.getDebug()) {
            PrintStream log = session.getDebugOut();
            log.println("Response Body:");
            int count;
            while ((count = stream.read(buf, 0, 65536)) != -1) {
              log.write(buf, 0, count);
            }
            log.flush();
            log.println();
          } else {
            while (stream.read(buf, 0, 65536) != -1)
              ;
          }
        } catch (Exception ignore) {
        } finally {
          try {
            stream.close();
          } catch (Exception ignore2) {
          }
        }
      } finally {
        authTest.releaseConnection();
      }
    }
    if (!authenticated) {
      PostMethod op = new PostMethod(server + SIGN_ON_URI);
      op.setRequestHeader("Content-Type", FORM_URLENCODED_CONTENT_TYPE);
View Full Code Here

     * Tests that an OPTIONS request can be sent to resource containing only a
     * GET method.
     */
    public void testOPTIONSRequest() {
        try {
            OptionsMethod httpMethod = new OptionsMethod();
            httpMethod.setURI(new URI(BASE_URI, false));
            httpclient = new HttpClient();

            try {
                int result = httpclient.executeMethod(httpMethod);
                System.out.println("Response status code: " + result);
                System.out.println("Response body: ");
                String responseBody = httpMethod.getResponseBodyAsString();
                System.out.println(responseBody);
                assertEquals(204, result);
                Enumeration<?> allowedMethods = httpMethod.getAllowedMethods();
                assertNotNull(allowedMethods);
                assertTrue(allowedMethods.hasMoreElements());
                List<String> methods = new ArrayList<String>();
                while (allowedMethods.hasMoreElements()) {
                    methods.add((String)allowedMethods.nextElement());
                }
                assertTrue(methods.contains("HEAD"));
                assertTrue(methods.contains("GET"));
                assertTrue(methods.contains("OPTIONS"));
            } catch (IOException ioe) {
                ioe.printStackTrace();
                fail(ioe.getMessage());
            } finally {
                httpMethod.releaseConnection();
            }
        } catch (URIException e) {
            e.printStackTrace();
            fail(e.getMessage());
        }
View Full Code Here

     * Tests that a OPTIONS request can be sent to resource annotated with a
     * custom OPTIONS annotation.
     */
    public void testCustomOPTIONSRequest() {
        try {
            OptionsMethod httpMethod = new OptionsMethod();
            httpMethod.setURI(new URI(ALT_URI, false));
            httpclient = new HttpClient();

            try {
                int result = httpclient.executeMethod(httpMethod);
                System.out.println("Response status code: " + result);
                System.out.println("Response body: ");
                String responseBody = httpMethod.getResponseBodyAsString();
                System.out.println(responseBody);
                assertEquals(200, result);
                assertEquals("", responseBody);
                Header header = httpMethod.getResponseHeader("Allow");
                assertNotNull(header);
                String value = header.getValue();
                assertTrue(value.contains("HEAD"));
                assertTrue(value.contains("OPTIONS"));
                assertTrue(value.contains("GET"));
            } catch (IOException ioe) {
                ioe.printStackTrace();
                fail(ioe.getMessage());
            } finally {
                httpMethod.releaseConnection();
            }
        } catch (URIException e) {
            e.printStackTrace();
            fail(e.getMessage());
        }
View Full Code Here

        }
    }

    public void testAllowHeaders() throws Exception {
        try {
            OptionsMethod httpMethod = new OptionsMethod();
            httpMethod.setURI(new URI(getBaseURI() + "/headersallow1/allow1", false));
            httpClient = new HttpClient();
            try {
                int result = httpClient.executeMethod(httpMethod);
                assertEquals(204, result);
                assertNotNull(httpMethod.getResponseHeader("Allow"));
                List<String> allowedMethods =
                    Arrays.asList(httpMethod.getResponseHeader("Allow").getValue().split(", "));
                System.out.println(allowedMethods);
                assertEquals(3, allowedMethods.size());
                assertTrue(allowedMethods.contains("HEAD"));
                assertTrue(allowedMethods.contains("OPTIONS"));
                assertTrue(allowedMethods.contains("GET"));
            } catch (IOException ioe) {
                ioe.printStackTrace();
                fail(ioe.getMessage());
            } finally {
                httpMethod.releaseConnection();
            }
        } catch (URIException e) {
            e.printStackTrace();
            fail(e.getMessage());
        }

        try {
            OptionsMethod httpMethod = new OptionsMethod();
            httpMethod.setURI(new URI(getBaseURI() + "/headersallow2", false));
            httpClient = new HttpClient();
            try {
                int result = httpClient.executeMethod(httpMethod);
                assertEquals(204, result);
                assertNotNull(httpMethod.getResponseHeader("Allow"));
                List<String> allowedMethods =
                    Arrays.asList(httpMethod.getResponseHeader("Allow").getValue().split(", "));
                System.out.println(allowedMethods);
                assertEquals(6, allowedMethods.size());
                assertTrue(allowedMethods.contains("HEAD"));
                assertTrue(allowedMethods.contains("OPTIONS"));
                assertTrue(allowedMethods.contains("GET"));
                assertTrue(allowedMethods.contains("PUT"));
                assertTrue(allowedMethods.contains("POST"));
                assertTrue(allowedMethods.contains("DELETE"));
            } catch (IOException ioe) {
                ioe.printStackTrace();
                fail(ioe.getMessage());
            } finally {
                httpMethod.releaseConnection();
            }
        } catch (URIException e) {
            e.printStackTrace();
            fail(e.getMessage());
        }
View Full Code Here

TOP

Related Classes of org.apache.commons.httpclient.methods.OptionsMethod

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.