예제 #1
0
 public void sendResponse() {
   int statusCode = context.getResponse().getStatus().getCode();
   if (statusCode >= 400) {
     context.clientError(statusCode);
   } else {
     context.getResponse().send(MediaType.TEXT_HTML, responseContent);
   }
 }
예제 #2
0
  public RatpackWebContext(Context ctx, TypedData body, SessionData session) {
    this.context = ctx;
    this.session = session;
    this.request = ctx.getRequest();
    this.response = ctx.getResponse();

    if (isFormAvailable(request, body)) {
      this.form = FormDecoder.parseForm(ctx, body, MultiValueMap.empty());
    } else {
      this.form = new DefaultForm(MultiValueMap.empty(), MultiValueMap.empty());
    }
  }
 @Override
 public void handle(Context ctx, RPCConfig rpc) {
   ctx.get(HttpClient.class)
       .requestStream(
           rpc.getURI(),
           requestSpec -> {
             requestSpec.post();
             requestSpec.body(body -> body.type(jsonType).text(buildStatusReq()));
             requestSpec.redirects(0);
             if (rpc.getUsername() != null) {
               requestSpec.basicAuth(rpc.getUsername(), rpc.getPassword());
             }
           })
       .then(
           responseStream -> {
             // TODO: Extract from JsonRpcResponse and return more restful JSON format (no RPC
             // wrapper)
             responseStream.forwardTo(ctx.getResponse());
           });
 }
예제 #4
0
 public void redirect(Context context, String location, int code) {
   context.getResponse().status(code);
   String normalizedLocation = generateRedirectLocation(context, context.getRequest(), location);
   context.getResponse().getHeaders().set(HttpHeaderConstants.LOCATION, normalizedLocation);
   context.getResponse().send();
 }
예제 #5
0
 public void sendResponse(RequiresHttpAction action) {
   context.getResponse().status(action.getCode());
   sendResponse();
 }
예제 #6
0
 @Override
 public void setResponseHeader(String name, String value) {
   context.getResponse().getHeaders().set(name, value);
 }
예제 #7
0
 @Override
 public void setResponseStatus(int code) {
   context.getResponse().status(code);
 }