Esempio n. 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);
   }
 }
Esempio n. 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());
           });
 }
Esempio n. 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();
 }
Esempio n. 5
0
 public void sendResponse(RequiresHttpAction action) {
   context.getResponse().status(action.getCode());
   sendResponse();
 }
Esempio n. 6
0
 @Override
 public void setResponseHeader(String name, String value) {
   context.getResponse().getHeaders().set(name, value);
 }
Esempio n. 7
0
 @Override
 public void setResponseStatus(int code) {
   context.getResponse().status(code);
 }