Search in sources :

Example 1 with Redirector

use of org.restlet.routing.Redirector in project pinot by linkedin.

the class ControllerRestApplication method configureRouter.

protected void configureRouter(Router router) {
    // Remove server-side HTTP timeout (see http://stackoverflow.com/questions/12943447/restlet-server-socket-timeout)
    getContext().getParameters().add("maxIoIdleTimeMs", ONE_HOUR_IN_MILLIS);
    getContext().getParameters().add("ioMaxIdleTimeMs", ONE_HOUR_IN_MILLIS);
    router.setDefaultMatchingMode(Template.MODE_EQUALS);
    /**
     * Start Routers 2.0
     */
    attachRoutesForClass(router, PinotTenantRestletResource.class);
    attachRoutesForClass(router, PinotSchemaRestletResource.class);
    attachRoutesForClass(router, PinotTableRestletResource.class);
    // GET
    attachRoutesForClass(router, PinotTableInstances.class);
    attachRoutesForClass(router, PinotTableSchema.class);
    attachRoutesForClass(router, PinotSegmentRestletResource.class);
    attachRoutesForClass(router, TableSize.class);
    // PUT
    attachRoutesForClass(router, PinotTableSegmentConfigs.class);
    attachRoutesForClass(router, PinotTableIndexingConfigs.class);
    attachRoutesForClass(router, PinotTableTenantConfigs.class);
    attachRoutesForClass(router, PinotTableMetadataConfigs.class);
    // Uploading Downloading segments
    attachRoutesForClass(router, PinotSegmentUploadRestletResource.class);
    attachRoutesForClass(router, PinotVersionRestletResource.class);
    // SegmentCompletionProtocol implementation on the controller
    attachRoutesForClass(router, LLCSegmentCommit.class);
    attachRoutesForClass(router, LLCSegmentConsumed.class);
    attachRoutesForClass(router, LLCSegmentStoppedConsuming.class);
    // GET... add it here because it can block visibility of
    // some of the existing paths (like indexingConfigs) added above
    attachRoutesForClass(router, TableViews.class);
    router.attach("/api", SwaggerResource.class);
    /**
     *  End Routes 2.0
     */
    attachRoutesForClass(router, PinotInstanceRestletResource.class);
    router.attach("/pinot-controller/admin", PinotControllerHealthCheck.class);
    router.attach("/pql", PqlQueryResource.class);
    try {
        final Directory webdir = new Directory(getContext(), CONSOLE_WEBAPP_ROOT_PATH);
        webdir.setDeeplyAccessible(true);
        webdir.setIndexName("index.html");
        router.attach("/query", webdir);
    } catch (Exception e) {
        LOGGER.warn("Failed to initialize route for /query", e);
    }
    try {
        final Directory swaggerIndexDir = new Directory(getContext(), getClass().getClassLoader().getResource("swagger-ui").toString());
        swaggerIndexDir.setIndexName("index.html");
        swaggerIndexDir.setDeeplyAccessible(true);
        router.attach("/swagger-ui", swaggerIndexDir);
    } catch (Exception e) {
        LOGGER.warn("Failed to initialize route for /swagger-ui", e);
    }
    try {
        final Directory swaggerUiDir = new Directory(getContext(), getClass().getClassLoader().getResource("META-INF/resources/webjars/swagger-ui/2.2.2").toString());
        swaggerUiDir.setDeeplyAccessible(true);
        router.attach("/swaggerui-dist", swaggerUiDir);
    } catch (Exception e) {
        LOGGER.warn("Failed to initialize route for /swaggerui-dist", e);
    }
    try {
        final Redirector redirector = new Redirector(getContext(), "/swagger-ui/index.html?url=/api", Redirector.MODE_CLIENT_TEMPORARY);
        router.attach("/help", redirector);
    } catch (Exception e) {
        LOGGER.warn("Failed to initialize route for /help", e);
    }
    try {
        final Directory landing = new Directory(getContext(), getClass().getClassLoader().getResource("landing").toString());
        landing.setDeeplyAccessible(false);
        landing.setIndexName("index.html");
        router.attach("/", landing);
    } catch (Exception e) {
        LOGGER.warn("Failed to initialize route for /", e);
    }
}
Also used : Directory(org.restlet.resource.Directory) Redirector(org.restlet.routing.Redirector)

Example 2 with Redirector

use of org.restlet.routing.Redirector in project OpenAM by OpenRock.

the class EndSession method handleRedirect.

private Representation handleRedirect(OAuth2Request request, String idToken, String redirectUri) throws RedirectUriMismatchException, InvalidClientException, RelativeRedirectUriException, NotFoundException {
    validateRedirect(request, idToken, redirectUri);
    Response response = getResponse();
    new Redirector(getContext(), new Reference(redirectUri).toString(), Redirector.MODE_CLIENT_FOUND).handle(getRequest(), response);
    return response == null ? null : response.getEntity();
}
Also used : Response(org.restlet.Response) Reference(org.restlet.data.Reference) Redirector(org.restlet.routing.Redirector)

Example 3 with Redirector

use of org.restlet.routing.Redirector in project OpenAM by OpenRock.

the class OAuth2Representation method toRepresentation.

/**
     * Converts the authorization token into a representation to send back to the user agent.
     *
     * @param context The Restlet context.
     * @param request The Restlet request.
     * @param response The Restlet response.
     * @param authorizationToken The authorization token.
     * @param redirectUri The redirect uri.
     * @return The representation to send to the user agent.
     */
Representation toRepresentation(Context context, Request request, Response response, AuthorizationToken authorizationToken, String redirectUri) {
    final Form tokenForm = toForm(authorizationToken);
    final Reference redirectReference = new Reference(redirectUri);
    if (authorizationToken.isFragment()) {
        redirectReference.setFragment(tokenForm.getQueryString());
    } else {
        final Iterator<Parameter> iter = tokenForm.iterator();
        while (iter.hasNext()) {
            redirectReference.addQueryParameter(iter.next());
        }
    }
    if (isFormPostRequest(requestFactory.create(request))) {
        return getFormPostRepresentation(context, authorizationToken, redirectReference.toString());
    }
    final Redirector dispatcher = new Redirector(context, redirectReference.toString(), Redirector.MODE_CLIENT_FOUND);
    dispatcher.handle(request, response);
    return response == null ? null : response.getEntity();
}
Also used : Form(org.restlet.data.Form) Reference(org.restlet.data.Reference) Parameter(org.restlet.data.Parameter) Redirector(org.restlet.routing.Redirector)

Example 4 with Redirector

use of org.restlet.routing.Redirector in project OpenAM by OpenRock.

the class ExceptionHandler method handle.

/**
     * Handles a OAuth2RestletException that is thrown when processing a OAuth2 authorization request.
     * <br/>
     * If the OAuth2RestletException has a status of {@link Status#REDIRECTION_TEMPORARY} the user agent will be
     * redirected to the redirect uri set on the exception.
     * <br/>
     * If the OAuth2RestletException does not have a redirect status but still has a redirect uri set, the user
     * agent will be redrected to the redirect uri with the exception message in the redirect uri.
     * <br/>
     * In all other cases the OAuth2 error page will be presented.
     *
     * @param exception The OAuth2RestletException.
     * @param context The Restlet context.
     * @param request The Restlet request.
     * @param response The Restlet response.
     */
private void handle(OAuth2RestletException exception, Context context, Request request, Response response) {
    if (exception.getStatus().equals(Status.REDIRECTION_TEMPORARY)) {
        Redirector redirector = new Redirector(new Context(), exception.getRedirectUri(), Redirector.MODE_CLIENT_PERMANENT);
        redirector.handle(request, response);
        return;
    } else {
        response.setStatus(exception.getStatus());
    }
    if (!isEmpty(exception.getRedirectUri())) {
        Reference ref = new Reference(exception.getRedirectUri());
        if (UrlLocation.FRAGMENT.equals(exception.getParameterLocation())) {
            ref.setFragment(representation.toForm(exception.asMap()).getQueryString());
        } else {
            ref.addQueryParameters(representation.toForm(exception.asMap()));
        }
        final Redirector redirector = new Redirector(context, ref.toString(), Redirector.MODE_CLIENT_FOUND);
        redirector.handle(request, response);
        return;
    }
    final Map<String, String> data = new HashMap<>(exception.asMap());
    final String realm = requestFactory.create(request).getParameter("realm");
    data.put("realm", realm);
    data.put("baseUrl", baseURLProviderFactory.get(realm).getRootURL(ServletUtils.getRequest(request)));
    response.setEntity(representation.getRepresentation(context, "page", "error.ftl", data));
}
Also used : Context(org.restlet.Context) HashMap(java.util.HashMap) Reference(org.restlet.data.Reference) Redirector(org.restlet.routing.Redirector)

Aggregations

Redirector (org.restlet.routing.Redirector)4 Reference (org.restlet.data.Reference)3 HashMap (java.util.HashMap)1 Context (org.restlet.Context)1 Response (org.restlet.Response)1 Form (org.restlet.data.Form)1 Parameter (org.restlet.data.Parameter)1 Directory (org.restlet.resource.Directory)1