List of usage examples for org.apache.commons.httpclient.params HttpMethodParams setParameter
public void setParameter(String paramString, Object paramObject)
From source file:org.jboss.test.NamingUtil.java
/** * This methods calls servlet which must be deployed at server to create JNDI objects remotely to byepass security. * /*www. j ava 2s. co m*/ * @param jndiName * @param dataKey * @param data * @param useHAJNDI * @throws Exception */ public static void createRemoteTestJNDIBinding(String jndiName, String dataKey, Object data, String serverHost, boolean useHAJNDI) throws Exception { HttpClient httpClient = new HttpClient(); String url = "http://" + serverHost + ":8080/naming-util/naming-util-servlet"; HttpMethodParams params = new HttpMethodParams(); params.setParameter("jndiName", jndiName); if (data != null) { params.setParameter("dataKey", dataKey); params.setParameter("data", data); } params.setBooleanParameter("useHAJndi", useHAJNDI); url = url + "?jndiName=" + jndiName; url = url + "&dataKey=" + dataKey; url = url + "&data=" + data; url = url + "&useHAJndi=" + Boolean.toString(useHAJNDI); GetMethod jndiGet = new GetMethod(url); //jndiGet.setParams(params); int responseCode = httpClient.executeMethod(jndiGet); String body = jndiGet.getResponseBodyAsString(); if (responseCode != HttpURLConnection.HTTP_OK || !body.contains("OK")) { throw new Exception(body); } }
From source file:org.ngrinder.agent.controller.AgentManagerRestAPIControllerTest.java
@Ignore @Test/*from w w w.ja v a 2 s.c o m*/ public void testRestAPI() throws IOException { HttpClient client = new HttpClient(); // To be avoided unless in debug mode Credentials defaultcreds = new UsernamePasswordCredentials("admin", "111111"); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultcreds); PutMethod method = new PutMethod("http://localhost:8080/agent/api/36"); final HttpMethodParams params = new HttpMethodParams(); params.setParameter("action", "approve"); method.setParams(params); final int i = client.executeMethod(method); System.out.println(method.getResponseBodyAsString()); }
From source file:org.pentaho.pac.server.PacServiceImpl.java
public String getHomePageAsHtml(String url) { String html = null;//from ww w. j a va 2 s . c om HttpClient client = new HttpClient(); GetMethod get = null; try { String timeOut = AppConfigProperties.getInstance().getHomepageTimeout(); HttpMethodParams params = new HttpMethodParams(); params.setParameter(HttpMethodParams.SO_TIMEOUT, Integer.parseInt(timeOut)); get = new GetMethod(url); get.setParams(params); client.executeMethod(get); //getResponseBodyAsString() and the like were decoding as ISO-8859-1 instead of UTF-8. //This is indeed the default behavior of HttpClient if the charset is not defined in //the Content-Type reponse header. We're overriding that since we know our source is //UTF-8 byte[] bytes = get.getResponseBody(); html = new String(bytes, "UTF-8"); //$NON-NLS-1$ } catch (Exception e) { logger.error(e); html = showStatic(); } finally { if (get != null) { get.releaseConnection(); } } final String BODY_TAG = "<body>"; //$NON-NLS-1$ int afterBodyIdx = html.indexOf(BODY_TAG); if (-1 != afterBodyIdx) { html = html.substring(html.indexOf(BODY_TAG) + BODY_TAG.length()); html = html.substring(0, html.indexOf("</body>")); //$NON-NLS-1$ } return html; }