Search in sources :

Example 1 with RequestAttributes

use of org.springframework.web.context.request.RequestAttributes 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 RequestAttributes

use of org.springframework.web.context.request.RequestAttributes in project ORCID-Source by ORCID.

the class OrcidExceptionMapper method getApiVersion.

private String getApiVersion() {
    RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
    String apiVersion = (String) requestAttributes.getAttribute(ApiVersionFilter.API_VERSION_REQUEST_ATTRIBUTE_NAME, RequestAttributes.SCOPE_REQUEST);
    return apiVersion;
}
Also used : RequestAttributes(org.springframework.web.context.request.RequestAttributes) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes)

Example 3 with RequestAttributes

use of org.springframework.web.context.request.RequestAttributes in project ORCID-Source by ORCID.

the class OrcidValidationJaxbContextResolver method getApiVersion.

private String getApiVersion() {
    RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
    String apiVersion = (String) requestAttributes.getAttribute(ApiVersionFilter.API_VERSION_REQUEST_ATTRIBUTE_NAME, RequestAttributes.SCOPE_REQUEST);
    return apiVersion;
}
Also used : RequestAttributes(org.springframework.web.context.request.RequestAttributes)

Example 4 with RequestAttributes

use of org.springframework.web.context.request.RequestAttributes in project ORCID-Source by ORCID.

the class ValidationManagerForLegacyApiVersionsImpl method doSchemaValidation.

@Override
protected void doSchemaValidation(OrcidMessage orcidMessage) {
    // Hack to support legacy API versions
    RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
    if (requestAttributes instanceof ServletRequestAttributes) {
        ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) requestAttributes;
        String contentType = servletRequestAttributes.getRequest().getContentType();
        if (!StringUtils.containsIgnoreCase(contentType, "json")) {
            super.doSchemaValidation(orcidMessage);
        }
    } else {
        super.doSchemaValidation(orcidMessage);
    }
}
Also used : ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) RequestAttributes(org.springframework.web.context.request.RequestAttributes) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes)

Example 5 with RequestAttributes

use of org.springframework.web.context.request.RequestAttributes in project geode by apache.

the class ShellCommandsControllerJUnitTest method getControllerWebServiceEndpoints.

private List<String> getControllerWebServiceEndpoints() {
    RequestAttributes requestAttrs = RequestContextHolder.getRequestAttributes();
    HttpServletRequest servletRequest = ((ServletRequestAttributes) requestAttrs).getRequest();
    String scheme = servletRequest.getScheme();
    try {
        Set<Class<?>> controllerClasses = scanPackageForClassesExtending("org.apache.geode.management.internal.web.controllers", AbstractCommandsController.class);
        List<String> controllerWebServiceEndpoints = new ArrayList<>(controllerClasses.size());
        for (Class<?> controllerClass : controllerClasses) {
            if (!AbstractCommandsController.class.equals(controllerClass)) {
                for (Method method : controllerClass.getMethods()) {
                    if (method.isAnnotationPresent(RequestMapping.class)) {
                        RequestMapping requestMappingAnnotation = method.getAnnotation(RequestMapping.class);
                        String webServiceEndpoint = String.format("%1$s %2$s", requestMappingAnnotation.method()[0], UriUtils.decode(controller.toUri(requestMappingAnnotation.value()[0], scheme).toString()));
                        String[] requestParameters = requestMappingAnnotation.params();
                        if (requestParameters.length > 0) {
                            webServiceEndpoint += "?".concat(StringUtils.join(requestParameters, "&amp;"));
                        }
                        controllerWebServiceEndpoints.add(webServiceEndpoint);
                    }
                }
            }
        }
        return controllerWebServiceEndpoints;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) ArrayList(java.util.ArrayList) RequestAttributes(org.springframework.web.context.request.RequestAttributes) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) Method(java.lang.reflect.Method) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) BeforeClass(org.junit.BeforeClass) AfterClass(org.junit.AfterClass)

Aggregations

RequestAttributes (org.springframework.web.context.request.RequestAttributes)81 ServletRequestAttributes (org.springframework.web.context.request.ServletRequestAttributes)51 HttpServletRequest (javax.servlet.http.HttpServletRequest)20 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)15 Test (org.junit.Test)11 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)3 DefaultPrettyPrinter (com.fasterxml.jackson.core.util.DefaultPrettyPrinter)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Response (javax.ws.rs.core.Response)3 XWorkRequestAttributes (org.onebusaway.presentation.impl.users.XWorkRequestAttributes)3 DBUnitTest (org.orcid.test.DBUnitTest)3 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)3 ProjectService (ca.corefacility.bioinformatics.irida.service.ProjectService)2 UserService (ca.corefacility.bioinformatics.irida.service.user.UserService)2 UserSession (com.haulmont.cuba.security.global.UserSession)2 ActionContext (com.opensymphony.xwork2.ActionContext)2 RecordDefinition (com.revolsys.record.schema.RecordDefinition)2 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)2