Examples of HttpResponse


Examples of org.xlightweb.HttpResponse

  private static final class BlockingReadHandler implements IHttpRequestHandler {
   
    public void onRequest(IHttpExchange exchange) throws IOException {

      String body = exchange.getRequest().getBlockingBody().readString();
      exchange.send(new HttpResponse(200, "text/plain", body));
     
    }
View Full Code Here

Examples of org.xlightweb.HttpResponse

  public void testSimple() throws Exception {
     
        IHttpRequestHandler reqHdl = new IHttpRequestHandler() {
           
            public void onRequest(IHttpExchange exchange) throws IOException, BadMessageException {
                HttpResponse resp = new HttpResponse(200, "text/plain", "test");
                resp.setHeader("Cache-Control", "public, max-age=1000");
                exchange.send(resp);
            }
        };
       
        HttpServer server = new HttpServer(reqHdl);
        server.start();
       
        HttpClient httpClient = new HttpClient();
        httpClient.setCacheMaxSizeKB(100);
       
        IHttpResponse resp = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/"));
        Assert.assertEquals(200, resp.getStatus());
        Assert.assertEquals("test", resp.getBody().readString());
        Assert.assertNull(resp.getHeader(CacheHandler.XHEADER_NAME));
       
        QAUtil.sleep(1000);
       
        resp = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/"));
        Assert.assertEquals(200, resp.getStatus());
        Assert.assertTrue(resp.getHeader(CacheHandler.XHEADER_NAME).startsWith("HIT"));
        Assert.assertEquals("test", resp.getBody().readString());
       
       
        Assert.assertEquals(1, httpClient.getNumCacheHit());
        Assert.assertEquals(1, httpClient.getNumCacheMiss());
       
View Full Code Here

Examples of org.xlightweb.HttpResponse

    public void testRevalidate() throws Exception {
       
        IHttpRequestHandler reqHdl = new IHttpRequestHandler() {
           
            public void onRequest(IHttpExchange exchange) throws IOException, BadMessageException {
                HttpResponse resp = new HttpResponse(200, "text/plain", "test");
                resp.setHeader("Cache-Control", "public, max-age=1000, must-revalidate");
                exchange.send(resp);
            }
        };
       
        HttpServer server = new HttpServer(reqHdl);
        server.start();
       
        HttpClient httpClient = new HttpClient();
        httpClient.setCacheMaxSizeKB(100);
       
        IHttpResponse resp = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/"));
        Assert.assertEquals(200, resp.getStatus());
        Assert.assertEquals("test", resp.getBody().readString());
        Assert.assertNull(resp.getHeader(CacheHandler.XHEADER_NAME));
       
        QAUtil.sleep(1000);
       
        resp = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/"));
        Assert.assertEquals(200, resp.getStatus());
        Assert.assertNull(resp.getHeader(CacheHandler.XHEADER_NAME));
        Assert.assertEquals("test", resp.getBody().readString());
       
       
        Assert.assertEquals(0, httpClient.getNumCacheHit());
        Assert.assertEquals(2, httpClient.getNumCacheMiss());
       
View Full Code Here

Examples of org.xmlBlaster.util.http.HttpResponse

   public HttpResponse service(String urlPath, Map properties) {
          if (log.isLoggable(Level.FINE)) {
         log.fine("Invoking with '" + urlPath + "' urlPath, properties='" + properties + "'");
          }
      if (urlPath == null || urlPath.length() < 1) {
         return new HttpResponse("<html><h2>Empty request, please provide a URL path</h2></html>");
      }
      try {
         String path;
         String parameter = null;
          if (urlPath.indexOf('?') > -1) {
                         // has Parameter
                 path = urlPath.substring(0, urlPath.indexOf('?'));
          parameter = URLDecoder.decode(urlPath.substring(urlPath.indexOf('?') + 1,
                                        urlPath.length()), Constants.UTF8_ENCODING);
                 } else {
                        // has no parameter
                        path = urlPath;
                 }
         byte[] text;
         String mimeType = getMimeType(path.toString());
         if (this.urlPathClasspathSet.contains(path)) { // "/status.html"
            if (urlPath.startsWith("/")) {
               // "status.html": lookup where the java class resides in xmlBlaster.jar
               urlPath = urlPath.substring(1);
            }
            text = ServerScope.getFromClasspath(urlPath, this);
            if (log.isLoggable(Level.FINE)) log.fine("Reading '" + urlPath + "' from CLASSPATH");
         }
         else {
            File f = new File(path);
            // FIXME: check for security
            // dangerous because one could send: ../../../
            String name = f.getName();
            if (log.isLoggable(Level.FINE)) log.fine("Invoking with '" + urlPath + "' urlPath, name='" + name + "'");
            File template = new File(this.documentRoot, name);
            text = FileLocator.readFile(template.toString());
            if (log.isLoggable(Level.FINE)) log.fine("Reading template  '" + template.toString() + "'");
         }
         if (parameter != null && !(parameter.length() < 0)) {
            invokeAction(parameter);
         }
         if (mimeType.startsWith("text")) {
            text = replaceAllVariables(new String(text)).getBytes();
         }
         return new HttpResponse(text, mimeType);
      }
      catch (Throwable e) {
         e.printStackTrace();
         return new HttpResponse("<html><h2>" + e.toString() + "</h2></html>");
      }
   }
View Full Code Here

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

Examples of pt.opensoft.http.HttpResponse

    } finally {
      ((HttpURLConnection) myConnection).disconnect();
    }

        // Return the result
        return new HttpResponse(0, ByteUtil.toString(bOut.toByteArray()), null, null);
    }
View Full Code Here

Examples of railo.commons.net.http.HTTPResponse

        proxyport=pd==null?0:pd.getPort();
        proxyuser=pd==null?null:pd.getUsername();
        proxypassword=pd==null?null:pd.getPassword();
      }
     
      HTTPResponse method = HTTPEngine.get(url, authUser, authPassword, -1,HTTPEngine.MAX_REDIRECT, null, userAgent,
          ProxyDataImpl.getInstance(proxyserver, proxyport, proxyuser, proxypassword),null);
     
      // mimetype
      if(StringUtil.isEmpty(strMimetype)) {
        ContentType ct = method.getContentType();
        if(ct!=null)
          setMimetype(ct.toString());
       
      }
      InputStream is = new ByteArrayInputStream(method.getContentAsByteArray());
      try {
       
        render(pd4ml, is, os,url);
      }
      finally {
View Full Code Here

Examples of threescale.v3.api.HttpResponse

            connection.setRequestProperty("Accept-Charset", "UTF-8");

            connection.connect();


            return new HttpResponse(connection.getResponseCode(), getBody(connection.getInputStream()));

        } catch (IOException ex) {
            try {
                return new HttpResponse(connection.getResponseCode(), getBody(connection.getErrorStream()));
            } catch (IOException e) {
                throw new ServerError(e.getMessage());
            }
        } finally {
            if (connection != null) {
View Full Code Here

Examples of twitter4j.internal.http.HttpResponse

    @Test
    public void sendTwitterMessageWithInvalidUserId() throws Exception {
        DateTime now = TimeUtil.getCurrentDateTime();
        TimeUtil.setCurrentDateTime(now);

        HttpResponse res = mock(HttpResponse.class);
        doReturn(null).when(res).getResponseHeader(eq("X-RateLimit-Limit"));
        doReturn(null).when(res).getResponseHeader(eq("X-RateLimit-Remaining"));
        doReturn(null).when(res).getResponseHeader(eq("X-RateLimit-Reset"));
        doThrow(new TwitterException("message", res)).when(PartakeApp.getTwitterService()).updateStatus(anyString(), anyString(), eq(TWITTER_MESSAGE_WILLFAIL_MESSAGE));
View Full Code Here

Examples of yalp.libs.WS.HttpResponse

        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
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.