Search in sources :

Example 1 with ApiSection

use of org.orcid.core.version.ApiSection in project ORCID-Source by ORCID.

the class OrcidExceptionMapper method getApiSection.

private ApiSection getApiSection() {
    RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
    ApiSection apiSection = (ApiSection) requestAttributes.getAttribute(ApiVersionFilter.API_SECTION_REQUEST_ATTRIBUTE_NAME, RequestAttributes.SCOPE_REQUEST);
    return apiSection != null ? apiSection : ApiSection.V1;
}
Also used : ApiSection(org.orcid.core.version.ApiSection) RequestAttributes(org.springframework.web.context.request.RequestAttributes) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes)

Example 2 with ApiSection

use of org.orcid.core.version.ApiSection in project ORCID-Source by ORCID.

the class ApiVersionFilter method checkSection.

private void checkSection(HttpServletRequest httpRequest, String version) {
    String path = httpRequest.getServletPath();
    Matcher notifcationsMatcher = NOTIFICATIONS_PATTERN.matcher(path);
    ApiSection section = ApiSection.V1;
    if (notifcationsMatcher.find()) {
        section = ApiSection.NOTIFICATIONS;
    } else if (version != null && version.startsWith("2.")) {
        section = ApiSection.V2;
    } else if (version != null && version.startsWith("3.")) {
        section = ApiSection.V3;
    }
    httpRequest.setAttribute(API_SECTION_REQUEST_ATTRIBUTE_NAME, section);
}
Also used : ApiSection(org.orcid.core.version.ApiSection) Matcher(java.util.regex.Matcher)

Aggregations

ApiSection (org.orcid.core.version.ApiSection)2 Matcher (java.util.regex.Matcher)1 RequestAttributes (org.springframework.web.context.request.RequestAttributes)1 ServletRequestAttributes (org.springframework.web.context.request.ServletRequestAttributes)1