List of usage examples for org.apache.commons.httpclient.methods PostMethod setParameter
public void setParameter(String paramString1, String paramString2)
From source file:org.pentaho.pac.server.common.ThreadSafeHttpClient.java
private static void setPostMethodParams(PostMethod method, Map<String, Object> mapParams) { for (Map.Entry<String, Object> entry : mapParams.entrySet()) { Object o = entry.getValue(); if (o instanceof String[]) { for (String s : (String[]) o) { method.addParameter(entry.getKey(), s); }//from w ww . j a v a2 s.c o m } else { method.setParameter(entry.getKey(), (String) o); } } }
From source file:org.review_board.ereviewboard.core.client.ReviewboardHttpClient.java
public String executePost(String url, Map<String, String> parameters, IProgressMonitor monitor) throws ReviewboardException { PostMethod postRequest = new PostMethod(stripSlash(location.getUrl()) + url); configureRequestForJson(postRequest); for (Map.Entry<String, String> entry : parameters.entrySet()) postRequest.setParameter(entry.getKey(), entry.getValue()); return executeMethod(postRequest, monitor); }
From source file:org.sakaiproject.nakamura.grouper.changelog.HttpNakamuraManagerImpl.java
/** * Create the full set of objects that are necessary to have a working * course in Sakai OAE.//www . j a v a2 s .c o m * * Written on the back of the amazing John King who pulled out all of this * for nakamura/testscripts/SlingRuby/dataload/full_group_creator.rb * @throws GroupModificationException */ @Override public void createWorld(String grouperName, String worldId, String title, String description, String[] tags, String visibility, String joinability, String template, String message, Map<String, String> usersRolesToAdd) throws GroupModificationException { JSONObject params = makeCreateWorldParams(worldId, worldId, tags, worldId, visibility, joinability, template, message, usersRolesToAdd); PostMethod method = new PostMethod(url + WORLD_CREATE_URI); method.setParameter(DATA_PARAM, params.toString()); method.setParameter(CHARSET_PARAM, UTF_8); try { if (!dryrun) { HttpClient client = NakamuraHttpUtils.getHttpClient(url, username, password); NakamuraHttpUtils.http(client, method); AuditLogUtils.audit(AuditLogUtils.GROUP_CREATED, null, worldId, description, AuditLogUtils.SUCCESS); setGrouperNameProperties(worldId, grouperName); } } catch (GroupModificationException gme) { AuditLogUtils.audit(AuditLogUtils.GROUP_CREATED, null, worldId, description, AuditLogUtils.FAILURE); throw gme; } log.info("Successfully created the OAE world " + worldId + " for " + grouperName); }
From source file:org.sakaiproject.nakamura.grouper.changelog.HttpNakamuraManagerImpl.java
public void setProperties(String groupId, Map<String, String> properties) throws GroupModificationException { PostMethod method = new PostMethod(url.toString() + getUpdateURI(groupId)); for (Entry<String, String> entry : properties.entrySet()) { method.setParameter(entry.getKey(), entry.getValue()); }/*www . j av a 2 s . c o m*/ method.setParameter(CHARSET_PARAM, UTF_8); try { if (!dryrun) { NakamuraHttpUtils.http(NakamuraHttpUtils.getHttpClient(url, username, password), method); for (Entry<String, String> entry : properties.entrySet()) { AuditLogUtils.audit(AuditLogUtils.GROUP_MODIFIED, null, groupId, entry.getKey() + "=" + entry.getValue(), AuditLogUtils.SUCCESS); log.info("Set " + groupId + " : " + entry.getKey() + "=" + entry.getValue()); } } } catch (GrouperException ge) { AuditLogUtils.audit(AuditLogUtils.GROUP_MODIFIED, null, groupId, properties.toString(), AuditLogUtils.FAILURE); throw ge; } }
From source file:org.sakaiproject.nakamura.grouper.changelog.HttpNakamuraManagerImpl.java
/** * Send a batch request to delete the group and its pseudoGroups * @param groupId id of the group or one of its pseudoGroups * @param groupName/*from ww w. ja v a 2 s.c om*/ * @throws GroupModificationException */ public void deleteGroup(String groupId, String groupName) throws GroupModificationException { String parentGroupId = groupIdAdapter.getWorldId(groupId); HttpClient client = NakamuraHttpUtils.getHttpClient(url, username, password); JSONArray batchRequests = new JSONArray(); // Add the delete requests for the parent group JSONObject request = new JSONObject(); request.put(METHOD_PARAM, "POST"); request.put(CHARSET_PARAM, UTF_8); request.put(URL_PARAM, getDeleteURI(parentGroupId)); JSONObject params = new JSONObject(); params.put(OPERATION_PARAM, "delete"); request.put(PARAMETERS_PARAM, params); batchRequests.add(request); // Add the delete requests for the pseudoGroups for (String suffix : pseudoGroupSuffixes) { JSONObject psRequest = new JSONObject(); psRequest.put(METHOD_PARAM, "POST"); psRequest.put(CHARSET_PARAM, UTF_8); psRequest.put(URL_PARAM, getDeleteURI(parentGroupId + "-" + suffix)); JSONObject psParams = new JSONObject(); psParams.put(OPERATION_PARAM, "delete"); psParams.put(PARAMETERS_PARAM, psParams); batchRequests.add(psRequest); } PostMethod method = new PostMethod(url + BATCH_URI); JSONArray json = JSONArray.fromObject(batchRequests); method.setParameter(BATCH_REQUESTS_PARAM, json.toString()); method.setParameter(CHARSET_PARAM, UTF_8); try { if (!dryrun) { NakamuraHttpUtils.http(client, method); AuditLogUtils.audit(AuditLogUtils.GROUP_DELETED, null, parentGroupId, "deleted", AuditLogUtils.SUCCESS); for (String suffix : pseudoGroupSuffixes) { AuditLogUtils.audit(AuditLogUtils.GROUP_DELETED, null, parentGroupId + "-" + suffix, "deleted", AuditLogUtils.SUCCESS); } } } catch (GroupModificationException e) { AuditLogUtils.audit(AuditLogUtils.GROUP_DELETED, null, parentGroupId, "deleted", AuditLogUtils.FAILURE); for (String suffix : pseudoGroupSuffixes) { AuditLogUtils.audit(AuditLogUtils.GROUP_DELETED, null, parentGroupId + "-" + suffix, "deleted", AuditLogUtils.FAILURE); } throw e; } }
From source file:org.sakaiproject.nakamura.grouper.changelog.HttpNakamuraManagerImpl.java
/** * Create a pseudoGroup in Sakai OAE.//from ww w. j a va 2 s. c o m * A pseudoGroup is an Authorizable that represents a role group for a course. * @param nakamuraGroupId the id of the psuedoGroup in OAE * @param groupName the name of the Grouper group. * @param description a description for the group in OAE * @throws GroupModificationException */ protected void createPseudoGroup(String nakamuraGroupId, String groupName, String description) throws GroupModificationException { String role = nakamuraGroupId.substring(nakamuraGroupId.lastIndexOf('-') + 1); HttpClient client = NakamuraHttpUtils.getHttpClient(url, username, password); PostMethod method = new PostMethod(url + GROUP_CREATE_URI); method.addParameter(":name", nakamuraGroupId); method.addParameter(CHARSET_PARAM, UTF_8); method.addParameter("sakai:group-id", nakamuraGroupId); method.addParameter("sakai:excludeSearch", WorldConstants.TRUE); method.addParameter("sakai:group-description", description); method.addParameter("sakai:group-title", nakamuraGroupId + "(" + role + ")"); method.addParameter("sakai:pseudoGroup", WorldConstants.TRUE); method.addParameter("sakai:pseudogroupparent", groupIdAdapter.getWorldId(nakamuraGroupId)); method.setParameter("sakai:group-joinable", WorldConstants.NO); method.addParameter(GROUPER_NAME_PROP, groupName.substring(0, groupName.lastIndexOf(":") + 1) + nakamuraGroupId.substring(nakamuraGroupId.lastIndexOf("-") + 1)); method.setParameter(GROUPER_PROVISIONED_PROP, WorldConstants.TRUE); try { if (!dryrun) { NakamuraHttpUtils.http(client, method); } log.info("Created pseudoGroup in OAE for " + nakamuraGroupId); AuditLogUtils.audit(AuditLogUtils.GROUP_CREATED, null, nakamuraGroupId, description, AuditLogUtils.SUCCESS); } catch (GroupModificationException e) { AuditLogUtils.audit(AuditLogUtils.GROUP_CREATED, null, nakamuraGroupId, description, AuditLogUtils.FAILURE); throw e; } }
From source file:org.sakaiproject.nakamura.grouper.changelog.HttpNakamuraManagerImpl.java
/** * Send a batch request to Sakai OAE.//w w w.j a v a 2 s.c o m * @param requests a JSONArray for JSONObjects. Each JSONObject represents a request. * @throws GroupModificationException */ protected void batchPost(JSONArray requests) throws GroupModificationException { PostMethod method = new PostMethod(url + BATCH_URI); method.setParameter(BATCH_REQUESTS_PARAM, requests.toString()); method.setParameter(CHARSET_PARAM, UTF_8); if (!dryrun) { NakamuraHttpUtils.http(NakamuraHttpUtils.getHttpClient(url, username, password), method); } }
From source file:org.sakaiproject.search.component.service.impl.BaseSearchServiceImpl.java
public SearchList search(String searchTerms, List<String> contexts, int start, int end, String filterName, String sorterName) throws InvalidSearchQueryException { try {//from w w w.j a v a2s . c om BooleanQuery query = new BooleanQuery(); QueryParser qp = new QueryParser(Version.LUCENE_29, SearchService.FIELD_CONTENTS, getAnalyzer()); Query textQuery = qp.parse(searchTerms); // Support cross context searches if (contexts != null && contexts.size() > 0) { BooleanQuery contextQuery = new BooleanQuery(); for (Iterator<String> i = contexts.iterator(); i.hasNext();) { // Setup query so that it will allow results from any // included site, not all included sites. contextQuery.add(new TermQuery(new Term(SearchService.FIELD_SITEID, (String) i.next())), BooleanClause.Occur.SHOULD); // This would require term to be in all sites :-( // contextQuery.add(new TermQuery(new Term( // SearchService.FIELD_SITEID, (String) i.next())), // BooleanClause.Occur.MUST); } query.add(contextQuery, BooleanClause.Occur.MUST); } query.add(textQuery, BooleanClause.Occur.MUST); log.debug("Compiled Query is " + query.toString()); //$NON-NLS-1$ if (localSearch.get() == null && searchServerUrl != null && searchServerUrl.length() > 0) { try { PostMethod post = new PostMethod(searchServerUrl); String userId = sessionManager.getCurrentSessionUserId(); StringBuilder sb = new StringBuilder(); for (Iterator<String> ci = contexts.iterator(); ci.hasNext();) { sb.append(ci.next()).append(";"); //$NON-NLS-1$ } String contextParam = sb.toString(); post.setParameter(REST_CHECKSUM, digestCheck(userId, searchTerms)); post.setParameter(REST_CONTEXTS, contextParam); post.setParameter(REST_END, String.valueOf(end)); post.setParameter(REST_START, String.valueOf(start)); post.setParameter(REST_TERMS, searchTerms); post.setParameter(REST_USERID, userId); int status = httpClient.executeMethod(post); if (status != 200) { throw new RuntimeException("Failed to perform remote search, http status was " + status); //$NON-NLS-1$ } String response = post.getResponseBodyAsString(); return new SearchListResponseImpl(response, textQuery, start, end, getAnalyzer(), filter, searchIndexBuilder, this); } catch (Exception ex) { log.error("Remote Search Failed ", ex); //$NON-NLS-1$ throw new IOException(ex.getMessage()); } } else { IndexSearcher indexSearcher = getIndexSearcher(false); int MAX_RESULTS = 1000000; if (indexSearcher != null) { TopDocs topDocs = null; Filter indexFilter = (Filter) luceneFilters.get(filterName); Sort indexSorter = (Sort) luceneSorters.get(sorterName); if (log.isDebugEnabled()) { log.debug("Using Filter " + filterName + ":" //$NON-NLS-1$ //$NON-NLS-2$ + indexFilter + " and " + sorterName + ":" //$NON-NLS-1$ //$NON-NLS-2$ + indexSorter); } if (indexFilter != null && indexSorter != null) { topDocs = indexSearcher.search(query, indexFilter, MAX_RESULTS, indexSorter); } else if (indexFilter != null) { topDocs = indexSearcher.search(query, indexFilter, MAX_RESULTS); } else if (indexSorter != null) { topDocs = indexSearcher.search(query, null, MAX_RESULTS, indexSorter); } else { topDocs = indexSearcher.search(query, MAX_RESULTS); } if (log.isDebugEnabled()) { log.debug("Got " + topDocs.totalHits + " hits"); //$NON-NLS-1$ //$NON-NLS-2$ } String context = null; if (contexts != null && contexts.size() > 0) { //seeing events doesn't support multi context use the first context = contexts.get(0); } eventTrackingService.post( eventTrackingService.newEvent(EVENT_SEARCH, EVENT_SEARCH_REF + textQuery.toString(), context, true, NotificationService.PREF_IMMEDIATE)); return new SearchListImpl(topDocs, indexSearcher, textQuery, start, end, getAnalyzer(), filter, searchIndexBuilder, this); } else { throw new RuntimeException("Failed to start the Lucene Searche Engine"); //$NON-NLS-1$ } } } catch (ParseException e) { throw new InvalidSearchQueryException("Failed to parse Query ", e); //$NON-NLS-1$ } catch (IOException e) { throw new RuntimeException("Failed to run Search ", e); //$NON-NLS-1$ } }
From source file:org.tinygroup.httpvisit.impl.HttpVisitorImpl.java
public String postUrl(String url, Map<String, ?> parameter) { PostMethod post = new PostMethod(url); if (parameter != null) { for (String key : parameter.keySet()) { Object value = parameter.get(key); if (value.getClass().isArray()) { Object[] arrayValue = (Object[]) value; for (Object o : arrayValue) { post.addParameter(key, o.toString()); }//from w w w . j a va 2 s. co m } else { post.setParameter(key, value.toString()); } } } addHeader(post, headerMap); return execute(post); }
From source file:org.vamdc.taverna.vamdc_taverna_suite.common.UWSCaller.java
/** * @param strURL/*from www .j a v a 2 s . c om*/ * @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()); }