Examples of BasicResponseHandler


Examples of org.apache.http.impl.client.BasicResponseHandler

          //For every page of the subreddit we are to scrape from
          String lastItemId = "";
          for(int i = 0; i < INITIAL_PAGE_COUNT; i++){
            //Retrieve the page
            HttpGet getRequest = new HttpGet(URL +"&count=" + count + "&after=" + lastItemId);
            ResponseHandler<String> responseHandler = new BasicResponseHandler();
           
            String responseBody = httpClient.execute(getRequest, responseHandler);
           
            //Parse it as JSON
            JSONParser parser= new JSONParser();
           
            JSONObject wrappingObject = (JSONObject) parser.parse(responseBody);
           
            JSONObject wrappingObjectData = (JSONObject) wrappingObject.get("data");
           
            JSONArray children = (JSONArray) wrappingObjectData.get("children");
           
            if(children.size() == 0)
              break;
           
            //reverse order so printed order is consistent
            for(int c=children.size()-1; c>=0; c--){
              JSONObject childData = (JSONObject) ((JSONObject) children.get(c)).get("data");
              QUEUE.add(new Post((String) childData.get("title"), SUBREDDIT));
            }
           
            lastItemId = (String) wrappingObjectData.get("after");
           
            //If this is the first page, then it's the point we want to store to ensure that we don't get repeated posts
            if(i == 0){
              latestTimestamp = ((Double) ((JSONObject)((JSONObject) children.get(0)).get("data")).get("created")).longValue();
            }
           
            //Rate limit
            if(i != INITIAL_PAGE_COUNT - 1)
              Utils.sleep(1000);
            count += 100;
          }
          initialPull = false;
        }else{
          //Rate limit for the API (pages are cached for 30 seconds)
          Utils.sleep(10000);
          //Get the page
          HttpGet getRequest = new HttpGet(URL);
          ResponseHandler<String> responseHandler = new BasicResponseHandler();
               
          String responseBody = httpClient.execute(getRequest, responseHandler);
         
          //Parse it
          JSONParser parser= new JSONParser();
View Full Code Here

Examples of org.apache.http.impl.client.BasicResponseHandler

    }

    @Test
    public void testHttpMsg() throws IOException, InterruptedException, DeploymentException, ExecutionException {
        assertEquals("httpResponse", HttpClients.createDefault().
                execute(new HttpGet("http://localhost:8080"), new BasicResponseHandler()));
    }
View Full Code Here

Examples of org.apache.http.impl.client.BasicResponseHandler

    @Test
    public void testWebSocketMsg() throws IOException, InterruptedException, DeploymentException, ExecutionException {
        BasicCookieStore cookieStore = new BasicCookieStore();
        HttpClients.custom().setDefaultCookieStore(cookieStore).build().
                execute(new HttpGet("http://localhost:8080"), new BasicResponseHandler());

        final SettableFuture<String> res = new SettableFuture<>();
        try (Session s = ContainerProvider.getWebSocketContainer().connectToServer(
                sendAndGetTextEndPoint("test it", res), EmbedSessionConfig(cookieStore), URI.create("ws://localhost:8080/ws"))) {
            assertEquals("test it", res.get());
View Full Code Here

Examples of org.apache.http.impl.client.BasicResponseHandler

    @GET
    @Path("/http")
    @Timed
    public String http(@QueryParam("name") Optional<String> name) throws InterruptedException, SuspendExecution, IOException {
        return httpClient.execute(new HttpGet("http://localhost:8080/?sleep=10&name=" + name.or("name")), new BasicResponseHandler());
    }
View Full Code Here

Examples of org.apache.http.impl.client.BasicResponseHandler

        // Request the options from the server so we can find out if the broker we are
        // talking to supports GZip compressed content.  If so and useCompression is on
        // then we can compress our POST data, otherwise we must send it uncompressed to
        // ensure backwards compatibility.
        HttpOptions optionsMethod = new HttpOptions(remoteUrl.toString());
        ResponseHandler<String> handler = new BasicResponseHandler() {
            @Override
            public String handleResponse(HttpResponse response) throws HttpResponseException, IOException {

                for(Header header : response.getAllHeaders()) {
                    if (header.getName().equals("Accepts-Encoding") && header.getValue().contains("gzip")) {
                        LOG.info("Broker Servlet supports GZip compression.");
                        canSendCompressed = true;
                        break;
                    }
                }

                return super.handleResponse(response);
            }
        };


        try {
            httpClient.execute(httpMethod, new BasicResponseHandler());
            httpClient.execute(optionsMethod, handler);
        } catch(Exception e) {
            throw new IOException("Failed to perform GET on: " + remoteUrl + " as response was: " + e.getMessage());
        }
View Full Code Here

Examples of org.apache.http.impl.client.BasicResponseHandler

        final HttpEntity entity = this.getParamsEntity();
        if (null != entity) {
            method.setEntity(entity);
        }

        final ResponseHandler<String> responseHandler = new BasicResponseHandler();

        // Execute the method.
        final String response = client.execute(method, responseHandler);
        return response;
    }
View Full Code Here

Examples of org.apache.http.impl.client.BasicResponseHandler

//        for (final String name : keys) {
//            final String value = _methodParams.get(name).toString();
//            method.getParams().setParameter(name, value);
//        }

        final ResponseHandler<String> responseHandler = new BasicResponseHandler();

        // Execute the method.
        final String response = client.execute(method, responseHandler);
        return response;
    }
View Full Code Here

Examples of org.apache.http.impl.client.BasicResponseHandler

    private String getResponseBody()
        throws IOException
    {
        HttpGet httpGet = new HttpGet( getWebappUrl() );
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        return httpClient.execute( httpGet, responseHandler );
    }
View Full Code Here

Examples of org.apache.http.impl.client.BasicResponseHandler

                qparams.add(new BasicNameValuePair("login", getEmail()));
                qparams.add(new BasicNameValuePair("password", getPassword()));
                URI uri = URIUtils.createURI(getShema(), getApiJelastic(), getPort(), getUrlAuthentication(), URLEncodedUtils.format(qparams, "UTF-8"), null);
                getLog().debug(uri.toString());
                HttpGet httpGet = new HttpGet(uri);
                ResponseHandler<String> responseHandler = new BasicResponseHandler();
                String responseBody = httpclient.execute(httpGet, responseHandler);
                cookieStore = httpclient.getCookieStore();

                List<Cookie> cookies = cookieStore.getCookies();
                for (Cookie cookie : cookies) {
View Full Code Here

Examples of org.apache.http.impl.client.BasicResponseHandler

            getLog().debug(uri.toString());
            HttpPost httpPost = new HttpPost(uri);
            addHeaders(httpPost);
            httpPost.setEntity(multipartEntity);

            ResponseHandler<String> responseHandler = new BasicResponseHandler();
            String responseBody = httpclient.execute(httpPost, responseHandler);
            getLog().debug(responseBody);
            upLoader = mapper.readValue(responseBody, UpLoader.class);
        } catch (URISyntaxException e) {
            getLog().error(e.getMessage(), e);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.