List of usage examples for org.apache.commons.httpclient.methods GetMethod GetMethod
public GetMethod(String uri)
From source file:info.jtrac.mylyn.JtracClient.java
private String doGet(String url) throws Exception { HttpMethod get = new GetMethod(url); String response = null;//from w w w.j a v a2s . c om int code; try { code = httpClient.executeMethod(get); if (code != HttpURLConnection.HTTP_OK) { throw new HttpException("HTTP Response Code: " + code); } response = get.getResponseBodyAsString(); } finally { get.releaseConnection(); } return response; }
From source file:demo.jaxrs.search.client.Client.java
private static void search(final String url, final HttpClient httpClient, final String expression) throws IOException, HttpException { System.out.println("Sent HTTP GET request to search the books in catalog: " + expression); final GetMethod get = new GetMethod(url + "/search"); get.setQueryString("$filter=" + expression); try {/*from w w w .ja va 2s .c o m*/ int status = httpClient.executeMethod(get); if (status == 200) { System.out.println(get.getResponseBodyAsString()); } } finally { get.releaseConnection(); } }
From source file:eu.europeana.sip.licensing.network.LicenseServiceImpl.java
@Override public CreativeCommonsModel retrieveStandardLicenseSet() throws IOException { LOG.info(String.format("Sending request to server")); GetMethod getMethod = new GetMethod(CC_STANDARD); int result = httpClient.executeMethod(getMethod); XStream xStream = new XStream(new DomDriver()); // todo: do we need a domdriver? xStream.setClassLoader(CustomClassLoader.getInstance()); xStream.processAnnotations(CreativeCommonsModel.class); LOG.info(String.format("Got response from server : %d%n%s", result, getMethod.getResponseBodyAsString())); return (CreativeCommonsModel) xStream.fromXML(getMethod.getResponseBodyAsString()); }
From source file:com.fatwire.dta.sscrawler.UrlRenderingCallable.java
public ResultPage call() throws Exception { if (log.isDebugEnabled()) { log.debug("downloading " + uri); }//from w w w . ja v a 2 s. c om final long startTime = System.currentTimeMillis(); final ResultPage page = new ResultPage(qs); final GetMethod httpGet = new GetMethod(uri); httpGet.setFollowRedirects(true); try { final int responseCode = httpClientService.get().executeMethod(httpGet); page.setResponseCode(responseCode); // log.info(iGetResultCode); page.setResponseHeaders(httpGet.getResponseHeaders()); if (responseCode == 200) { final String charSet = httpGet.getResponseCharSet(); // log.info(charSet); final InputStream in = httpGet.getResponseBodyAsStream(); if (in != null) { final Reader reader = new InputStreamReader(in, Charset.forName(charSet)); final String responseBody = copy(reader); in.close(); page.setReadTime(System.currentTimeMillis() - startTime); if (responseBody != null) { if (log.isTraceEnabled()) { log.trace(responseBody); } page.setBody(responseBody); } } } else { page.setReadTime(System.currentTimeMillis() - startTime); log.error("reponse code is " + responseCode + " for " + httpGet.getURI().toString()); } } catch (final Exception e) { httpGet.abort(); throw e; } finally { httpGet.releaseConnection(); } return page; }
From source file:mupomat.utility.LongLatService.java
public void getLongitudeLatitude(String address) { try {/*from ww w . j a va 2s . c o m*/ StringBuilder urlBuilder = new StringBuilder(GEOCODE_REQUEST_URL); if (StringUtils.isNotBlank(address)) { urlBuilder.append("&address=").append(URLEncoder.encode(address, "UTF-8")); } final GetMethod getMethod = new GetMethod(urlBuilder.toString()); try { httpClient.executeMethod(getMethod); Reader reader = new InputStreamReader(getMethod.getResponseBodyAsStream(), getMethod.getResponseCharSet()); int data = reader.read(); char[] buffer = new char[1024]; Writer writer = new StringWriter(); while ((data = reader.read(buffer)) != -1) { writer.write(buffer, 0, data); } String result = writer.toString(); System.out.println(result.toString()); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader("<" + writer.toString().trim())); Document doc = db.parse(is); strLatitude = getXpathValue(doc, "//GeocodeResponse/result/geometry/location/lat/text()"); System.out.println("Latitude:" + strLatitude); strLongtitude = getXpathValue(doc, "//GeocodeResponse/result/geometry/location/lng/text()"); System.out.println("Longitude:" + strLongtitude); } finally { getMethod.releaseConnection(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.tw.go.plugin.material.artifactrepository.yum.exec.HttpConnectionChecker.java
GetMethod getGetMethod(String url) {
return new GetMethod(url);
}
From source file:com.sun.syndication.propono.blogclient.metaweblog.MetaWeblogResource.java
/** * Get media resource as input stream./*from w w w . ja v a2s .c om*/ */ public InputStream getAsStream() throws BlogClientException { HttpClient httpClient = new HttpClient(); GetMethod method = new GetMethod(permalink); try { httpClient.executeMethod(method); } catch (Exception e) { throw new BlogClientException("ERROR: error reading file", e); } if (method.getStatusCode() != 200) { throw new BlogClientException("ERROR HTTP status=" + method.getStatusCode()); } try { return method.getResponseBodyAsStream(); } catch (Exception e) { throw new BlogClientException("ERROR: error reading file", e); } }
From source file:at.ac.tuwien.auto.sewoa.http.HttpRetrieverImpl.java
public byte[] retrieveData(String url) { byte[] result = new byte[] {}; HttpClient httpClient = httpClientFactory.createClient(); GetMethod getMethod = new GetMethod(url); HttpConnectionManagerParams params = httpClient.getHttpConnectionManager().getParams(); params.setConnectionTimeout((int) TimeUnit.SECONDS.toMillis(CONNECTION_TO)); params.setSoTimeout((int) TimeUnit.SECONDS.toMillis(SOCKET_TO)); getMethod.addRequestHeader("Content-Type", "application/xml"); getMethod.addRequestHeader("Accept", "application/xml"); try {/*from w ww . j a v a 2s . c om*/ result = send(httpClient, getMethod); } catch (Exception e) { e.printStackTrace(); } return result; }
From source file:com.owncloud.android.operations.OwnCloudServerCheckOperation.java
private boolean tryConnection(WebdavClient wc, String urlSt) { boolean retval = false; GetMethod get = null;//from w w w .j ava 2 s. c o m try { get = new GetMethod(urlSt); int status = wc.executeMethod(get, TRY_CONNECTION_TIMEOUT, TRY_CONNECTION_TIMEOUT); String response = get.getResponseBodyAsString(); if (status == HttpStatus.SC_OK) { JSONObject json = new JSONObject(response); if (!json.getBoolean("installed")) { mLatestResult = new RemoteOperationResult( RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED); } else { mOCVersion = new OwnCloudVersion(json.getString("version")); if (!mOCVersion.isVersionValid()) { mLatestResult = new RemoteOperationResult(RemoteOperationResult.ResultCode.BAD_OC_VERSION); } else { mLatestResult = new RemoteOperationResult( urlSt.startsWith("https://") ? RemoteOperationResult.ResultCode.OK_SSL : RemoteOperationResult.ResultCode.OK_NO_SSL); retval = true; } } } else { mLatestResult = new RemoteOperationResult(false, status); } } catch (JSONException e) { mLatestResult = new RemoteOperationResult(RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED); } catch (Exception e) { mLatestResult = new RemoteOperationResult(e); } finally { if (get != null) get.releaseConnection(); } if (mLatestResult.isSuccess()) { Log_OC.i(TAG, "Connection check at " + urlSt + ": " + mLatestResult.getLogMessage()); } else if (mLatestResult.getException() != null) { Log_OC.e(TAG, "Connection check at " + urlSt + ": " + mLatestResult.getLogMessage(), mLatestResult.getException()); } else { Log_OC.e(TAG, "Connection check at " + urlSt + ": " + mLatestResult.getLogMessage()); } return retval; }
From source file:com.kagilum.plugins.icescrum.IceScrumSession.java
public boolean isConnect() { GetMethod method = new GetMethod(settings.getUrl() + "/version/"); if (executeMethod(method)) { try {/*from ww w . j a va2 s. c o m*/ String version = body; if (version.isEmpty()) { throw new IOException(Messages.IceScrumSession_icescrum_http_notfound()); } if (version.startsWith("7.")) { method = new GetMethod(settings.getUrl() + "/ws/p/" + settings.getPkey() + "/build"); return executeMethod(method, 200); } else { //Only Pro version contains build business object if (!version.contains("Pro")) { throw new IOException(Messages.IceScrumSession_only_pro_version()); } //Got R6#5.1 Pro (Cloud) -> 6.51 in order to compare float version = version.replaceAll(" Pro", "").replaceAll(" Cloud", "").replaceAll("R", "") .replaceAll("\\.", "").replaceAll("#", "."); if (version.length() == 3) { version = version.replaceAll("\\.", ".0"); } if (Float.parseFloat(version) < REQUIRED_VERSION) { throw new IOException(Messages.IceScrumSession_not_compatible_version()); } method = new GetMethod(settings.getUrl() + "/ws/p/" + settings.getPkey() + "/task"); return executeMethod(method); } } catch (IOException e) { httpError = e.getMessage(); } } return false; }