예제 #1
0
  private String generateRedirectLocation(Context context, Request request, String path) {
    // Rules
    // 1. Given absolute URL use it
    // 2. Given Starting Slash prepend public facing domain:port if provided if not use base URL of
    // request
    // 3. Given relative URL prepend public facing domain:port plus parent path of request URL
    // otherwise full parent path

    PublicAddress publicAddress = context.get(PublicAddress.class);
    String generatedPath;
    URI host = publicAddress.getAddress(context);

    if (ABSOLUTE_PATTERN.matcher(path).matches()) {
      // Rule 1 - Path is absolute
      generatedPath = path;
    } else {
      if (path.charAt(0) == '/') {
        // Rule 2 - Starting Slash
        generatedPath = host.toString() + path;
      } else {
        // Rule 3
        generatedPath = host.toString() + getParentPath(request.getUri()) + path;
      }
    }

    return generatedPath;
  }
 @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());
           });
 }
예제 #3
0
 private URI getAddress() {
   return context.get(PublicAddress.class).get();
 }