List of usage examples for org.apache.commons.httpclient URIException getMessage
public String getMessage()
From source file:org.apache.wink.itest.EncodingParamTest.java
public void testSingleEncodedMatrixParamMethod() { try {/*from w ww . j a v a 2 s . c om*/ GetMethod httpMethod = new GetMethod(); httpMethod.setURI( new URI(BASE_URI_ENCODE + "/method/street;location=Burnet%2B%20Road;appversion=1.1%2B", true)); 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("getShopOnStreetMethod:location=Burnet%2B%20Road;appversion=1.1%2B", responseBody); } 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.EncodingParamTest.java
public void testSingleDecodedFormParam() throws Exception { try {/* w w w.ja va 2s. com*/ PostMethod httpMethod = new PostMethod(); httpMethod.setURI(new URI(BASE_URI_DECODE + "/region;appversion=", true)); // httpMethod.setParameter("location", "The%20Southwest"); httpMethod.setRequestEntity(new StringRequestEntity( "location=%21%20%2A%20%27%20%28%20%29%20%3B%20%3A%20%40%20%26%20%3D%20%2B%20%24%20%2C%20%2F%20%3F%20%25%20%23%20%5B%20%5D", "application/x-www-form-urlencoded", "UTF-8")); 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("getShopInRegionDecoded:location=! * ' ( ) ; : @ & = + $ , / ? % # [ ];appversion=", responseBody); } 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.EncodingParamTest.java
public void testSingleEncodedFormParam() throws Exception { try {// www . j a va 2s .c o m PostMethod httpMethod = new PostMethod(); httpMethod.setURI(new URI(BASE_URI_ENCODE + "/region;appversion=1.1%2B", true)); // httpMethod.setParameter("location", "The%20Southwest"); httpMethod.setRequestEntity(new StringRequestEntity("location=The%20Southwest", "application/x-www-form-urlencoded", "UTF-8")); 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("getShopInRegion:location=The%20Southwest;appversion=1.1%2B", responseBody); } 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.EncodingParamTest.java
public void testSingleEncodedFormParamMethod() throws Exception { try {/* w w w. j ava2 s. c o m*/ PostMethod httpMethod = new PostMethod(); httpMethod.setURI(new URI(BASE_URI_ENCODE + "/method/region;appversion=1.1%2B", true)); httpMethod.setRequestEntity(new StringRequestEntity("location=The%20Southwest", "application/x-www-form-urlencoded", "UTF-8")); 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("getShopInRegionMethod:location=The%20Southwest;appversion=1.1%2B", responseBody); } 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.HeaderParamTest.java
/** * Tests that a custom header is sent and received properly. Uses * constructor, property, field, and parameter parameters. */// w ww . jav a 2s. c o m public void testCustomHeaderParam() { HttpClient httpclient = new HttpClient(); try { GetMethod httpMethod = new GetMethod(); httpMethod.setURI(new URI(BASE_URI, false)); httpMethod.setRequestHeader("customHeaderParam", "somevalue"); httpMethod.setRequestHeader(new Header("User-Agent", "httpclient")); httpMethod.setRequestHeader("Accept-Language", "en"); System.out.println(Arrays.asList(httpMethod.getRequestHeaders())); 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("secret", httpMethod.getResponseHeader("custResponseHeader").getValue()); assertEquals("getHeaderParam:somevalue;User-Agent:httpclient;Accept-Language:en;language-method:en", responseBody); } 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.headers.HeadersTest.java
public void testGetWithCookies() throws Exception { try {/*from www.j ava 2 s.c om*/ GetMethod httpMethod = new GetMethod(); httpMethod.setURI(new URI(getBaseURI() + "/headers/cookie", false)); httpClient = new HttpClient(); httpMethod.setRequestHeader("Cookie", "$Version=\"1\";login=\"jdoe\""); try { int result = httpClient.executeMethod(httpMethod); System.out.println("Response status code: " + result); assertEquals(200, result); assertNotNull(httpMethod.getResponseHeader("login")); assertEquals("jdoe", httpMethod.getResponseHeader("login").getValue()); } 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.headers.HeadersTest.java
public void testGetWithLanguage() throws Exception { try {//from w ww.j av a 2s . c o m GetMethod httpMethod = new GetMethod(); httpMethod.setURI(new URI(getBaseURI() + "/headers/language", false)); httpClient = new HttpClient(); httpMethod.setRequestHeader("Content-Language", "en-us"); try { int result = httpClient.executeMethod(httpMethod); System.out.println("Response status code: " + result); assertEquals(200, result); assertNotNull(httpMethod.getResponseHeader("language")); assertEquals("en:US", httpMethod.getResponseHeader("language").getValue()); } 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.headers.HeadersTest.java
public void testGetWithContent() throws Exception { try {/* ww w. ja v a2s . c om*/ GetMethod httpMethod = new GetMethod(); httpMethod.setURI(new URI(getBaseURI() + "/headers/content", false)); httpClient = new HttpClient(); httpMethod.setRequestHeader("Content-Type", "application/html"); try { int result = httpClient.executeMethod(httpMethod); System.out.println("Response status code: " + result); assertEquals(200, result); assertNotNull(httpMethod.getResponseHeader("content")); assertEquals("application/html", httpMethod.getResponseHeader("content").getValue()); } 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.headers.HeadersTest.java
public void testGetWithAccept() throws Exception { try {/* ww w .j a va 2 s . co m*/ GetMethod httpMethod = new GetMethod(); httpMethod.setURI(new URI(getBaseURI() + "/headers/accept", false)); httpClient = new HttpClient(); httpMethod.setRequestHeader("Accept", "text/*, text/html, text/html;level=1, */*"); try { int result = httpClient.executeMethod(httpMethod); System.out.println("Response status code: " + result); assertEquals(200, result); assertNotNull(httpMethod.getResponseHeader("test-accept")); // all q-values = 1, should come back like it was sent String value = httpMethod.getResponseHeader("test-accept").getValue(); assertTrue(value, value.endsWith("*/*")); assertTrue(value, value.contains("text/*")); assertTrue(value, value.contains("text/html")); assertTrue(value, value.contains("text/html;level=1")); } 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.headers.HeadersTest.java
public void testGetWithAcceptLanguage() throws Exception { try {/*from ww w .ja va 2s .c o m*/ GetMethod httpMethod = new GetMethod(); httpMethod.setURI(new URI(getBaseURI() + "/headers/acceptlang", false)); httpClient = new HttpClient(); httpMethod.setRequestHeader("Accept-Language", "fr"); try { int result = httpClient.executeMethod(httpMethod); System.out.println("Response status code: " + result); assertEquals(200, result); assertNotNull(httpMethod.getResponseHeader("acceptlang")); assertEquals("fr", httpMethod.getResponseHeader("acceptlang").getValue()); } catch (IOException ioe) { ioe.printStackTrace(); fail(ioe.getMessage()); } finally { httpMethod.releaseConnection(); } } catch (URIException e) { e.printStackTrace(); fail(e.getMessage()); } }