Codota Logo
HttpIO
Code IndexAdd Codota to your IDE (free)

How to use
HttpIO
in
org.rapidoid.http.impl.lowlevel

Best Java code snippets using org.rapidoid.http.impl.lowlevel.HttpIO (Showing top 20 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
ScheduledThreadPoolExecutor s =
  • Codota Iconnew ScheduledThreadPoolExecutor(corePoolSize)
  • Codota IconThreadFactory threadFactory;new ScheduledThreadPoolExecutor(corePoolSize, threadFactory)
  • Codota IconString str;new ScheduledThreadPoolExecutor(1, new ThreadFactoryBuilder().setNameFormat(str).build())
  • Smart code suggestions by Codota
}
origin: rapidoid/rapidoid

@Override
public HttpStatus handle(Channel ctx, boolean isKeepAlive, Req req) {
  if (!HttpUtils.isGetReq(req)) return HttpStatus.NOT_FOUND;
  try {
    String[] staticFilesLocations = customization.staticFilesPath();
    if (!U.isEmpty(staticFilesLocations)) {
      Res res = HttpUtils.staticResource(req, staticFilesLocations);
      if (res != null) {
        StaticFilesSecurity staticFilesSecurity = customization.staticFilesSecurity();
        if (staticFilesSecurity.canServe(req, res)) {
          byte[] bytes = res.getBytesOrNull();
          if (bytes != null) {
            MediaType contentType = U.or(MediaType.getByFileName(res.getName()), MediaType.BINARY);
            HttpIO.INSTANCE.write200(HttpUtils.maybe(req), ctx, isKeepAlive, contentType, bytes);
            return HttpStatus.DONE;
          }
        }
      }
    }
    return HttpStatus.NOT_FOUND;
  } catch (Exception e) {
    return HttpIO.INSTANCE.errorAndDone(req, e, LogLevel.ERROR);
  }
}
origin: rapidoid/rapidoid

protected void writeJsonBody(MaybeReq req, Channel ctx, Object value) {
  writeContentTypeHeader(ctx, MediaType.JSON);
  ReusableWritable out = Msc.locals().jsonRenderingStream();
  JSON.stringify(value, out);
  HttpIO.INSTANCE.writeContentLengthHeader(ctx, out.size());
  HttpIO.INSTANCE.closeHeaders(req, ctx.output());
  ctx.write(out.array(), 0, out.size());
}
origin: rapidoid/rapidoid

private void onDone() {
  if (stopped) {
    return;
  }
  boolean willBeDone = true;
  if (!rendering) {
    renderResponseOrError();
    willBeDone = false;
  }
  if (!completed) {
    // FIXME is this still required?
    completed = true;
  }
  if (response != null) {
    response.finish();
  }
  if (willBeDone) {
    HttpIO.INSTANCE.done(ReqImpl.this);
  }
}
origin: rapidoid/rapidoid

private void handleError(Throwable error, final Req req, final Resp resp, final ProxyMapping mapping, final int attempts, final long since) {
  if (error instanceof ConnectException || error instanceof IOException) {
    if (HttpUtils.isGetReq(req) && !U.timedOut(since, timeout())) {
      Jobs.after(retryDelay()).milliseconds(() -> process(req, resp, mapping, attempts + 1, since));
    } else {
      HttpIO.INSTANCE.errorAndDone(req, U.rte("Couldn't connect to the upstream!", error), LogLevel.DEBUG);
    }
  } else {
    HttpIO.INSTANCE.errorAndDone(req, error, LogLevel.ERROR);
  }
}
origin: rapidoid/rapidoid

private void renderResponse(int code, MediaType contentType, RespBody body) {
  rendering = true;
  completed = body != null;
  HttpIO.INSTANCE.respond(
    HttpUtils.maybe(this), channel, connId, handle,
    code, isKeepAlive, contentType, body,
    response != null ? response.headers() : null,
    response != null ? response.cookies() : null
  );
}
origin: rapidoid/rapidoid

BufRange path = data.path;
HttpIO.INSTANCE.removeTrailingSlash(buf, path);
HttpIO.INSTANCE.removeTrailingSlash(buf, uri);
  HttpIO.INSTANCE.writeBadRequest(channel);
  return;
origin: rapidoid/rapidoid

private void handleError(Req req, Throwable e) {
  req.revert();
  req.async();
  HttpIO.INSTANCE.error(req, e, LogLevel.ERROR);
  // the Req object will do the rendering
  req.done();
}
origin: rapidoid/rapidoid

@Override
public HttpStatus handle(Channel ctx, boolean isKeepAlive, Req req) {
  HttpIO.INSTANCE.write200(HttpUtils.maybe(req), ctx, isKeepAlive, contentType, response);
  return HttpStatus.DONE;
}
origin: rapidoid/rapidoid

protected void writeBody(Channel ctx, byte[] body, int offset, int length, MediaType contentType) {
  writeContentTypeHeader(ctx, contentType);
  HttpIO.INSTANCE.writeContentLengthHeader(ctx, length);
  ctx.write(CR_LF);
  ctx.write(body, offset, length);
}
origin: rapidoid/rapidoid

  HttpIO.INSTANCE.writeHttpResp(maybeReq, ctx, isKeepAlive, 500, MediaType.PLAIN_TEXT_UTF_8, "Internal server error!".getBytes());
HttpIO.INSTANCE.writeHttpResp(maybeReq, ctx, isKeepAlive, code, ctype, result);
origin: rapidoid/rapidoid

private boolean handleError(Channel channel, boolean isKeepAlive, Req req, Throwable e) {
  if (req != null) {
    if (!((ReqImpl) req).isStopped()) {
      try {
        HttpIO.INSTANCE.errorAndDone(req, e, LogLevel.ERROR);
      } catch (Exception e1) {
        Log.error("HTTP error handler error!", e1);
        internalServerError(channel, isKeepAlive, req);
      }
    }
    return true;
  } else {
    Log.error("Low-level HTTP handler error!", e);
    internalServerError(channel, isKeepAlive, null);
  }
  return false;
}
origin: rapidoid/rapidoid

  @Override
  public void onRequest(Channel channel, RapidoidHelper data) {
    boolean isKeepAlive = data.isKeepAlive.value;

    RespBody body = new RespBodyBytes("Not found!".getBytes());

    HttpIO.INSTANCE.respond(HttpUtils.noReq(), channel, -1, -1, 404, isKeepAlive, MediaType.PLAIN_TEXT_UTF_8, body, null, null);

    channel.send().closeIf(!isKeepAlive);
  }
}
origin: org.rapidoid/rapidoid-http-fast

BufRange path = data.path;
HttpIO.INSTANCE.removeTrailingSlash(buf, path);
HttpIO.INSTANCE.removeTrailingSlash(buf, uri);
  HttpIO.INSTANCE.writeBadRequest(channel);
  return;
origin: rapidoid/rapidoid

static RespBody toRespBody(Req req, RespImpl resp) {
  try {
    return createRespBodyFromResult(req, resp);
  } catch (Throwable e) {
    HttpIO.INSTANCE.error(req, e, LogLevel.ERROR);
    try {
      return createRespBodyFromResult(req, resp);
    } catch (Exception e1) {
      Log.error("Internal rendering error!", e1);
      return new RespBodyBytes(HttpUtils.getErrorMessageAndSetCode(resp, e1).getBytes());
    }
  }
}
origin: rapidoid/rapidoid

@Override
public HttpStatus handle(Channel ctx, boolean isKeepAlive, Req req) {
  byte[] bytes = resource.getBytesOrNull();
  if (bytes != null) {
    HttpIO.INSTANCE.write200(HttpUtils.maybe(req), ctx, isKeepAlive, contentType, bytes);
    return HttpStatus.DONE;
  } else {
    return HttpStatus.NOT_FOUND;
  }
}
origin: org.rapidoid/rapidoid-http-fast

protected void writeBody(Channel ctx, byte[] body, int offset, int length, MediaType contentType) {
  writeContentTypeHeader(ctx, contentType);
  HttpIO.INSTANCE.writeContentLengthHeader(ctx, length);
  ctx.write(CR_LF);
  ctx.write(body, offset, length);
}
origin: org.rapidoid/rapidoid-http-fast

  HttpIO.INSTANCE.writeHttpResp(maybeReq, ctx, isKeepAlive, 500, MediaType.PLAIN_TEXT_UTF_8, "Internal server error!".getBytes());
HttpIO.INSTANCE.writeHttpResp(maybeReq, ctx, isKeepAlive, code, ctype, result);
origin: org.rapidoid/rapidoid-http-fast

@Override
public HttpStatus handle(Channel ctx, boolean isKeepAlive, Req req) {
  if (!HttpUtils.isGetReq(req)) return HttpStatus.NOT_FOUND;
  try {
    String[] staticFilesLocations = customization.staticFilesPath();
    if (!U.isEmpty(staticFilesLocations)) {
      Res res = HttpUtils.staticResource(req, staticFilesLocations);
      if (res != null) {
        StaticFilesSecurity staticFilesSecurity = customization.staticFilesSecurity();
        if (staticFilesSecurity.canServe(req, res)) {
          byte[] bytes = res.getBytesOrNull();
          if (bytes != null) {
            MediaType contentType = U.or(MediaType.getByFileName(res.getName()), MediaType.BINARY);
            HttpIO.INSTANCE.write200(HttpUtils.maybe(req), ctx, isKeepAlive, contentType, bytes);
            return HttpStatus.DONE;
          }
        }
      }
    }
    return HttpStatus.NOT_FOUND;
  } catch (Exception e) {
    return HttpIO.INSTANCE.errorAndDone(req, e, LogLevel.ERROR);
  }
}
origin: org.rapidoid/rapidoid-http-server

private void handleError(Throwable error, final Req req, final Resp resp, final ProxyMapping mapping, final int attempts, final long since) {
  if (error instanceof ConnectException || error instanceof IOException) {
    if (HttpUtils.isGetReq(req) && !Msc.timedOut(since, timeout())) {
      Jobs.after(retryDelay()).milliseconds(new Runnable() {
        @Override
        public void run() {
          process(req, resp, mapping, attempts + 1, since);
        }
      });
    } else {
      HttpIO.INSTANCE.errorAndDone(req, U.rte("Couldn't connect to the upstream!", error), LogLevel.DEBUG);
    }
  } else {
    HttpIO.INSTANCE.errorAndDone(req, error, LogLevel.ERROR);
  }
}
origin: rapidoid/rapidoid

private void serveCached(ReqImpl req, CachedResp resp) {
  Channel channel = req.channel();
  req.cached(true);
  HttpIO.INSTANCE.respond(HttpUtils.req(req), channel, -1, -1, resp.statusCode,
    req.isKeepAlive(), resp.contentType, new RespBodyBuffer(resp.body.duplicate()), resp.headers, null);
  channel.send().closeIf(!req.isKeepAlive());
}
org.rapidoid.http.impl.lowlevelHttpIO

Most used methods

  • errorAndDone
  • closeHeaders
  • done
  • error
  • removeTrailingSlash
  • respond
  • write200
  • writeBadRequest
  • writeContentLengthHeader
  • writeHttpResp

Popular in Java

  • Parsing JSON documents to java classes using gson
  • getSystemService (Context)
  • setRequestProperty (URLConnection)
    Sets the general request property. If a property with the key already exists, overwrite its value wi
  • setScale (BigDecimal)
    Returns a BigDecimal whose scale is the specified value, and whose value is numerically equal to thi
  • Thread (java.lang)
    A thread is a thread of execution in a program. The Java Virtual Machine allows an application to ha
  • Connection (java.sql)
    A connection represents a link from a Java application to a database. All SQL statements and results
  • PriorityQueue (java.util)
    An unbounded priority Queue based on a priority heap. The elements of the priority queue are ordered
  • ExecutorService (java.util.concurrent)
    An Executor that provides methods to manage termination and methods that can produce a Future for tr
  • Modifier (javassist)
    The Modifier class provides static methods and constants to decode class and member access modifiers
  • Servlet (javax.servlet)
    Defines methods that all servlets must implement.A servlet is a small Java program that runs within
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now