use of org.springframework.web.context.request.ServletRequestAttributes 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);
}
}
use of org.springframework.web.context.request.ServletRequestAttributes 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, "&"));
}
controllerWebServiceEndpoints.add(webServiceEndpoint);
}
}
}
}
return controllerWebServiceEndpoints;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.springframework.web.context.request.ServletRequestAttributes in project spring-framework by spring-projects.
the class FrameworkServlet method processRequest.
/**
* Process this request, publishing an event regardless of the outcome.
* <p>The actual event handling is performed by the abstract
* {@link #doService} template method.
*/
protected final void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
long startTime = System.currentTimeMillis();
Throwable failureCause = null;
LocaleContext previousLocaleContext = LocaleContextHolder.getLocaleContext();
LocaleContext localeContext = buildLocaleContext(request);
RequestAttributes previousAttributes = RequestContextHolder.getRequestAttributes();
ServletRequestAttributes requestAttributes = buildRequestAttributes(request, response, previousAttributes);
WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
asyncManager.registerCallableInterceptor(FrameworkServlet.class.getName(), new RequestBindingInterceptor());
initContextHolders(request, localeContext, requestAttributes);
try {
doService(request, response);
} catch (ServletException ex) {
failureCause = ex;
throw ex;
} catch (IOException ex) {
failureCause = ex;
throw ex;
} catch (Throwable ex) {
failureCause = ex;
throw new NestedServletException("Request processing failed", ex);
} finally {
resetContextHolders(request, previousLocaleContext, previousAttributes);
if (requestAttributes != null) {
requestAttributes.requestCompleted();
}
if (logger.isDebugEnabled()) {
if (failureCause != null) {
this.logger.debug("Could not complete request", failureCause);
} else {
if (asyncManager.isConcurrentHandlingStarted()) {
logger.debug("Leaving response open for concurrent processing");
} else {
this.logger.debug("Successfully completed request");
}
}
}
publishRequestHandledEvent(request, response, startTime, failureCause);
}
}
use of org.springframework.web.context.request.ServletRequestAttributes in project spring-boot by spring-projects.
the class LinksEnhancerTests method setup.
@Before
public void setup() {
MockHttpServletRequest request = new MockHttpServletRequest();
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
}
use of org.springframework.web.context.request.ServletRequestAttributes in project spring-framework by spring-projects.
the class ClassPathBeanDefinitionScannerScopeIntegrationTests method setUp.
@Before
public void setUp() {
MockHttpServletRequest oldRequestWithSession = new MockHttpServletRequest();
oldRequestWithSession.setSession(new MockHttpSession());
this.oldRequestAttributesWithSession = new ServletRequestAttributes(oldRequestWithSession);
MockHttpServletRequest newRequestWithSession = new MockHttpServletRequest();
newRequestWithSession.setSession(new MockHttpSession());
this.newRequestAttributesWithSession = new ServletRequestAttributes(newRequestWithSession);
}
Aggregations