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:edu.caltech.ipac.firefly.server.network.HttpServices.java

public static int getDataViaUrl(URL url, OutputStream results) {
    GetMethod getter = null;/*w w  w . ja v a  2 s.  c o m*/
    try {
        getter = new GetMethod(url.toURI().toString());
        executeMethod(getter);
        readBody(results, getter.getResponseBodyAsStream());
        return getter.getStatusLine().getStatusCode();
    } catch (Exception e) {
        LOG.error(e);
    } finally {
        if (getter != null) {
            getter.releaseConnection();
        }
    }
    return 500;
}

From source file:com.endpoint.lg.director.bridge.MasterApi.java

private StandardJsonNavigator sendRequest(String path) {
    String url = masterUrl + "/" + path;
    log.info("Hitting url: " + url);
    GetMethod method = new GetMethod(url);
    StandardJsonNavigator responseJson = null;

    try {/*  w w  w.  j  a  v a  2s . c o m*/
        // Execute the method.
        int statusCode = client.executeMethod(method);

        if (statusCode != HttpStatus.SC_OK) {
            System.err.println("Method failed: " + method.getStatusLine());
        }

        // Read the response body.
        String responseBody = new String(method.getResponseBody());
        log.info(responseBody);
        responseJson = new StandardJsonNavigator(jsonMapper.parseObject(responseBody));

    } catch (HttpException e) {
        System.err.println("Fatal protocol violation: " + e.getMessage());
        e.printStackTrace();
    } catch (IOException e) {
        System.err.println("Fatal transport error: " + e.getMessage());
        e.printStackTrace();
    } finally {
        // Release the connection.
        method.releaseConnection();
    }

    return responseJson;
}

From source file:net.sf.taverna.t2.uiexts.bioswr.ui.worker.CheckCredentialsWorker.java

@Override
protected Boolean doInBackground() throws Exception {
    HttpClient client = new HttpClient();
    client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));

    GetMethod get = new GetMethod(uri.toString());
    get.setDoAuthentication(true);//from  w  w w. j a va  2  s .  co  m

    try {
        final int status = client.executeMethod(get);
        return status != HttpURLConnection.HTTP_UNAUTHORIZED;
    } finally {
        get.releaseConnection();
    }

    //        HttpURLConnection connection = (HttpURLConnection) uri.toURL().openConnection();
    //        connection.setAllowUserInteraction(false);
    //        connection.setRequestProperty ("Authorization", authorization);
    //        connection.connect();
    //        return connection.getResponseCode() != HttpURLConnection.HTTP_UNAUTHORIZED;
}

From source file:com.navercorp.pinpoint.plugin.httpclient3.HttpClientIT.java

@Test
public void test() throws Exception {
    HttpClient client = new HttpClient();
    client.getParams().setConnectionManagerTimeout(CONNECTION_TIMEOUT);
    client.getParams().setSoTimeout(SO_TIMEOUT);

    GetMethod method = new GetMethod(webServer.getCallHttpUrl());

    // Provide custom retry handler is necessary
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
            new DefaultHttpMethodRetryHandler(3, false));
    method.setQueryString(new NameValuePair[] { new NameValuePair("key2", "value2") });

    try {/* w  w w .j  av a  2  s . c  o m*/
        // Execute the method.
        client.executeMethod(method);
    } catch (Exception ignored) {
    } finally {
        method.releaseConnection();
    }

    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    verifier.printCache();
}

From source file:com.predic8.membrane.core.interceptor.balancer.ClusterNotificationInterceptorTest.java

@Test
public void testUpEndpoint() throws Exception {
    GetMethod get = new GetMethod("http://localhost:3002/clustermanager/up?"
            + createQueryString("host", "node1.clustera", "port", "3018", "cluster", "c1"));

    assertEquals(204, new HttpClient().executeMethod(get));
    assertEquals("node1.clustera",
            BalancerUtil.lookupBalancer(router, "Default").getAllNodesByCluster("c1").get(0).getHost());

}

From source file:com.jmeter.alfresco.utils.HttpUtils.java

/**
 * Gets the login response.//  www  .j  av  a  2s  .  c o  m
 *
 * @param authURI the path
 * @param username the username
 * @param password the password
 * @return the login response
 * @throws ParseException the parse exception
 * @throws IOException Signals that an I/O exception has occurred.
 */
public Map<String, String> getAuthResponse(final String authURI, final String username, final String password)
        throws ParseException, IOException {

    LOG.debug("Authenticating request..");
    final Map<String, String> responseMap = new ConcurrentHashMap<String, String>();
    GetMethod getRequest = null;
    try {
        final HttpClient httpclient = new HttpClient();
        getRequest = new GetMethod(getAuthURL(authURI, username, password));
        final int statusCode = httpclient.executeMethod(getRequest);
        LOG.debug("Auth Response Status: " + statusCode + "|" + getRequest.getStatusText());

        responseMap.put(Constants.RESP_BODY, getRequest.getResponseBodyAsString());
        responseMap.put(Constants.CONTENT_TYPE,
                getRequest.getResponseHeader(Constants.CONTENT_TYPE_HDR).getValue());
        responseMap.put(Constants.STATUS_CODE, String.valueOf(statusCode));

    } finally {
        if (getRequest != null) {
            getRequest.releaseConnection();
        }
    }
    return responseMap;
}

From source file:com.owncloud.android.utils.glide.HttpStreamFetcher.java

@Override
public InputStream loadData(Priority priority) throws Exception {

    Account mAccount = AccountUtils.getCurrentOwnCloudAccount(MainApp.getAppContext());
    OwnCloudAccount ocAccount = new OwnCloudAccount(mAccount, MainApp.getAppContext());
    OwnCloudClient mClient = OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(ocAccount,
            MainApp.getAppContext());// w  ww . j ava 2  s. c  o  m

    OwnCloudVersion serverOCVersion = AccountUtils.getServerVersion(mAccount);
    if (mClient != null && serverOCVersion != null) {
        if (serverOCVersion.supportsRemoteThumbnails()) {
            GetMethod get = null;
            try {
                get = new GetMethod(mURL);
                get.setRequestHeader("Cookie", "nc_sameSiteCookielax=true;nc_sameSiteCookiestrict=true");
                get.setRequestHeader(RemoteOperation.OCS_API_HEADER, RemoteOperation.OCS_API_HEADER_VALUE);
                int status = mClient.executeMethod(get);
                if (status == HttpStatus.SC_OK) {
                    return get.getResponseBodyAsStream();
                } else {
                    mClient.exhaustResponse(get.getResponseBodyAsStream());
                }
            } catch (Exception e) {
                Log_OC.d(TAG, e.getMessage(), e);
            }
        } else {
            Log_OC.d(TAG, "Server too old");
        }
    }
    return null;
}

From source file:net.duckling.ddl.web.controller.UploadImgController.java

@RequestMapping
public void execute(HttpServletRequest request, HttpServletResponse response) throws IOException {
    Site site = VWBContext.findSite(request);
    FileVersion attachItem = new FileVersion();
    response.setContentType("text/xml");
    response.setCharacterEncoding("UTF-8");
    ///*from  w w w.  j a  v a 2 s. c o  m*/
    String url = request.getParameter("url");
    HttpClient client = new HttpClient();
    GetMethod getMethod = new GetMethod(url);
    String fakeReferer = getFakeReferer(url);//??
    if (fakeReferer != null) {
        String thisReferer = request.getHeader("Referer");
        if (thisReferer.contains(fakeReferer)) {//????
            response.getWriter().write(getReturnXml(site, 0, "??", attachItem));
            response.flushBuffer();
            return;
        }
        getMethod.setRequestHeader("Referer", fakeReferer);
    }
    client.executeMethod(getMethod);

    //?

    try {
        attachItem = uploadImg(getMethod, request);
    } catch (NoEnoughSpaceException e) {
        JSONObject j = new JSONObject();
        j.put("result", false);
        j.put("message", e.getMessage());
        j.put("error", e.getMessage());
        JsonUtil.writeJSONObject(response, j);
        return;
    }
    //
    response.getWriter().write("");
    response.getWriter().write(getReturnXml(site, 1, "????", attachItem));
    response.flushBuffer();
}

From source file:com.swdouglass.joid.consumer.Discoverer.java

public Boolean findWithYadis(String identityUrl, ServerAndDelegate serverAndDelegate) throws Exception {
    boolean found = false;

    GetMethod get = new GetMethod(identityUrl);
    httpGet(get);/* ww  w . j  av a2  s  . c  o  m*/
    Header contentType = get.getResponseHeader("Content-Type");
    if (contentType != null && contentType.getValue().contains("application/xrds+xml")) {
        // then we're looking at the xrds service doc already
        XRDSDocument xrdsDocument = buildXrdsDocument(get);
        handleXrdsDocument(serverAndDelegate, xrdsDocument);
        found = true;
    } else {
        Header locationHeader = get.getResponseHeader("X-XRDS-Location");
        if (locationHeader != null) {
            // then we go to this URL
            get.releaseConnection();
            debug("found yadis header: " + locationHeader.getValue());
            XRDSDocument xrdsDocument = fetchYadisDocument(locationHeader.getValue());
            handleXrdsDocument(serverAndDelegate, xrdsDocument);
            found = true;
        }
    }

    return found;
}

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

@SuppressWarnings("serial")
public static TaskState getState(String task) throws IOException {
    HttpClient client = new HttpClient();
    GetMethod method = new GetMethod(task);
    HttpMethodHelper.addMethodHeaders(method, new HashMap<String, String>() {
        {/*from w w w .j av  a  2  s.co  m*/
            put("Accept", "application/rdf+xml");
        }
    });
    method.getParams().setParameter("http.socket.timeout", new Integer(Activator.TIME_OUT));
    method.setRequestHeader("Accept", "application/rdf+xml");
    client.executeMethod(method);
    int status = method.getStatusCode();
    logger.debug("Task status: " + status);

    TaskState state = new TaskState();
    logger.debug("Task: " + task);
    logger.debug(" -> " + status);
    InputStream result = method.getResponseBodyAsStream();
    // logger.debug("RDF: " + result);
    switch (status) {
    case 404:
        logger.error("Task gone missing (404): " + task);
        state.setExists(false);
        break;
    case 200:
        if (result == null)
            throw new IOException("Missing dataset URI for finished (200) Task: " + task);
        state.setFinished(true);
        state.setResults(getResultSetURI(createStore(result)));
        break;
    case 201:
        state.setFinished(true);
        state.setRedirected(true);
        state.setResults(getResultSetURI(createStore(result)));
        break;
    case 202:
        state.setFinished(false);
        state.setPercentageCompleted(getPercentageCompleted(createStore(result)));
        break;
    case 500:
        state.setFinished(true);
        state.setStatus(STATUS.ERROR);
        IRDFStore store = createStore(result);
        try {
            logger.debug("RDF: " + rdf.asRDFN3(store));
        } catch (BioclipseException e) {
        }
        String error = getErrorMessage(store);
        throw new IllegalStateException("Service error (500) for " + task + ": " + error);
    default:
        logger.error("Task error (" + status + "): " + task);
        logger.debug("Response: " + result);
        throw new IllegalStateException("Service error: " + status + ":\n  " + method.getStatusText());
    }

    method.releaseConnection();
    return state;
}