List of usage examples for org.apache.commons.httpclient HttpClient HttpClient
public HttpClient()
From source file:net.duckling.ddl.util.HttpClientUtil.java
public static HttpClient getHttpClient(Logger logger) { if (httpClient == null) { synchronized (logger) { if (httpClient == null) { httpClient = new HttpClient(); httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(30000); }/*from w w w. j a va2s.co m*/ } } return httpClient; }
From source file:com.pieframework.runtime.utils.CampfireNotifier.java
public static boolean notify(String msg, String url, String user, String password) { HttpClient client = new HttpClient(); PostMethod post = new PostMethod(url); // stuff the Authorization request header byte[] encodedPassword = (user + ":" + password).getBytes(); BASE64Encoder encoder = new BASE64Encoder(); post.setRequestHeader("Authorization", "Basic " + encoder.encode(encodedPassword)); try {//ww w. j ava 2 s .co m RequestEntity entity = new StringRequestEntity("<message><body>" + msg + "</body></message>", "application/xml", "UTF-8"); post.setRequestEntity(entity); client.executeMethod(post); String responseMsg = "httpStatus: " + post.getStatusCode() + " " + "Content-type: " + post.getResponseHeader("Content-Type") + " " + post.getResponseBodyAsString(); Configuration.log().info(responseMsg); } catch (Exception e) { e.printStackTrace(); } return true; }
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 {//from www . 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.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.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); ///* w w w. j av 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:TestMapObjInterface.java
public static ArrayList<String> getChunks(String file, String fsName, String cnaddress) throws Exception { ArrayList<String> output = new ArrayList<String>(); File target = new File(file); HttpClient client = new HttpClient(); URI uri = new URI("http://" + cnaddress + ":14149/mproxy/map_obj"); HTTPChunkLocator loc = new HTTPChunkLocator(client, uri); ChunkLocation[] chunks = loc.getChunkLocations(target, fsName); int i = 0;/*from w w w .j av a2 s.co m*/ for (i = 0; i < chunks.length; i++) { StringBuilder b = new StringBuilder(); b.append("[" + i + "] " + chunks[i].getChunkInfo().toString()); b.append(": Filelength " + chunks[i].getFileLength()); StorageNodeInfo[] nodes = chunks[i].getStorageNodeInfo(); int j = 0; for (j = 0; j < nodes.length; j++) { b.append(" <" + j + ">" + nodes[j].toString()); } output.add(b.toString()); } return output; }
From source file:de.mpg.imeji.presentation.metadata.extractors.BasicExtractor.java
public static List<String> extractTechMd(Item item) throws Exception { List<String> techMd = new ArrayList<String>(); URI uri = item.getFullImageUrl(); String imageUrl = uri.toURL().toString(); GetMethod method = new GetMethod(imageUrl); method.setFollowRedirects(false);/*from w w w .j av a 2 s.c o m*/ String userHandle = null; userHandle = LoginHelper.login(PropertyReader.getProperty("imeji.escidoc.user"), PropertyReader.getProperty("imeji.escidoc.password")); method.addRequestHeader("Cookie", "escidocCookie=" + userHandle); HttpClient client = new HttpClient(); client.executeMethod(method); InputStream input = method.getResponseBodyAsStream(); ImageInputStream iis = ImageIO.createImageInputStream(input); Iterator<ImageReader> readers = ImageIO.getImageReaders(iis); if (readers.hasNext()) { // pick the first available ImageReader ImageReader reader = readers.next(); // attach source to the reader reader.setInput(iis, true); // read metadata of first image IIOMetadata metadata = reader.getImageMetadata(0); String[] names = metadata.getMetadataFormatNames(); int length = names.length; for (int i = 0; i < length; i++) { displayMetadata(techMd, metadata.getAsTree(names[i])); } } return techMd; }
From source file:com.ibm.watson.apis.conversation_enhanced.filters.LookUp.java
private HttpClient getHttpClient() { HttpClient client = new HttpClient(); client.getHttpConnectionManager().getParams().setConnectionTimeout(5000); return client; }
From source file:edu.unc.lib.dl.ui.service.XMLRetrievalService.java
public static Document getXMLDocument(String url) throws HttpException, IOException, JDOMException { SAXBuilder builder = new SAXBuilder(); HttpClient client = new HttpClient(); HttpMethod method = new GetMethod(url); method.getParams().setParameter("http.socket.timeout", new Integer(2000)); method.getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES); method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); method.getParams().setParameter("http.useragent", ""); InputStream responseStream = null; Document document = null;/*from w w w.j a v a2s.c o m*/ try { client.executeMethod(method); responseStream = method.getResponseBodyAsStream(); document = builder.build(responseStream); } finally { if (responseStream != null) responseStream.close(); method.releaseConnection(); } return document; }
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 *//*from ww w.j a v a 2 s. co m*/ 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; }