Package ratpack.http

Examples of ratpack.http.Request


    new ErrorPageRenderer() {
      @Override
      protected void render() {
        render(context, "Internal Error", w -> {
          messages(w, "Internal Error", () -> {
            Request request = context.getRequest();
            meta(w, m -> m
                .put("URI:", request.getRawUri())
                .put("Method:", request.getMethod().getName())
            );
          });
          stack(w, null, throwable);
        });
View Full Code Here


   * @param statusCode The 4xx status code that explains the problem
   */
  @Override
  public void error(Context context, int statusCode) {
    HttpResponseStatus status = HttpResponseStatus.valueOf(statusCode);
    Request request = context.getRequest();
    LOGGER.error(statusCode + " client error for request to " + request.getRawUri());
    context.getResponse().status(statusCode);

    new ErrorPageRenderer() {
      protected void render() {
        render(context, status.reasonPhrase(), w ->
            messages(w, "Client Error", () ->
                meta(w, m -> m
                    .put("URI:", request.getRawUri())
                    .put("Method:", request.getMethod().getName())
                    .put("Status Code:", status.code())
                    .put("Phrase:", status.reasonPhrase())
                )
            )
        );
View Full Code Here

  public AssetHandler(ImmutableList<String> indexFiles) {
    this.indexFiles = indexFiles;
  }

  public void handle(Context context) throws Exception {
    Request request = context.getRequest();

    String path = context.maybeGet(PathBinding.class)
      .map(PathBinding::getPastBinding)
      .orElse(request.getPath());

    // Decode the path.
    try {
      path = new URI(path).getPath();
    } catch (URISyntaxException e) {
View Full Code Here

      });
    }
  }

  private String currentUriWithTrailingSlash(Context context) {
    Request request = context.getRequest();
    String redirectUri = "/" + request.getPath() + "/";
    String query = request.getQuery();
    if (!query.isEmpty()) {
      redirectUri += "?" + query;
    }
    return redirectUri;
  }
View Full Code Here

import static ratpack.util.ExceptionUtils.uncheck;

public abstract class FormDecoder {

  public static Form parseForm(Context context, TypedData requestBody) throws RuntimeException {
    Request request = context.getRequest();
    HttpMethod method = io.netty.handler.codec.http.HttpMethod.valueOf(request.getMethod().getName());
    HttpRequest nettyRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, method, request.getUri());
    nettyRequest.headers().add(HttpHeaders.Names.CONTENT_TYPE, request.getBody().getContentType().toString());
    HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(nettyRequest);

    HttpContent content = new DefaultHttpContent(requestBody.getBuffer());

    decoder.offer(content);
View Full Code Here

  }

  @Override
  public void handle(final Context context) throws Exception {
    final MetricRegistry metricRegistry = context.get(MetricRegistry.class);
    final Request request = context.getRequest();
    BlockingExecTimingInterceptor blockingExecTimingInterceptor = new BlockingExecTimingInterceptor(metricRegistry, request);

    context.addInterceptor(blockingExecTimingInterceptor, new Action<Execution>() {
      @Override
      public void execute(Execution execution) throws Exception {
        String tag = buildRequestTimerTag(request.getUri(), request.getMethod().getName());
        final Timer.Context timer = metricRegistry.timer(tag).time();
        context.onClose(new Action<RequestOutcome>() {
          public void execute(RequestOutcome thing) throws Exception {
            timer.stop();
          }
View Full Code Here

    Handler handler = Handlers.chain(launchConfig, registry, chainAction);
    return invoke(handler, launchConfig, registry);
  }

  private HandlingResult invoke(Handler handler, LaunchConfig launchConfig, Registry registry) throws HandlerTimeoutException {
    Request request = new DefaultRequest(requestHeaders, method, uri, requestBody);

    try {
      return new DefaultHandlingResult(
        request,
        responseHeaders,
View Full Code Here

      throw uncheck(e);
    }

    WebSocketServerHandshakerFactory factory = new WebSocketServerHandshakerFactory(wsPath.toString(), null, false, maxLength);

    Request request = context.getRequest();
    HttpMethod method = valueOf(request.getMethod().getName());
    FullHttpRequest nettyRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, method, request.getUri());
    nettyRequest.headers().add(SEC_WEBSOCKET_VERSION, request.getHeaders().get(SEC_WEBSOCKET_VERSION));
    nettyRequest.headers().add(SEC_WEBSOCKET_KEY, request.getHeaders().get(SEC_WEBSOCKET_KEY));

    final WebSocketServerHandshaker handshaker = factory.newHandshaker(nettyRequest);

    final DirectChannelAccess directChannelAccess = context.getDirectChannelAccess();
    final Channel channel = directChannelAccess.getChannel();
View Full Code Here

      nettyRequest.release();
      return;
    }

    final long startTime = addResponseTimeHeader ? System.nanoTime() : 0;
    final Request request = new DefaultRequest(new NettyHeadersBackedHeaders(nettyRequest.headers()), nettyRequest.getMethod().name(), nettyRequest.getUri(), nettyRequest.content());
    final Channel channel = ctx.channel();
    final HttpHeaders nettyHeaders = new DefaultHttpHeaders(false);
    final MutableHeaders responseHeaders = new NettyHeadersBackedMutableHeaders(nettyHeaders);
    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 {
View Full Code Here

  private URI getAddress() {
    return context.get(PublicAddress.class).getAddress(context);
  }

  private boolean isFormAvailable() {
    Request request = context.getRequest();
    HttpMethod method = request.getMethod();
    return request.getBody().getContentType().isForm() && (method.isPost() || method.isPut());
  }
View Full Code Here

TOP

Related Classes of ratpack.http.Request

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.