List of usage examples for org.apache.commons.httpclient.methods PostMethod addParameter
public void addParameter(String paramString1, String paramString2) throws IllegalArgumentException
From source file:com.zimbra.cs.service.mail.CheckSpelling.java
private ServerResponse checkSpelling(String url, String dictionary, List<String> ignoreWords, String text, boolean ignoreAllCaps) throws IOException { PostMethod post = new PostMethod(url); post.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); if (dictionary != null) { post.addParameter("dictionary", dictionary); }/*from ww w . j av a2 s . c o m*/ if (text != null) { post.addParameter("text", text); } if (!ListUtil.isEmpty(ignoreWords)) { post.addParameter("ignore", StringUtil.join(",", ignoreWords)); } if (ignoreAllCaps) { post.addParameter("ignoreAllCaps", "on"); } HttpClient http = ZimbraHttpConnectionManager.getExternalHttpConnMgr().newHttpClient(); ServerResponse response = new ServerResponse(); try { response.statusCode = HttpClientUtil.executeMethod(http, post); response.content = post.getResponseBodyAsString(); } finally { post.releaseConnection(); } return response; }
From source file:cz.vity.freerapid.plugins.services.rapidshare_premium.RapidShareRunner.java
private String login(String login, String password) throws IOException, BadLoginException, ServiceConnectionProblemException { if (RapidShareRunner.cookie != null) { return RapidShareRunner.cookie; }/* w w w. j a v a 2 s . co m*/ final PostMethod pm = getPostMethod("https://api.rapidshare.com/cgi-bin/rsapi.cgi"); pm.addParameter("sub", "getaccountdetails"); pm.addParameter("withcookie", "1"); pm.addParameter("type", "prem"); pm.addParameter("login", login); pm.addParameter("password", password); logger.info("Logging to RS..."); try { int status = client.makeRequest(pm, false); if (status == HttpStatus.SC_OK) { String response = client.getContentAsString(); pm.releaseConnection(); if (response.startsWith("ERROR:")) { throw new BadLoginException(response.replace("ERROR: ", "")); } Map<String, String> params = RapidShareSupport.parseRapidShareResponse(response); RapidShareRunner.cookie = params.get("cookie"); return RapidShareRunner.cookie; } else { throw new ServiceConnectionProblemException("Server return status " + status); } } finally { pm.abort(); pm.releaseConnection(); } }
From source file:com.dreamlinx.automation.DINRelay.java
/** * Creates an HttpClient to communicate with the DIN relay. * @throws MalformedURLException// w w w . j a v a 2 s .c om * @throws HttpException * @throws IOException */ private void setupHttpClient() throws MalformedURLException, HttpException, IOException { httpClient = new HttpClient(); httpClient.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); GetMethod getMethod = new GetMethod("http://" + ipAddress); int result = httpClient.executeMethod(getMethod); if (result != 200) { throw new HttpException(result + " - " + getMethod.getStatusText()); } String response = getMethod.getResponseBodyAsString(); getMethod.releaseConnection(); String regex = "name=\"Challenge\" value=\".*\""; Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(response); String challenge = ""; while (matcher.find()) { int start = matcher.start(0); int end = matcher.end(0); challenge = response.substring(start + 24, end - 1); } String md5Password = challenge + username + password + challenge; md5Password = toMD5(md5Password); PostMethod postMethod = new PostMethod("http://" + ipAddress + "/login.tgi"); postMethod.addParameter("Username", username); postMethod.addParameter("Password", md5Password); result = httpClient.executeMethod(postMethod); if (result != 200) { throw new HttpException(result + " - " + postMethod.getStatusText()); } postMethod.releaseConnection(); }
From source file:egpi.tes.ahv.servicio.MenuReporteJasper.java
/** * //from w w w.j av a 2 s . c om */ public void obtenerDescriptorGeneral() throws ReporteJasperException { boolean privado = false; try { String user = autenticacionVO != null && autenticacionVO.getUsername() != null ? autenticacionVO.getUsername() : this.properties.getProperty("usuariopublico"); String pass = autenticacionVO != null && autenticacionVO.getPassword() != null ? autenticacionVO.getPassword() : this.properties.getProperty("password"); if (this.properties != null && user != null && this.properties.getProperty("usuariopublico") != null && !this.properties.getProperty("usuariopublico").equals(user)) { pathaplicacion = "pathprivado"; privado = true; } else { pathaplicacion = "pathpublico"; } System.out.println("pathaplicacion==" + pathaplicacion + " privado=" + privado); PostMethod postMethod = new PostMethod(properties.getProperty("urllogueo")); postMethod.addParameter("j_username", user); postMethod.addParameter("j_password", pass); status = client.executeMethod(postMethod); System.out.println("status 01=" + status + "pathaplicacion:" + pathaplicacion); if (status == 200) { String resourseURL = properties.getProperty("urlrecursos") + "" + properties.getProperty(pathaplicacion); GetMethod getMethod = new GetMethod(resourseURL); getMethod.setQueryString("?type=reportUnit&recursive=1"); status = client.executeMethod(getMethod); if (status == 200) { String descriptorSource = getMethod.getResponseBodyAsString(); listaReporte = (ArrayList) this.listadoReportes.getReportes(descriptorSource); sincronizarMenu.setProperties(properties); sincronizarMenu.setUSER(user); sincronizarMenu.setPASS(pass); sincronizarMenu.sincronizarArbolNavegacion(listaReporte); obj.put("status", String.valueOf(status)); obj.put("user", String.valueOf(user)); obj.put("privado", String.valueOf(privado)); } else { throw new ReporteJasperException(this.properties.getProperty("msg_" + String.valueOf(status))); } } else { throw new ReporteJasperException(this.properties.getProperty("msg_" + String.valueOf(status))); } } catch (IOException ex) { ex.printStackTrace(); throw new ReporteJasperException(ex.getMessage()); } }
From source file:com.sun.faban.harness.util.CLI.java
private void doPostKill(String master, String user, String password, ArrayList<String> argList) throws IOException { String url = master + argList.get(0) + '/' + argList.get(1); PostMethod post = new PostMethod(url); if (user == null) user = ""; if (password == null) password = ""; post.addParameter("sun", user); post.addParameter("sp", password); makeRequest(post);/*from ww w.j a v a 2 s . c om*/ }
From source file:com.clarkparsia.sbol.editor.sparql.StardogEndpoint.java
protected HttpMethodBase executeQuery(String query) throws HttpException, IOException, QueryEvaluationException { PostMethod post = new PostMethod(url + "/query"); post.addParameter("query", query); post.addRequestHeader("Accept", tupleParser.getTupleQueryResultFormat().getDefaultMIMEType()); execute(post);//from w w w . ja va 2 s.c om return post; }
From source file:edu.wustl.bulkoperator.client.BulkOperationServiceImpl.java
/** * Logout.//from ww w.j a v a 2 s . c om * * @param url the url * @param applicationUserName the application user name * @param applicationUserPassword the application user password * @param keyStoreLocation the key store location * * @throws HttpException the http exception * @throws IOException Signals that an I/O exception has occurred. */ public void logout(String url) throws HttpException, IOException { setApplicationDetails(url, applicationUserName, applicationUserPassword, keyStoreLocation); PostMethod postMethod = new PostMethod(url + "/Logout.do"); try { postMethod.addParameter(USER_NAME, applicationUserName); postMethod.addParameter(PASSWORD, applicationUserPassword); client.executeMethod(postMethod); } finally { postMethod.releaseConnection(); } }
From source file:net.sf.antcontrib.net.httpclient.PostMethodTask.java
public void setParameters(File parameters) { PostMethod post = getPostMethod(); Properties p = new Properties(); Iterator it = p.entrySet().iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); post.addParameter(entry.getKey().toString(), entry.getValue().toString()); }/*from w ww . jav a 2 s .c o m*/ }
From source file:datasoul.util.OnlinePublishFrame.java
private void btnPublishActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPublishActionPerformed if (ServiceListTable.getActiveInstance() == null || ServiceListTable.getActiveInstance().getRowCount() == 0) { JOptionPane.showMessageDialog(this, java.util.ResourceBundle.getBundle("datasoul/internationalize") .getString("YOU CAN NOT PUBLISH AN EMPTY SERVICE."), "Datasoul", JOptionPane.ERROR_MESSAGE); return;/* w w w . ja va2s. co m*/ } String content = ServiceListTable.getActiveInstance().getJSon(); String title = txtTitle.getText(); String locale = System.getProperty("user.language"); HttpClient client = new HttpClient(); client.getParams().setParameter("http.protocol.content-charset", "UTF-8"); PostMethod method = new PostMethod(OnlineUpdateCheck.ONLINE_BASE_URL + "/service/"); try { System.out.println(URLEncoder.encode(title, "UTF-8")); method.addParameter("title", URLEncoder.encode(title, "UTF-8")); method.addParameter("content", URLEncoder.encode(content, "UTF-8")); method.addParameter("locale", URLEncoder.encode(locale, "UTF-8")); method.addParameter("description", URLEncoder.encode(txtDescription.getText(), "UTF-8")); client.executeMethod(method); String url = method.getResponseBodyAsString().trim(); lblUrl.setText("<html><a href='url'>" + url + "</a></html>"); btnPublish.setEnabled(false); txtDescription.setEnabled(false); txtTitle.setEnabled(false); java.awt.Desktop.getDesktop().browse(new URI(url)); } catch (Exception e) { e.printStackTrace(); } finally { method.releaseConnection(); } }
From source file:com.springsource.hq.plugin.tcserver.serverconfig.web.services.SettingsLoaderImpl.java
public void restartServer(RemoteSettings remoteSettings) throws SettingsLoaderException { try {//from www . jav a 2 s. c o m logger.debug("Attempting to restart server for '" + remoteSettings.getSettings().getEid() + "'"); PostMethod method = new PostMethod( remoteSettings.getBasePath() + "/hqu/tomcatserverconfig/tomcatserverconfig/restartServer.hqu"); method.addParameter("isJmxListenerChanged", Boolean.toString(remoteSettings.isJmxListenerChanged())); configureMethod(method, remoteSettings.getSettings().getEid(), remoteSettings.getSessionId(), remoteSettings.getCsrfNonce()); httpClient.executeMethod(method); if (method.getStatusCode() >= 300 && method.getStatusCode() < 400) { logger.info("Unable to restart server for '" + remoteSettings.getSettings().getEid() + "', HQ session expired"); throw new SettingsLoaderException(SESSION_EXPIRED_MESSAGE); } else if (method.getStatusCode() >= 400) { logger.warn("Unable to restart server for '" + remoteSettings.getSettings().getEid() + "', " + method.getStatusCode() + " " + method.getStatusText()); throw new SettingsLoaderException(method.getStatusText()); } remoteSettings.setCsrfNonce(method.getResponseBodyAsString()); logger.debug("Restarted server for '" + remoteSettings.getSettings().getEid() + "'"); } catch (SSLHandshakeException e) { logger.error("Server SSL certificate is untrusted: " + e.getMessage(), e); throw new SettingsLoaderException( "Unable to restart server because the server is using an untrusted SSL certificate. " + "Please check the documentation for more information.", e); } catch (IOException e) { logger.error("Unable to restart server for '" + remoteSettings.getSettings().getEid() + "': " + e.getMessage(), e); throw new SettingsLoaderException( "Server restart failed because of a server error, please check the logs for more details", e); } }