List of usage examples for org.apache.commons.httpclient.methods PostMethod addParameter
public void addParameter(String paramString1, String paramString2) throws IllegalArgumentException
From source file:org.wso2.carbon.identity.provisioning.connector.salesforce.SalesforceProvisioningConnector.java
/** * authenticate to salesforce API.//from w w w . ja va 2s.com */ private String authenticate() throws IdentityProvisioningException { boolean isDebugEnabled = log.isDebugEnabled(); HttpClient httpclient = new HttpClient(); String url = configHolder.getValue(SalesforceConnectorConstants.PropertyConfig.OAUTH2_TOKEN_ENDPOINT); PostMethod post = new PostMethod( StringUtils.isNotBlank(url) ? url : IdentityApplicationConstants.SF_OAUTH2_TOKEN_ENDPOINT); post.addParameter(SalesforceConnectorConstants.CLIENT_ID, configHolder.getValue(SalesforceConnectorConstants.PropertyConfig.CLIENT_ID)); post.addParameter(SalesforceConnectorConstants.CLIENT_SECRET, configHolder.getValue(SalesforceConnectorConstants.PropertyConfig.CLIENT_SECRET)); post.addParameter(SalesforceConnectorConstants.PASSWORD, configHolder.getValue(SalesforceConnectorConstants.PropertyConfig.PASSWORD)); post.addParameter(SalesforceConnectorConstants.GRANT_TYPE, SalesforceConnectorConstants.GRANT_TYPE_PASSWORD); post.addParameter(SalesforceConnectorConstants.USERNAME, configHolder.getValue(SalesforceConnectorConstants.PropertyConfig.USERNAME)); StringBuilder sb = new StringBuilder(); try { // send the request int responseStatus = httpclient.executeMethod(post); if (isDebugEnabled) { log.debug("Authentication to salesforce returned with response code: " + responseStatus); } sb.append("HTTP status " + post.getStatusCode() + " creating user\n\n"); if (post.getStatusCode() == HttpStatus.SC_OK) { JSONObject response = new JSONObject( new JSONTokener(new InputStreamReader(post.getResponseBodyAsStream()))); if (isDebugEnabled) { log.debug("Authenticate response: " + response.toString(2)); } Object attributeValObj = response.opt("access_token"); if (attributeValObj instanceof String) { if (isDebugEnabled) { log.debug("Access token is : " + (String) attributeValObj); } return (String) attributeValObj; } else { log.error("Authentication response type : " + attributeValObj.toString() + " is invalide"); } } else { log.error("recieved response status code :" + post.getStatusCode() + " text : " + post.getStatusText()); } } catch (JSONException | IOException e) { throw new IdentityProvisioningException("Error in decoding response to JSON", e); } finally { post.releaseConnection(); } return ""; }
From source file:org.wso2.carbon.identity.provisioning.connector.sample.SampleProvisioningConnector.java
/** * authenticate to salesforce API./*ww w . j a v a 2s.c om*/ */ private String authenticate() throws IdentityProvisioningException { boolean isDebugEnabled = log.isDebugEnabled(); HttpClient httpclient = new HttpClient(); PostMethod post = new PostMethod(SampleConnectorConstants.OAUTH2_TOKEN_ENDPOINT); post.addParameter(SampleConnectorConstants.CLIENT_ID, configHolder.getValue(SampleConnectorConstants.PropertyConfig.CLIENT_ID)); post.addParameter(SampleConnectorConstants.CLIENT_SECRET, configHolder.getValue(SampleConnectorConstants.PropertyConfig.CLIENT_SECRET)); post.addParameter(SampleConnectorConstants.PASSWORD, configHolder.getValue(SampleConnectorConstants.PropertyConfig.PASSWORD)); post.addParameter(SampleConnectorConstants.GRANT_TYPE, SampleConnectorConstants.GRANT_TYPE_PASSWORD); post.addParameter(SampleConnectorConstants.USERNAME, configHolder.getValue(SampleConnectorConstants.PropertyConfig.USERNAME)); StringBuilder sb = new StringBuilder(); try { // send the request int responseStatus = httpclient.executeMethod(post); if (isDebugEnabled) { log.debug("Authentication to salesforce returned with response code: " + responseStatus); } sb.append("HTTP status " + post.getStatusCode() + " creating user\n\n"); if (post.getStatusCode() == HttpStatus.SC_OK) { JSONObject response = new JSONObject( new JSONTokener(new InputStreamReader(post.getResponseBodyAsStream()))); if (isDebugEnabled) { log.debug("Authenticate response: " + response.toString(2)); } Object attributeValObj = response.opt("access_token"); if (attributeValObj instanceof String) { if (isDebugEnabled) { log.debug("Access token is : " + (String) attributeValObj); } return (String) attributeValObj; } else { log.error("Authentication response type : " + attributeValObj.toString() + " is invalide"); } } else { log.error("recieved response status code :" + post.getStatusCode() + " text : " + post.getStatusText()); } } catch (JSONException e) { throw new IdentityProvisioningException("Error in decoding response to JSON", e); } catch (IOException e) { throw new IdentityProvisioningException( "Error in invoking authentication operation. Check your network connection", e); } finally { post.releaseConnection(); } return ""; }
From source file:org.xaloon.wicket.component.captcha.ReCaptchaValidator.java
public static boolean validate(String privateKey, String remoteAddress, String response, String challenge) { HttpClient client = new HttpClient(); PostMethod post = new PostMethod("http://api-verify.recaptcha.net/verify"); post.addParameter("privatekey", privateKey); post.addParameter("remoteip", remoteAddress); post.addParameter("challenge", challenge); post.addParameter("response", response); try {/* w ww .j a v a2 s .c om*/ int code = client.executeMethod(post); if (code != HttpStatus.SC_OK) { throw new RuntimeException("Could not send request: " + post.getStatusLine()); } String resp = readString(post.getResponseBodyAsStream()); if (resp.startsWith("false")) { return false; } } catch (Exception e) { log.error(e); } return true; }
From source file:org.xaloon.wicket.plugin.captcha.RecaptchaValidator.java
private boolean validate(String remoteIpAddress, String recaptcha_challenge_field, String recaptcha_response_field) { HttpClient httpClient = new HttpClient(); PostMethod post = new PostMethod(recaptchaPluginBean.getVerificationUrl()); post.addParameter(PRIVATEKEY, recaptchaPluginBean.getPrivateKey()); post.addParameter(REMOTEIP, remoteIpAddress); post.addParameter(CHALLENGE, recaptcha_challenge_field); post.addParameter(RESPONSE, recaptcha_response_field); try {/*from w ww .j a v a 2s.c om*/ int code = httpClient.executeMethod(post); if (code != HttpStatus.SC_OK) { throw new RuntimeException("Could not send request: " + post.getStatusLine()); } String resp = readString(post.getResponseBodyAsStream()); if (resp.toLowerCase().startsWith(Boolean.TRUE.toString().toLowerCase())) { return true; } } catch (Exception e) { LOGGER.error("Could not process Recaptcha!", e); } return false; }
From source file:org.xwiki.test.storage.framework.StoreTestUtils.java
/** Method to easily do a post request to the site. */ public static HttpMethod doPost(final String address, final UsernamePasswordCredentials userNameAndPassword, final Map<String, String> parameters) throws IOException { final HttpClient client = new HttpClient(); final PostMethod method = new PostMethod(address); if (userNameAndPassword != null) { client.getState().setCredentials(AuthScope.ANY, userNameAndPassword); client.getParams().setAuthenticationPreemptive(true); }/* w ww . j a v a 2s . co m*/ if (parameters != null) { for (Map.Entry<String, String> e : parameters.entrySet()) { method.addParameter(e.getKey(), e.getValue()); } } client.executeMethod(method); return method; }
From source file:org.zend.php.zendserver.deployment.core.targets.OpenShiftTargetInitializer.java
private HttpMethodBase createPostRequest(String url, Map<String, String> params) { PostMethod method = new PostMethod(url); Set<String> keyList = params.keySet(); for (String key : keyList) { method.addParameter(key, params.get(key)); }//from ww w . j av a 2s . co m return method; }
From source file:org.zend.php.zendserver.monitor.internal.ui.RequestGeneratorJob.java
private HttpMethodBase createPostRequest(String url, List<Parameter> parameters) { PostMethod method = new PostMethod(url); NameValuePair[] query = new NameValuePair[parameters.size()]; for (int i = 0; i < query.length; i++) { Parameter param = parameters.get(i); method.addParameter(param.getName(), param.getValue()); }//from w w w .j av a2 s. c o m return method; }
From source file:oscar.eform.actions.ManageEFormAction.java
public ActionForward exportEFormSend(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String username = request.getParameter("username"); String password = request.getParameter("password"); String fid = request.getParameter("fid"); MiscUtils.getLogger().debug("fid: " + fid); EForm eForm = new EForm(fid, "1"); //=================== HttpClient client = new HttpClient(); client.getParams().setCookiePolicy(CookiePolicy.RFC_2109); PostMethod method = new PostMethod("http://mydrugref.org/sessions"); method.addParameter("session[email]", username); method.addParameter("session[password]", password); int statusCode = client.executeMethod(method); //need to check if login worked byte[] responseBody = method.getResponseBody(); MiscUtils.getLogger().debug(new String(responseBody)); MiscUtils.getLogger()/*from w w w . j av a 2 s .c o m*/ .debug("--------------------------------------------------------------------------------------"); MultipartPostMethod eformPost = new MultipartPostMethod("http://mydrugref.org/e_forms/"); String documentDir = OscarProperties.getInstance().getProperty("DOCUMENT_DIR"); File docDir = new File(documentDir); String exportFilename = "eformExport" + System.currentTimeMillis() + "" + (Math.random() * 100); MiscUtils.getLogger().debug("Exported file name " + exportFilename); File exportFile = new File(documentDir, exportFilename); FileOutputStream fos = new FileOutputStream(exportFile); EFormExportZip eFormExportZip = new EFormExportZip(); List<EForm> eForms = new ArrayList<EForm>(); eForms.add(eForm); eFormExportZip.exportForms(eForms, fos); fos.close(); eformPost.addParameter("e_form[name]", eForm.getFormName()); eformPost.addParameter("e_form[category]", request.getParameter("category")); eformPost.addParameter("e_form[uploaded_data]", exportFile.getName(), exportFile); int statusCode2 = client.executeMethod(eformPost); byte[] responseBody2 = eformPost.getResponseBody(); MiscUtils.getLogger().debug("ST " + statusCode2); MiscUtils.getLogger().debug(new String(responseBody2)); //TODO:Need to handle errors return mapping.findForward("success"); }
From source file:pt.webdetails.browserid.BrowserIdVerifier.java
/** * Verify if the given assertion is valid * @param assertion The assertion as returned * @param audience//from www . ja v a 2s .c o m * @return * @throws HttpException if an HTTP protocol exception occurs or the service returns a code not in the 200 range. * @throws IOException if a transport error occurs. * @throws JSONException if the result cannot be parsed as JSON markup */ public BrowserIdResponse verify(String assertion, String audience) throws HttpException, IOException, JSONException { if (StringUtils.isEmpty(assertion)) throw new IllegalArgumentException("assertion is mandatory"); if (StringUtils.isEmpty(audience)) throw new IllegalArgumentException("audience is mandatory"); HttpClient client = new HttpClient(); //TODO: check certificate? PostMethod post = new PostMethod(url); post.addParameter("assertion", assertion); post.addParameter("audience", audience); try { int statusCode = client.executeMethod(post); if (isHttpResponseOK(statusCode)) { return new BrowserIdResponse(post.getResponseBodyAsString()); } else throw new HttpException(HttpStatus.getStatusText(statusCode)); } finally { post.releaseConnection(); } }
From source file:pukiwikiCommunicator.connector.SaveButtonDebugFrame.java
private void replaceTextWith(String x) { // System.out.println("updateButton.actionPerformed, event="+evt); //TODO add your code for updateButton.actionPerformed /* make the body (fig) */ /*/* w ww .j av a 2 s. co m*/ try{ fig=new String(fig.getBytes("UTF-8"), "UTF-8"); } catch(Exception e){ return; } */ if (this.updateText == null) this.updateText = ""; this.updateText = this.updateText + "\n " + insertSpaceAfterNewLine(x); this.urlField.setText(this.actionUrl); String url = this.urlField.getText(); this.println("url=" + url); // this.messageTextArea.append(this.updateText); BufferedReader br = null; // System.out.println("updateText="+this.updateText); this.println("editWriteValue=" + this.editWriteValue); this.println("editCmd=" + this.editCmd); this.println("editPage=" + this.editPage); this.println("digest=" + this.editDigest); try { PostMethod method = new PostMethod(url); if (this.client == null) return; method.getParams().setContentCharset(this.pageCharSet); method.setParameter("msg", this.updateText); // method.setParameter("encode_hint",this.editEncodeHint); method.addParameter("write", this.editWriteValue); method.addParameter("cmd", this.editCmd); method.addParameter("page", this.editPage); method.addParameter("digest", this.editDigest); int status = client.executeMethod(method); if (status != HttpStatus.SC_OK) { this.println("Method failed: " + method.getStatusLine()); method.getResponseBodyAsString(); } else { br = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream())); String readLine; while (((readLine = br.readLine()) != null)) { this.println(readLine); } } method.releaseConnection(); } catch (Exception e) { // this.messageTextArea.append(e.toString()+"\n"); System.out.println("" + e); e.printStackTrace(); } }