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.jboss.web.loadbalancer.Loadbalancer.java
protected HttpMethod addRequestData(HttpServletRequest request, HttpMethod method) { // add GET-data to query string if (request.getQueryString() != null) { method.setQueryString(request.getQueryString()); }/* w w w .ja v a 2s .co m*/ // add POST-data to the request if (method instanceof PostMethod) { PostMethod postMethod = (PostMethod) method; Enumeration paramNames = request.getParameterNames(); while (paramNames.hasMoreElements()) { String paramName = (String) paramNames.nextElement(); postMethod.addParameter(paramName, request.getParameter(paramName)); } } return method; }
From source file:org.jbpm.bpel.tools.ant.AdministrationTask.java
protected void writeRequest(PostMethod post) throws IOException { post.addParameter("operation", operation != null ? operation.getValue() : Operation.CREATE_SCHEMA); log("performing operation: " + operation); }
From source file:org.jivesoftware.sparkimpl.updater.CheckUpdates.java
/** * Returns true if there is a new build available for download. * * @return true if there is a new build available for download. *//*www .j a v a 2 s . co m*/ public SparkVersion isNewBuildAvailableFromJivesoftware() { PostMethod post = new PostMethod(mainUpdateURL); if (Spark.isWindows()) { post.addParameter("os", "windows"); } else if (Spark.isMac()) { post.addParameter("os", "mac"); } else { post.addParameter("os", "linux"); } // Properties isBetaCheckingEnabled is now used to indicate if updates are allowed // // Check to see if the beta should be included. // LocalPreferences pref = SettingsManager.getLocalPreferences(); // boolean isBetaCheckingEnabled = pref.isBetaCheckingEnabled(); // if (isBetaCheckingEnabled) { // post.addParameter("beta", "true"); // } Protocol.registerProtocol("https", new Protocol("https", new EasySSLProtocolSocketFactory(), 443)); HttpClient httpclient = new HttpClient(); String proxyHost = System.getProperty("http.proxyHost"); String proxyPort = System.getProperty("http.proxyPort"); if (ModelUtil.hasLength(proxyHost) && ModelUtil.hasLength(proxyPort)) { try { httpclient.getHostConfiguration().setProxy(proxyHost, Integer.parseInt(proxyPort)); } catch (NumberFormatException e) { Log.error(e); } } try { int result = httpclient.executeMethod(post); if (result != 200) { return null; } String xml = post.getResponseBodyAsString(); // Server Version SparkVersion serverVersion = (SparkVersion) xstream.fromXML(xml); if (isGreater(serverVersion.getVersion(), JiveInfo.getVersion())) { return serverVersion; } } catch (IOException e) { Log.error(e); } return null; }
From source file:org.kgj.playlist.metier.checkAndDispatch.DispatcherPersistenceSide.java
public void sendToVS(Query query) { HttpClient client = new HttpClient(); PostMethod post = new PostMethod(getUrlViewSide()); post.addParameter("query", ServeurHttpPersistenceSideMessagingServiceManager.getInstance().queryToString(query)); try {/*from w w w . j a va 2 s . c o m*/ int statusRequest = client.executeMethod(post); if (statusRequest != -1) { logger.info("Acknowledge http request : " + post.getResponseBodyAsString()); } } catch (IOException e) { e.printStackTrace(); } }
From source file:org.kgj.playlist.metier.checkAndDispatch.DispatcherPersistenceSide.java
public void sendToVS(String queryToString) { HttpClient client = new HttpClient(); PostMethod post = new PostMethod(getUrlViewSide()); post.addParameter("query", queryToString); try {//from ww w .j a v a 2s. c om int statusRequest = client.executeMethod(post); if (statusRequest != -1) { logger.info("Acknowledge http request : " + post.getResponseBodyAsString()); } } catch (IOException e) { e.printStackTrace(); } }
From source file:org.kuali.mobility.events.service.CalendarEventServiceImpl.java
private String authorizeRequestToken(OAuthConsumerToken requestToken) throws HttpException, IOException { int resultCode = 0; System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol"); HttpClient httpClient = new HttpClient(); PostMethod authorizeMethod = new PostMethod(SERVER_URL_OAUTH_AUTHZ); authorizeMethod.addParameter("requestToken", requestToken.getValue()); authorizeMethod.addParameter("authorize", "Authorize"); authorizeMethod.setFollowRedirects(false); resultCode = httpClient.executeMethod(authorizeMethod); String body = authorizeMethod.getResponseBodyAsString(); String redirectURL = authorizeMethod.getResponseHeader("Location").getValue(); authorizeMethod.releaseConnection(); if (redirectURL != null && redirectURL.indexOf("oauth_verifier") > -1) { return redirectURL.substring(redirectURL.indexOf("oauth_verifier") + 15); }// w ww . j a va 2 s . co m return ""; }
From source file:org.mule.module.pubsubhubbub.AbstractPuSHTestCase.java
protected MuleMessage sendRequestToHub(final Map<String, List<String>> subscriptionRequest, final String contentType) throws Exception { final String hubUrl = "http://localhost:" + getHubPort() + "/hub"; final PostMethod postMethod = new PostMethod(hubUrl); postMethod.setRequestHeader(HttpConstants.HEADER_CONTENT_TYPE, contentType); for (final Entry<String, List<String>> param : subscriptionRequest.entrySet()) { for (final String value : param.getValue()) { postMethod.addParameter(param.getKey(), value); }/*from ww w . j a v a2s. co m*/ } final Integer responseStatus = httpClient.executeMethod(postMethod); final MuleMessage response = new DefaultMuleMessage(postMethod.getResponseBodyAsString(), Collections.singletonMap("http.status", (Object) responseStatus.toString()), null, null, muleContext); return response; }
From source file:org.mule.transport.http.transformers.ObjectToHttpClientMethodRequest.java
protected HttpMethod createPostMethod(MuleMessage msg, String outputEncoding) throws Exception { URI uri = getURI(msg);//from ww w . ja v a2s.c o m PostMethod postMethod = new PostMethod(uri.toString()); String bodyParameterName = getBodyParameterName(msg); Object src = msg.getPayload(); if (src instanceof Map) { for (Map.Entry<?, ?> entry : ((Map<?, ?>) src).entrySet()) { postMethod.addParameter(entry.getKey().toString(), entry.getValue().toString()); } } else if (bodyParameterName != null) { postMethod.addParameter(bodyParameterName, src.toString()); } else { setupEntityMethod(src, outputEncoding, msg, postMethod); } checkForContentType(msg, postMethod); return postMethod; }
From source file:org.ngrinder.http.MeasureProtocolRequest.java
/** * Execute http post method and send data to Google Analytics * /*ww w. ja va 2 s . com*/ * @param Name * @param value */ public boolean execRequest(String name, String value) { HttpClient client = new HttpClient(); PostMethod method = new PostMethod(AnalyticsParameterConstants.POST_URL); method.addParameter(AnalyticsParameterConstants.PROTOCAL_VERSION, "1"); method.addParameter(AnalyticsParameterConstants.TRACKING_ID, track_ID); method.addParameter(AnalyticsParameterConstants.CLIENT_ID, client_ID); method.addParameter(AnalyticsParameterConstants.HIT_TYPE, "event"); method.addParameter(AnalyticsParameterConstants.APPLICATION_NAME, applicationName); method.addParameter(AnalyticsParameterConstants.APPLICATION_VERSION, (!(this.appVersion == null || this.appVersion.length() == 0)) ? this.appVersion : AnalyticsParameterConstants.DEFAULT_VERSION); method.addParameter(AnalyticsParameterConstants.EVENT_CATEGORY, eventCategory); method.addParameter(AnalyticsParameterConstants.EVENT_ACTION, eventAction); method.addParameter(AnalyticsParameterConstants.EVENT_LABEL, name); method.addParameter(AnalyticsParameterConstants.EVENT_VALUE, value); try { // Checks whether the String a valid number. Integer.parseInt(value); int returnCode = client.executeMethod(method); return (returnCode == HttpStatus.SC_OK); } catch (NumberFormatException e) { throw new RuntimeException("Only valid number is allowed", e); } catch (Exception e) { LOG.error("ERROR: {}", e.getMessage()); return false; } }
From source file:org.olat.modules.tu.IframeTunnelController.java
/** * Constructor for a tunnel component wrapper controller * /*from w w w .j av a 2s . co m*/ * @param ureq the userrequest * @param wControl the windowcontrol * @param config the module configuration */ public IframeTunnelController(final UserRequest ureq, final WindowControl wControl, final ModuleConfiguration config) { super(ureq, wControl); // use iframe translator for generic iframe title text setTranslator(Util.createPackageTranslator(IFrameDisplayController.class, ureq.getLocale())); this.config = config; // configuration.... final int configVersion = config.getConfigurationVersion(); // since config version 1 final String proto = (String) config.get(TUConfigForm.CONFIGKEY_PROTO); final String host = (String) config.get(TUConfigForm.CONFIGKEY_HOST); final Integer port = (Integer) config.get(TUConfigForm.CONFIGKEY_PORT); final String user = (String) config.get(TUConfigForm.CONFIGKEY_USER); final String startUri = (String) config.get(TUConfigForm.CONFIGKEY_URI); final String pass = (String) config.get(TUConfigForm.CONFIGKEY_PASS); String firstQueryString = null; if (configVersion == 2) { // query string is available since config version 2 firstQueryString = (String) config.get(TUConfigForm.CONFIGKEY_QUERY); } final boolean usetunnel = config.getBooleanSafe(TUConfigForm.CONFIG_TUNNEL); myContent = createVelocityContainer("iframe_index"); if (!usetunnel) { // display content directly final String rawurl = TUConfigForm.getFullURL(proto, host, port, startUri, firstQueryString).toString(); myContent.contextPut("url", rawurl); } else { // tunnel final Identity ident = ureq.getIdentity(); if (user != null && user.length() > 0) { httpClientInstance = HttpClientFactory.getHttpClientInstance(host, port.intValue(), proto, user, pass); } else { httpClientInstance = HttpClientFactory.getHttpClientInstance(host, port.intValue(), proto, null, null); } final Locale loc = ureq.getLocale(); final Mapper mapper = new Mapper() { @Override public MediaResource handle(final String relPath, final HttpServletRequest hreq) { MediaResource mr = null; final String method = hreq.getMethod(); String uri = relPath; HttpMethod meth = null; if (uri == null) { uri = (startUri == null) ? "" : startUri; } if (uri.length() > 0 && uri.charAt(0) != '/') { uri = "/" + uri; } // String contentType = hreq.getContentType(); // if (allowedToSendPersonalHeaders) { final String userName = ident.getName(); final User u = ident.getUser(); final String lastName = u.getProperty(UserConstants.LASTNAME, loc); final String firstName = u.getProperty(UserConstants.FIRSTNAME, loc); final String email = u.getProperty(UserConstants.EMAIL, loc); if (method.equals("GET")) { final GetMethod cmeth = new GetMethod(uri); final String queryString = hreq.getQueryString(); if (queryString != null) { cmeth.setQueryString(queryString); } meth = cmeth; // if response is a redirect, follow it if (meth == null) { return null; } meth.setFollowRedirects(true); } else if (method.equals("POST")) { // if (contentType == null || contentType.equals("application/x-www-form-urlencoded")) { // regular post, no file upload // } final Map params = hreq.getParameterMap(); final PostMethod pmeth = new PostMethod(uri); final Set postKeys = params.keySet(); for (final Iterator iter = postKeys.iterator(); iter.hasNext();) { final String key = (String) iter.next(); final String vals[] = (String[]) params.get(key); for (int i = 0; i < vals.length; i++) { pmeth.addParameter(key, vals[i]); } meth = pmeth; } if (meth == null) { return null; // Redirects are not supported when using POST method! // See RFC 2616, section 10.3.3, page 62 } } // Add olat specific headers to the request, can be used by external // applications to identify user and to get other params // test page e.g. http://cgi.algonet.se/htbin/cgiwrap/ug/test.py meth.addRequestHeader("X-OLAT-USERNAME", userName); meth.addRequestHeader("X-OLAT-LASTNAME", lastName); meth.addRequestHeader("X-OLAT-FIRSTNAME", firstName); meth.addRequestHeader("X-OLAT-EMAIL", email); boolean ok = false; try { httpClientInstance.executeMethod(meth); ok = true; } catch (final Exception e) { // handle error later } if (!ok) { // error meth.releaseConnection(); return new NotFoundMediaResource(relPath); } // get or post successfully final Header responseHeader = meth.getResponseHeader("Content-Type"); if (responseHeader == null) { // error return new NotFoundMediaResource(relPath); } mr = new HttpRequestMediaResource(meth); return mr; } }; final String amapPath = registerMapper(mapper); String alluri = amapPath + startUri; if (firstQueryString != null) { alluri += "?" + firstQueryString; } myContent.contextPut("url", alluri); } final String frameId = "ifdc" + hashCode(); // for e.g. js use myContent.contextPut("frameId", frameId); putInitialPanel(myContent); }