Package ratpack.http

Examples of ratpack.http.Response


    this.encoder = new Encoder(bufferAllocator);
  }

  @Override
  public void render(Context context, ServerSentEvents object) throws Exception {
    Response response = context.getResponse();
    response.getHeaders().add(HttpHeaderConstants.CONTENT_TYPE, TEXT_EVENT_STREAM_CHARSET_UTF_8);
    response.getHeaders().add(HttpHeaderConstants.CACHE_CONTROL, HttpHeaderConstants.NO_CACHE_FULL);
    response.getHeaders().add(HttpHeaderConstants.PRAGMA, HttpHeaderConstants.NO_CACHE);
    response.sendStream(Streams.map(object.getPublisher(), encoder));
  }
View Full Code Here


    Date date = new Date(attributes.lastModifiedTime().toMillis());

    context.lastModified(date, new Runnable() {
      public void run() {
        final String ifNoneMatch = context.getRequest().getHeaders().get(HttpHeaders.Names.IF_NONE_MATCH);
        Response response = context.getResponse();
        if (ifNoneMatch != null && ifNoneMatch.trim().equals("*")) {
          response.status(NOT_MODIFIED.code()).send();
          return;
        }

        if (!response.getHeaders().contains(HttpHeaders.Names.CONTENT_TYPE)) {
          String contentType = context.get(MimeTypes.class).getContentType(file.getFileName().toString());
          response.contentType(contentType);
        }

        try {
          response.sendFile(attributes, file);
        } catch (Exception e) {
          throw ExceptionUtils.uncheck(e);
        }
      }
    });
View Full Code Here

  public void handle(Context context) {
    HttpMethod requestMethod = context.getRequest().getMethod();
    if (requestMethod.name(method)) {
      context.next();
    } else if (requestMethod.isOptions()) {
      Response response = context.getResponse();
      response.getHeaders().add(HttpHeaderConstants.ALLOW, method);
      response.status(200).send();
    } else {
      context.clientError(405);
    }
  }
View Full Code Here

      + "Original throwable: " + getStackTraceAsString(original) + "\n"
      + "Error handler throwable: " + getStackTraceAsString(errorHandlerThrowable);

    LOGGER.error(msg);

    Response response = requestConstants.response.status(500);
    if (getLaunchConfig().isDevelopment()) {
      response.send(msg);
    } else {
      response.send();
    }
  }
View Full Code Here

    final DefaultEventController<RequestOutcome> requestOutcomeEventController = new DefaultEventController<>();
    final AtomicBoolean transmitted = new AtomicBoolean(false);

    final DefaultResponseTransmitter responseTransmitter = new DefaultResponseTransmitter(transmitted, execControl, channel, nettyRequest, request, nettyHeaders, requestOutcomeEventController, launchConfig.isCompressResponses(), shouldCompress, startTime);

    final Response response = new DefaultResponse(execControl, responseHeaders, ctx.alloc(), responseTransmitter);
    ctx.attr(RESPONSE_TRANSMITTER_ATTRIBUTE_KEY).set(responseTransmitter);

    InetSocketAddress socketAddress = (InetSocketAddress) channel.localAddress();
    final BindAddress bindAddress = new InetSocketAddressBackedBindAddress(socketAddress);

    Action<Action<Object>> subscribeHandler = thing -> {
      transmitted.set(true);
      channelSubscriptions.put(channel, thing);
      channel.closeFuture().addListener(future -> channelSubscriptions.remove(channel));
    };

    final DirectChannelAccess directChannelAccess = new DefaultDirectChannelAccess(channel, subscribeHandler);

    final DefaultContext.RequestConstants requestConstants = new DefaultContext.RequestConstants(
      applicationConstants, bindAddress, request, response, directChannelAccess, requestOutcomeEventController.getRegistry()
    );

    DefaultContext.start(execController.getControl(), requestConstants, registry, handlers, execution -> {
      if (!transmitted.get()) {
        Handler lastHandler = requestConstants.handler;
        StringBuilder description = new StringBuilder();
        description
          .append("No response sent for ")
          .append(request.getMethod().getName())
          .append(" request to ")
          .append(request.getUri())
          .append(" (last handler: ");

        if (lastHandler instanceof DescribingHandler) {
          ((DescribingHandler) lastHandler).describeTo(description);
        } else {
          DescribingHandlers.describeTo(lastHandler, description);
        }

        description.append(")");
        String message = description.toString();
        LOGGER.warn(message);

        response.status(500);

        if (launchConfig.isDevelopment()) {
          response.send(message);
        } else {
          response.send();
        }
      }
    });
  }
View Full Code Here

  public static final TypeToken<Renderer<ResponseChunks>> TYPE = new TypeToken<Renderer<ResponseChunks>>() {};

  @Override
  public void render(Context context, ResponseChunks chunks) throws Exception {
    Response response = context.getResponse();
    response.getHeaders().add(HttpHeaderConstants.TRANSFER_ENCODING, HttpHeaderConstants.CHUNKED);
    response.getHeaders().set(HttpHeaderConstants.CONTENT_TYPE, chunks.getContentType());
    Publisher<? extends ByteBuf> publisher = chunks.publisher(context.getLaunchConfig().getBufferAllocator());
    response.sendStream(publisher);
  }
View Full Code Here

TOP

Related Classes of ratpack.http.Response

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.