Example usage for org.apache.http.impl.client DefaultHttpClient DefaultHttpClient

List of usage examples for org.apache.http.impl.client DefaultHttpClient DefaultHttpClient

Introduction

In this page you can find the example usage for org.apache.http.impl.client DefaultHttpClient DefaultHttpClient.

Prototype

public DefaultHttpClient() 

Source Link

Usage

From source file:com.sanjaydalvi.spacestationlocator.LoadISSLocation.java

public LoadISSLocation(Context context, String action) {
    mContext = context;
    mAction = action;
    mClient = new DefaultHttpClient();
}

From source file:fichiercentraltheses.TheseXMLCaller.java

public void callForXMLResponse(int year) throws URISyntaxException, IOException {
    HttpClient httpclient = new DefaultHttpClient();
    TheseAPIXMLResponseParser xmlParser;
    Set<Academic> doctors;/*from ww w.  j av  a  2  s.com*/
    index = 1;

    //        URIBuilder builder = new URIBuilder();
    //        builder.setScheme("http").setHost("www.theses.fr").setPath("/")
    //                .setParameter("q", "")
    //                .setParameter("fq", "dateSoutenance:[2013-01-01T23:59:59Z%2BTO%2B2013-12-31T23:59:59Z]")
    //                .setParameter("sort", "dateSoutenance+desc")
    //                .setParameter("format", "xml");
    //        URI uri = builder.build();
    //        HttpGet httpget = new HttpGet(uri);
    boolean finished = false;
    while (!finished) {

        int indexBefore = index;
        HttpGet httpget = new HttpGet("http://www.theses.fr/?q=&fq=dateSoutenance:[" + year + "-" + "01"
                + "-01T23:59:59Z%2BTO%2B" + year + "-" + "12" + "-" + "31"
                + "T23:59:59Z]&sort=dateSoutenance+desc&start=" + index + "&format=xml");

        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();
        if (entity == null) {
            System.out.println("empty response to API call");
        }

        String responseString = EntityUtils.toString(entity);

        if (!responseString.contains("<doc>")) {
            finished = true;
        } else {
            xmlParser = new TheseAPIXMLResponseParser(responseString);
            doctors = xmlParser.parse();
            System.out.println("just finished year " + year + ", docs " + indexBefore + " to " + (index - 1));

            for (Academic academic : doctors) {
                //                    res.put(academic.getPpn(), academic.getFullname());
                App.resNoId.add(academic.getFullname());
            }

        }
    }
    //        System.out.println(responseString);
}

From source file:cn.loveapple.client.android.util.ApiUtil.java

public static String getHttpBody(String url, PackageManager packageManager) {
    if (StringUtils.isEmpty(url)) {
        return null;
    }//from ww  w  . j a  v  a2  s .  c o m

    String body = null;
    DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpParams params = httpClient.getParams();
    // SYSTEM INFO
    params.setParameter("", "");
    params.setParameter("", "");
    params.setParameter("", "");
    HttpConnectionParams.setConnectionTimeout(params, 1000);
    HttpConnectionParams.setSoTimeout(params, 1000);
    HttpPost httpRequest = new HttpPost(url);
    HttpResponse httpResponse = null;

    try {
        httpResponse = httpClient.execute(httpRequest);
    } catch (Exception e) {
        Log.e(LOG_TAG, "http response execute failed.", e);
        return null;
    }
    if (httpResponse != null && httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
        HttpEntity httpEntity = httpResponse.getEntity();

        try {
            body = EntityUtils.toString(httpEntity);
        } catch (Exception e) {
            Log.e(LOG_TAG, "get http response body failed.", e);
            return null;
        } finally {
            try {
                httpEntity.consumeContent();
            } catch (IOException e) {
            }
        }
    }
    httpClient.getConnectionManager().shutdown();

    return body;
}

From source file:WSpatern.FileCategory.java

public void getFile(String token, String id) {
    try {//from  w ww .  ja v a2  s .  co  m
        DefaultHttpClient client = new DefaultHttpClient();
        HttpGet get = new HttpGet(
                "http://documenta-dms.com/DMSWS/api/v1/file/" + token + "/category_by_id/" + id);
        HttpResponse response = client.execute(get);
        BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        String line = "";
        while ((line = rd.readLine()) != null) {

            System.out.println(line);
            parseXML(line);

        }
    } catch (IOException ex) {
        Logger.getLogger(ValidTokenWS.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:eu.musesproject.windowsclient.contextmonitoring.sensors.RESTController.java

public static Map<String, String> requestSensorInfo(String sensorType, String[] params) throws IOException {
    HttpClient client = new DefaultHttpClient();

    // join params
    String paramsStr = "/";
    for (String param : params) {
        paramsStr += param + "/";
    }/* w  w  w .j a v a 2s  . c o m*/

    HttpGet request = new HttpGet("http://localhost:9000/api/" + sensorType + paramsStr);
    HttpResponse response = client.execute(request);
    BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    String responseData = "";
    Gson gson = new Gson();
    //ToDo:check for readLine function
    responseData = rd.readLine();

    return gson.fromJson(responseData, new HashMap<String, String>().getClass());
}

From source file:org.keycloak.example.AdminClient.java

public static List<RoleRepresentation> getRealmRoles(HttpServletRequest req) throws Failure {
    KeycloakSecurityContext session = (KeycloakSecurityContext) req
            .getAttribute(KeycloakSecurityContext.class.getName());

    HttpClient client = new DefaultHttpClient();
    try {/*from w  ww . ja v  a  2s  .c  o  m*/
        HttpGet get = new HttpGet(
                UriUtils.getOrigin(req.getRequestURL().toString()) + "/auth/admin/realms/demo/roles");
        get.addHeader("Authorization", "Bearer " + session.getTokenString());
        try {
            HttpResponse response = client.execute(get);
            if (response.getStatusLine().getStatusCode() != 200) {
                throw new Failure(response.getStatusLine().getStatusCode());
            }
            HttpEntity entity = response.getEntity();
            InputStream is = entity.getContent();
            try {
                return JsonSerialization.readValue(is, TypedList.class);
            } finally {
                is.close();
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    } finally {
        client.getConnectionManager().shutdown();
    }
}

From source file:org.apache.usergrid.apm.service.UsergridInternalRestServerConnector.java

public static boolean isCrashNotificationDisabled(String orgName, String appName) {
    String restServerUrl = DeploymentConfig.geDeploymentConfig().getUsergridRestUrl();
    //String restServerUrl = "http://instaops-apigee-mobile-app-prod.apigee.net/";
    restServerUrl += "/" + orgName + "/" + appName + "/apm/apigeeMobileConfig";
    log.info("Checking if crash notification is disabled for " + orgName + " app : " + appName);

    DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpGet getMethod = new HttpGet(restServerUrl);
    HttpResponse response;//from  ww  w  .  j a va2s  .  c o  m
    try {
        response = httpClient.execute(getMethod);

        HttpEntity entity = response.getEntity();
        String jsonObject = EntityUtils.toString(entity);
        ObjectMapper mapper = new ObjectMapper();
        App app = mapper.readValue(jsonObject, App.class);
        Set<AppConfigCustomParameter> parameters = app.getDefaultAppConfig().getCustomConfigParameters();
        for (AppConfigCustomParameter param : parameters) {
            if (param.getTag().equalsIgnoreCase("ALARM")
                    && param.getParamKey().equalsIgnoreCase("SUPPRESS_ALARMS")
                    && param.getParamValue().equalsIgnoreCase("TRUE"))
                ;
            {
                return true;
            }
        }

    } catch (ClientProtocolException e) {
        log.error("Problem connectiong to Usergrid internal REST server " + restServerUrl);
        e.printStackTrace();

    } catch (IOException e) {
        log.error("Problem connectiong to Usergrid internal REST server " + restServerUrl);
        e.printStackTrace();
    }
    httpClient = null;
    return false;
}

From source file:br.com.estudogrupo.online.DicionarioOnline02.java

@Override
public void run() {
    HttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost("http://www.md5pass.info");
    try {//w w  w .  ja  va 2 s  .c o m
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
        nameValuePairs.add(new BasicNameValuePair("hash", getRecebe()));
        nameValuePairs.add(new BasicNameValuePair("get_pass", "Get+Pass"));
        post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = client.execute(post);
        BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        String line = "";
        while ((line = rd.readLine()) != null) {
            if (line.startsWith("Password -")) {
                System.out.println("Senha  : "
                        + line.replace("<b>", "").replace("</b>", "").replace("-", "").replace("Password", ""));
                System.exit(0);
            }
        }
    } catch (IOException | NullPointerException e) {
        e.printStackTrace();
    }

}

From source file:org.mustard.util.MustardUtil.java

public static void snapshot(String id, String version, String accountNumber) {
    try {/*from   w w  w.j ava2s  .c o m*/
        HttpPost post = new HttpPost("http://mustard.macno.org/snapshot.php");
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("v", version));
        params.add(new BasicNameValuePair("n", accountNumber));
        params.add(new BasicNameValuePair("m", id));
        post.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
        DefaultHttpClient hc = new DefaultHttpClient();
        HttpProtocolParams.setUserAgent(post.getParams(), "Mustard/1.0");
        HttpProtocolParams.setUseExpectContinue(post.getParams(), false);
        hc.execute(post);
    } catch (Exception e) {
    }
}

From source file:ch.ffhs.esa.bewegungsmelder.tasks.POSTTask.java

protected String doInBackground(String... params) {
    Log.d("POSTTask", "Running async request..");
    HttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost("http://" + params[0] + ":" + params[1] + "/ping");

    try {//from  w w  w.j  a va 2s .  c om
        List<NameValuePair> data = new ArrayList<NameValuePair>(0);
        httpPost.setEntity(new UrlEncodedFormEntity(data));
        httpClient.execute(httpPost);
    } catch (UnsupportedEncodingException e) {
    } catch (IOException e) {
    }
    return null;
}