Search in sources :

Example 1 with Finder

use of org.restlet.resource.Finder in project qi4j-sdk by Qi4j.

the class RestApplication method createFinder.

private Finder createFinder(Class<? extends ServerResource> resource) {
    Finder finder = module.newObject(Finder.class);
    finder.setTargetClass(resource);
    return finder;
}
Also used : Finder(org.restlet.resource.Finder)

Example 2 with Finder

use of org.restlet.resource.Finder in project pinot by linkedin.

the class SwaggerResource method get.

@Get
@Override
public Representation get() {
    try {
        // Info
        JSONObject info = new JSONObject();
        info.put("title", "Pinot Controller");
        info.put("version", "0.1");
        // Paths
        JSONObject paths = new JSONObject();
        Router router = PinotRestletApplication.getRouter();
        RouteList routeList = router.getRoutes();
        for (Route route : routeList) {
            if (route instanceof TemplateRoute) {
                TemplateRoute templateRoute = (TemplateRoute) route;
                JSONObject pathObject = new JSONObject();
                String routePath = templateRoute.getTemplate().getPattern();
                // Check which methods are present
                Restlet routeTarget = templateRoute.getNext();
                if (routeTarget instanceof Finder) {
                    Finder finder = (Finder) routeTarget;
                    generateSwaggerForFinder(pathObject, routePath, finder);
                } else if (routeTarget instanceof Filter) {
                    do {
                        Filter filter = (Filter) routeTarget;
                        routeTarget = filter.getNext();
                    } while (routeTarget instanceof Filter);
                    if (routeTarget instanceof Finder) {
                        Finder finder = (Finder) routeTarget;
                        generateSwaggerForFinder(pathObject, routePath, finder);
                    }
                }
                if (pathObject.keys().hasNext()) {
                    paths.put(routePath, pathObject);
                }
            }
        }
        // Tags
        JSONArray tags = new JSONArray();
        addTag(tags, "tenant", "Tenant-related operations");
        addTag(tags, "instance", "Instance-related operations");
        addTag(tags, "table", "Table-related operations");
        addTag(tags, "segment", "Segment-related operations");
        addTag(tags, "schema", "Schema-related operations");
        addTag(tags, "version", "Version-related operations");
        // Swagger
        JSONObject swagger = new JSONObject();
        swagger.put("swagger", "2.0");
        swagger.put("info", info);
        swagger.put("paths", paths);
        swagger.put("tags", tags);
        StringRepresentation representation = new StringRepresentation(swagger.toString());
        // Set up CORS
        Series<Header> responseHeaders = (Series<Header>) getResponse().getAttributes().get("org.restlet.http.headers");
        if (responseHeaders == null) {
            responseHeaders = new Series(Header.class);
            getResponse().getAttributes().put("org.restlet.http.headers", responseHeaders);
        }
        responseHeaders.add(new Header("Access-Control-Allow-Origin", "*"));
        return representation;
    } catch (JSONException e) {
        return new StringRepresentation(e.toString());
    }
}
Also used : Restlet(org.restlet.Restlet) TemplateRoute(org.restlet.routing.TemplateRoute) Finder(org.restlet.resource.Finder) JSONArray(org.json.JSONArray) Router(org.restlet.routing.Router) JSONException(org.json.JSONException) RouteList(org.restlet.util.RouteList) Series(org.restlet.util.Series) JSONObject(org.json.JSONObject) Header(org.restlet.engine.header.Header) Filter(org.restlet.routing.Filter) StringRepresentation(org.restlet.representation.StringRepresentation) Route(org.restlet.routing.Route) TemplateRoute(org.restlet.routing.TemplateRoute) Get(org.restlet.resource.Get)

Example 3 with Finder

use of org.restlet.resource.Finder in project OpenAM by OpenRock.

the class OAuth2FlowFinder method create.

/**
     * Creates a new instance of the handler for the correct OAuth2 endpoint based from the grant type specified in
     * the requests query parameters.
     *
     * @param request {@inheritDoc}
     * @param response {@inheritDoc}
     * @return {@inheritDoc}
     */
public ServerResource create(Request request, Response response) {
    final OAuth2Request oAuth2Request = requestFactory.create(request);
    final String grantType = oAuth2Request.getParameter("grant_type");
    if (isEmpty(grantType)) {
        logger.error("Type is not set");
        return new ErrorResource(exceptionHandler, new InvalidRequestException("Grant type is not set"));
    }
    Finder finder = endpointClasses.get(grantType);
    if (finder == null) {
        logger.error("Unsupported grant type: Type is not supported: " + grantType);
        return new ErrorResource(exceptionHandler, new UnsupportedGrantTypeException("Grant type is not supported: " + grantType));
    }
    try {
        return finder.create(request, response);
    } catch (Exception e) {
        logger.warn("Exception while instantiating the target server resource.", e);
        return new ErrorResource(exceptionHandler, new ServerException(e.getMessage()));
    }
}
Also used : OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) ServerException(org.forgerock.oauth2.core.exceptions.ServerException) Finder(org.restlet.resource.Finder) InvalidRequestException(org.forgerock.oauth2.core.exceptions.InvalidRequestException) UnsupportedGrantTypeException(org.forgerock.oauth2.core.exceptions.UnsupportedGrantTypeException) ServerException(org.forgerock.oauth2.core.exceptions.ServerException) InvalidRequestException(org.forgerock.oauth2.core.exceptions.InvalidRequestException) UnsupportedGrantTypeException(org.forgerock.oauth2.core.exceptions.UnsupportedGrantTypeException)

Aggregations

Finder (org.restlet.resource.Finder)3 OAuth2Request (org.forgerock.oauth2.core.OAuth2Request)1 InvalidRequestException (org.forgerock.oauth2.core.exceptions.InvalidRequestException)1 ServerException (org.forgerock.oauth2.core.exceptions.ServerException)1 UnsupportedGrantTypeException (org.forgerock.oauth2.core.exceptions.UnsupportedGrantTypeException)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1 Restlet (org.restlet.Restlet)1 Header (org.restlet.engine.header.Header)1 StringRepresentation (org.restlet.representation.StringRepresentation)1 Get (org.restlet.resource.Get)1 Filter (org.restlet.routing.Filter)1 Route (org.restlet.routing.Route)1 Router (org.restlet.routing.Router)1 TemplateRoute (org.restlet.routing.TemplateRoute)1 RouteList (org.restlet.util.RouteList)1 Series (org.restlet.util.Series)1