use of org.springframework.web.context.request.ServletRequestAttributes in project ORCID-Source by ORCID.
the class ProfileLastModifiedAspect method retrieveLastModifiedDate.
/** Fetches the last modified from the request-scope last modified cache
* If not present, fetches from the DB and populates the request-scope last modified cache.
*
* @param orcid
* @return
*/
public Date retrieveLastModifiedDate(String orcid) {
ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
Date lastMod = null;
if (sra != null)
lastMod = (Date) sra.getAttribute(sraKey(orcid), ServletRequestAttributes.SCOPE_REQUEST);
if (lastMod == null) {
lastMod = profileDao.retrieveLastModifiedDate(orcid);
if (sra != null)
sra.setAttribute(sraKey(orcid), lastMod, ServletRequestAttributes.SCOPE_REQUEST);
}
return lastMod;
}
use of org.springframework.web.context.request.ServletRequestAttributes in project ORCID-Source by ORCID.
the class SourceNameCacheManagerImpl method getProfileSourceNameFromDb.
private String getProfileSourceNameFromDb(String orcid) {
RecordNameEntity recordName = null;
try {
recordName = recordNameDao.getRecordName(orcid);
if (recordName == null) {
throw new IllegalArgumentException("Unable to find source name for: " + orcid);
}
} catch (Exception e) {
LOGGER.warn("Cannot find source name from profile matching " + orcid, e);
throw new IllegalArgumentException("Unable to find source name for: " + orcid);
}
String name = RecordNameUtils.getPublicName(recordName);
ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
if (sra != null) {
sra.setAttribute(getProfileNameSRAKey(orcid), name != null ? name : StringUtils.EMPTY, ServletRequestAttributes.SCOPE_REQUEST);
}
return name;
}
use of org.springframework.web.context.request.ServletRequestAttributes in project series-rest-api by 52North.
the class RequestUtils method resolveQueryLessRequestUrl.
/**
* Get the request {@link URL} without the query parameter
*
* @param externalUrl the external URL.
* @return Request {@link URL} without query parameter
*/
public static String resolveQueryLessRequestUrl(String externalUrl) {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
if (LOGGER.isDebugEnabled()) {
StringBuilder sb = new StringBuilder("\n----- Start of HTTP Header -----\n");
Enumeration<?> headerNames = request.getHeaderNames();
while (headerNames.hasMoreElements()) {
String headerName = (String) headerNames.nextElement();
sb.append(headerName + ": " + request.getHeader(headerName));
sb.append("\n");
}
sb.append("----- END of HTTP Header -----");
LOGGER.debug(sb.toString());
}
return externalUrl == null || externalUrl.isEmpty() ? createRequestUrl(request) : createRequestUrl(externalUrl);
}
use of org.springframework.web.context.request.ServletRequestAttributes in project uPortal by Jasig.
the class PortalWebUtils method currentRequestContextPath.
/**
* Get the request context path from the current request. Copes with both HttpServletRequest and
* PortletRequest and so usable when handling Spring-processed Servlet or Portlet requests.
* Requires that Spring have bound the request, as in the case of dispatcher servlet or portlet
* or when the binding filter or listener is active. This should be the case for all requests in
* the uPortal framework and framework portlets.
*
* @return request.getContextPath() for the relevant servlet or portlet request
* @throws IllegalStateException if the request is not Spring-bound or is neither Servlet nor
* Portlet flavored
*/
public static String currentRequestContextPath() {
final RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
if (null == requestAttributes) {
throw new IllegalStateException("Request attributes are not bound. " + "Not operating in context of a Spring-processed Request?");
}
if (requestAttributes instanceof ServletRequestAttributes) {
final ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) requestAttributes;
final HttpServletRequest request = servletRequestAttributes.getRequest();
return request.getContextPath();
} else if (requestAttributes instanceof PortletRequestAttributes) {
final PortletRequestAttributes portletRequestAttributes = (PortletRequestAttributes) requestAttributes;
final PortletRequest request = portletRequestAttributes.getRequest();
return request.getContextPath();
} else {
throw new IllegalStateException("Request attributes are an unrecognized implementation.");
}
}
use of org.springframework.web.context.request.ServletRequestAttributes in project geode by apache.
the class ShellCommandsControllerJUnitTest method setupBeforeClass.
@BeforeClass
public static void setupBeforeClass() {
controller = new ShellCommandsController();
MockHttpServletRequest request = new MockHttpServletRequest();
request.setContextPath("gemfire");
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
}
Aggregations