List of usage examples for org.apache.commons.httpclient.methods GetMethod GetMethod
public GetMethod(String uri)
From source file:com.bt.aloha.batchtest.v2.scenarios.CreateCallTerminateCallScenario.java
public void run(String scenarioId) { HttpClient httpClient = new HttpClient(); String makeCallAddress = String.format("http://%s/SpringRing/makeCall?caller=%s&callee=%s", getHttpEndpoint(), getTestEndpoint(), getTestEndpoint()); HttpMethod makeCallMethod = new GetMethod(makeCallAddress); ScenarioRunResult runResult = new ScenarioRunResult(scenarioId, this.getName()); try {//from w w w. j a va2 s . c om log.debug("Executing GET on " + makeCallAddress); acquireSyncSemaphore(); int result = httpClient.executeMethod(makeCallMethod); log.debug("GET returned " + result); if (result != 200) { runResult.setResult(false, String.format("HTTP %d received from host when calling makeCall", result)); log.error(makeCallMethod.getResponseBodyAsString()); } else { String resultString = makeCallMethod.getResponseBodyAsString(); Properties makeCallResult = new Properties(); makeCallResult.load(new ByteArrayInputStream(resultString.getBytes())); String callId = makeCallResult.getProperty("callid", null); log.debug("result from makeCall " + callId); String terminateCallAddress = "http://%s/SpringRing/terminateCall?callid=%s"; HttpMethod terminateCallMethod = new GetMethod( String.format(terminateCallAddress, getHttpEndpoint(), callId)); result = httpClient.executeMethod(terminateCallMethod); resultString = terminateCallMethod.getResponseBodyAsString(); Properties terminateCallResult = new Properties(); terminateCallResult.load(new ByteArrayInputStream(resultString.getBytes())); log.debug("result from terminateCall " + result); if (result != 200) { runResult.setResult(false, String.format("HTTP %d received from host when calling terminateCall", result)); log.error(terminateCallMethod.getResponseBodyAsString()); } else { String makeLocalHostName = makeCallResult.getProperty("local.host.name"); String termLocalHostName = terminateCallResult.getProperty("local.host.name"); Map<String, String> data = new HashMap<String, String>(); data.put("make", makeLocalHostName); data.put("terminate", termLocalHostName); runResult.setResult(true, "OK", data); } } } catch (Throwable e) { e.printStackTrace(); runResult.setResult(false, String.format("Exception %s", e.getMessage())); } finally { publishResultOnScenarioComplete(runResult); } }
From source file:net.servicefixture.fitnesse.TestRunner.java
private void executeTest(String[] args) throws IOException { parseArgs(args);//from www . jav a 2s . c o m baseUrl = "http://" + host + ":" + port + "/"; testUrl = baseUrl + page + "?" + testType; GetMethod get = new GetMethod(testUrl); try { HttpClient client = new HttpClient(); int status; try { verbose("Executing fitnesse test: " + testUrl); status = client.executeMethod(get); } catch (Exception e) { throw new RuntimeException("Unable to execute fitnesse test:" + testUrl, e); } if (status != -1) { String response = get.getResponseBodyAsString(); printTestSummary(response); writeToResultHtmlFile(response); verbose("Fitnesse test completed successfully."); } else { throw new RuntimeException( "Unable to execute fitnesse test:" + testUrl + ", httpclient status:" + status); } } finally { get.releaseConnection(); } }
From source file:cn.edu.seu.herald.ws.api.impl.RequestGetMethodFactoryImpl.java
@Override public GetMethod newCsvRequestGetMethod(URI uri) { GetMethod getMethod = new GetMethod(uri.toASCIIString()); getMethod.setRequestHeader(HTTP_HEADER_ACCEPT, MEDIA_TYPE_TEXT_CSV); return getMethod; }
From source file:com.predic8.membrane.core.interceptor.InternalInvocationTest.java
private void callService(int port) throws HttpException, IOException { new HttpClient().executeMethod(new GetMethod("http://localhost:" + port)); }
From source file:com.bigrocksoftware.metarparser.MetarFetcher.java
public static String fetch(String station, int timeout) { metarData = null;/* w w w. jav a 2 s . c o m*/ // create the http client HttpClient client = new HttpClient(); // set the timeout is specified if (timeout != 0) { log.debug("MetarFetch: setting timeout to '" + timeout + "' milliseconds"); long start = System.currentTimeMillis(); client.setConnectionTimeout(timeout); long end = System.currentTimeMillis(); if (end - start < timeout) { client.setTimeout((int) (end - start)); } else { return null; } } // create the http method we will use HttpMethod method = new GetMethod(httpMetarURL + station + ".TXT"); // connect to the NOAA site, retrying up to the specified num int statusCode = -1; //for (int attempt = 0; statusCode == -1 && attempt < 3; attempt++) { try { // execute the get method log.debug("MetarFetcher: downloading data for station '" + station + "'"); statusCode = client.executeMethod(method); } catch (HttpRecoverableException e) { log.error("a recoverable exception occurred, " + "retrying." + e.getMessage()); } catch (IOException e) { log.error("failed to download file: " + e); } //} // check that we didn't run out of retries if (statusCode != HttpStatus.SC_OK) { log.error("failed to download station data for '" + station + "'"); return null; } else { // read the response body byte[] responseBody = method.getResponseBody(); // release the connection method.releaseConnection(); // deal with the response. // FIXME - ensure we use the correct character encoding here metarData = new String(responseBody) + "\n"; log.debug("MetarFetcher: metar data: " + metarData); } return metarData; }
From source file:com.zimbra.cs.index.ElasticSearchIndexTest.java
@Override protected boolean indexStoreAvailable() { String indexUrl = String.format("%s?_status", LC.zimbra_index_elasticsearch_url_base.value()); HttpMethod method = new GetMethod(indexUrl); try {/* w w w. j a va 2 s . com*/ ElasticSearchConnector connector = new ElasticSearchConnector(); connector.executeMethod(method); } catch (HttpException e) { ZimbraLog.index.error("Problem accessing the ElasticSearch Index store", e); return false; } catch (IOException e) { ZimbraLog.index.error("Problem accessing the ElasticSearch Index store", e); return false; } return true; }
From source file:com.atlassian.theplugin.util.InfoServer.java
protected static VersionInfo getLatestPluginVersion(final String serviceUrl, final UsageStatisticsGenerator usageStatisticsGenerator) throws VersionServiceException, IncorrectVersionException { String getMethodUrl = serviceUrl; try {// w w w.java2 s.c o m HttpClient client; try { client = HttpClientFactory.getClient(); } catch (HttpProxySettingsException e) { throw new VersionServiceException("Connection error while retrieving the latest plugin version.", e); } if (usageStatisticsGenerator != null) { getMethodUrl += "?" + usageStatisticsGenerator.getStatisticsUrlSuffix(); } GetMethod method = new GetMethod(getMethodUrl); try { client.executeMethod(method); } catch (IllegalArgumentException e) { throw new VersionServiceException("Connection error while retrieving the latest plugin version.", e); } InputStream is = method.getResponseBodyAsStream(); SAXBuilder builder = new SAXBuilder(); builder.setValidation(false); Document doc = builder.build(is); return new VersionInfo(doc); } catch (InvalidCredentialsException e) { throw new VersionServiceException("Connection error while retrieving the latest plugin version.", e); } catch (IOException e) { throw new VersionServiceException("Connection error while retrieving the latest plugin version.", e); } catch (JDOMException e) { throw new VersionServiceException( "Error while parsing xml response from version service server at " + getMethodUrl, e); } }
From source file:com.discursive.jccook.httpclient.ConditionalGetExample.java
public void start() throws HttpException, IOException { HttpClient client = new HttpClient(); HttpMethod method = new GetMethod("http://www.apache.org"); for (int i = 0; i < 3; i++) { setHeaders(method);/*from w ww . ja v a2 s . c om*/ client.executeMethod(method); processResults(method); method.releaseConnection(); method.recycle(); } }
From source file:de.intranda.goobi.plugins.utils.SRUClient.java
/** * Queries the given catalog via Z.3950 (SRU) and returns its response. * // ww w. j a va2s. c o m * @param cat The catalog to query. * @param query The query. * @param recordSchema The expected record schema. * @return Query result XML string. */ public static String querySRU(ConfigOpacCatalogue cat, String query, String recordSchema) { String ret = null; if (query != null && !query.isEmpty()) { query = query.trim(); } if (cat != null) { String url = "http://"; url += cat.getAddress(); url += ":" + cat.getPort(); url += "/" + cat.getDatabase(); url += "?version=1.1"; url += "&operation=searchRetrieve"; url += "&query=" + query; url += "&maximumRecords=5"; url += "&recordSchema=" + recordSchema; logger.debug("SRU URL: " + url); HttpClient client = new HttpClient(); GetMethod method = new GetMethod(url); try { client.executeMethod(method); ret = method.getResponseBodyAsString(); if (!method.getResponseCharSet().equalsIgnoreCase(ENCODING)) { // If response XML is not UTF-8, re-encode ret = convertStringEncoding(ret, method.getResponseCharSet(), ENCODING); } } catch (HttpException e) { logger.error(e.getMessage(), e); } catch (IOException e) { logger.error(e.getMessage(), e); } finally { method.releaseConnection(); } } return ret; }
From source file:com.predic8.membrane.core.interceptor.rest.REST2SOAPInterceptorIntegrationTest.java
@Test public void testRest() throws Exception { HttpClient client = new HttpClient(); client.getParams().setParameter(HttpProtocolParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); GetMethod get = new GetMethod("http://localhost:3004/bank/37050198"); int status = client.executeMethod(get); //System.out.println(get.getResponseBodyAsString()); assertEquals(200, status);/*w w w . j a v a 2 s . c o m*/ }