Example usage for org.apache.commons.httpclient.methods GetMethod GetMethod

List of usage examples for org.apache.commons.httpclient.methods GetMethod GetMethod

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.methods GetMethod GetMethod.

Prototype

public GetMethod(String uri) 

Source Link

Usage

From source file:com.mycompany.neo4jprotein.neoStart.java

static public int getServerStatus() {
    int status = 500;
    try {/*from   w  ww  .j  ava 2 s  .  c o m*/

        HttpClient client = new HttpClient();
        GetMethod mGet = new GetMethod(SERVER_ROOT_URI);
        status = client.executeMethod(mGet);
        mGet.releaseConnection();
    } catch (Exception e) {
        System.out.println("Exception in connecting to neo4j : " + e);
    }

    return status;
}

From source file:cz.muni.fi.pa165.creatures.rest.client.services.impl.RegionCRUDServiceImpl.java

@Override
public void getById(Long id) {
    GetMethod getMethod = new GetMethod(uri + "/" + id);
    CRUDServiceHelper.send(getMethod);
}

From source file:net.adamcin.granite.client.packman.http3.Http3PackageManagerClient.java

@Override
protected Either<? extends Exception, Boolean> checkServiceAvailability(final boolean checkTimeout,
        final long timeoutRemaining) {

    final GetMethod request = new GetMethod(getJsonUrl());
    final int oldTimeout = getClient().getHttpConnectionManager().getParams().getConnectionTimeout();
    if (checkTimeout) {
        getClient().getHttpConnectionManager().getParams().setConnectionTimeout((int) timeoutRemaining);
        request.getParams().setSoTimeout((int) timeoutRemaining);
    }//from  w w  w .  j ava  2 s . co  m

    try {
        int status = getClient().executeMethod(request);

        if (status == 401) {
            return left(new UnauthorizedException("401 Unauthorized"), Boolean.class);
        } else {
            return right(Exception.class, status == 405);
        }
    } catch (IOException e) {
        return left(e, Boolean.class);
    } finally {
        request.releaseConnection();
        if (checkTimeout) {
            getClient().getHttpConnectionManager().getParams().setConnectionTimeout(oldTimeout);
        }
    }
}

From source file:exception.handler.configuration.compatibility.ExceptionHandlerRedirectConfigTest.java

@Test
public void notHandlerConfiguration() throws HttpException, IOException {
    HttpClient client = new HttpClient();
    GetMethod method = new GetMethod(deploymentUrl + "/index.jsf");

    client.executeMethod(method);/*ww  w. j  a v  a  2 s . co  m*/
    String message = method.getResponseBodyAsString();
    assertTrue(message.contains("Called the page /error_page"));
}

From source file:com.panet.imeta.trans.steps.http.HTTP.java

private Object[] callHttpService(RowMetaInterface rowMeta, Object[] rowData) throws KettleException {
    String url = determineUrl(rowMeta, rowData);
    try {/*  w w  w.jav a 2s.co  m*/
        if (log.isDetailed())
            logDetailed(Messages.getString("HTTP.Log.Connecting", url));

        // Prepare HTTP get
        // 
        HttpClient httpclient = new HttpClient();
        HttpMethod method = new GetMethod(environmentSubstitute(url));

        // Execute request
        // 
        try {
            int result = httpclient.executeMethod(method);

            // The status code
            if (log.isDebug())
                log.logDebug(toString(), Messages.getString("HTTP.Log.ResponseStatusCode", "" + result));

            // the response
            InputStream inputStream = method.getResponseBodyAsStream();
            StringBuffer bodyBuffer = new StringBuffer();
            int c;
            while ((c = inputStream.read()) != -1)
                bodyBuffer.append((char) c);
            inputStream.close();

            String body = bodyBuffer.toString();
            if (log.isDebug())
                log.logDebug(toString(), "Response body: " + body);

            return RowDataUtil.addValueData(rowData, rowMeta.size(), body);
        } finally {
            // Release current connection to the connection pool once you are done
            method.releaseConnection();
        }
    } catch (Exception e) {
        throw new KettleException(Messages.getString("HTTP.Log.UnableGetResult", url), e);
    }
}

From source file:com.epam.wilma.service.http.WilmaHttpClient.java

/**
 * Calls the given URL via HTTP GET method and returns {@code true} if the
 * request was successful./*  w  w w  .  j a  v a 2 s  .co  m*/
 *
 * @param url the given URL
 * @return {@code true} if the request is successful, otherwise return {@code false}
 */
public boolean sendSetterRequest(final String url) {
    boolean requestSuccessful;

    GetMethod method = new GetMethod(url);
    requestSuccessful = executeCall(method, url);
    method.releaseConnection();

    return requestSuccessful;
}

From source file:net.sf.ehcache.constructs.web.filter.GzipFilterTest.java

/**
 * A 0 length body should give a 0 length gzip body and content length
 * <p/>//w  w  w  .  j  a  v  a2 s  . c om
 * Manual test: wget -d --server-response --timestamping --header='If-modified-Since: Fri, 13 May 3006 23:54:18 GMT' --header='Accept-Encoding: gzip' http://localhost:9080/empty_gzip/empty.html
 */
public void testZeroLengthHTML() throws Exception {

    String url = "http://localhost:9080/empty_gzip/empty.html";
    HttpClient httpClient = new HttpClient();
    HttpMethod httpMethod = new GetMethod(url);
    httpMethod.addRequestHeader("If-modified-Since", "Fri, 13 May 3006 23:54:18 GMT");
    httpMethod.addRequestHeader("Accept-Encoding", "gzip");
    int responseCode = httpClient.executeMethod(httpMethod);
    assertEquals(HttpURLConnection.HTTP_NOT_MODIFIED, responseCode);
    byte[] responseBody = httpMethod.getResponseBody();
    assertEquals(null, responseBody);
    assertNull(httpMethod.getResponseHeader("Content-Encoding"));
    checkNullOrZeroContentLength(httpMethod);
}

From source file:com.owncloud.activity.Downloader.java

public void downloadFile(Intent i) {
    if (isOnline()) {
        String url = i.getData().toString();
        GetMethod gm = new GetMethod(url);

        try {/*from ww  w  . j av a 2s. c  o m*/
            int status = BaseActivity.httpClient.executeMethod(gm);
            //            Toast.makeText(getApplicationContext(), String.valueOf(status),2).show();
            Log.e("HttpStatus", "==============>" + String.valueOf(status));
            if (status == HttpStatus.SC_OK) {
                InputStream input = gm.getResponseBodyAsStream();

                String fileName = new StringBuffer(url).reverse().toString();
                String[] fileNameArray = fileName.split("/");
                fileName = new StringBuffer(fileNameArray[0]).reverse().toString();

                fileName = URLDecoder.decode(fileName);
                File folder = new File(BaseActivity.mDownloadDest);
                boolean success = false;
                if (!folder.exists()) {
                    success = folder.mkdir();
                }
                if (!success) {
                    // Do something on success
                    File file = new File(BaseActivity.mDownloadDest, fileName);
                    OutputStream fOut = new FileOutputStream(file);

                    int byteCount = 0;
                    byte[] buffer = new byte[4096];
                    int bytesRead = -1;

                    while ((bytesRead = input.read(buffer)) != -1) {
                        fOut.write(buffer, 0, bytesRead);
                        byteCount += bytesRead;
                        //                     DashBoardActivity.updateNotation();
                    }

                    fOut.flush();
                    fOut.close();
                } else {
                    // Do something else on failure
                    Log.d("Download Prob..", String.valueOf(success) + ", Some problem in folder creating");
                }

            }
        } catch (HttpException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        gm.releaseConnection();

        Bundle extras = i.getExtras();

        if (extras != null) {
            Messenger messenger = (Messenger) extras.get(EXTRA_MESSENGER);
            Message msg = Message.obtain();

            msg.arg1 = Activity.RESULT_OK;

            try {
                messenger.send(msg);
            } catch (android.os.RemoteException e1) {
                Log.w(getClass().getName(), "Exception sending message", e1);
            }
        }
    } else {
        WebNetworkAlert();
    }
}

From source file:net.bioclipse.opentox.api.Dataset.java

@SuppressWarnings("serial")
public static List<String> getCompoundList(String datasetURI) throws IOException {
    HttpClient client = new HttpClient();
    datasetURI = normalizeURI(datasetURI);
    GetMethod method = new GetMethod(datasetURI + "compounds");
    HttpMethodHelper.addMethodHeaders(method, new HashMap<String, String>() {
        {/* ww w. j a v a  2s.c om*/
            put("Accept", "text/uri-list");
        }
    });
    client.executeMethod(method);
    List<String> compounds = new ArrayList<String>();
    BufferedReader reader = new BufferedReader(new StringReader(method.getResponseBodyAsString()));
    String line;
    while ((line = reader.readLine()) != null) {
        line = line.trim();
        if (line.length() > 0)
            compounds.add(line);
    }
    reader.close();
    method.releaseConnection();
    return compounds;
}

From source file:com.intellij.plugins.firstspirit.languagesupport.FirstSpiritClassPathHack.java

public void addFirstSpiritClientJar(UrlClassLoader classLoader, HttpScheme schema, String serverName, int port,
        String firstSpiritUserName, String firstSpiritUserPassword) throws Exception {
    System.out.println("starting to download fs-client.jar");

    String resolvalbleAddress = null;

    // asking DNS for IP Address, if some error occur choose the given value from user
    try {/*from   w w  w  .  j a  v a2  s .  com*/
        InetAddress address = InetAddress.getByName(serverName);
        resolvalbleAddress = address.getHostAddress();
        System.out.println("Resolved address: " + resolvalbleAddress);
    } catch (Exception e) {
        System.err.println("DNS cannot resolve address, using your given value: " + serverName);
        resolvalbleAddress = serverName;
    }

    String uri = schema + "://" + resolvalbleAddress + ":" + port + "/clientjar/fs-client.jar";
    String versionUri = schema + "://" + resolvalbleAddress + ":" + port + "/version.txt";
    String tempDirectory = System.getProperty("java.io.tmpdir");

    System.out.println(uri);
    System.out.println(versionUri);

    HttpClient client = new HttpClient();
    HttpMethod getVersion = new GetMethod(versionUri);
    client.executeMethod(getVersion);
    String currentServerVersionString = getVersion.getResponseBodyAsString();
    System.out
            .println("FirstSpirit server you want to connect to is at version: " + currentServerVersionString);

    File fsClientJar = new File(tempDirectory, "fs-client-" + currentServerVersionString + ".jar");

    if (!fsClientJar.exists()) {
        // get an authentication cookie from FirstSpirit
        HttpMethod post = new PostMethod(uri);
        post.setQueryString("login.user=" + URLEncoder.encode(firstSpiritUserName, "UTF-8") + "&login.password="
                + URLEncoder.encode(firstSpiritUserPassword, "UTF-8") + "&login=webnonsso");
        client.executeMethod(post);
        String setCookieJsession = post.getResponseHeader("Set-Cookie").getValue();

        // download the fs-client.jar by using the authentication cookie
        HttpMethod get = new GetMethod(uri);
        get.getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
        get.setRequestHeader("Cookie", setCookieJsession);
        client.executeMethod(get);

        InputStream inputStream = get.getResponseBodyAsStream();
        FileOutputStream outputStream = new FileOutputStream(fsClientJar);
        outputStream.write(IOUtils.readFully(inputStream, -1, false));
        outputStream.close();
        System.out.println("tempfile of fs-client.jar created within path: " + fsClientJar);
    }

    addFile(classLoader, fsClientJar);
}