List of usage examples for org.apache.commons.httpclient.methods PostMethod PostMethod
public PostMethod(String paramString)
From source file:com.ebt.platform.utility.WebServiceCaller.java
public static String CallCasWebService(String xml) { PostMethod postMethod = new PostMethod("http://ws.e-baotong.cn:8085/CASServer.asmx?wsdl"); String responseString = null; try {//from ww w . ja va 2 s .c om byte[] b = xml.getBytes("utf-8"); InputStream inS = new ByteArrayInputStream(b, 0, b.length); RequestEntity req = new InputStreamRequestEntity(inS, b.length, "text/xml; charset=utf-8"); postMethod.setRequestEntity(req); HttpClient httpClient = new HttpClient(); int statusCode = httpClient.executeMethod(postMethod); if (statusCode == 200) { responseString = new String(postMethod.getResponseBodyAsString().getBytes("ISO-8859-1"), "UTF-8"); System.out.println("WebService??====" + responseString); } else { System.out.println("WebService??" + statusCode); } } catch (Exception e) { e.printStackTrace(); } return responseString; }
From source file:com.ebay.pulsar.collector.Simulator.java
private static void sendMessage() throws IOException, JsonProcessingException, JsonGenerationException, JsonMappingException, UnsupportedEncodingException, HttpException { ObjectMapper mapper = new ObjectMapper(); Map<String, Object> m = new HashMap<String, Object>(); m.put("si", "12345"); m.put("ct", System.currentTimeMillis()); String payload = mapper.writeValueAsString(m); HttpClient client = new HttpClient(); PostMethod method = new PostMethod("http://localhost:8080/tracking/ingest/PulsarRawEvent"); // method.addRequestHeader("Accept-Encoding", "gzip,deflate,sdch"); method.setRequestEntity(new StringRequestEntity(payload, "application/json", "UTF-8")); int status = client.executeMethod(method); System.out.println(Arrays.toString(method.getResponseHeaders())); System.out.println("Status code: " + status + ", Body: " + method.getResponseBodyAsString()); }
From source file:com.utest.domain.service.util.FileUploadUtil.java
public static void uploadFile(final File targetFile, final String targetURL, final String targerFormFieldName_) throws Exception { final PostMethod filePost = new PostMethod(targetURL); filePost.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true); filePost.addRequestHeader("X-Atlassian-Token", "no-check"); try {//ww w. ja v a 2 s .c om final FilePart fp = new FilePart(targerFormFieldName_, targetFile); fp.setTransferEncoding(null); final Part[] parts = { fp }; filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams())); final HttpClient client = new HttpClient(); client.getHttpConnectionManager().getParams().setConnectionTimeout(5000); final int status = client.executeMethod(filePost); if (status == HttpStatus.SC_OK) { Logger.getLogger(FileUploadUtil.class) .info("Upload complete, response=" + filePost.getResponseBodyAsString()); } else { Logger.getLogger(FileUploadUtil.class) .info("Upload failed, response=" + HttpStatus.getStatusText(status)); } } catch (final Exception ex) { Logger.getLogger(FileUploadUtil.class) .error("ERROR: " + ex.getClass().getName() + " " + ex.getMessage(), ex); throw ex; } finally { Logger.getLogger(FileUploadUtil.class).debug(new String(filePost.getResponseBody())); filePost.releaseConnection(); } }
From source file:com.cisco.tbd.stec.client.ServerConnection.java
public static void pushDetectedThreat(AttackLogEntry logEntry) throws IOException { String request = "http://10.154.244.56/stec/insert_threats.php"; HttpClient client = new HttpClient(); PostMethod method = new PostMethod(request); // Add POST parameters method.addParameter("token", Runner.DEVICE_ID); method.addParameter("exchange", Runner.EXCHANGE_ID); method.addParameter("ip", logEntry.getAttackIp()); method.addParameter("descr", logEntry.toString()); method.addParameter("type", "dos"); method.addParameter("level", logEntry.getPriorityLevel()); // Send POST request int statusCode = client.executeMethod(method); ///*from w w w.jav a2 s.co m*/ // InputStream rstream = null; // // rstream = method.getResponseBodyAsStream(); // // BufferedReader br = new BufferedReader(new InputStreamReader(rstream)); // // String line; // // while ((line = br.readLine()) != null) { // // System.out.println(line); // // } // br.close(); // Get the response body }
From source file:com.mycompany.semconsolewebapp.FileUpload.java
public static void uploadImage(String urlString, Part[] parts) throws FileNotFoundException, IOException { PostMethod postMessage = new PostMethod(urlString); postMessage.setRequestEntity(new MultipartRequestEntity(parts, postMessage.getParams())); HttpClient client = new HttpClient(); int status = client.executeMethod(postMessage); System.out.println("Got status message " + status); }
From source file:com.mogotest.ci.TestRunFactory.java
public static void create(final String apiKey, final String testPlanId, final String source) { final HttpClient client = new HttpClient(); final String url = String.format("https://mogotest.com/api/v1/test_plans/%s/tests.json", testPlanId); final PostMethod post = new PostMethod(url); try {/* ww w . j av a 2 s .c o m*/ post.addParameter("user_credentials", apiKey); post.addParameter("source", source); client.executeMethod(post); } catch (final Exception e) { logger.log(Level.SEVERE, "Error creating Mogotest test run.", e); } finally { post.releaseConnection(); } }
From source file:com.dotmarketing.util.UpdateUtil.java
/** * @return the new version if found. Null if up to date. * @throws DotDataException if an error is encountered *//*w w w. j a v a 2 s .c om*/ public static String getNewVersion() throws DotDataException { //Loading the update url Properties props = loadUpdateProperties(); String fileUrl = props.getProperty(Constants.PROPERTY_UPDATE_FILE_UPDATE_URL, ""); Map<String, String> pars = new HashMap<String, String>(); pars.put("version", ReleaseInfo.getVersion()); //pars.put("minor", ReleaseInfo.getBuildNumber() + ""); pars.put("check_version", "true"); pars.put("level", System.getProperty("dotcms_level")); if (System.getProperty("dotcms_license_serial") != null) { pars.put("license", System.getProperty("dotcms_license_serial")); } HttpClient client = new HttpClient(); PostMethod method = new PostMethod(fileUrl); Object[] keys = (Object[]) pars.keySet().toArray(); NameValuePair[] data = new NameValuePair[keys.length]; for (int i = 0; i < keys.length; i++) { String key = (String) keys[i]; NameValuePair pair = new NameValuePair(key, pars.get(key)); data[i] = pair; } method.setRequestBody(data); String ret = null; try { client.executeMethod(method); int retCode = method.getStatusCode(); if (retCode == 204) { Logger.info(UpdateUtil.class, "No new updates found"); } else { if (retCode == 200) { String newMinor = method.getResponseHeader("Minor-Version").getValue(); String newPrettyName = null; if (method.getResponseHeader("Pretty-Name") != null) { newPrettyName = method.getResponseHeader("Pretty-Name").getValue(); } if (newPrettyName == null) { Logger.info(UpdateUtil.class, "New Version: " + newMinor); ret = newMinor; } else { Logger.info(UpdateUtil.class, "New Version: " + newPrettyName + "/" + newMinor); ret = newPrettyName; } } else { throw new DotDataException( "Unknown return code: " + method.getStatusCode() + " (" + method.getStatusText() + ")"); } } } catch (HttpException e) { Logger.error(UpdateUtil.class, "HttpException: " + e.getMessage(), e); throw new DotDataException("HttpException: " + e.getMessage(), e); } catch (IOException e) { Logger.error(UpdateUtil.class, "IOException: " + e.getMessage(), e); throw new DotDataException("IOException: " + e.getMessage(), e); } return ret; }
From source file:ClientPost.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { HttpClient httpClient = new HttpClient(); PostMethod postMethod = new PostMethod("http://localhost:8080/home/viewPost.jsp"); NameValuePair[] postData = { new NameValuePair("username", "devgal"), new NameValuePair("department", "development"), new NameValuePair("email", "devgal@yahoo.com") }; //the 2.0 beta1 version has a // PostMethod.setRequestBody(NameValuePair[]) //method, as addParameters is deprecated postMethod.addParameters(postData);//from w w w . j av a 2 s .com httpClient.executeMethod(postMethod); //display the response to the POST method response.setContentType("text/html"); java.io.PrintWriter out = response.getWriter(); //A "200 OK" HTTP Status Code if (postMethod.getStatusCode() == HttpStatus.SC_OK) { out.println(postMethod.getResponseBodyAsString()); } else { out.println("The POST action raised an error: " + postMethod.getStatusLine()); } //release the connection used by the method postMethod.releaseConnection(); }
From source file:net.duckling.ddl.web.bean.ClbHelper.java
public static String getClbToken(int docId, int version, Properties properties) { HttpClient client = HttpClientUtil.getHttpClient(LOGGER); PostMethod method = new PostMethod(getClbTokenUrl(properties)); method.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "utf-8"); method.addParameter("appname", properties.getProperty("duckling.clb.aone.user")); method.addParameter("docid", docId + ""); method.addParameter("version", version + ""); try {//from w w w . j a va2 s . c o m method.addParameter("password", Base64.encodeBytes(properties.getProperty("duckling.clb.aone.password").getBytes("utf-8"))); } catch (IllegalArgumentException | UnsupportedEncodingException e) { } try { int status = client.executeMethod(method); String responseString = null; if (status < 400) { responseString = method.getResponseBodyAsString(); org.json.JSONObject j = new org.json.JSONObject(responseString); Object st = j.get("status"); if ("failed".equals(st)) { LOGGER.error("?clb token?"); return null; } else { return j.get("pf").toString(); } } else { LOGGER.error("STAUTS:" + status + ";MESSAGE:" + responseString); } } catch (HttpException e) { LOGGER.error("", e); } catch (IOException e) { LOGGER.error("", e); } catch (ParseException e) { LOGGER.error("", e); } return null; }
From source file:edu.utk.gsda.CalaisHttpClient.java
public void initMethod() { method = new PostMethod(CALAIS_URL); // Set mandatory parameters // method.setRequestHeader("x-calais-licenseID", "gffvtc7epu3tn7xkyrhbtdvk"); method.setRequestHeader("x-ag-access-token", "5CSCGy1jw4x7vY0FtLERrHZHDaRwynKq"); // Set input content type method.setRequestHeader("Content-Type", "TEXT/RAW; charset=UTF-8"); //method.setRequestHeader("Content-Type", "text/html; charset=UTF-8"); //method.setRequestHeader("Content-Type", "text/raw; charset=UTF-8"); method.setRequestHeader("omitOutputtingOriginalText", "true"); // Set response/output format // method.setRequestHeader("Accept", "text/simple"); method.setRequestHeader("outputFormat", "application/json"); // Enable Social Tags processing // method.setRequestHeader("enableMetadataType", "SocialTags"); method.setRequestHeader("x-calais-selectiveTags", "socialtags"); }