public SessionAwareNettyHttpChannel(
     final RestChannel channel,
     final SessionStore sessionStore,
     final boolean detailedErrorsEnabled) {
   super(channel.request(), detailedErrorsEnabled);
   this.channel = channel;
   this.sessionStore = sessionStore;
 }
Ejemplo n.º 2
0
 public static RestResponse buildResponse(Table table, RestChannel channel) throws Exception {
   RestRequest request = channel.request();
   XContentType xContentType =
       XContentType.fromMediaTypeOrFormat(request.param("format", request.header("Accept")));
   if (xContentType != null) {
     return buildXContentBuilder(table, channel);
   }
   return buildTextPlainResponse(table, channel);
 }
Ejemplo n.º 3
0
  public static RestResponse buildXContentBuilder(Table table, RestChannel channel)
      throws Exception {
    RestRequest request = channel.request();
    XContentBuilder builder = channel.newBuilder();
    List<DisplayHeader> displayHeaders = buildDisplayHeaders(table, request);

    builder.startArray();
    for (int row = 0; row < table.getRows().size(); row++) {
      builder.startObject();
      for (DisplayHeader header : displayHeaders) {
        builder.field(
            header.display, renderValue(request, table.getAsMap().get(header.name).get(row).value));
      }
      builder.endObject();
    }
    builder.endArray();
    return new BytesRestResponse(RestStatus.OK, builder);
  }
Ejemplo n.º 4
0
  public static RestResponse buildTextPlainResponse(Table table, RestChannel channel)
      throws IOException {
    RestRequest request = channel.request();
    boolean verbose = request.paramAsBoolean("v", false);

    List<DisplayHeader> headers = buildDisplayHeaders(table, request);
    int[] width = buildWidths(table, request, verbose, headers);

    BytesStreamOutput bytesOut = channel.bytesOutput();
    UTF8StreamWriter out = new UTF8StreamWriter().setOutput(bytesOut);
    int lastHeader = headers.size() - 1;
    if (verbose) {
      for (int col = 0; col < headers.size(); col++) {
        DisplayHeader header = headers.get(col);
        boolean isLastColumn = col == lastHeader;
        pad(
            new Table.Cell(header.display, table.findHeaderByName(header.name)),
            width[col],
            request,
            out,
            isLastColumn);
        if (!isLastColumn) {
          out.append(" ");
        }
      }
      out.append("\n");
    }
    for (int row = 0; row < table.getRows().size(); row++) {
      for (int col = 0; col < headers.size(); col++) {
        DisplayHeader header = headers.get(col);
        boolean isLastColumn = col == lastHeader;
        pad(table.getAsMap().get(header.name).get(row), width[col], request, out, isLastColumn);
        if (!isLastColumn) {
          out.append(" ");
        }
      }
      out.append("\n");
    }
    out.close();
    return new BytesRestResponse(
        RestStatus.OK, BytesRestResponse.TEXT_CONTENT_TYPE, bytesOut.bytes());
  }