List of usage examples for org.apache.commons.httpclient HttpMethod getStatusCode
public abstract int getStatusCode();
From source file:org.apache.shindig.social.sample.service.SampleContainerHandler.java
private String fetchStateDocument(String stateFileLocation) { String errorMessage = "The json state file " + stateFileLocation + " could not be fetched and parsed."; HttpMethod jsonState = new GetMethod(stateFileLocation); HttpClient client = new HttpClient(); try {/*from w ww.ja v a 2 s. c o m*/ client.executeMethod(jsonState); if (jsonState.getStatusCode() != 200) { throw new RuntimeException(errorMessage); } return jsonState.getResponseBodyAsString(); } catch (IOException e) { throw new RuntimeException(errorMessage, e); } finally { jsonState.releaseConnection(); } }
From source file:org.apache.webdav.lib.WebdavResource.java
/** * Execute the http request method. And get its status code. * * @param client The http client.// ww w. jav a2 s .c om * @param method The http method. * @return The status code. * @see #retrieveSessionInstance() */ public int executeHttpRequestMethod(HttpClient client, HttpMethod method) throws IOException, HttpException { client.executeMethod(method); return method.getStatusCode(); }
From source file:org.apache.wink.itest.addressbook.StringTest.java
public void clearDatabase() { /*// ww w . j a va2s . c om * clear the database entries */ HttpMethod method = null; try { method = new PostMethod(getBaseURI() + "/clear"); client.executeMethod(method); assertEquals(204, method.getStatusCode()); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } finally { if (method != null) { method.releaseConnection(); } } }
From source file:org.apache.wink.itest.addressbook.StringTest.java
/** * This will drive a POST request with parameters from the query string *//*from w w w. j a v a 2s .c om*/ public void testPostWithQueryParams() { HttpMethod method = null; HttpMethod getMethod = null; try { // make sure everything is clear before testing HttpClient client = new HttpClient(); method = new PostMethod(getBaseURI()); method.setQueryString("entryName=newAddress&streetAddress=1234+Any+Street&city=" + "AnyTown&zipCode=90210&state=TX&country=US"); client.executeMethod(method); // now let's see if the address we just created is available getMethod = new GetMethod(getBaseURI() + "/newAddress"); client.executeMethod(getMethod); assertEquals(200, getMethod.getStatusCode()); String responseBody = getMethod.getResponseBodyAsString(); assertNotNull(responseBody); assertTrue(responseBody, responseBody.contains("newAddress")); assertTrue(responseBody, responseBody.contains("1234 Any Street")); assertTrue(responseBody, responseBody.contains("AnyTown")); assertTrue(responseBody, responseBody.contains("90210")); assertTrue(responseBody, responseBody.contains("TX")); assertTrue(responseBody, responseBody.contains("US")); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } finally { if (method != null) { method.releaseConnection(); } if (getMethod != null) { getMethod.releaseConnection(); } } }
From source file:org.apache.wink.itest.cachetest.ClientTest.java
@Override public void setUp() { /*//from w w w. java2 s . c o m * clear the database entries */ HttpClient client = new HttpClient(); HttpMethod method = null; try { System.out.println(NEWS_BASE_URI + "/clear"); method = new PostMethod(NEWS_BASE_URI + "/clear"); client.executeMethod(method); assertEquals(204, method.getStatusCode()); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } finally { if (method != null) { method.releaseConnection(); } } }
From source file:org.apache.wink.itest.nofindmethods.DoNotUseMethodNamesForHTTPVerbsTest.java
/** * Negative tests that method names that begin with HTTP verbs are not * invoked on a root resource./*from ww w . j ava2 s . c o m*/ * * @throws HttpException * @throws IOException */ public void testMethodsNotValid() throws HttpException, IOException { HttpMethod method = new PostMethod(getBaseURI() + "/nousemethodnamesforhttpverbs/someresource"); try { client.executeMethod(method); assertEquals(405, method.getStatusCode()); } finally { method.releaseConnection(); } method = new GetMethod(getBaseURI() + "/nousemethodnamesforhttpverbs/someresource"); try { client.executeMethod(method); assertEquals(405, method.getStatusCode()); } finally { method.releaseConnection(); } method = new PutMethod(getBaseURI() + "/nousemethodnamesforhttpverbs/someresource"); try { client.executeMethod(method); assertEquals(405, method.getStatusCode()); } finally { method.releaseConnection(); } method = new DeleteMethod(getBaseURI() + "/nousemethodnamesforhttpverbs/someresource"); try { client.executeMethod(method); assertEquals(405, method.getStatusCode()); } finally { method.releaseConnection(); } method = new GetMethod(getBaseURI() + "/nousemethodnamesforhttpverbs/counter/root"); try { client.executeMethod(method); assertEquals(200, method.getStatusCode()); assertEquals("0", method.getResponseBodyAsString()); } finally { method.releaseConnection(); } }
From source file:org.apache.wink.itest.nofindmethods.DoNotUseMethodNamesForHTTPVerbsTest.java
/** * Negative tests that method names that begin with HTTP verbs are not * invoked on a sublocator method./*from w w w . java 2s . c om*/ * * @throws HttpException * @throws IOException */ public void testSublocatorMethodsNotValid() throws HttpException, IOException { HttpMethod method = new PostMethod(getBaseURI() + "/nousemethodnamesforhttpverbs/sublocatorresource/sub"); try { client.executeMethod(method); assertEquals(405, method.getStatusCode()); } finally { method.releaseConnection(); } method = new GetMethod(getBaseURI() + "/nousemethodnamesforhttpverbs/sublocatorresource/sub"); try { client.executeMethod(method); assertEquals(405, method.getStatusCode()); } finally { method.releaseConnection(); } method = new PutMethod(getBaseURI() + "/nousemethodnamesforhttpverbs/sublocatorresource/sub"); try { client.executeMethod(method); assertEquals(405, method.getStatusCode()); } finally { method.releaseConnection(); } method = new DeleteMethod(getBaseURI() + "/nousemethodnamesforhttpverbs/sublocatorresource/sub"); try { client.executeMethod(method); assertEquals(405, method.getStatusCode()); } finally { method.releaseConnection(); } method = new GetMethod(getBaseURI() + "/nousemethodnamesforhttpverbs/counter/sublocator"); try { client.executeMethod(method); assertEquals(200, method.getStatusCode()); assertEquals("0", method.getResponseBodyAsString()); } finally { method.releaseConnection(); } }
From source file:org.apache.wookie.tests.functional.ProxyTest.java
@Test public void getValidSiteAndValidXMLContentType() throws Exception { String url = PROXY_URL + "?instanceid_key=" + instance_id_key + "&url=" + VALID_SITE_XML_URL; HttpClient client = new HttpClient(); HttpMethod req = new GetMethod(url); client.executeMethod(req);/*from w ww. j a v a 2 s .co m*/ int code = req.getStatusCode(); req.releaseConnection(); assertEquals(200, code); assertTrue(req.getResponseHeader("Content-Type").toString().contains("text/xml")); }
From source file:org.apache.wookie.tests.functional.ProxyTest.java
@Test public void getValidSiteAndValidHTMLContentType() throws Exception { String url = PROXY_URL + "?instanceid_key=" + instance_id_key + "&url=" + VALID_SITE_URL; HttpClient client = new HttpClient(); HttpMethod req = new GetMethod(url); client.executeMethod(req);// w w w . j a v a 2 s . c om int code = req.getStatusCode(); req.releaseConnection(); assertEquals(200, code); assertTrue(req.getResponseHeader("Content-Type").toString().contains("text/html")); }
From source file:org.apache.wookie.tests.functional.ProxyTest.java
@Test public void getProtectedSiteWithoutAuth() throws Exception { HttpClient client = new HttpClient(); HttpMethod req; req = new GetMethod(PROXY_URL + "?instanceid_key=" + instance_id_key + "&url=" + PROTECTED_SITE_URL); client.executeMethod(req);/*from w ww .j av a2 s .c om*/ int code = req.getStatusCode(); req.releaseConnection(); assertEquals(401, code); }