List of usage examples for org.apache.commons.httpclient.methods PostMethod setParameter
public void setParameter(String paramString1, String paramString2)
From source file:org.apache.sling.launchpad.webapp.integrationtest.servlets.post.PostServletDeleteParentTest.java
@Test public void testDeleteNonExisting() throws Exception { final String path = TEST_PATH + "/" + EXISTING_PATH; final String testNodeUrl = H.getTestClient().createNode(HttpTest.HTTP_BASE_URL + "/" + path, null); assertTrue("Expecting created node path to end with " + path, testNodeUrl.endsWith(path)); H.assertHttpStatus(testNodeUrl + ".json", 200, "Expecting test node to exist before test"); // POST :delete to non-existing child node with a path that // generates selector + suffix final String selectorsPath = TEST_PATH + "/" + deletePath; final PostMethod post = new PostMethod(HttpTest.HTTP_BASE_URL + "/" + selectorsPath); post.setParameter(":operation", "delete"); final int status = H.getHttpClient().executeMethod(post); assertEquals("Expecting 403 status for delete operation", 403, status); // Test node should still be here H.assertHttpStatus(testNodeUrl + ".json", 200, "Expecting test node to exist after test"); }
From source file:org.apache.sling.launchpad.webapp.integrationtest.servlets.post.SlingPostProcessorTest.java
@Test public void processorsActive() throws HttpException, IOException { final PostMethod post = new PostMethod(testUrl + SlingPostConstants.DEFAULT_CREATE_SUFFIX); post.setFollowRedirects(false);//from w ww . j a va 2 s .c o m post.setParameter("DummyModification", "true"); try { T.getHttpClient().executeMethod(post); final String content = post.getResponseBodyAsString(); final int i1 = content.indexOf("source:SlingPostProcessorOne"); assertTrue("Expecting first processor to be present", i1 > 0); final int i2 = content.indexOf("source:SlingPostProcessorTwo"); assertTrue("Expecting second processor to be present", i2 > 0); assertTrue("Expecting service ranking to put processor one first", i1 < i2); } finally { post.releaseConnection(); } }
From source file:org.eclipse.mylyn.internal.gerrit.core.client.GerritHttpClient.java
private HttpMethodBase[] getFormAuthMethods(String repositoryUrl, AuthenticationCredentials credentials) { PostMethod post = new PostMethod(WebUtil.getRequestPath(repositoryUrl + LOGIN_URL)); post.setParameter("username", credentials.getUserName()); //$NON-NLS-1$ post.setParameter("password", credentials.getPassword()); //$NON-NLS-1$ post.setFollowRedirects(false);/* ww w.j av a 2 s .c om*/ GetMethod get = new GetMethod(WebUtil.getRequestPath(repositoryUrl + LOGIN_URL)); get.setFollowRedirects(false); return new HttpMethodBase[] { post, get }; }
From source file:org.eclipse.virgo.web.test.AbstractWebIntegrationTests.java
/** * @param context the context path of the web-app, which if non-null, will be prepended to the resource path * @param resource the resource path to test against * @param params parameters in the form of name-value pairs to be passed in the initial POST request * @param followRedirectsForGet whether or not to automatically follow redirects for a GET request following the * initial POST request/*www .j a v a2 s .c o m*/ * @param expectedPostResponseCode the expected HTTP response code for the initial POST request * @param expectedGetAfterPostResponseCode the expected HTTP response code for the subsequent GET request * @param expectedContents text expected to exist in the returned resource */ protected void assertPostRequest(String context, String resource, Map<String, String> params, boolean followRedirectsForGet, int expectedPostResponseCode, int expectedGetAfterPostResponseCode, String expectedContents) throws Exception { final String address = "http://localhost:8080/" + (context == null ? "" : context + "/") + resource; System.out.println("AbstractWebIntegrationTests: executing POST request for [" + address + "]."); final PostMethod post = new PostMethod(address); for (String name : params.keySet()) { post.setParameter(name, params.get(name)); } int responseCode = getHttpClient().executeMethod(post); assertEquals("Verifying HTTP POST response code for URL [" + address + "]", expectedPostResponseCode, responseCode); if (responseCode / 100 == 2 && expectedContents != null) { String body = post.getResponseBodyAsString(); assertNotNull("The response body for URL [" + address + "] should not be null.", body); // System.err.println(body); assertTrue("The response body for URL [" + address + "] should contain [" + expectedContents + "].", body.contains(expectedContents)); } else if (responseCode == SC_FOUND && expectedContents != null) { String location = post.getResponseHeader("Location").getValue(); assertGetRequest(location, followRedirectsForGet, expectedGetAfterPostResponseCode, Arrays.asList(expectedContents)); } }
From source file:org.exoplatform.rest.client.openfire.Utils.java
static Response doPost(URL url, HashMap<String, String> params) throws HttpException, IOException { if (params == null || params.size() == 0) return doPost(url); HttpClient httpClient = new HttpClient(); httpClient.getState().setCredentials(new AuthScope(url.getHost(), url.getPort()), usernamePasswordCredentials); PostMethod post = new PostMethod(url.toString()); post.setDoAuthentication(true);/* ww w .jav a2 s .c om*/ Set<String> key_set = params.keySet(); for (String key : key_set) { post.setParameter(key, params.get(key)); } int status = httpClient.executeMethod(post); Document resDoc = null; try { if (post.getResponseBody().length > 0) { // if response has body resDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder() .parse(post.getResponseBodyAsStream()); } } catch (Exception e) { throw new HttpException("XML parsing error : " + e); } finally { post.releaseConnection(); } return new Response(status, resDoc); }
From source file:org.helio.taverna.helio_taverna_suite.common.UWSCaller.java
/** * @param strURL//from w ww.j ava2s .c o m * @param append * @throws Exception */ private static void abortJob(String strURL, String append) throws Exception { if (append != null && !append.trim().equals("")) { strURL = strURL + "/" + append; } //Post PostMethod post = new PostMethod(strURL); post.setFollowRedirects(false); post.setParameter("phase", "ABORT"); // Get HTTP client HttpClient httpclient = new HttpClient(); int result = httpclient.executeMethod(post); int statuscode = post.getStatusCode(); //System.out.println(post.getResponseBodyAsString()); }
From source file:org.helio.taverna.helio_taverna_suite.common.UWSCaller.java
/** * //from w ww .j a v a 2 s .c om * @param strURL * @param append * @throws Exception */ private static void executeJob(String strURL, String append) throws Exception { if (append != null && !append.trim().equals("")) { strURL = strURL + "/" + append; } PostMethod post = new PostMethod(strURL); post.setFollowRedirects(false); post.setParameter("phase", "RUN"); // HttpClient httpclient = new HttpClient(); int result = httpclient.executeMethod(post); int statuscode = post.getStatusCode(); //System.out.println(post.getResponseBodyAsString()); }
From source file:org.mule.module.activiti.action.remote.CreateProcessAction.java
@Override protected void prepareMethod(PostMethod method, MuleMessage message) throws Exception { String json = ""; Map map = this.getParametersMap(message); if (map.containsKey("processDefinitionKey")) { method.setParameter("processDefinitionKey", (String) map.get("processDefinitionKey")); }/*from w w w. j av a2s. c o m*/ json = this.mapper.writeValueAsString(map); RequestEntity requestEntity = new StringRequestEntity(json, "application/json", "UTF-8"); method.setRequestEntity(requestEntity); }
From source file:org.na.WebHelper.java
private void setCedentials(JiraCfgDto cfg, PostMethod post) { if (cfg.getJiraUser() != null && !"".equals(cfg.getJiraUser())) { post.setParameter("os_username", cfg.getJiraUser()); if (cfg.getJiraPass() != null && !"".equals(cfg.getJiraPass())) { post.setParameter("os_password", cfg.getJiraPass()); authorisation = true;/*from ww w . ja va 2s.co m*/ return; } } authorisation = false; }
From source file:org.opencms.applet.upload.FileUploadApplet.java
/** * Checks if the given client files exist on the server and internally stores duplications.<p> * //from w ww . j a v a 2 s . c o m * Comparison is made by cutting the current directory of the file chooser from the path of the given files. * The server files (VFS files) to compare to are found by the current session of the user which finds the correct site and * the knowledge about the current directory. File translation rules are taken into account on the server. <p> * * @param files the local files to check if they exist in the VFS * * @return one of {@link ModalDialog#ERROR_OPTION} , {@link ModalDialog#CANCEL_OPTION}, {@link ModalDialog#APPROVE_OPTION}. */ int checkServerOverwrites(File[] files) { m_action = m_actionOverwriteCheck; repaint(); int rtv = ModalDialog.ERROR_OPTION; // collect files List fileNames = new ArrayList(); for (int i = 0; i < files.length; i++) { getRelativeFilePaths(files[i], fileNames); } StringBuffer uploadFiles = new StringBuffer(); Iterator it = fileNames.iterator(); // Http post header is limited, therefore only a ceratain amount of files may be checked // for server overwrites. Solution is: multiple requests. int count = 0; List duplications; // request to server HttpClient client = new HttpClient(); this.m_overwrites = new ArrayList(); try { while (it.hasNext()) { count++; uploadFiles.append(((String) it.next())).append('\n'); if (((count % 40) == 0) || (!it.hasNext())) { // files to upload: PostMethod post = new PostMethod(m_targetUrl); Header postHeader = new Header("uploadFiles", URLEncoder.encode(uploadFiles.toString(), "utf-8")); post.addRequestHeader(postHeader); // upload folder in vfs: Header header2 = new Header("uploadFolder", URLEncoder.encode(getParameter("filelist"), "utf-8")); post.addRequestHeader(header2); // the action constant post.setParameter("action", DIALOG_CHECK_OVERWRITE); // add jsessionid query string String sessionId = getParameter("sessionId"); String query = ";" + C_JSESSIONID.toLowerCase() + "=" + sessionId; post.setQueryString(query); post.addRequestHeader(C_JSESSIONID, sessionId); HttpConnectionParams connectionParams = client.getHttpConnectionManager().getParams(); connectionParams.setConnectionTimeout(5000); // add the session cookie client.getState(); client.getHostConfiguration().getHost(); HttpState initialState = new HttpState(); URI uri = new URI(m_targetUrl, false); Cookie sessionCookie = new Cookie(uri.getHost(), C_JSESSIONID, sessionId, "/", null, false); initialState.addCookie(sessionCookie); client.setState(initialState); int status = client.executeMethod(post); if (status == HttpStatus.SC_OK) { String response = post.getResponseBodyAsString(); duplications = parseDuplicateFiles(URLDecoder.decode(response, "utf-8")); this.m_overwrites.addAll(duplications); } else { // continue without overwrite check String error = m_errorLine1 + "\n" + post.getStatusLine(); System.err.println(error); } count = 0; uploadFiles = new StringBuffer(); } } if (m_overwrites.size() > 0) { rtv = showDuplicationsDialog(m_overwrites); } else { rtv = ModalDialog.APPROVE_OPTION; } } catch (HttpException e) { // TODO Auto-generated catch block e.printStackTrace(System.err); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(System.err); } return rtv; }