List of usage examples for org.apache.commons.httpclient.methods GetMethod GetMethod
public GetMethod(String uri)
From source file:edu.northwestern.bioinformatics.studycalendar.security.plugin.cas.direct.DirectLoginHttpFacade.java
/** * Contacts the CAS server and GETs its login form, returning the content as a string. *//*from ww w . j av a2 s . c om*/ public String getForm() throws IOException { log.trace("GETting {} to obtain login ticket", loginUrl); GetMethod get = initMethod(new GetMethod(loginUrl)); get.setQueryString(new NameValuePair[] { new NameValuePair("service", getServiceUrl()) }); try { httpClient.executeMethod(get); if (get.getStatusCode() == HttpStatus.SC_OK) { return get.getResponseBodyAsString(); } else { throw new CasDirectException("Retrieving the login form %s failed: %s", loginUrl, get.getStatusLine()); } } finally { get.releaseConnection(); } }
From source file:com.voidsearch.voidbase.client.VoidBaseHttpClient.java
public byte[] get(String query) throws Exception { GetMethod method = new GetMethod(query); method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); StringBuilder sb = new StringBuilder(); // TODO : add a content dependent fetch try {//from w ww . ja v a 2 s . co m int statusCode = client.executeMethod(method); if (statusCode == HttpStatus.SC_OK) { InputStreamReader is = new InputStreamReader(method.getResponseBodyAsStream()); BufferedReader in = new BufferedReader(is); String line = null; while ((line = in.readLine()) != null) { sb.append(line); } } } catch (HttpException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { method.releaseConnection(); } return (sb.toString()).getBytes(); }
From source file:com.lyncode.performance.PerformanceRequester.java
public void requestDuration(String url) throws IOException { GetMethod getMethod = new GetMethod(BASE + url); long start = nanoTime() / 1000; // System.out.println("Start: "+start); client.executeMethod(getMethod);/*from w w w .j a va 2s . c o m*/ getMethod.getResponseContentLength(); long end = nanoTime() / 1000; // System.out.println("End: "+end); long value = end - start; measurements.add(value); System.err.println(value); }
From source file:net.bioclipse.cir.business.CirManager.java
public ICDKMolecule getByName(String name) throws BioclipseException { HttpClient client = new HttpClient(); String fullURL = SERVICE + name + "/sdf"; System.out.println(("URL: " + fullURL)); GetMethod method = new GetMethod(fullURL); addMethodHeaders(method, new HashMap<String, String>() { {//from ww w. j a v a 2 s. co m put("Accept", "text/plain"); } }); try { client.executeMethod(method); String content = method.getResponseBodyAsString(); if (content.contains("http://www.w3.org/1999/xhtml")) { throw new BioclipseException("HTML page returned: probably multiple search hits"); } InputStream reader = method.getResponseBodyAsStream(); return cdk.loadMolecule(reader, (IChemFormat) MDLV2000Format.getInstance(), null, null); } catch (HttpException exception) { throw new BioclipseException("Error while accessing CIR: " + exception.getMessage(), exception); } catch (IOException exception) { throw new BioclipseException("Error while reading the CIR response: " + exception.getMessage(), exception); } }
From source file:documentToVector.spotlight.evaluation.external.DBpediaSpotlightClient.java
@Override public List<DBpediaResource> extract(Text text) throws AnnotationException { LOG.info("Querying API."); String spotlightResponse;//from w w w . j av a 2s. c o m try { GetMethod getMethod = new GetMethod(API_URL + "rest/annotate/?" + "confidence=" + CONFIDENCE + "&support=" + SUPPORT + "&text=" + URLEncoder.encode(text.text(), "utf-8")); getMethod.addRequestHeader(new Header("Accept", "application/json")); spotlightResponse = request(getMethod); } catch (UnsupportedEncodingException e) { throw new AnnotationException("Could not encode text.", e); } assert spotlightResponse != null; JSONObject resultJSON = null; JSONArray entities = null; try { resultJSON = new JSONObject(spotlightResponse); entities = resultJSON.getJSONArray("Resources"); } catch (JSONException e) { throw new AnnotationException("Received invalid response from DBpedia Spotlight API."); } LinkedList<DBpediaResource> resources = new LinkedList<DBpediaResource>(); for (int i = 0; i < entities.length(); i++) { try { JSONObject entity = entities.getJSONObject(i); resources.add(new DBpediaResource(entity.getString("@URI"), Integer.parseInt(entity.getString("@support"))) ); } catch (JSONException e) { LOG.error("JSON exception " + e); } } return resources; }
From source file:com.predic8.membrane.core.interceptor.UserFeatureTest.java
private void callService(String s) throws HttpException, IOException { HttpClient httpClient = new HttpClient(); httpClient.executeMethod(new GetMethod("http://localhost:3030/" + s + "/")); httpClient.getHttpConnectionManager().closeIdleConnections(0); }
From source file:net.sourceforge.jwbf.actions.mw.util.GetEnvironmentVars.java
/** * //from ww w . ja va 2 s.c om * @param name of article * @param tab ref on a tabel with inner values * @param login a */ public GetEnvironmentVars(final String name, Hashtable<String, String> tab, LoginData login) { String uS = ""; this.tab = tab; try { uS = "/index.php?title=" + URLEncoder.encode(name, MediaWikiBot.CHARSET) + "&action=edit&dontcountme=s"; } catch (UnsupportedEncodingException e) { e.printStackTrace(); } msgs.add(new GetMethod(uS)); }
From source file:net.neurowork.cenatic.centraldir.workers.xml.XmlTokenImporter.java
public String getXmlToken() { String token = null;// w ww. java 2 s. c o m HttpClient httpclient = XMLRestWorker.getHttpClient(); GetMethod get = new GetMethod(restUrl.getTokenUrl()); get.addRequestHeader("Accept", "application/xml"); NameValuePair userParam = new NameValuePair(XMLRestWorker.USERNAME_PARAM, satelite.getUser()); NameValuePair passwordParam = new NameValuePair(XMLRestWorker.PASSWORD_PARAM, satelite.getPassword()); NameValuePair[] params = new NameValuePair[] { userParam, passwordParam }; get.setQueryString(params); try { int statusCode = httpclient.executeMethod(get); if (statusCode != HttpStatus.SC_OK) { logger.error("Method failed: " + get.getStatusLine()); } token = XMLRestWorker.parseToken(get.getResponseBodyAsString()); } catch (HttpException e) { logger.error(e.getMessage()); } catch (IOException e) { logger.error(e.getMessage()); } catch (ParserConfigurationException e) { logger.error(e.getMessage()); } catch (SAXException e) { logger.error(e.getMessage()); } finally { get.releaseConnection(); } return token; }
From source file:com.connexience.server.workflow.service.clients.DataProcessorDataSourceHttpClient.java
/** Get hold of a piece of input data */ public InputStream getInputDataStream(String invocationId, String contextId, String inputName) throws DataProcessorException { HttpClient client = new HttpClient(); GetMethod method = new GetMethod(baseUrl); method.getParams().setParameter("invocationid", invocationId); method.getParams().setParameter("contextid", contextId); method.getParams().setParameter("inputname", inputName); try {/* ww w . j a v a 2 s .c o m*/ client.executeMethod(method); return method.getResponseBodyAsStream(); } catch (Exception e) { throw new DataProcessorException("Error getting data stream: " + e.getMessage()); } }