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

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

Introduction

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

Prototype

public CloseableHttpResponse execute(final HttpUriRequest request) throws IOException, ClientProtocolException 

Source Link

Usage

From source file:br.com.agendatech.cadastro.DrawableManager.java

private InputStream fetch(String urlString) throws MalformedURLException, IOException {
    DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpGet request = new HttpGet(urlString);
    HttpResponse response = httpClient.execute(request);
    return response.getEntity().getContent();
}

From source file:com.soulgalore.web.pagesavings.impl.HTTPClientBodyFetcher.java

public String getBody(String url) throws IOException {
    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(url);

    try {/*from   w w w  .j  a  v a 2s  . c o  m*/
        HttpResponse response = httpclient.execute(httpGet);
        HttpEntity entity = response.getEntity();

        final String encoding = entity.getContentEncoding() != null ? entity.getContentEncoding().getValue()
                : "UTF-8";

        final String body = (readBody(entity, encoding));

        EntityUtils.consume(entity);
        return body;
    } finally {
        httpGet.releaseConnection();
    }

}

From source file:org.wso2.carbon.esb.passthru.transport.test.ESBJAVA1897HttpHeadMethodTestCase.java

@Test(groups = "wso2.esb", description = "test to verify that the HTTP HEAD method works with PTT.")
public void testHttpHeadMethod() throws Exception {
    Thread.sleep(5000);/*from w w  w  .  j  a va  2  s  .  c om*/
    String restURL = (getProxyServiceURLHttp(SERVICE_NAME)) + "/students";
    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpHead httpHead = new HttpHead(restURL);
    HttpResponse response = httpclient.execute(httpHead);

    // http head method should return a 202 Accepted
    assertTrue(response.getStatusLine().getStatusCode() == 202);
    // it should not contain a message body
    assertTrue(response.getEntity() == null);

}

From source file:com.redhat.scp.pipdl.PIPDLRequestProcessor.java

@VisibleForTesting
boolean enqueueJob(final StorageFileItem item) {
    log.debug("Enqueueing PIPDL job: {}", item.getPath());
    boolean done = true;

    for (Pipdl pipdl : pipdls) {
        if (pipdl.enqueueJob(item)) {
            eventBus.post(new PipdlEvent(item.getRepositoryItemUid().getRepository(), item));
        } else {//w  w w.  j  av  a 2  s  .c  o m
            done = false;
            // error, retry?
        }
    }

    DefaultHttpClient hc = new DefaultHttpClient();
    try {
        hc.execute(new HttpGet(
                String.format("http://queue/new?item=%s&hash=%s", item.getPath(), "not-so-random-for-now")));
    } catch (IOException e) {
        log.info("Error enqueing job: {}", e);
    }

    return done;
}

From source file:de.doering.dwca.iocwbn.ChecklistBuilder.java

private void parsePage(Eml eml) throws IOException, SAXException, ParserConfigurationException {
    // get webapge
    String url = XML_DOWNLOAD.replace("{VERSION}", VERSION);
    log.info("Downloading latest IOC world bird list from {}", url);

    DefaultHttpClient client = new DefaultHttpClient();
    HttpGet get = new HttpGet(url);

    // execute//  w w w.jav  a  2 s  . c  o  m
    HttpResponse response = client.execute(get);
    HttpEntity entity = response.getEntity();
    // parse page
    SAXParserFactory factory = SAXParserFactory.newInstance();

    final SAXParser parser = factory.newSAXParser();
    IocXmlHandler handler = new IocXmlHandler(writer, eml);
    try {
        Reader reader = new InputStreamReader(entity.getContent(), ENCODING);
        parser.parse(new InputSource(reader), handler);
    } catch (Exception e) {
        log.error("Cannot process IOC XML", e);
    }
}

From source file:com.webbfontaine.valuewebb.action.tt.dataimporter.TTMergeTest.java

@Test(parameters = "daiTTURL")
public void testTTMerge(String daiTTURL) throws Exception {

    DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpUriRequest httpGet = new HttpGet(daiTTURL);

    HttpResponse response = httpClient.execute(httpGet);

    assert response.getStatusLine().getStatusCode() == 200;

    TtGen daiTT = (TtGen) Doc2Bytes.unmarshal(response.getEntity().getContent(), TtGen.class);
    assert daiTT != null;

    TtGen ttGen = getTT();/*from   w ww  . j  a  v a  2  s . c  om*/
    MergeLoadedTT.merge(daiTT, ttGen);
    assert ttGen.getAppTin().equals(daiTT.getAppTin());
    assert !ttGen.getAppAdr().isEmpty(); // keep original

    assert ttGen.getFirstTtInvs().getInvCur().equals(daiTT.getFirstTtInvs().getInvCur());
    assert ttGen.getFirstTtInvs().getInsuranceF() != null; // keep original

    Pd pd = ttGen.getFirstTtInvs().getPds().get(0);
    Pd daiPD = daiTT.getFirstTtInvs().getPds().get(0);
    assert pd.getCtyOrig().equals(daiPD.getCtyOrig());
    assert pd.getHsCodeD().equals(daiPD.getHsCodeD());
}

From source file:org.apache.tika.parser.recognition.tf.TensorflowRESTRecogniser.java

@Override
public void initialize(Map<String, Param> params) throws TikaConfigException {
    try {/*  www .ja va  2  s.co m*/
        DefaultHttpClient client = new DefaultHttpClient();
        HttpResponse response = client.execute(new HttpGet(healthUri));
        available = response.getStatusLine().getStatusCode() == 200;
        LOG.info("Available = {}, API Status = {}", available, response.getStatusLine());
    } catch (Exception e) {
        available = false;
        throw new TikaConfigException(e.getMessage(), e);
    }
}

From source file:org.jboss.as.test.integration.web.cookie.CookieUnitTestCase.java

@Test
public void testCookieSetCorrectly() throws Exception {
    log.info("testCookieSetCorrectly()");
    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpResponse response = httpclient.execute(new HttpGet(cookieReadURL.toURI() + "CookieReadServlet"));
    if (response.getEntity() != null)
        response.getEntity().getContent().close();

    log.info("Sending request with cookie");
    response = httpclient.execute(new HttpPost(cookieReadURL.toURI() + "CookieReadServlet"));
}

From source file:WSpatern.WorkFlow.java

public void getWorkFlow(String token, String id) {
    try {// ww  w .ja  va2  s. co  m
        DefaultHttpClient client = new DefaultHttpClient();
        HttpGet get = new HttpGet("https://documenta-dms.com/DMSWS/api/v1/flow/" + token + "/get/" + 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:JsonParser.java

public JSONObject getJSONFromUrl(String url) {
    // make HTTP request
    try {/*  w w  w  . j a  va  2s  .co  m*/
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpGet httpGet = new HttpGet(url);

        HttpResponse httpResponse = httpClient.execute(httpGet);
        HttpEntity httpEntity = httpResponse.getEntity();
        InputStream inputStream = httpEntity.getContent();
        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"), 8);

        JSONObject jsonObject = createJsonObject(reader);
        inputStream.close();

        return jsonObject;
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return null;
}