Package play.libs.WS

Examples of play.libs.WS.HttpResponse


  public Data<ImageExt> search(String terms, int offset, int limit) throws IOException {
    Data<ImageExt> images = new Data<ImageExt>();
    images.total = 0;
    images.data = new ArrayList<ImageExt>();
    if(limit>8) limit=8;
    HttpResponse response = WS.url(searchPattern, terms, ""+offset, ""+limit).get();
    if( response.getStatus() == 200 ) {
      Reader reader = new InputStreamReader(response.getStream());
      JsonObject jsobj = new JsonParser().parse(reader).getAsJsonObject();
      StringBuilder sb = new StringBuilder();
        String line;
        BufferedReader r1 = new BufferedReader(new InputStreamReader(response.getStream(), "UTF-8"));
        while ((line = r1.readLine()) != null) {
          sb.append(line).append("\n");
        }
        //System.out.println(sb.toString());
        if(jsobj.get("responseData").isJsonNull()) {
View Full Code Here


  public Data<ImageExt> search(String terms, int offset, int limit) throws IOException {
    if(limit>10) limit=10;
    Data<ImageExt> images = new Data<ImageExt>();
    images.total = 0;
    images.data = new ArrayList<ImageExt>();
    HttpResponse response = WS.url(searchPattern, terms, ""+offset, ""+limit).get();
     if( response.getStatus() == 200 ) {
      Reader reader = new InputStreamReader(response.getStream());
      JsonObject jsobj = new JsonParser().parse(reader).getAsJsonObject();
      int totalResults = jsobj.get("queries").getAsJsonObject().get("nextPage").getAsJsonArray().iterator().next().getAsJsonObject().get("totalResults").getAsInt()
      images.total = totalResults;
      Iterator<JsonElement> itemsIt = jsobj.get("items").getAsJsonArray().iterator();
      while(itemsIt.hasNext()) {
View Full Code Here

    }

    @Test
    public void testHead() throws Exception {
        HttpResponse headResponse = WS.url("http://localhost:9003/ressource/%s", Rest.filterString("ééééééçççççç汉语漢語")).head();
        List<Header> headResponseHeaders = headResponse.getHeaders();
        assertTrue(headResponse.getStatus() == 200);
        assertEquals("", headResponse.getString());
        HttpResponse getResponse = WS.url("http://localhost:9003/ressource/%s", Rest.filterString("ééééééçççççç汉语漢語")).get();
        assertTrue(getResponse.getStatus() == 200);
        List<Header> getResponseHeaders = getResponse.getHeaders();
        for (int i = 0; i < getResponseHeaders.size(); i++) {
            if (!"Set-Cookie".equals(getResponseHeaders.get(i).name)) {
                assertEquals(getResponseHeaders.get(i).value(), headResponseHeaders.get(i).value());
            }
        }
View Full Code Here

        String res = WS.url("http://localhost:9003/ressource/returnParam").params(params).get().getString();
        Logger.info("res: " + res);
        assertEquals("param: %%%æøåÆØÅ", res);
       
        // try it again with different encoding
        HttpResponse r = WS.withEncoding("iso-8859-1").url("http://localhost:9003/ressource/returnParam").params(params).get();
        Logger.info("res.contentType: " + r.getContentType());
        assertEquals("param: %%%æøåÆØÅ", r.getString());
       
        // do the same with post..
        res = WS.url("http://localhost:9003/ressource/returnParam").params(params).post().getString();
        Logger.info("res: " + res);
        assertEquals("param: %%%æøåÆØÅ", res);
       
        // try it again with different encoding
        r = WS.withEncoding("iso-8859-1").url("http://localhost:9003/ressource/returnParam").params(params).post();
        Logger.info("res.contentType: " + r.getContentType());
        assertEquals("param: %%%æøåÆØÅ", r.getString());
       
       
    }
View Full Code Here

            try {
                final Promise<HttpResponse> smartFuture = new Promise<HttpResponse>();
                prepare(builder).execute(new AsyncCompletionHandler<HttpResponse>() {
                    @Override
                    public HttpResponse onCompleted(Response response) throws Exception {
                        HttpResponse httpResponse = new HttpAsyncResponse(response);
                        smartFuture.invoke(httpResponse);
                        return httpResponse;
                    }
                    @Override
                    public void onThrowable(Throwable t) {
View Full Code Here

            try {
                final Promise<HttpResponse> smartFuture = new Promise<HttpResponse>();
                prepare(builder).execute(new AsyncCompletionHandler<HttpResponse>() {
                    @Override
                    public HttpResponse onCompleted(Response response) throws Exception {
                        HttpResponse httpResponse = new HttpAsyncResponse(response);
                        smartFuture.invoke(httpResponse);
                        return httpResponse;
                    }
                    @Override
                    public void onThrowable(Throwable t) {
View Full Code Here

        Map<String, Object> params = new HashMap<String, Object>();
        params.put("client_id", clientid);
        params.put("client_secret", secret);
        params.put("redirect_uri", callbackURL);
        params.put("code", accessCode);
        HttpResponse response = WS.url(accessTokenURL).params(params).get();
        return new Response(response);
    }
View Full Code Here

    }

    @Test
    public void testHead() throws Exception {
        HttpResponse headResponse = WS.url("http://localhost:9003/ressource/%s", Rest.filterString("ééééééçççççç汉语漢語")).head();
        List<Header> headResponseHeaders = headResponse.getHeaders();
        assertTrue(headResponse.getStatus() == 200);
        assertEquals("", headResponse.getString());
        HttpResponse getResponse = WS.url("http://localhost:9003/ressource/%s", Rest.filterString("ééééééçççççç汉语漢語")).get();
        assertTrue(getResponse.getStatus() == 200);
        List<Header> getResponseHeaders = getResponse.getHeaders();
        for (int i = 0; i < getResponseHeaders.size(); i++) {
            if (!"Set-Cookie".equals(getResponseHeaders.get(i).name)) {
                assertEquals(getResponseHeaders.get(i).value(), headResponseHeaders.get(i).value());
            }
        }
View Full Code Here

        String res = WS.url("http://localhost:9003/ressource/returnParam").params(params).get().getString();
        Logger.info("res: " + res);
        assertEquals("param: %%%æøåÆØÅ", res);
       
        // try it again with different encoding
        HttpResponse r = WS.withEncoding("iso-8859-1").url("http://localhost:9003/ressource/returnParam").params(params).get();
        Logger.info("res.contentType: " + r.getContentType());
        assertEquals("param: %%%æøåÆØÅ", r.getString());
       
        // do the same with post..
        res = WS.url("http://localhost:9003/ressource/returnParam").params(params).post().getString();
        Logger.info("res: " + res);
        assertEquals("param: %%%æøåÆØÅ", res);
       
        // try it again with different encoding
        r = WS.withEncoding("iso-8859-1").url("http://localhost:9003/ressource/returnParam").params(params).post();
        Logger.info("res.contentType: " + r.getContentType());
        assertEquals("param: %%%æøåÆØÅ", r.getString());
       
       
    }
View Full Code Here

    }

    @Test
    public void testHead() throws Exception {
        HttpResponse headResponse = WS.url("http://localhost:9003/ressource/%s", Rest.filterString("ééééééçççççç汉语漢語")).head();
        List<Header> headResponseHeaders = headResponse.getHeaders();
        assertTrue(headResponse.getStatus() == 200);
        assertEquals("", headResponse.getString());
        HttpResponse getResponse = WS.url("http://localhost:9003/ressource/%s", Rest.filterString("ééééééçççççç汉语漢語")).get();
        assertTrue(getResponse.getStatus() == 200);
        List<Header> getResponseHeaders = getResponse.getHeaders();
        for (int i = 0; i < getResponseHeaders.size(); i++) {
            if (!"Set-Cookie".equals(getResponseHeaders.get(i).name)) {
                assertEquals(getResponseHeaders.get(i).value(), headResponseHeaders.get(i).value());
            }
        }
View Full Code Here

TOP

Related Classes of play.libs.WS.HttpResponse

Copyright © 2018 www.massapicom. 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.