List of usage examples for org.apache.commons.httpclient URI URI
public URI(URI base, URI relative) throws URIException
From source file:org.apache.servicemix.http.processors.ProviderProcessor.java
private HostConfiguration getHostConfiguration(String locationURI, MessageExchange exchange, NormalizedMessage message) throws Exception { HostConfiguration host;//w w w . j a v a 2s . c o m URI uri = new URI(locationURI, false); if (uri.getScheme().equals("https")) { synchronized (this) { if (protocol == null) { ProtocolSocketFactory sf = new CommonsHttpSSLSocketFactory(endpoint.getSsl(), KeystoreManager.Proxy.create(endpoint.getKeystoreManager())); protocol = new Protocol("https", sf, 443); } } HttpHost httphost = new HttpHost(uri.getHost(), uri.getPort(), protocol); host = new HostConfiguration(); host.setHost(httphost); } else { host = new HostConfiguration(); host.setHost(uri.getHost(), uri.getPort()); } if (endpoint.getProxy() != null) { if ((endpoint.getProxy().getProxyHost() != null) && (endpoint.getProxy().getProxyPort() != 0)) { host.setProxy(endpoint.getProxy().getProxyHost(), endpoint.getProxy().getProxyPort()); } if (endpoint.getProxy().getProxyCredentials() != null) { endpoint.getProxy().getProxyCredentials().applyProxyCredentials(getClient(), exchange, message); } } else if ((getConfiguration().getProxyHost() != null) && (getConfiguration().getProxyPort() != 0)) { host.setProxy(getConfiguration().getProxyHost(), getConfiguration().getProxyPort()); } //host.getParams().setLongParameter(HttpConnectionParams.CONNECTION_TIMEOUT, getClient().getParams().getSoTimeout()); return host; }
From source file:org.apache.webdav.ant.ResourceProperties.java
public void storeProperties(PropFindMethod propFind) throws URIException { // for each content element, check resource type and classify for (Enumeration e = propFind.getAllResponseURLs(); e.hasMoreElements();) { String href = (String) e.nextElement(); URI uri = new URI(propFind.getURI(), href); String key = uri.toString(); List properties = (List) this.resourceMap.get(key); if (properties == null) { properties = new ArrayList(); this.resourceMap.put(key, properties); }//from w w w.jav a 2 s. c o m for (Enumeration f = propFind.getResponseProperties(href); f.hasMoreElements();) { properties.add(f.nextElement()); } } }
From source file:org.apache.wink.itest.CookieFieldsTest.java
/** * Test that the HttpHeaders.getCookies() method returns correct cookies and * information/* w w w . j a va 2 s . c o m*/ * * @throws Exception */ public void testHttpHeadersGetCookie() throws Exception { setCookies(); // call get to exercise HttpHeaders.getCookies() GetMethod getHttpMethod = new GetMethod(); getHttpMethod.getParams().setCookiePolicy(CookiePolicy.RFC_2965); getHttpMethod.setURI(new URI(BASE_URI + "/getAll", false)); System.out.println("Request headers:"); System.out.println(Arrays.asList(getHttpMethod.getRequestHeaders())); try { int result = httpclient.executeMethod(getHttpMethod); System.out.println("Response status code: " + result); System.out.println("Response body: "); String responseBody = getHttpMethod.getResponseBodyAsString(); System.out.println(responseBody); System.out.println("Response headers:"); List<Header> headers = Arrays.asList(getHttpMethod.getResponseHeaders()); System.out.println(headers); assertEquals(200, result); StringTokenizer t = new StringTokenizer(responseBody, "\r\n\t\f"); String next = null; boolean name3Found = false; boolean name2Found = false; boolean nameFound = false; String contextRoot = ServerEnvironmentInfo.getContextRoot(); if (!"".equals(contextRoot)) { contextRoot = "/" + contextRoot; } String servletPath = (ServerEnvironmentInfo.isRestFilterUsed()) ? "" : "/newcookies"; while (t.hasMoreTokens()) { next = t.nextToken(); if (next.startsWith("name3")) { System.out.println("name3: " + next); assertEquals("name3,value3," + contextRoot + servletPath + "/cookiestests," + ServerEnvironmentInfo.getHostname().toLowerCase(), next); name3Found = true; } else if (next.startsWith("name2")) { System.out.println("name2: " + next); assertEquals("name2,value2," + contextRoot + servletPath + "/cookiestests," + ServerEnvironmentInfo.getHostname().toLowerCase(), next); name2Found = true; } else if (next.startsWith("name")) { System.out.println("name: " + next); assertEquals("name,value," + contextRoot + servletPath + "/cookiestests," + ServerEnvironmentInfo.getHostname().toLowerCase(), next); nameFound = true; } else fail("Received an unexpected cookie: " + next); } if (!nameFound || !name2Found || !name3Found) fail("Did not receive all the expected cookies." + nameFound + name2Found + name3Found); } finally { getHttpMethod.releaseConnection(); } }
From source file:org.apache.wink.itest.CookieFieldsTest.java
/** * Test the @CookieParameter annotation on a private class field * /*ww w . j a va 2 s .co m*/ * @throws Exception */ public void testCookieParamPrivateVar() throws Exception { setCookies(); GetMethod getHttpMethod = new GetMethod(); getHttpMethod.getParams().setCookiePolicy(CookiePolicy.RFC_2965); getHttpMethod.setURI(new URI(BASE_URI + "/getValue2", false)); System.out.println("Request headers:"); System.out.println(Arrays.asList(getHttpMethod.getRequestHeaders())); try { int result = httpclient.executeMethod(getHttpMethod); System.out.println("Response status code: " + result); System.out.println("Response body: "); String responseBody = getHttpMethod.getResponseBodyAsString(); System.out.println(responseBody); System.out.println("Response headers:"); List<Header> headers = Arrays.asList(getHttpMethod.getResponseHeaders()); System.out.println(headers); assertEquals(400, result); assertEquals("value2", responseBody.trim()); } finally { getHttpMethod.releaseConnection(); } }
From source file:org.apache.wink.itest.CookieFieldsTest.java
/** * Test the @CookieParameter annotation bean property * /* ww w .ja v a 2 s . c o m*/ * @throws Exception */ // public void testCookieParamBeanProp() throws Exception { // httpclient = new HttpClient(); // setCookies(); // GetMethod getHttpMethod = new GetMethod(); // getHttpMethod.getParams().setCookiePolicy(CookiePolicy.RFC_2965); // getHttpMethod.setURI(new URI(BASE_URI+"/getValue3", false)); // System.out.println("Request headers:"); // System.out.println(Arrays.asList(getHttpMethod.getRequestHeaders())); // try { // int result = httpclient.executeMethod(getHttpMethod); // System.out.println("Response status code: " + result); // System.out.println("Response body: "); // String responseBody = getHttpMethod.getResponseBodyAsString(); // System.out.println(responseBody); // System.out.println("Response headers:"); // List<Header> headers = Arrays.asList(getHttpMethod.getResponseHeaders()); // System.out.println(headers); // assertEquals(400, result); // assertEquals("value3", responseBody.trim()); // } finally { // getHttpMethod.releaseConnection(); // } // } private void setCookies() throws Exception { // call put to set the cookies PutMethod putHttpMethod = new PutMethod(); putHttpMethod.getParams().setCookiePolicy(CookiePolicy.RFC_2965); putHttpMethod.setURI(new URI(BASE_URI, false)); System.out.println("Request headers:"); System.out.println(Arrays.asList(putHttpMethod.getRequestHeaders())); try { int result = httpclient.executeMethod(putHttpMethod); System.out.println("Response status code: " + result); System.out.println("Response body: "); String responseBody = putHttpMethod.getResponseBodyAsString(); System.out.println(responseBody); System.out.println("Response headers:"); List<Header> headers = Arrays.asList(putHttpMethod.getResponseHeaders()); System.out.println(headers); assertEquals(200, result); } finally { putHttpMethod.releaseConnection(); } }
From source file:org.apache.wink.itest.CookieParamTest.java
/** * Tests that a cookie parameter is retrieved. *///from w ww .jav a 2s .c o m public void testCookieParam() { try { PutMethod httpMethod = new PutMethod(); httpMethod.getParams().setCookiePolicy(CookiePolicy.RFC_2109); httpMethod.setURI(new URI(BASE_URI, false)); System.out.println("Request headers:"); 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); System.out.println("Response headers:"); System.out.println(Arrays.asList(httpMethod.getResponseHeaders())); assertEquals(200, result); assertEquals("swiped:" + 0, responseBody); } catch (IOException ioe) { ioe.printStackTrace(); fail(ioe.getMessage()); } finally { httpMethod.releaseConnection(); } System.out.println("---"); httpMethod = new PutMethod(); httpMethod.getParams().setCookiePolicy(CookiePolicy.RFC_2109); httpMethod.setURI(new URI(BASE_URI, false)); httpMethod.setRequestHeader("Cookie", "jar=1"); System.out.println("Request headers:"); 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); System.out.println("Response headers:"); System.out.println(Arrays.asList(httpMethod.getResponseHeaders())); assertEquals(200, result); assertEquals("swiped:" + 1, 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.DefaultValueParamTest.java
/** * Test that if no parameters are passed, the default values are used. *///w w w .ja va 2s .c o m public void testDefaultValue() { try { GetMethod httpMethod = new GetMethod(); httpMethod.setURI(new URI(BASE_URI, false)); 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( "getRow:" + "offset=" + "0" + ";version=" + "1.0" + ";limit=" + "100" + ";sort=" + "normal", 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.DefaultValueParamTest.java
/** * Test using some default values.//from w w w . java 2 s . c om */ public void testUseSomeDefaultValue() { try { GetMethod httpMethod = new GetMethod(); httpMethod.setURI(new URI(BASE_URI + "?sort=backward&offset=314", false)); 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("getRow:" + "offset=" + "314" + ";version=" + "1.0" + ";limit=" + "100" + ";sort=" + "backward", 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 testSingleDecodedQueryParam() { try {//from w w w.j a va 2s . com GetMethod httpMethod = new GetMethod(); // httpMethod.setURI(new URI(BASE_URI_DECODE // + // "/city;appversion=1.1?location=! * ' ( ) ; : @ & = + $ , / ? % # [ ]" // , false)); httpMethod.setURI(new URI(BASE_URI_DECODE + "/city;appversion=1.1?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", 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("getShopInCityDecoded:location=! * ' ( ) ; : @ & = + $ , / ? % # [ ];appversion=1.1", 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 testSingleEncodedQueryParam() { try {//from www . ja v a2 s.co m GetMethod httpMethod = new GetMethod(); httpMethod .setURI(new URI(BASE_URI_ENCODE + "/city;appversion=1.1%2B?location=Austin%2B%20Texas", 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("getShopInCity:location=Austin%2B%20Texas;appversion=1.1%2B", responseBody); } catch (IOException ioe) { ioe.printStackTrace(); fail(ioe.getMessage()); } finally { httpMethod.releaseConnection(); } } catch (URIException e) { e.printStackTrace(); fail(e.getMessage()); } }