Search in sources :

Example 1 with ApiVersionRouterContext

use of org.forgerock.http.routing.ApiVersionRouterContext in project OpenAM by OpenRock.

the class ResourceApiVersionRoutingFilter method handle.

void handle(Request request, Response response, RestletRouter next) {
    ApiVersionRouterContext apiVersionRouterContext = createApiVersionRouterContext(new RootContext());
    next.handle(apiVersionRouterContext, request, response);
    if (apiVersionRouterContext.getResourceVersion() != null) {
        addContentAPIVersion(response, enforcedProtocolVersion, apiVersionRouterContext.getResourceVersion());
        // If warnings are wanted, and we haven't thrown an exception by this point let's see what we can do...
        if (behaviourManager.isWarningEnabled()) {
            Version requestedVersion = parseResourceApiVersion(request);
            if (requestedVersion == null) {
                // If no version specified at all, we can warn about that
                AdviceWarning warningHeader = AdviceWarning.newAdviceWarning(AGENT_NAME, "No " + AcceptApiVersionHeader.NAME + " specified");
                ServletUtils.getResponse(response).addHeader("Warning", warningHeader.toString());
            }
        }
    }
}
Also used : RootContext(org.forgerock.services.context.RootContext) Version(org.forgerock.http.routing.Version) ResourceApiVersionRestlet.parseResourceApiVersion(org.forgerock.openam.rest.service.ResourceApiVersionRestlet.parseResourceApiVersion) AdviceWarning(org.forgerock.json.resource.AdviceWarning) ApiVersionRouterContext(org.forgerock.http.routing.ApiVersionRouterContext)

Aggregations

ApiVersionRouterContext (org.forgerock.http.routing.ApiVersionRouterContext)1 Version (org.forgerock.http.routing.Version)1 AdviceWarning (org.forgerock.json.resource.AdviceWarning)1 ResourceApiVersionRestlet.parseResourceApiVersion (org.forgerock.openam.rest.service.ResourceApiVersionRestlet.parseResourceApiVersion)1 RootContext (org.forgerock.services.context.RootContext)1