List of usage examples for org.apache.commons.httpclient.methods PostMethod setRequestBody
public void setRequestBody(NameValuePair[] paramArrayOfNameValuePair) throws IllegalArgumentException
From source file:org.dbpedia.spotlight.evaluation.external.AlchemyClient.java
protected String process(String text) throws AnnotationException { PostMethod method = new PostMethod(url); method.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); NameValuePair[] params = { new NameValuePair("text", text), new NameValuePair("apikey", this.apikey) }; method.setRequestBody(params); String response = request(method); //System.out.println(response); return response; }
From source file:org.dbpedia.spotlight.evaluation.external.OpenCalaisClient.java
protected String process(String text) throws AnnotationException { PostMethod method = new PostMethod(url); // Set mandatory parameters method.setRequestHeader("x-calais-licenseID", apikey); // Set input content type method.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); // Set response/output format method.setRequestHeader("Accept", "application/json"); // Define params for the body NameValuePair[] params = { new NameValuePair("licenseID", apikey), new NameValuePair("content", text), new NameValuePair("paramsXML", paramsXml) }; method.setRequestBody(params); String response = request(method); //System.out.println(response); return response; }
From source file:org.dbpedia.spotlight.evaluation.external.WikiMachineClient.java
protected String process(String text) throws AnnotationException { String url = "http://thewikimachine.fbk.eu/gui/basic"; PostMethod method = new PostMethod(url); method.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); NameValuePair[] params = { new NameValuePair("context", text), new NameValuePair("type", "link"), new NameValuePair("si", "10"), }; method.setRequestBody(params); LOG.debug("Sending request to WikiMachine: " + params); String response = request(method); return response; }
From source file:org.dbpedia.spotlight.evaluation.external.ZemantaClient.java
protected String process(String text) throws AnnotationException { String url = "http://api.zemanta.com/services/rest/0.0/"; PostMethod method = new PostMethod(url); method.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); // Grabbed from the bookmarklet NameValuePair[] params = { new NameValuePair("method", "zemanta.suggest"), new NameValuePair("api_key", api_key), new NameValuePair("text", text), new NameValuePair("format", "xml") }; method.setRequestBody(params); LOG.debug("Sending request to Zemanta: " + params); String response = request(method); return response; }
From source file:org.demo.workflow.integration.Helper.java
@SuppressWarnings("deprecation") private String requestFormProcessor(String item_kind, String item_id, String body) throws HttpException, IOException { // compute alfresco url for contact formprocessor webscript String connectionUrl = replaceTokensInURL(ALF_URL_SERV_FORM[1], "host", host); connectionUrl = replaceTokensInURL(connectionUrl, "item_kind", item_kind); connectionUrl = replaceTokensInURL(connectionUrl, "item_id", item_id); // instance POST method PostMethod method = new PostMethod(connectionUrl); method.setDoAuthentication(true);//ww w .j a v a2 s . c o m method.setRequestHeader("Content-Type", "application/json; charset=UTF-8"); method.setRequestBody(body); System.out.println("execute post method"); System.out.println("url :" + connectionUrl); System.out.println("POST :" + body); client.executeMethod(method); String response = method.getResponseBodyAsString(); return response; }
From source file:org.eclipse.epp.internal.mpc.core.service.DefaultMarketplaceService.java
public void reportInstallError(IProgressMonitor monitor, IStatus result, Set<Node> nodes, Set<String> iuIdsAndVersions, String resolutionDetails) throws CoreException { HttpClient client = new HttpClient(); client.getParams().setParameter(HttpMethodParams.USER_AGENT, MarketplaceClientCore.BUNDLE_ID); URL location;//from w w w.j av a 2 s. c o m PostMethod method; try { location = new URL(baseUrl, "install/error/report"); //$NON-NLS-1$ method = new PostMethod(location.toURI().toString()); } catch (URISyntaxException e) { throw new IllegalStateException(e); } catch (MalformedURLException e) { throw new IllegalStateException(e); } try { List<NameValuePair> parameters = new ArrayList<NameValuePair>(); parameters.add(new NameValuePair("status", Integer.toString(result.getSeverity()))); //$NON-NLS-1$ parameters.add(new NameValuePair("statusMessage", result.getMessage())); //$NON-NLS-1$ for (Node node : nodes) { parameters.add(new NameValuePair("node", node.getId())); //$NON-NLS-1$ } if (iuIdsAndVersions != null && !iuIdsAndVersions.isEmpty()) { for (String iuAndVersion : iuIdsAndVersions) { parameters.add(new NameValuePair("iu", iuAndVersion)); //$NON-NLS-1$ } } parameters.add(new NameValuePair("detailedMessage", resolutionDetails)); //$NON-NLS-1$ if (!parameters.isEmpty()) { method.setRequestBody(parameters.toArray(new NameValuePair[parameters.size()])); client.executeMethod(method); } } catch (IOException e) { String message = NLS.bind(Messages.DefaultMarketplaceService_cannotCompleteRequest_reason, location.toString(), e.getMessage()); throw new CoreException(createErrorStatus(message, e)); } finally { method.releaseConnection(); } }
From source file:org.eclipse.mylyn.github.internal.GitHubService.java
/** * Verify that the provided credentials are correct * @param credentials/*w w w .j a v a 2s.c o m*/ * * @return true if and only if the credentials are correct */ public boolean verifyCredentials(GitHubCredentials credentials) throws GitHubServiceException { PostMethod method = null; boolean success = false; try { method = new PostMethod(gitURLBase + gitUserRoot + EMAILS); // Set the users login and API token final NameValuePair login = new NameValuePair("login", credentials.getUsername()); final NameValuePair token = new NameValuePair("token", credentials.getApiToken()); method.setRequestBody(new NameValuePair[] { login, token }); executeMethod(method); // if we reach here we know that credentials were good success = true; } catch (PermissionDeniedException e) { // if we provide bad credentials, GitHub will return 403 or 401 return false; } catch (GitHubServiceException e) { throw e; } catch (final RuntimeException runtimeException) { throw runtimeException; } catch (final Exception exception) { throw new GitHubServiceException(exception); } finally { if (method != null) method.releaseConnection(); } return success; }
From source file:org.eclipse.mylyn.github.internal.GitHubService.java
/** * Add a label to an existing GitHub issue. * /*from www . jav a2s. c o m*/ * @param user * - The user the repository is owned by * @param repo * - The git repository where the issue tracker is hosted * @param label * - The text label to add to the existing issue * @param issueNumber * - The issue number to add a label to * @param api * - The users GitHub * * @return A boolean representing the success of the function call * * @throws GitHubServiceException * * @note API Doc: issues/label/add/:user/:repo/:label/:number API POST * Variables: login, api-token */ public boolean addLabel(final String user, final String repo, final String label, final int issueNumber, final GitHubCredentials credentials) throws GitHubServiceException { PostMethod method = null; boolean success = false; try { // build HTTP GET method method = new PostMethod(gitURLBase + gitIssueRoot + ADD_LABEL + user + "/" + repo + "/" + label + "/" + Integer.toString(issueNumber)); // Set the users login and API token final NameValuePair login = new NameValuePair("login", credentials.getUsername()); final NameValuePair token = new NameValuePair("token", credentials.getApiToken()); method.setRequestBody(new NameValuePair[] { login, token }); // execute HTTP GET method executeMethod(method); // Check the response, make sure the action was successful final String response = method.getResponseBodyAsString(); if (response.contains(label.subSequence(0, label.length()))) { success = true; } if (LOG.isDebugEnabled()) { LOG.debug("Response: " + method.getResponseBodyAsString()); LOG.debug("URL: " + method.getURI()); } } catch (GitHubServiceException e) { throw e; } catch (final RuntimeException runtimeException) { throw runtimeException; } catch (final Exception exception) { throw new GitHubServiceException(exception); } finally { if (method != null) method.releaseConnection(); } return success; }
From source file:org.eclipse.mylyn.github.internal.GitHubService.java
/** * Remove an existing label from an existing GitHub issue. * //from w ww . j ava 2s . c o m * @param user * - The user the repository is owned by * @param repo * - The git repository where the issue tracker is hosted * @param label * @param issueNumber * @param api * * @return A list of GitHub issues in the response text. * * @throws GitHubServiceException * * API Doc: issues/label/remove/:user/:repo/:label/:number API * POST Variables: login, api-token */ public boolean removeLabel(final String user, final String repo, final String label, final int issueNumber, final GitHubCredentials credentials) throws GitHubServiceException { PostMethod method = null; boolean success = false; try { // build HTTP GET method method = new PostMethod(gitURLBase + gitIssueRoot + REMOVE_LABEL + user + "/" + repo + "/" + label + "/" + Integer.toString(issueNumber)); // Set the users login and API token final NameValuePair login = new NameValuePair("login", credentials.getUsername()); final NameValuePair token = new NameValuePair("token", credentials.getUsername()); method.setRequestBody(new NameValuePair[] { login, token }); // execute HTTP GET method executeMethod(method); // Check the response, make sure the action was successful final String response = method.getResponseBodyAsString(); if (!response.contains(label.subSequence(0, label.length()))) { success = true; } if (LOG.isDebugEnabled()) { LOG.debug("Response: " + method.getResponseBodyAsString()); LOG.debug("URL: " + method.getURI()); } } catch (GitHubServiceException e) { throw e; } catch (final RuntimeException runtimeException) { throw runtimeException; } catch (final Exception exception) { throw new GitHubServiceException(exception); } finally { if (method != null) method.releaseConnection(); } return success; }
From source file:org.eclipse.mylyn.github.internal.GitHubService.java
/** * Open a new issue using the GitHub Issues API. * // ww w . jav a 2 s . co m * @param user * - The user the repository is owned by * @param repo * - The git repository where the issue tracker is hosted * @param issue * - The GitHub issue object to create on the issue tracker. * * @return the issue that was created * * @throws GitHubServiceException * * API Doc: issues/open/:user/:repo API POST Variables: login, * api-token, title, body */ public GitHubIssue openIssue(final String user, final String repo, final GitHubIssue issue, final GitHubCredentials credentials) throws GitHubServiceException { GitHubShowIssue showIssue = null; PostMethod method = null; try { // Create the HTTP POST method method = new PostMethod(gitURLBase + gitIssueRoot + OPEN + user + "/" + repo); // Set the users login and API token final NameValuePair login = new NameValuePair("login", credentials.getUsername()); final NameValuePair token = new NameValuePair("token", credentials.getApiToken()); final NameValuePair body = new NameValuePair("body", issue.getBody()); final NameValuePair title = new NameValuePair("title", issue.getTitle()); method.setRequestBody(new NameValuePair[] { login, token, body, title }); executeMethod(method); showIssue = gson.fromJson(new String(method.getResponseBody()), GitHubShowIssue.class); if (showIssue == null || showIssue.getIssue() == null) { if (LOG.isErrorEnabled()) { LOG.error("Unexpected server response: " + method.getResponseBodyAsString()); } throw new GitHubServiceException("Unexpected server response"); } if (LOG.isDebugEnabled()) { LOG.debug("Response: " + method.getResponseBodyAsString()); LOG.debug("URL: " + method.getURI()); } return showIssue.getIssue(); } catch (GitHubServiceException e) { throw e; } catch (final RuntimeException runTimeException) { throw runTimeException; } catch (final Exception e) { throw new GitHubServiceException(e); } finally { if (method != null) { method.releaseConnection(); } } }