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 ORCID-Source by ORCID.
the class ProfileLastModifiedAspect method updateLastModifiedDateAndIndexingStatus.
/** Updates the last modified date and clears the request-scope last modified cache.
*
* @param orcid
*/
public void updateLastModifiedDateAndIndexingStatus(String orcid) {
if (!enabled) {
return;
}
profileDao.updateLastModifiedDateAndIndexingStatus(orcid, IndexingStatus.PENDING);
ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
if (sra != null)
sra.setAttribute(sraKey(orcid), null, ServletRequestAttributes.SCOPE_REQUEST);
}
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 midpoint by Evolveum.
the class SecurityUtil method getCurrentConnectionInformation.
/**
* Returns current connection information, as derived from HTTP request stored in current thread.
* May be null if the thread is not associated with any HTTP request (e.g. task threads, operations invoked from GUI but executing in background).
*/
public static HttpConnectionInformation getCurrentConnectionInformation() {
RequestAttributes attr = RequestContextHolder.getRequestAttributes();
if (!(attr instanceof ServletRequestAttributes)) {
return null;
}
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) attr;
HttpServletRequest request = servletRequestAttributes.getRequest();
if (request == null) {
return null;
}
HttpConnectionInformation rv = new HttpConnectionInformation();
HttpSession session = request.getSession(false);
if (session != null) {
rv.setSessionId(session.getId());
}
rv.setLocalHostName(request.getLocalName());
rv.setRemoteHostAddress(getRemoteHostAddress(request));
return rv;
}
use of org.springframework.web.context.request.ServletRequestAttributes in project ocvn by devgateway.
the class AbstractSpringDataRestControllerTest method mockHttpServletRequestForResouceAssemblerSupport.
/**
* http://stackoverflow.com/a/36960968
* This is needed if you do
* {@link PagedResourcesAssembler#toResource(org.springframework.data.domain.Page)}
* in your controller
*/
private void mockHttpServletRequestForResouceAssemblerSupport() {
String localHost = "http://localhost";
HttpServletRequest httpServletRequestMock = mock(HttpServletRequest.class);
when(httpServletRequestMock.getRequestURL()).thenReturn(new StringBuffer(localHost));
when(httpServletRequestMock.getHeaderNames()).thenReturn(Collections.emptyEnumeration());
when(httpServletRequestMock.getRequestURI()).thenReturn(localHost);
when(httpServletRequestMock.getContextPath()).thenReturn(StringUtils.EMPTY);
when(httpServletRequestMock.getServletPath()).thenReturn(StringUtils.EMPTY);
ServletRequestAttributes servletRequestAttributes = new ServletRequestAttributes(httpServletRequestMock);
RequestContextHolder.setRequestAttributes(servletRequestAttributes);
}
Aggregations