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.owncloud.android.lib.resources.shares.CreateRemoteShareOperation.java
@Override protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result = null; int status = -1; PostMethod post = null; try {//from w w w .j a v a 2s . c om // Post Method post = new PostMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH); //Log_OC.d(TAG, "URL ------> " + client.getBaseUri() + ShareUtils.SHARING_API_PATH); post.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8"); // necessary for special characters post.addParameter(PARAM_PATH, mRemoteFilePath); post.addParameter(PARAM_SHARE_TYPE, Integer.toString(mShareType.getValue())); post.addParameter(PARAM_SHARE_WITH, mShareWith); post.addParameter(PARAM_PUBLIC_UPLOAD, Boolean.toString(mPublicUpload)); if (mPassword != null && mPassword.length() > 0) { post.addParameter(PARAM_PASSWORD, mPassword); } post.addParameter(PARAM_PERMISSIONS, Integer.toString(mPermissions)); post.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); status = client.executeMethod(post); if (isSuccess(status)) { String response = post.getResponseBodyAsString(); result = new RemoteOperationResult(ResultCode.OK); // Parse xml response --> obtain the response in ShareFiles ArrayList // convert String into InputStream InputStream is = new ByteArrayInputStream(response.getBytes()); ShareXMLParser xmlParser = new ShareXMLParser(); mShares = xmlParser.parseXMLResponse(is); if (xmlParser.isSuccess()) { if (mShares != null) { Log_OC.d(TAG, "Created " + mShares.size() + " share(s)"); result = new RemoteOperationResult(ResultCode.OK); ArrayList<Object> sharesObjects = new ArrayList<Object>(); for (OCShare share : mShares) { sharesObjects.add(share); } result.setData(sharesObjects); } } else if (xmlParser.isFileNotFound()) { result = new RemoteOperationResult(ResultCode.SHARE_NOT_FOUND); } else if (xmlParser.isFailure()) { result = new RemoteOperationResult(ResultCode.SHARE_FORBIDDEN); } else { result = new RemoteOperationResult(false, status, post.getResponseHeaders()); } } else { result = new RemoteOperationResult(false, status, post.getResponseHeaders()); } } catch (Exception e) { result = new RemoteOperationResult(e); Log_OC.e(TAG, "Exception while Creating New Share", e); } finally { if (post != null) { post.releaseConnection(); } } return result; }
From source file:com.liferay.events.global.mobile.service.impl.MessageServiceImpl.java
@AccessControlled(guestAccessEnabled = true) @Override/*from w w w . j a va 2 s . co m*/ public Message sendMessage(final String eventId, final long contactId, final long targetContactId, final String message, String signature) throws Exception { Map<String, String> args = new HashMap<String, String>() { { put("eventId", StringUtil.valueOf(eventId)); put("contactId", StringUtil.valueOf(contactId)); put("targetContactId", StringUtil.valueOf(targetContactId)); put("message", StringUtil.valueOf(message)); } }; if (!Utils.isValidSignature(args, signature)) { throw new InvalidSignatureException("invalid signature"); } if (!MatchLocalServiceUtil.matches(eventId, contactId, targetContactId)) { throw new UnmatchedException("Sender has not been matched with recipient"); } EventContact sender = EventContactLocalServiceUtil.getEventContact(contactId); EventContact targetContact = EventContactLocalServiceUtil.getEventContact(targetContactId); final String groupName = GroupConstants.GUEST; final long companyId = PortalUtil.getDefaultCompanyId(); final long guestGroupId = GroupLocalServiceUtil.getGroup(companyId, groupName).getGroupId(); Message result = MessageLocalServiceUtil.addMessage(getUserId(), guestGroupId, new ServiceContext(), eventId, contactId, targetContactId, Utils.removeUnicode(message)); JSONObject payloadObj = JSONFactoryUtil.createJSONObject(); payloadObj.put("eventId", eventId); payloadObj.put("screen", ""); payloadObj.put("body", Utils.removeUnicode(message)); payloadObj.put("sound", "default"); payloadObj.put("title", sender.getFullName()); payloadObj.put("smallIcon", "ic_stat_lrlogo.png"); payloadObj.put("ticker", message); payloadObj.put("badge", 1); payloadObj.put("vibrate", true); payloadObj.put("screen", "connectChat"); payloadObj.put("screenDetail", String.valueOf(contactId)); try { Map<String, String> postArgs = new HashMap<String, String>(); final PostMethod postMethod = new PostMethod( "http://localhost:8080/api/jsonws/push-notifications-portlet.pushnotificationsdevice/send-push-notification"); postArgs.put("channel", eventId); postArgs.put("emailAddress", targetContact.getEmailAddress()); postArgs.put("payload", payloadObj.toString()); String sig = Utils.generateSig(postArgs); postMethod.addParameter("channel", eventId); postMethod.addParameter("emailAddress", targetContact.getEmailAddress()); postMethod.addParameter("payload", payloadObj.toString()); postMethod.addParameter("signature", sig); final HttpClient httpClient = new HttpClient(); httpClient.executeMethod(postMethod); } catch (Exception ex) { ex.printStackTrace(); } return result; }
From source file:com.cloud.network.nicira.NiciraNvpApi.java
/** * Logs into the Nicira API. The cookie is stored in the <code>_authcookie<code> variable. * <p>//www. j a va 2s. c om * The method returns false if the login failed or the connection could not be made. * */ private void login() throws NiciraNvpApiException { String url; try { url = new URL(_protocol, _host, "/ws.v1/login").toString(); } catch (MalformedURLException e) { s_logger.error("Unable to build Nicira API URL", e); throw new NiciraNvpApiException("Unable to build Nicira API URL", e); } PostMethod pm = new PostMethod(url); pm.addParameter("username", _adminuser); pm.addParameter("password", _adminpass); try { _client.executeMethod(pm); } catch (HttpException e) { throw new NiciraNvpApiException("Nicira NVP API login failed ", e); } catch (IOException e) { throw new NiciraNvpApiException("Nicira NVP API login failed ", e); } finally { pm.releaseConnection(); } if (pm.getStatusCode() != HttpStatus.SC_OK) { s_logger.error("Nicira NVP API login failed : " + pm.getStatusText()); throw new NiciraNvpApiException("Nicira NVP API login failed " + pm.getStatusText()); } // Success; the cookie required for login is kept in _client }
From source file:fr.msch.wissl.server.TestUsers.java
@Test public void test() throws IOException, JSONException { HttpClient client = new HttpClient(); // check the users and sessions created by TServer GetMethod get = new GetMethod(TServer.URL + "users"); get.addRequestHeader("sessionId", this.user_sessionId); client.executeMethod(get);/*from w w w . j a v a 2s. com*/ Assert.assertEquals(200, get.getStatusCode()); JSONObject obj = new JSONObject(get.getResponseBodyAsString()); JSONArray users = obj.getJSONArray("users"); Assert.assertEquals(2, users.length()); for (int i = 0; i < 2; i++) { JSONObject u = users.getJSONObject(i); String username = u.getString("username"); if (username.equals(this.user_username)) { Assert.assertEquals(this.user_userId, u.getInt("id")); Assert.assertEquals(2, u.getInt("auth")); Assert.assertEquals(0, u.getInt("downloaded")); } else if (username.equals(this.admin_username)) { Assert.assertEquals(this.admin_userId, u.getInt("id")); Assert.assertEquals(1, u.getInt("auth")); Assert.assertEquals(0, u.getInt("downloaded")); } else { Assert.fail("Unexpected user:" + username); } } JSONArray sessions = obj.getJSONArray("sessions"); Assert.assertEquals(2, sessions.length()); for (int i = 0; i < 2; i++) { JSONObject s = sessions.getJSONObject(i); String username = s.getString("username"); if (username.equals(this.user_username)) { Assert.assertEquals(this.user_userId, s.getInt("user_id")); Assert.assertTrue(s.getInt("last_activity") >= 0); // might be 0 Assert.assertTrue(s.getInt("created_at") >= 0); Assert.assertFalse(s.has("origins")); // admin only Assert.assertFalse(s.has("last_played_song")); } } // unknown user: 404 get = new GetMethod(TServer.URL + "user/100"); get.addRequestHeader("sessionId", this.user_sessionId); client.executeMethod(get); Assert.assertEquals(404, get.getStatusCode()); // check admin user get = new GetMethod(TServer.URL + "user/" + this.admin_userId); get.addRequestHeader("sessionId", this.admin_sessionId); client.executeMethod(get); Assert.assertEquals(200, get.getStatusCode()); obj = new JSONObject(get.getResponseBodyAsString()); JSONObject u = obj.getJSONObject("user"); Assert.assertEquals(this.admin_userId, u.getInt("id")); Assert.assertEquals(this.admin_username, u.getString("username")); Assert.assertEquals(1, u.getInt("auth")); Assert.assertEquals(0, u.getInt("downloaded")); sessions = obj.getJSONArray("sessions"); Assert.assertEquals(1, sessions.length()); JSONObject s = sessions.getJSONObject(0); Assert.assertEquals(this.admin_userId, s.getInt("user_id")); Assert.assertTrue(s.getInt("last_activity") >= 0); // might be 0 Assert.assertTrue(s.getInt("created_at") > 0); Assert.assertTrue(s.has("origins")); // admin only Assert.assertFalse(s.has("last_played_song")); Assert.assertTrue(obj.getJSONArray("playlists").length() == 0); // create a new user with user account: error 401 PostMethod post = new PostMethod(TServer.URL + "user/add"); post.addRequestHeader("sessionId", this.user_sessionId); post.addParameter("username", "new-user"); post.addParameter("password", "new-pw"); client.executeMethod(post); Assert.assertEquals(401, post.getStatusCode()); // create new user with empty username: err 400 post = new PostMethod(TServer.URL + "user/add"); post.addRequestHeader("sessionId", this.admin_sessionId); post.addParameter("username", ""); post.addParameter("password", "new-pw"); post.addParameter("auth", "1"); client.executeMethod(post); Assert.assertEquals(400, post.getStatusCode()); // create new user with short password: err 400 post = new PostMethod(TServer.URL + "user/add"); post.addRequestHeader("sessionId", this.admin_sessionId); post.addParameter("username", "new-user"); post.addParameter("password", "pw"); post.addParameter("auth", "1"); client.executeMethod(post); Assert.assertEquals(400, post.getStatusCode()); // create new user with invalid auth: err 400 post = new PostMethod(TServer.URL + "user/add"); post.addRequestHeader("sessionId", this.admin_sessionId); post.addParameter("username", "new-user"); post.addParameter("password", "pw"); post.addParameter("auth", "3"); client.executeMethod(post); Assert.assertEquals(400, post.getStatusCode()); int new_userId = -1; String new_sessionId = null; String new_username = "new-user"; String new_password = "new-pw"; // create new user post = new PostMethod(TServer.URL + "user/add"); post.addRequestHeader("sessionId", this.admin_sessionId); post.addParameter("username", new_username); post.addParameter("password", new_password); post.addParameter("auth", "2"); client.executeMethod(post); Assert.assertEquals(200, post.getStatusCode()); u = new JSONObject(post.getResponseBodyAsString()).getJSONObject("user"); new_userId = u.getInt("id"); Assert.assertEquals(new_username, u.getString("username")); Assert.assertEquals(2, u.getInt("auth")); // check new user get = new GetMethod(TServer.URL + "user/" + new_userId); get.addRequestHeader("sessionId", this.user_sessionId); client.executeMethod(get); Assert.assertEquals(200, get.getStatusCode()); obj = new JSONObject(get.getResponseBodyAsString()); Assert.assertTrue(obj.getJSONArray("playlists").length() == 0); Assert.assertEquals(0, obj.getJSONArray("sessions").length()); // login new user obj = new JSONObject(this.login(new_username, new_password)); Assert.assertEquals(new_userId, obj.getInt("userId")); new_sessionId = obj.getString("sessionId"); // check if logged in with /users get = new GetMethod(URL + "users"); get.addRequestHeader("sessionId", new_sessionId); client.executeMethod(get); Assert.assertEquals(200, get.getStatusCode()); obj = new JSONObject(get.getResponseBodyAsString()); users = obj.getJSONArray("users"); Assert.assertEquals(3, users.length()); for (int i = 0; i < 3; i++) { u = users.getJSONObject(i); String username = u.getString("username"); if (username.equals(new_username)) { Assert.assertEquals(new_userId, u.getInt("id")); } else { Assert.assertTrue(username.equals(user_username) || username.equals(admin_username)); } } sessions = obj.getJSONArray("sessions"); Assert.assertEquals(3, sessions.length()); for (int i = 0; i < 3; i++) { s = sessions.getJSONObject(i); String username = s.getString("username"); if (username.equals(new_username)) { Assert.assertEquals(new_userId, s.getInt("user_id")); Assert.assertTrue(s.getInt("last_activity") >= 0); // might be 0 Assert.assertTrue(s.getInt("created_at") > 0); Assert.assertFalse(s.has("origins")); // admin only Assert.assertFalse(s.has("last_played_song")); } else { Assert.assertTrue(username.equals(user_username) || username.equals(admin_username)); } } // try to change password without the old password: 401 post = new PostMethod(URL + "user/password"); post.addRequestHeader("sessionId", new_sessionId); post.addParameter("old_password", "password"); post.addParameter("new_password", "password2"); client.executeMethod(post); Assert.assertEquals(401, post.getStatusCode()); // change password for new user post = new PostMethod(URL + "user/password"); post.addRequestHeader("sessionId", new_sessionId); post.addParameter("old_password", new_password); new_password = "something else"; post.addParameter("new_password", new_password); client.executeMethod(post); Assert.assertEquals(204, post.getStatusCode()); // logout and relogin with new password post = new PostMethod(URL + "logout"); post.addRequestHeader("sessionId", new_sessionId); client.executeMethod(post); Assert.assertEquals(204, post.getStatusCode()); obj = new JSONObject(this.login(new_username, new_password)); Assert.assertEquals(new_userId, obj.getInt("userId")); new_sessionId = obj.getString("sessionId"); // try to delete an user as user: 401 post = new PostMethod(URL + "user/remove"); post.addRequestHeader("sessionId", user_sessionId); post.addParameter("user_ids[]", "" + new_userId); client.executeMethod(post); Assert.assertEquals(401, post.getStatusCode()); // try to delete no user: 400 post = new PostMethod(URL + "user/remove"); post.addRequestHeader("sessionId", admin_sessionId); client.executeMethod(post); Assert.assertEquals(400, post.getStatusCode()); // try to delete admin with admin: 400 post = new PostMethod(URL + "user/remove"); post.addRequestHeader("sessionId", admin_sessionId); post.addParameter("user_ids[]", "" + admin_userId); client.executeMethod(post); Assert.assertEquals(400, post.getStatusCode()); // delete both regular users post = new PostMethod(URL + "user/remove"); post.addRequestHeader("sessionId", admin_sessionId); post.addParameter("user_ids[]", "" + user_userId); post.addParameter("user_ids[]", "" + new_userId); client.executeMethod(post); Assert.assertEquals(204, post.getStatusCode()); // check that old sessions do not work anymore get = new GetMethod(URL + "users"); get.addRequestHeader("sessionId", user_sessionId); client.executeMethod(get); Assert.assertEquals(401, get.getStatusCode()); // check that there is only 1 user get = new GetMethod(URL + "users"); get.addRequestHeader("sessionId", admin_sessionId); client.executeMethod(get); Assert.assertEquals(200, get.getStatusCode()); obj = new JSONObject(get.getResponseBodyAsString()); Assert.assertEquals(obj.getJSONArray("users").length(), 1); Assert.assertEquals(obj.getJSONArray("sessions").length(), 1); }
From source file:com.google.api.ads.dfp.lib.AuthToken.java
/** * Makes the POST to the client login API. * * @param postMethod the {@code PostMethod} which encapsulates the URL to * post against//w w w.j a v a2 s .co m * @return an HTTP status code as defined by {@code HttpStatus} * @throws IOException if the HTTP client could not establish a * connection */ private int postToClientLogin(PostMethod postMethod) throws IOException { HttpClient httpClient = new HttpClient(new MultiThreadedHttpConnectionManager()); setProxy(httpClient); HttpConnectionManagerParams connectionManagerParams = httpClient.getHttpConnectionManager().getParams(); connectionManagerParams.setTcpNoDelay(true); connectionManagerParams.setSoTimeout(HTTP_CLIENT_SOCKET_TIMEOUT_IN_MS); postMethod.addParameter("Email", email); postMethod.addParameter("Passwd", password); postMethod.addParameter("accountType", "GOOGLE"); postMethod.addParameter("service", "gam"); postMethod.addParameter("source", "google-dfpapi-java"); if (captchaToken != null) { postMethod.addParameter("logintoken", captchaToken); } if (captchaAnswer != null) { postMethod.addParameter("logincaptcha", captchaAnswer); } return httpClient.executeMethod(postMethod); }
From source file:com.testmax.uri.ExecuteHttpRequest.java
public String handleHTTPPostPerformance() throws Exception { String resp = null;//from w w w. j av a 2 s. com boolean isItemIdReplaced = false; String replacedParam = ""; // Create a method instance. List<NameValuePair> nvps = new ArrayList<NameValuePair>(); URLConfig urlConf = this.page.getPageURL().getUrlConfig(this.action); List<Element> globalItemList = urlConf.getItemListElement(); if (globalItemList.size() > 0) { urlConf.setItemList(); isItemIdReplaced = true; } String newurl = urlConf.replaceGlobalItemIdForUrl(this.url); PostMethod method = new PostMethod(newurl); System.out.println(newurl); Set<String> s = urlConf.getUrlParamset(); for (String param : s) { if (!isItemIdReplaced) { //nvps.add(new BasicNameValuePair(param,urlConf.getUrlParamValue(param))); method.addParameter(param, urlConf.getUrlParamValue(param)); } else { replacedParam = urlConf.getUrlReplacedItemIdParamValue(param); method.addParameter(param, replacedParam); //System.out.println(replacedParam); //nvps.add(new BasicNameValuePair(param,replacedParam)); } } org.apache.commons.httpclient.HttpClient client = new org.apache.commons.httpclient.HttpClient(); this.startRecording(); int startcount = 0; long starttime = this.getCurrentTime(); int statusCode = 0; try { // Execute the method. statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { WmLog.getCoreLogger() .info("Auth Server response received, but there was a ParserConfigurationException: "); } // Read the response body. byte[] responseBody = method.getResponseBody(); resp = new String(responseBody, "UTF-8"); // log the response WmLog.getCoreLogger().info("MDE Request : " + resp); } catch (HttpException e) { WmLog.getCoreLogger().info("Unable to retrieve response from MDE webservice : " + e.getMessage()); return null; } catch (IOException e) { WmLog.getCoreLogger().info("Unable to retrieve response from MDE webservice : " + e.getMessage()); return null; } finally { // Release the connection. method.releaseConnection(); } // Measure the time passed between response long elaspedTime = this.getElaspedTime(starttime); this.stopMethodRecording(statusCode, elaspedTime, startcount); //System.out.println(resp); System.out.println("ElaspedTime: " + elaspedTime); WmLog.getCoreLogger().info("Response XML: " + resp); WmLog.getCoreLogger().info("ElaspedTime: " + elaspedTime); this.printMethodRecording(statusCode, newurl); this.printMethodLog(statusCode, newurl); if (statusCode == 200 && validateAssert(urlConf, resp)) { this.addThreadActionMonitor(this.action, true, elaspedTime); } else { this.addThreadActionMonitor(this.action, false, elaspedTime); WmLog.getCoreLogger().info("Input XML: " + replacedParam); WmLog.getCoreLogger().info("Response XML: " + resp); } return (resp); }
From source file:mitm.common.sms.transport.clickatell.ClickatellSMSTransport.java
private void addParameter(PostMethod postMethod, String parameter, String value) { if (parameter == null) { return;/* ww w . j a v a 2 s. co m*/ } /* * Null values are now allowed */ if (value == null) { value = ""; } postMethod.addParameter(parameter, value); }
From source file:com.buzzdavidson.spork.client.OWAClient.java
/** * Perform login to OWA server given configuration parameters and supplied user/password * * @param userName user name for login// w w w . j a va 2s. c o m * @param password password for login * @return true if successfully authenticated */ public boolean login(String userName, String password) { /** * Set NT credentials on client */ Credentials cred; cred = new NTCredentials(userName, password, authHost, authDomain); client.getState().setCredentials(new AuthScope(authHost, AuthScope.ANY_PORT), cred); String authUrl = getBaseUrl() + loginPath; boolean retval = false; logger.info(String.format("Logging in to OWA using username [%s] at URL [%s] ", userName, authUrl)); PostMethod post = new PostMethod(authUrl); post.setRequestHeader(PARAM_CONTENT_TYPE, PostMethod.FORM_URL_ENCODED_CONTENT_TYPE); post.addParameter(PARAM_DEST, getBaseUrl() + docBasePath); post.addParameter(PARAM_UNAME, userName); post.addParameter(PARAM_PWD, password); post.addParameter(PARAM_FLAGS, publicComputer ? OWA_FLAG_VALUE_PUBLIC.toString() : OWA_FLAG_VALUE_PRIVATE.toString()); int status = 0; try { status = client.executeMethod(post); if (logger.isDebugEnabled()) { logger.debug("Post returned status code " + status); } } catch (Exception ex) { logger.error("Got error posting to login url", ex); } if (status == HttpStatus.SC_OK) { // We shouldn't see this in normal operation... Evaluate whether this actually ever occurs. logger.info("Login succeeded (no redirect specified)"); retval = true; } else if (status == HttpStatus.SC_MOVED_TEMPORARILY) { // We typically receive a redirect upon successful authentication; the target url is the user's inbox Header locationHeader = post.getResponseHeader(HEADER_LOCATION); if (locationHeader != null) { String mbxRoot = getMailboxRoot(locationHeader.getValue()); if (mbxRoot == null || mbxRoot.length() < 1) { logger.info("Login failed - Check configuration and credentials."); retval = false; } else { owaRootUrl = mbxRoot; inboxAddress = owaRootUrl + "/" + FOLDER_NAME_INBOX; // TODO is this sufficient? logger.info("Login succeeded, redirect specified (redirecting to " + owaRootUrl + ")"); retval = true; } } } else { logger.error("Login failed with error code " + status); } return retval; }
From source file:com.liferay.events.global.mobile.service.impl.EventContactLocalServiceImpl.java
public EventContact recordInterest(long userId, long groupId, ServiceContext serviceContext, String eventId, long contactId, long targetContactId) throws PortalException, SystemException { EventContact contact, targetContact; try {/*from ww w . ja v a2s . co m*/ contact = EventContactLocalServiceUtil.getVerifiedContact(contactId, true); targetContact = EventContactLocalServiceUtil.getVerifiedContact(targetContactId, true); } catch (PortalException ex) { throw new NoSuchEventContactException(ex); } long[] ints = StringUtil.split(contact.getInterestedIds(), StringPool.COMMA, 0L); long[] targetInts = StringUtil.split(targetContact.getInterestedIds(), StringPool.COMMA, 0L); Set<Long> intSet = new HashSet<Long>(ints.length); for (Long l : ints) { intSet.add(l); } Set<Long> targetIntSet = new HashSet<Long>(targetInts.length); for (Long l : targetInts) { targetIntSet.add(l); } if (intSet.contains(targetContactId)) { // already recorded return targetContact; } intSet.add(targetContactId); contact.setInterestedIds(StringUtil.merge(intSet, StringPool.COMMA)); EventContactLocalServiceUtil.updateEventContact(contact); if (targetIntSet.contains(contactId)) { MatchLocalServiceUtil.addMatch(groupId, userId, serviceContext, eventId, contactId, targetContactId); // its a match; send PN to target to targetContact JSONObject payloadObj = JSONFactoryUtil.createJSONObject(); payloadObj.put("screen", ""); payloadObj.put("eventId", eventId); payloadObj.put("body", "You are matched with " + contact.getFullName()); payloadObj.put("sound", "default"); payloadObj.put("title", "Liferay Events"); payloadObj.put("smallIcon", "ic_stat_lrlogo.png"); payloadObj.put("ticker", "New Notification from Liferay Events"); payloadObj.put("badge", 1); payloadObj.put("vibrate", true); payloadObj.put("screen", "connectConnections"); JSONArray nameArgs = JSONFactoryUtil.createJSONArray(); nameArgs.put(contact.getFullName()); payloadObj.put("localizedKey", "ITS_A_MATCH"); payloadObj.put("localizedArgs", nameArgs.toString()); try { Map<String, String> args = new HashMap<String, String>(); final PostMethod postMethod = new PostMethod( "http://localhost:8080/api/jsonws/push-notifications-portlet.pushnotificationsdevice/send-push-notification"); args.put("channel", eventId); args.put("emailAddress", targetContact.getEmailAddress()); args.put("payload", payloadObj.toString()); String sig = Utils.generateSig(args); postMethod.addParameter("channel", eventId); postMethod.addParameter("emailAddress", targetContact.getEmailAddress()); postMethod.addParameter("payload", payloadObj.toString()); postMethod.addParameter("signature", sig); final HttpClient httpClient = new HttpClient(); httpClient.executeMethod(postMethod); } catch (Exception ex) { ex.printStackTrace(); } return targetContact; } return null; }
From source file:com.sun.faban.harness.webclient.ResultAction.java
private Set<String> checkArchivedRuns(String[] runIds) throws FileNotFoundException, IOException { HashSet<String> existingRuns = new HashSet<String>(); String[] runIdTimeStamps = new String[runIds.length]; for (int r = 0; r < runIds.length; r++) { String runId = runIds[r]; runIdTimeStamps[r] = editResultInfo(runId); }//from w w w . j av a 2 s.c o m for (URL repository : Config.repositoryURLs) { URL repos = new URL(repository, "/controller/uploader/check_runs"); PostMethod post = new PostMethod(repos.toString()); post.addParameter("host", Config.FABAN_HOST); for (String runId : runIds) { post.addParameter("runId", runId); } for (String ts : runIdTimeStamps) { post.addParameter("ts", ts); } HttpClient client = new HttpClient(); client.getHttpConnectionManager().getParams().setConnectionTimeout(5000); int status = client.executeMethod(post); if (status != HttpStatus.SC_OK) logger.info("SC_OK not ok"); String response = post.getResponseBodyAsString(); StringTokenizer t = new StringTokenizer(response.trim(), "\n"); while (t.hasMoreTokens()) { existingRuns.add(t.nextToken().trim()); } } return existingRuns; }