List of usage examples for org.apache.commons.httpclient.methods OptionsMethod setURI
@Override public void setURI(URI uri) throws URIException
From source file:org.apache.wink.itest.headers.HeadersTest.java
public void testAllowHeaders() throws Exception { try {//from ww w. j ava2s . c o m 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()); } try { OptionsMethod httpMethod = new OptionsMethod(); httpMethod.setURI(new URI(getBaseURI() + "/headersallow3/sublocator", 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")); assertEquals(null, httpMethod.getResponseBodyAsString()); } catch (IOException ioe) { ioe.printStackTrace(); fail(ioe.getMessage()); } finally { httpMethod.releaseConnection(); } } catch (URIException e) { e.printStackTrace(); fail(e.getMessage()); } }
From source file:org.apache.wink.itest.methodannotations.HttpMethodTest.java
/** * Tests that an OPTIONS request can be sent to resource containing only a * GET method.//from w w w .j a v a 2 s.co m */ 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()); } }
From source file:org.apache.wink.itest.methodannotations.HttpMethodTest.java
/** * Tests that a OPTIONS request can be sent to resource annotated with a * custom OPTIONS annotation./*from w ww . ja v a2s . c om*/ */ 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()); } }