List of usage examples for org.apache.commons.httpclient.methods GetMethod GetMethod
public GetMethod(String uri)
From source file:com.knowledgebooks.info_spiders.DBpediaLookupClient.java
public DBpediaLookupClient(String query) throws Exception { this.query = query; //System.out.println("\n query: " + query); HttpClient client = new HttpClient(); String query2 = query.replaceAll(" ", "+"); // URLEncoder.encode(query, "utf-8"); //System.out.println("\n query2: " + query2); HttpMethod method = new GetMethod( "http://lookup.dbpedia.org/api/search.asmx/KeywordSearch?QueryString=" + query2); try {//from w ww.jav a 2 s. co m System.out.println("\n method: " + method.getURI()); client.executeMethod(method); System.out.println(method); InputStream ins = method.getResponseBodyAsStream(); SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser sax = factory.newSAXParser(); sax.parse(ins, this); } catch (HttpException he) { System.err.println("Http error connecting to lookup.dbpedia.org"); } catch (IOException ioe) { System.err.println("Unable to connect to lookup.dbpedia.org"); } method.releaseConnection(); }
From source file:de.l3s.souza.search.DBpediaLookupClient.java
public DBpediaLookupClient(String query) throws Exception { this.query = query; //System.out.println("\n query: " + query); HttpClient client = new HttpClient(); String query2 = query.replaceAll(" ", "+"); // URLEncoder.encode(query, "utf-8"); //System.out.println("\n query2: " + query2); HttpMethod method = new GetMethod( "http://lookup.dbpedia.org/api/search.asmx/KeywordSearch?QueryString=" + query2); try {/*from w ww . j ava 2 s. c o m*/ // System.out.println("\n method: " + method.getURI()); client.executeMethod(method); // System.out.println(method); InputStream ins = method.getResponseBodyAsStream(); SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser sax = factory.newSAXParser(); sax.parse(ins, this); } catch (HttpException he) { System.err.println("Http error connecting to lookup.dbpedia.org"); } catch (IOException ioe) { System.err.println("Unable to connect to lookup.dbpedia.org"); } method.releaseConnection(); }
From source file:com.epam.wilma.gepard.test.interceptor.InterceptorModeSwitch.java
/** * Set interceptor handling mode on/off, based on parameter. * * @param tc is the caller Test Case/*from w w w . jav a 2 s. c o m*/ * @param url to Wilma instance * @return with the response code * @throws Exception in case of problem */ public String switchInterceptorMode(final GepardTestClass tc, final String url) throws Exception { String responseCode; HttpClient httpClient = new HttpClient(); GetMethod httpGet = new GetMethod(url); int statusCode; statusCode = httpClient.executeMethod(httpGet); String onOrOff = url.substring(url.lastIndexOf('/') + 1); if (tc != null) { tc.logStep("Switching interceptor usage mode in Wilma to " + onOrOff); } responseCode = "status code: " + statusCode + "\n"; return responseCode; }
From source file:net.jadler.AbstractJadlerResetIntegrationTest.java
private void assertStatus(int expected) throws IOException { final HttpClient client = new HttpClient(); final GetMethod method = new GetMethod("http://localhost:" + port() + "/"); assertThat(client.executeMethod(method), is(expected)); method.releaseConnection();//from www. j a va 2 s.c o m }
From source file:net.datapipe.CloudStack.CloudStackAPI.java
protected HttpMethod makeHttpGet(LinkedList<NameValuePair> queryValues) throws Exception { String query_signature = sign_request(queryValues); queryValues.add(new NameValuePair("signature", query_signature)); HttpMethod method = new GetMethod(apiURL); method.setFollowRedirects(true);//from w ww . j av a 2 s .c om method.setQueryString(queryValues.toArray(new NameValuePair[0])); return method; }
From source file:com.voa.weixin.task.DownloadFileTask.java
@Override public void run() { generateUrl();//from ww w. j ava 2s . co m HttpClient client = new HttpClient(); GetMethod httpGet = new GetMethod(this.url); WeixinResult result = new WeixinResult(); try { client.executeMethod(httpGet); String contentType = httpGet.getResponseHeader("Content-Type").getValue(); if (contentType.equals("text/plain")) { String json = httpGet.getResponseBodyAsString(); result.setJson(json); } else { fileName = StringUtils.substringBetween(httpGet.getResponseHeader("Content-Type").getValue(), "filename=", "\""); fileLength = Integer.parseInt(httpGet.getResponseHeader("Content-Length").getValue()); result.setErrorCode(0); this.inputStream = httpGet.getResponseBodyAsStream(); } callbackWork(result); } catch (Exception e) { e.printStackTrace(); throw new WorkException("download file error.", e); } finally { if (inputStream != null) try { inputStream.close(); } catch (Exception e) { e.printStackTrace(); } httpGet.releaseConnection(); } }
From source file:com.cordys.cm.uiunit.framework.internal.selenium.GetActiveRCs.java
public String[] execute() { HttpClient client = new HttpClient(); GetMethod getMethod = new GetMethod(this.pathToServlet); try {//from w ww. j av a2s .co m try { if (client.executeMethod(getMethod) == HttpStatus.SC_OK) { InputStream responseBody = getMethod.getResponseBodyAsStream(); String response = convertStreamToString(responseBody); if (!response.equals("")) { //response= response.substring(1, response.length()-1); String[] activeRcs = response.split("\\,"); System.out.println(response + " " + activeRcs.length); return activeRcs; } } } catch (HttpException e) { throw new UIUnitRuntimeException(e); } catch (IOException e) { throw new UIUnitRuntimeException(e); } } finally { getMethod.releaseConnection(); } return null; }
From source file:com.pari.nm.modules.imgmgmt.ImagePropertyCCOHelper.java
private static void populateImagePropertiesFromCCOInternal(SoftwareImage image, String imageName, String url, boolean populateVersion, boolean populatePforms) throws PariException { HttpClient httpClient = new HttpClient(); GetMethod method = new GetMethod(url); method.setFollowRedirects(true);//ww w .j av a 2 s . c om try { httpClient.executeMethod(method); int statuscode = method.getStatusCode(); if (statuscode != HttpStatus.SC_OK) { throw new PariException(-1, "Unable to connect to cisco.com to get image properites for image: " + imageName + " Status: " + method.getStatusText()); } populateImagePropertiesFromHTTPOutput(method.getResponseBodyAsStream(), image, imageName, populateVersion, populatePforms); } catch (PariException pex) { logger.error("Pari Exception while getting image properties for image: " + imageName, pex); throw pex; } catch (Exception ex) { logger.error("Exception while getting image properties for image: " + imageName, ex); throw new PariException(-1, "Error while getting image properties from www.cisco.com for image: " + imageName); } }
From source file:com.buglabs.dragonfly.util.WSHelper.java
protected static String get(String url, String token) throws IOException { HttpClient c = new HttpClient(); GetMethod m = new GetMethod(url); m.setRequestHeader("Cookie", "token=" + token); c.executeMethod(m);//w w w.j a va 2s . co m return m.getResponseBodyAsString(); }
From source file:com.cisco.tbd.stec.client.ServerConnection.java
public static JSONArray pullNewRules(String timeStamp) throws IOException, ParseException { String request = "http://10.154.244.56/stec/get_threats.php?token=weiuyrwerywiuery&exchange=1&from=" + timeStamp;/*from www.j av a 2 s . co m*/ HttpClient client = new HttpClient(); GetMethod method = new GetMethod(request); int statusCode = client.executeMethod(method); InputStream rstream = null; rstream = method.getResponseBodyAsStream(); BufferedReader br = new BufferedReader(new InputStreamReader(rstream)); JSONObject json = (JSONObject) new JSONParser().parse(br.readLine()); //System.out.println(json.toString()); String newTimeStamp = json.get("timestamp").toString(); JSONArray rules = (JSONArray) json.get("data"); br.close(); if (FileUtils.removeFile(Runner.PATH_TO_TIME_STAMP_FILE)) { FileUtils.createFileWithText(Runner.PATH_TO_TIME_STAMP_FILE, newTimeStamp); } return rules; }