List of usage examples for org.apache.commons.httpclient HttpMethod getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:lucee.commons.net.http.httpclient3.HttpMethodCloner.java
/** * Clones a HttpMethod. <br>/*from ww w.ja v a 2 s . co m*/ * <b>Attention:</b> You have to clone a method before it has * been executed, because the URI can change if followRedirects * is set to true. * * @param m the HttpMethod to clone * * @return the cloned HttpMethod, null if the HttpMethod could * not be instantiated * * @throws java.io.IOException if the request body couldn't be read */ public static HttpMethod clone(HttpMethod m) { HttpMethod copy = null; try { copy = m.getClass().newInstance(); } catch (InstantiationException iEx) { } catch (IllegalAccessException iaEx) { } if (copy == null) { return null; } copy.setDoAuthentication(m.getDoAuthentication()); copy.setFollowRedirects(m.getFollowRedirects()); copy.setPath(m.getPath()); copy.setQueryString(m.getQueryString()); Header[] h = m.getRequestHeaders(); int size = (h == null) ? 0 : h.length; for (int i = 0; i < size; i++) { copy.setRequestHeader(new Header(h[i].getName(), h[i].getValue())); } copy.setStrictMode(m.isStrictMode()); if (m instanceof HttpMethodBase) { copyHttpMethodBase((HttpMethodBase) m, (HttpMethodBase) copy); } if (m instanceof EntityEnclosingMethod) { copyEntityEnclosingMethod((EntityEnclosingMethod) m, (EntityEnclosingMethod) copy); } return copy; }
From source file:org.pentaho.di.baserver.utils.web.HttpConnectionHelperTest.java
@Test public void testGetHttpMethod() throws Exception { Map<String, String> queryParameters = new HashMap<String, String>(); queryParameters.put("param1", "value1"); queryParameters.put("param2", "value2"); queryParameters.put("param3", "value3"); String url = "http://localhost:8080/pentaho"; HttpMethod method = httpConnectionHelperSpy.getHttpMethod(url, queryParameters, "GET"); assertEquals(method.getClass(), GetMethod.class); assertTrue(method.getURI().toString().startsWith(url)); assertNotNull(method.getQueryString()); method = httpConnectionHelperSpy.getHttpMethod(url, queryParameters, "PUT"); assertEquals(method.getClass(), PutMethod.class); assertTrue(method.getURI().toString().startsWith(url)); RequestEntity requestEntity = ((PutMethod) method).getRequestEntity(); assertNotNull(requestEntity);// w ww.j a v a2 s .c o m assertEquals(requestEntity.getContentType(), "application/x-www-form-urlencoded; charset=UTF-8"); assertNull(method.getQueryString()); assertEquals(requestEntity.getClass(), StringRequestEntity.class); assertNotNull(((StringRequestEntity) requestEntity).getContent()); method = httpConnectionHelperSpy.getHttpMethod(url, queryParameters, "POST"); assertEquals(method.getClass(), PostMethod.class); assertTrue(method.getURI().toString().startsWith(url)); requestEntity = ((PostMethod) method).getRequestEntity(); assertNotNull(requestEntity); assertEquals(requestEntity.getContentType(), "application/x-www-form-urlencoded; charset=UTF-8"); assertNull(method.getQueryString()); assertEquals(requestEntity.getClass(), StringRequestEntity.class); assertNotNull(((StringRequestEntity) requestEntity).getContent()); // POST without parameters method = httpConnectionHelperSpy.getHttpMethod(url, null, "POST"); assertEquals(method.getClass(), PostMethod.class); assertTrue(method.getURI().toString().startsWith(url)); requestEntity = ((PostMethod) method).getRequestEntity(); assertNotNull(requestEntity); assertEquals(requestEntity.getContentType(), "application/x-www-form-urlencoded; charset=UTF-8"); assertNull(method.getQueryString()); assertEquals(requestEntity.getClass(), StringRequestEntity.class); assertNotNull(((StringRequestEntity) requestEntity).getContent()); method = httpConnectionHelperSpy.getHttpMethod(url, queryParameters, "DELETE"); assertEquals(method.getClass(), DeleteMethod.class); assertTrue(method.getURI().toString().startsWith(url)); assertNotNull(method.getQueryString()); method = httpConnectionHelperSpy.getHttpMethod(url, queryParameters, "HEAD"); assertEquals(method.getClass(), HeadMethod.class); assertTrue(method.getURI().toString().startsWith(url)); assertNotNull(method.getQueryString()); method = httpConnectionHelperSpy.getHttpMethod(url, queryParameters, "OPTIONS"); assertEquals(method.getClass(), OptionsMethod.class); assertTrue(method.getURI().toString().startsWith(url)); assertNotNull(method.getQueryString()); }