List of usage examples for org.apache.commons.httpclient.methods GetMethod GetMethod
public GetMethod(String uri)
From source file:com.amazonaws.sqs.util.SQSClient.java
private HttpMethod sendRequest() throws Exception { prepareHttpRequest();/*from ww w.j a va 2 s.c om*/ HttpMethod method = new GetMethod(getUrl()); HttpClient client = new HttpClient(); client.executeMethod(method); return method; }
From source file:com.itude.mobile.mobbl.server.http.HttpDelegate.java
public HttpResponse connectGet(String url, String userAgent, ArrayList<Cookie> reqCookies, Header[] requestHeaders, boolean followRedirects) { logger.debug("HttpDelegate.connectGet(): " + url); GetMethod get = new GetMethod(url); try {//w w w . j a va 2s .c om prepareConnection(get, userAgent, reqCookies, requestHeaders, !url.contains("acceptxml=false"), followRedirects); if (logger.isDebugEnabled()) HeaderUtil.printRequestHeaders(logger, get); return executeHttpMethod(get); } catch (HttpException e) { logger.error(e.getMessage()); logger.trace(e.getMessage(), e); } catch (IOException e) { logger.error(e.getMessage()); logger.trace(e.getMessage(), e); } finally { get.releaseConnection(); } return null; }
From source file:ie.pars.nlp.sketchengine.interactions.SKEInteractionsBase.java
/** * Create a session id to communicate with the server * * @return//from ww w .java 2 s .co m */ protected HttpClient getSessionID() { String cookie_policy = CookiePolicy.DEFAULT; //use CookiePolicy.BROWSER_COMPATIBILITY in case cookie handling does not work HttpClient client = new HttpClient(); try { Protocol.registerProtocol("https", new Protocol("https", (ProtocolSocketFactory) new EasySSLProtocolSocketFactory(), 443)); client.getHostConfiguration().setHost(rootURL, 80, "http"); client.getParams().setCookiePolicy(cookie_policy); } catch (java.security.GeneralSecurityException | IOException e) { e.printStackTrace(); } client.getParams().setCookiePolicy(cookie_policy); // retrieve session id GetMethod authget = new GetMethod("/login/"); try { int code = client.executeMethod(authget); } catch (IOException ex) { System.err.println("Error: couldn't retrieve session ID from Sketch Engine server."); System.exit(1); } authget.releaseConnection(); return client; }
From source file:com.braindrainpain.docker.DockerRepository.java
/** * Call the Docker API.//w w w . j a va 2s. c o m * * @param packageConfiguration * @return */ private JsonObject allTags(final PackageConfiguration packageConfiguration) { JsonObject result = null; HttpClient client = super.getHttpClient(); String repository = MessageFormat.format(DockerAPI.V1.getUrl(), repositoryConfiguration.get(Constants.REGISTRY).getValue(), packageConfiguration.get(Constants.REPOSITORY).getValue()); try { GetMethod get = new GetMethod(repository); if (client.executeMethod(get) == HttpStatus.SC_OK) { String jsonString = get.getResponseBodyAsString(); LOG.info("RECIEVED: " + jsonString); result = (JsonObject) new JsonParser().parse(jsonString); } } catch (IOException e) { // Wrap into a runtime. There is nothing useful to do here // when this happens. throw new RuntimeException("Cannot fetch the tags from " + repository, e); } return result; }
From source file:com.owncloud.android.lib.resources.users.GetRemoteUserQuotaOperation.java
@Override protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result = null; int status;/* w ww.jav a2s . c om*/ GetMethod get = null; //Get the user try { OwnCloudCredentials credentials = client.getCredentials(); String url = client.getBaseUri() + OCS_ROUTE + credentials.getUsername(); get = new GetMethod(url); get.setQueryString(new NameValuePair[] { new NameValuePair("format", "json") }); get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); status = client.executeMethod(get); if (isSuccess(status)) { String response = get.getResponseBodyAsString(); // Parse the response JSONObject respJSON = new JSONObject(response); JSONObject respOCS = respJSON.getJSONObject(NODE_OCS); JSONObject respData = respOCS.getJSONObject(NODE_DATA); JSONObject quota = respData.getJSONObject(NODE_QUOTA); final Long quotaFree = quota.getLong(NODE_QUOTA_FREE); final Long quotaUsed = quota.getLong(NODE_QUOTA_USED); final Long quotaTotal = quota.getLong(NODE_QUOTA_TOTAL); final Double quotaRelative = quota.getDouble(NODE_QUOTA_RELATIVE); // Result result = new RemoteOperationResult(true, status, get.getResponseHeaders()); //Quota data in data collection ArrayList<Object> data = new ArrayList<Object>(); data.add(new Quota(quotaFree, quotaUsed, quotaTotal, quotaRelative)); result.setData(data); } else { result = new RemoteOperationResult(false, status, get.getResponseHeaders()); String response = get.getResponseBodyAsString(); Log_OC.e(TAG, "Failed response while getting user quota information "); if (response != null) { Log_OC.e(TAG, "*** status code: " + status + " ; response message: " + response); } else { Log_OC.e(TAG, "*** status code: " + status); } } } catch (Exception e) { result = new RemoteOperationResult(e); Log_OC.e(TAG, "Exception while getting OC user information", e); } finally { if (get != null) { get.releaseConnection(); } } return result; }
From source file:eu.alefzero.owncloud.authenticator.ConnectionCheckerRunnable.java
private boolean tryConnection(Uri uri) { WebdavClient wc = new WebdavClient(); wc.allowSelfsignedCertificates();/*from www . j a va 2s. co m*/ GetMethod get = new GetMethod(uri.toString()); boolean retval = false; try { int status = wc.executeMethod(get, TRY_CONNECTION_TIMEOUT); switch (status) { case HttpStatus.SC_OK: { String response = get.getResponseBodyAsString(); JSONObject json = new JSONObject(response); if (!json.getBoolean("installed")) { mLatestResult = ResultType.INSTANCE_NOT_CONFIGURED; break; } mOCVersion = new OwnCloudVersion(json.getString("version")); if (!mOCVersion.isVersionValid()) break; retval = true; break; } case HttpStatus.SC_NOT_FOUND: mLatestResult = ResultType.FILE_NOT_FOUND; break; case HttpStatus.SC_INTERNAL_SERVER_ERROR: mLatestResult = ResultType.INSTANCE_NOT_CONFIGURED; break; default: mLatestResult = ResultType.UNKNOWN_ERROR; Log.e(TAG, "Not handled status received from server: " + status); } } catch (Exception e) { if (e instanceof UnknownHostException || e instanceof ConnectException || e instanceof SocketTimeoutException) { mLatestResult = ResultType.HOST_NOT_AVAILABLE; } else if (e instanceof JSONException) { mLatestResult = ResultType.INSTANCE_NOT_CONFIGURED; } else if (e instanceof SSLHandshakeException) { mLatestResult = ResultType.SSL_INIT_ERROR; } else { mLatestResult = ResultType.UNKNOWN_ERROR; } e.printStackTrace(); } return retval; }
From source file:com.alternatecomputing.jschnizzle.renderer.YUMLRenderer.java
public BufferedImage render(Diagram diagram) { String script = diagram.getScript(); if (script == null) { throw new RendererException("no script defined."); }//w w w . j av a 2s . c om StringTokenizer st = new StringTokenizer(script.trim(), "\n"); StringBuilder buffer = new StringBuilder(); while (st.hasMoreTokens()) { String token = st.nextToken(); if (token.startsWith("#")) { continue; // skip over comments } buffer.append(token.trim()); if (st.hasMoreTokens()) { buffer.append(", "); } } buffer.append(".svg"); String style = diagram.getStyle().getValue(); String baseURL = getBaseURL(); try { HttpClient client = new HttpClient(); String proxyHost = System.getProperty("http.proxyHost"); String proxyPort = System.getProperty("http.proxyPort"); if (StringUtils.isNotBlank(proxyHost) && StringUtils.isNotBlank(proxyPort)) { client.getHostConfiguration().setProxy(proxyHost, Integer.parseInt(proxyPort)); } String postURI = baseURL + "diagram/" + style + "/" + diagram.getType().getUrlModifier() + "/"; LOGGER.debug(postURI); PostMethod postMethod = new PostMethod(postURI); postMethod.addParameter("dsl_text", buffer.toString()); client.executeMethod(postMethod); String svgResourceName = postMethod.getResponseBodyAsString(); postMethod.releaseConnection(); LOGGER.debug(svgResourceName); String getURI = baseURL + svgResourceName; LOGGER.debug(getURI); GetMethod getMethod = new GetMethod(getURI); client.executeMethod(getMethod); String svgContents = getMethod.getResponseBodyAsString(); getMethod.releaseConnection(); LOGGER.debug(svgContents); diagram.setEncodedImage(svgContents); TranscoderInput input = new TranscoderInput(new ByteArrayInputStream(svgContents.getBytes())); BufferedImageTranscoder imageTranscoder = new BufferedImageTranscoder(); imageTranscoder.transcode(input, null); return imageTranscoder.getBufferedImage(); } catch (MalformedURLException e) { throw new RendererException(e); } catch (IOException e) { throw new RendererException(e); } catch (TranscoderException e) { throw new RendererException(e); } }
From source file:com.apatar.core.ApatarHttpClient.java
public String sendGetHttpQuery(String query) throws IOException { GetMethod method = new GetMethod(query); return sendHttpQuery(method); }
From source file:arena.httpclient.commons.JakartaCommonsHttpClient.java
public HttpResponse get() throws IOException { NameValuePair params[] = new NameValuePair[0]; if (this.requestParameters != null) { List<NameValuePair> paramList = new ArrayList<NameValuePair>(); for (String key : this.requestParameters.keySet()) { String[] multipleValues = this.requestParameters.get(key); for (String value : multipleValues) { paramList.add(new NameValuePair(key, value)); }/*from ww w .j av a2 s .co m*/ } params = paramList.toArray(new NameValuePair[paramList.size()]); } HttpMethod method = null; if (this.isPost) { method = new PostMethod(this.url); if (this.encoding != null) { method.getParams().setContentCharset(this.encoding); } ((PostMethod) method).setRequestBody(params); } else { String url = this.url; for (int n = 0; n < params.length; n++) { url = URLUtils.addParamToURL(url, params[n].getName(), params[n].getValue(), this.encoding, false); } method = new GetMethod(url); method.setFollowRedirects(true); if (this.encoding != null) { method.getParams().setContentCharset(this.encoding); } } HttpClient client = new HttpClient(this.manager); if (this.connectTimeout != null) { client.getHttpConnectionManager().getParams().setConnectionTimeout(this.connectTimeout.intValue()); } if (this.readTimeout != null) { client.getHttpConnectionManager().getParams().setSoTimeout(this.readTimeout.intValue()); } client.setState(this.state); try { int statusCode = client.executeMethod(method); return new HttpResponse(getResponseBytes(method), statusCode, buildHeaderMap(method.getResponseHeaders())); } finally { if (method != null) { method.releaseConnection(); } } }
From source file:com.twinsoft.convertigo.engine.PacManager.java
private String downloadPacContent(String url) throws IOException { if (url == null) { Engine.logProxyManager.debug("(PacManager) Invalid PAC script URL: null"); throw new IOException("Invalid PAC script URL: null"); }//w w w . ja va 2s. co m HttpClient client = new HttpClient(); HttpMethod method = new GetMethod(url); int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { throw new IOException("(PacManager) Method failed: " + method.getStatusLine()); } return IOUtils.toString(method.getResponseBodyAsStream(), "UTF-8"); }