All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gitee.rabbitnoteeth.bedrock.http.server.context.HttpContext Maven / Gradle / Ivy

The newest version!
package com.gitee.rabbitnoteeth.bedrock.http.server.context;

import com.gitee.rabbitnoteeth.bedrock.core.util.StringUtils;
import com.gitee.rabbitnoteeth.bedrock.http.json.JsonResult;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.HttpServerRequest;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.ext.web.RoutingContext;

public class HttpContext {

  private final RoutingContext routingContext;

  public HttpContext(RoutingContext routingContext) {
    this.routingContext = routingContext;
  }

  public void writeResponse(JsonResult data) {
    routingContext.response().write(data.encode());
    routingContext.next();
  }

  public void writeResponse(Buffer data) {
    routingContext.response().write(data);
    routingContext.next();
  }

  public String getRequestParamAsString(String paramName) {
    return routingContext.request().getParam(paramName);
  }

  public Integer getRequestParamAsInt(String paramName) {
    String paramValue = routingContext.request().getParam(paramName);
    if (StringUtils.isBlank(paramValue)) {
      return null;
    }
    return Integer.parseInt(paramValue);
  }

  public HttpServerRequest getRequest() {
    return routingContext.request();
  }

  public HttpServerResponse getResponse() {
    return routingContext.response();
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy