Example usage for org.apache.http.client.methods HttpGet toString

List of usage examples for org.apache.http.client.methods HttpGet toString

Introduction

In this page you can find the example usage for org.apache.http.client.methods HttpGet toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:org.jenkinsci.plugins.skytap.SkytapUtils.java

/**
 * This method packages an http get request object, given a url and the
 * encoded Skytap authorization token.//from w  w w .  j a va2s. c  o  m
 * 
 * @param requestUrl
 * @param AuthToken
 * @return
 */
public static HttpGet buildHttpGetRequest(String requestUrl, String AuthToken) {

    HttpGet hg = new HttpGet(requestUrl);
    String authHeaderValue = "Basic " + AuthToken;

    hg.addHeader("Authorization", authHeaderValue);
    hg.addHeader("Accept", "application/json");
    hg.addHeader("Content-Type", "application/json");

    JenkinsLogger.log("HTTP GET Request: " + hg.toString());
    return hg;
}

From source file:org.openo.sdnhub.overlayvpndriver.http.OverlayVpnDriverSsoProxy.java

/**
 * Login AC Branch. <br>/* w w w  . j a  va 2  s  . c  o  m*/
 *
 * @param url The URL path
 * @return true is success, false is failure.
 * @since SDNO 0.5
 */
@SuppressWarnings({ "deprecation", "rawtypes" })
public boolean login(String url) {
    if (!isParamValide()) {
        LOGGER.info("AC Login Configuration is inValide, Login failed.");
        return false;
    }

    try {
        final String httpsUrl = getHttpsUrl();

        HttpGet request = new HttpGet(httpsUrl + url);
        request.addHeader("Accept", APPLICATION_JSON);
        request.addHeader("Content-Type", APPLICATION_JSON);

        LOGGER.info(request.toString());
        HttpResponse resp = httpClient.execute(request);
        LOGGER.info(resp.toString());

        String respContent = EntityUtils.toString(resp.getEntity());
        this.release(resp);
        LOGGER.info("PreLogin AC response.");
        JSONObject json = JSONObject.fromObject(respContent);

        HttpPost loginPost = new HttpPost(httpsUrl + url);
        loginPost.addHeader("Accept", APPLICATION_JSON);
        List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
        urlParameters.add(new BasicNameValuePair("username", acLoginName));
        urlParameters.add(new BasicNameValuePair("password", acLoginPassword));

        if (ErrorCode.SUCCESS != json.getInt("errCode")) {
            JSONObject data = json.getJSONObject("data");
            urlParameters.add(new BasicNameValuePair("_eventId", data.getString("_eventId")));
            urlParameters.add(new BasicNameValuePair("lt", data.getString("lt")));
            urlParameters.add(new BasicNameValuePair("execution", data.getString("execution")));
        }

        loginPost.setEntity(new UrlEncodedFormEntity(urlParameters));

        LOGGER.info(loginPost.getURI().toString());
        resp = httpClient.execute(loginPost);
        LOGGER.info(resp.toString());

        respContent = EntityUtils.toString(resp.getEntity(), HTTP.UTF_8);
        if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK
                && MapUtils.isEmpty((Map) (parserAcResponse(respContent).getData()))) {
            this.release(resp);
            return this.isLogin(url);
        }

        if (resp.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
            LOGGER.error("Login Failed:  " + resp.getStatusLine());
            LOGGER.error("   " + EntityUtils.toString(resp.getEntity()));
            return false;
        }
        this.release(resp);
        LOGGER.info("Login AC response:  " + respContent);
        json = JSONObject.fromObject(respContent);
        if (json.getInt("errCode") != 0) {
            LOGGER.info("Login failed:  " + respContent);
            return false;
        }

    } catch (IOException e) {
        LOGGER.error("Login Failed. ", e);
    }

    return this.isLogin(url);
}

From source file:org.openo.sdnhub.overlayvpndriver.http.OverlayVpnDriverSsoProxy.java

/**
 * Check whether client login to controller.<br>
 *
 * @param url URL for the login/*from w ww  .ja  v a  2  s.  c o  m*/
 * @return true if client login to controller
 * @since SDNO 0.5
 */
@SuppressWarnings("deprecation")
public boolean isLogin(String url) {
    try {
        final String httpsUrl = getHttpsUrl();

        HttpGet request = new HttpGet(httpsUrl + ControllerUrlConst.EXTERNAL_REDIRECT);
        request.addHeader("Content-Type", APPLICATION_JSON);
        request.addHeader("X-External-Redirect", "true");

        LOGGER.info(request.toString());
        HttpResponse resp = httpClient.execute(request);
        LOGGER.info(resp.toString());

        String respContent = null;
        if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
            respContent = EntityUtils.toString(resp.getEntity(), HTTP.UTF_8);
            LOGGER.info("IsLogin Response: " + respContent);
            this.release(resp);
            return true;
        }
        this.release(resp);
    } catch (ClientProtocolException e) {
        LOGGER.error("Login Failed. ", e);
    } catch (ParseException e) {
        LOGGER.error("Login Failed. ", e);
    } catch (IOException e) {
        LOGGER.error("Login Failed. ", e);
    }
    return false;
}