List of usage examples for org.apache.commons.httpclient.methods GetMethod GetMethod
public GetMethod(String uri)
From source file:be.ibridge.kettle.trans.step.http.HTTP.java
private Value callHttpService(Row row) throws KettleException { String url = determineUrl(row); try {/*from w ww . ja v a 2 s . c om*/ logDetailed("Connecting to : [" + url + "]"); // Prepare HTTP get // HttpClient httpclient = new HttpClient(); HttpMethod method = new GetMethod(url); // Execute request // try { int result = httpclient.executeMethod(method); // The status code log.logDebug(toString(), "Response status code: " + result); // the response InputStream inputStream = method.getResponseBodyAsStream(); StringBuffer bodyBuffer = new StringBuffer(); int c; while ((c = inputStream.read()) != -1) bodyBuffer.append((char) c); inputStream.close(); String body = bodyBuffer.toString(); log.logDebug(toString(), "Response body: " + body); return new Value(meta.getFieldName(), body); } finally { // Release current connection to the connection pool once you are done method.releaseConnection(); } } catch (Exception e) { throw new KettleException("Unable to get result from specified URL :" + url, e); } }
From source file:com.predic8.membrane.core.interceptor.balancer.ClusterNotificationInterceptorTest.java
@Test public void testDownEndpoint() throws Exception { GetMethod get = new GetMethod("http://localhost:3002/clustermanager/down?" + createQueryString("host", "node1.clustera", "port", "3018", "cluster", "c1")); assertEquals(204, new HttpClient().executeMethod(get)); assertEquals(1, BalancerUtil.lookupBalancer(router, "Default").getAllNodesByCluster("c1").size()); assertEquals(false,//from w ww . java 2 s . c o m BalancerUtil.lookupBalancer(router, "Default").getAllNodesByCluster("c1").get(0).isUp()); }
From source file:exception.handler.configuration.ExceptionNotHandlerConfigTest.java
@Test public void notHandlerConfiguration() throws HttpException, IOException { HttpClient client = new HttpClient(); GetMethod method = new GetMethod(deploymentUrl + "/index.jsf"); assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, client.executeMethod(method)); }
From source file:gov.nih.nci.cagwas.web.action.RemoteContentHelper.java
/** * getContent will connect to the passed in address and read in the contents and * return them as a String./* w ww . j av a 2 s . c o m*/ * <P> * @param addr The URL address to read the contents from * @return String the contents or null if unable to connect */ private String getContent(String addr) { String responseBody = null; HttpClient client = new HttpClient(); client.getHttpConnectionManager().getParams().setConnectionTimeout(5000); HttpMethod method = new GetMethod(addr); method.setFollowRedirects(true); try { client.executeMethod(method); responseBody = method.getResponseBodyAsString(); } catch (HttpException e) { logger.error("Error connecting to remote site", e); } catch (IOException e) { logger.error("Error connecting to remote site", e); } return responseBody; }
From source file:analysePortalU.AnalysePortalUData.java
public void analyse() throws HttpException, IOException, ParserConfigurationException, SAXException, TransformerException { Map<String, Map<String, String>> resultMap = new HashMap<String, Map<String, String>>(); Scanner in = new Scanner(getClass().getClassLoader().getResourceAsStream("keywords.txt")); while (in.hasNextLine()) { String keyword = URLEncoder.encode(in.nextLine().trim(), "UTF-8"); int currentPage = 1; boolean moreResults = true; while (moreResults) { String url = "http://www.portalu.de/opensearch/query?q=" + keyword.replace(' ', '+') + "+datatype:metadata+ranking:score&h=" + PAGE_SIZE + "&detail=1&ingrid=1&p=" + currentPage; HttpClientParams httpClientParams = new HttpClientParams(); HttpConnectionManager httpConnectionManager = new SimpleHttpConnectionManager(); httpClientParams.setSoTimeout(60 * 1000); httpConnectionManager.getParams().setConnectionTimeout(60 * 1000); httpConnectionManager.getParams().setSoTimeout(60 * 1000); HttpClient client = new HttpClient(httpClientParams, httpConnectionManager); HttpMethod method = new GetMethod(url); // set a request header // this can change in the result of the response since it might // be // interpreted differently // method.addRequestHeader("Accept-Language", language); // //"de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4"); System.out.println("Query: " + url); int status = client.executeMethod(method); if (status == 200) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(method.getResponseBodyAsStream()); XPathUtils xpath = new XPathUtils(new ConfigurableNamespaceContext()); NodeList results = xpath.getNodeList(doc, "/rss/channel/item"); int numberOfResults = results.getLength(); for (int i = 0; i < results.getLength(); i++) { Node node = results.item(i); String fileIdentifier = xpath.getString(node, ".//*/fileIdentifier/CharacterString"); if (!resultMap.containsKey(fileIdentifier)) { resultMap.put(fileIdentifier, new HashMap<String, String>()); }//from w w w .ja v a 2 s. c om Map<String, String> currentMap = resultMap.get(fileIdentifier); currentMap.put("uuid", fileIdentifier); currentMap.put("partner", xpath.getString(node, "partner")); currentMap.put("provider", xpath.getString(node, "provider")); currentMap.put("udk-class", xpath.getString(node, "udk-class")); currentMap.put("source", xpath.getString(node, "source")); currentMap.put("url", new URL(xpath.getString(node, "link")).toString()); currentMap.put("title", xpath.getString(node, ".//*/title/CharacterString")); currentMap.put("description", xpath.getString(node, ".//*/abstract/CharacterString")); Node addressNode = xpath.getNode(node, ".//*/contact/idfResponsibleParty"); String addressString = ""; String tmp = xpath.getString(addressNode, "indiviualName/CharacterString"); if (tmp != null && tmp.length() > 0) addressString += tmp + "\n"; tmp = xpath.getString(addressNode, "organisationName/CharacterString"); if (tmp != null && tmp.length() > 0) addressString += tmp + "\n"; tmp = xpath.getString(addressNode, "contactInfo/CI_Contact/address/CI_Address/deliveryPoint/CharacterString"); if (tmp != null && tmp.length() > 0) addressString += tmp + "\n"; tmp = xpath.getString(addressNode, "contactInfo/CI_Contact/address/CI_Address/postalCode/CharacterString"); if (tmp != null && tmp.length() > 0) addressString += tmp + " "; tmp = xpath.getString(addressNode, "ontactInfo/CI_Contact/address/CI_Address/city/CharacterString"); if (tmp != null && tmp.length() > 0) addressString += tmp + "\n"; tmp = xpath.getString(addressNode, "contactInfo/CI_Contact/address/CI_Address/country/CharacterString"); if (tmp != null && tmp.length() > 0) addressString += tmp + "\n"; tmp = xpath.getString(addressNode, "contactInfo/CI_Contact/address/CI_Address/electronicMailAddress/CharacterString"); if (tmp != null && tmp.length() > 0) addressString += "Email: " + tmp + "\n"; tmp = xpath.getString(addressNode, "contactInfo/CI_Contact/phone/CI_Telephone/voice/CharacterString"); if (tmp != null && tmp.length() > 0) addressString += "Tel: " + tmp + "\n"; tmp = xpath.getString(addressNode, "contactInfo/CI_Contact/phone/CI_Telephone/facsimile/CharacterString"); if (tmp != null && tmp.length() > 0) addressString += "Fax: " + tmp + "\n"; currentMap.put("pointOfContact", addressString); } if (numberOfResults > 0 && numberOfResults >= PAGE_SIZE) { currentPage++; } else { moreResults = false; } } else { moreResults = false; } } } StringWriter sw = new StringWriter(); ExcelCSVPrinter ecsvp = new ExcelCSVPrinter(sw); boolean fieldsWritten = false; for (String key : resultMap.keySet()) { Map<String, String> result = resultMap.get(key); if (!fieldsWritten) { for (String field : result.keySet()) { ecsvp.print(field); } ecsvp.println(""); fieldsWritten = true; } for (String value : result.values()) { ecsvp.print(value); } ecsvp.println(""); } PrintWriter out = new PrintWriter("result.csv"); out.write(sw.toString()); out.close(); in.close(); System.out.println("Done."); }
From source file:net.jadler.JadlerIntegrationTest.java
private void assertExpectedStatus() throws IOException { final HttpClient client = new HttpClient(); final GetMethod method = new GetMethod("http://localhost:" + port() + "/"); assertThat(client.executeMethod(method), is(EXPECTED_STATUS)); }
From source file:com.navercorp.pinpoint.plugin.httpclient3.HttpClientIT.java
@Test public void hostConfig() throws Exception { HttpClient client = new HttpClient(); client.getParams().setConnectionManagerTimeout(CONNECTION_TIMEOUT); client.getParams().setSoTimeout(SO_TIMEOUT); HostConfiguration config = new HostConfiguration(); config.setHost("weather.naver.com", 80, "http"); GetMethod method = new GetMethod("/rgn/cityWetrMain.nhn"); // Provide custom retry handler is necessary method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); method.setQueryString(new NameValuePair[] { new NameValuePair("key2", "value2") }); try {/*from w ww.j a v a 2 s.c o m*/ // Execute the method. client.executeMethod(config, method); } catch (Exception ignored) { } finally { method.releaseConnection(); } PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance(); verifier.printCache(); }
From source file:exception.handler.configuration.compatibility.ExceptionNotHandlerConfigTest.java
@Test public void notHandlerConfiguration() throws HttpException, IOException { HttpClient client = new HttpClient(); GetMethod method = new GetMethod(deploymentUrl + "/index.jsf"); int status = client.executeMethod(method); assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, status); }
From source file:com.zimbra.cs.store.http.HttpStoreManager.java
@Override public InputStream readStreamFromStore(String locator, Mailbox mbox) throws IOException { HttpClient client = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient(); GetMethod get = new GetMethod(getGetUrl(mbox, locator)); int statusCode = HttpClientUtil.executeMethod(client, get); if (statusCode == HttpStatus.SC_OK) { return new UserServlet.HttpInputStream(get); } else {//from w ww .j a va2 s . com get.releaseConnection(); throw new IOException("unexpected return code during blob GET: " + get.getStatusText()); } }
From source file:net.sf.j2ep.servers.ServerStatusChecker.java
/** * Checks all the servers marked as being online * if they still are online./*from w w w . j a va 2s.c om*/ */ @SuppressWarnings("unchecked") private synchronized void checkOnlineServers() { Iterator itr; itr = online.listIterator(); while (itr.hasNext()) { Server server = (Server) itr.next(); String url = getServerURL(server); GetMethod get = new GetMethod(url); get.setFollowRedirects(false); try { httpClient.executeMethod(get); if (!okServerResponse(get.getStatusCode())) { offline.add(server); itr.remove(); log.debug("Server going OFFLINE! " + getServerURL(server)); listener.serverOffline(server); } } catch (Exception e) { offline.add(server); itr.remove(); log.debug("Server going OFFLINE! " + getServerURL(server)); listener.serverOffline(server); } finally { get.releaseConnection(); } } }