fix #2668 remove LaRequestUtil.getRequest()
This commit is contained in:
parent
9bc30b336c
commit
3ead78e019
9 changed files with 156 additions and 167 deletions
|
@ -96,11 +96,7 @@ public abstract class BaseApiManager implements WebApiManager {
|
|||
buf.append("; charset=");
|
||||
final String enc;
|
||||
if (encoding == null) {
|
||||
if (LaRequestUtil.getRequest().getCharacterEncoding() == null) {
|
||||
enc = Constants.UTF_8;
|
||||
} else {
|
||||
enc = LaRequestUtil.getRequest().getCharacterEncoding();
|
||||
}
|
||||
enc = LaRequestUtil.getOptionalRequest().map(req -> req.getCharacterEncoding()).orElse(Constants.UTF_8);
|
||||
} else {
|
||||
enc = encoding;
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ public abstract class BaseJsonApiManager extends BaseApiManager {
|
|||
}
|
||||
|
||||
protected void writeJsonResponse(final int status, final String body) {
|
||||
final String callback = LaRequestUtil.getRequest().getParameter("callback");
|
||||
final String callback = LaRequestUtil.getOptionalRequest().map(req -> req.getParameter("callback")).get();
|
||||
final boolean isJsonp = ComponentUtil.getFessConfig().isApiJsonpEnabled() && StringUtil.isNotBlank(callback);
|
||||
|
||||
final StringBuilder buf = new StringBuilder(1000);
|
||||
|
|
|
@ -142,7 +142,7 @@ public class ListForm extends SearchRequestParams {
|
|||
|
||||
@Override
|
||||
public Object getAttribute(final String name) {
|
||||
return LaRequestUtil.getRequest().getAttribute(name);
|
||||
return LaRequestUtil.getOptionalRequest().map(req -> req.getAttribute(name)).get();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -114,11 +114,8 @@ public class SearchForm extends SearchRequestParams {
|
|||
|
||||
@Override
|
||||
public GeoInfo getGeoInfo() {
|
||||
final GeoInfo geoInfo = createGeoInfo(LaRequestUtil.getRequest());
|
||||
if (geoInfo != null) {
|
||||
return geoInfo;
|
||||
}
|
||||
return ComponentUtil.getQueryHelper().getDefaultGeoInfo();
|
||||
return LaRequestUtil.getOptionalRequest().map(req -> createGeoInfo(req))
|
||||
.orElseGet(() -> ComponentUtil.getQueryHelper().getDefaultGeoInfo());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -138,7 +135,7 @@ public class SearchForm extends SearchRequestParams {
|
|||
|
||||
@Override
|
||||
public Object getAttribute(final String name) {
|
||||
return LaRequestUtil.getRequest().getAttribute(name);
|
||||
return LaRequestUtil.getOptionalRequest().map(req -> req.getAttribute(name)).get();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -32,7 +32,6 @@ import java.util.concurrent.TimeUnit;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
@ -135,47 +134,40 @@ public class SearchLogHelper {
|
|||
searchLog.setUser(user.getUserId());
|
||||
});
|
||||
|
||||
final HttpServletRequest request = LaRequestUtil.getRequest();
|
||||
searchLog.setClientIp(StringUtils.abbreviate(ComponentUtil.getViewHelper().getClientIp(request), 100));
|
||||
searchLog.setReferer(StringUtils.abbreviate(request.getHeader("referer"), 1000));
|
||||
searchLog.setUserAgent(StringUtils.abbreviate(request.getHeader("user-agent"), 255));
|
||||
final Object accessType = request.getAttribute(Constants.SEARCH_LOG_ACCESS_TYPE);
|
||||
if (Constants.SEARCH_LOG_ACCESS_TYPE_JSON.equals(accessType)) {
|
||||
searchLog.setAccessType(Constants.SEARCH_LOG_ACCESS_TYPE_JSON);
|
||||
} else if (Constants.SEARCH_LOG_ACCESS_TYPE_GSA.equals(accessType)) {
|
||||
searchLog.setAccessType(Constants.SEARCH_LOG_ACCESS_TYPE_GSA);
|
||||
} else if (Constants.SEARCH_LOG_ACCESS_TYPE_OTHER.equals(accessType)) {
|
||||
searchLog.setAccessType(Constants.SEARCH_LOG_ACCESS_TYPE_OTHER);
|
||||
} else if (Constants.SEARCH_LOG_ACCESS_TYPE_ADMIN.equals(accessType)) {
|
||||
searchLog.setAccessType(Constants.SEARCH_LOG_ACCESS_TYPE_ADMIN);
|
||||
} else {
|
||||
searchLog.setAccessType(Constants.SEARCH_LOG_ACCESS_TYPE_WEB);
|
||||
}
|
||||
final Object languages = request.getAttribute(Constants.REQUEST_LANGUAGES);
|
||||
if (languages != null) {
|
||||
searchLog.setLanguages(StringUtils.join((String[]) languages, ","));
|
||||
} else {
|
||||
searchLog.setLanguages(StringUtil.EMPTY);
|
||||
}
|
||||
final String virtualHostKey = ComponentUtil.getVirtualHostHelper().getVirtualHostKey();
|
||||
if (StringUtil.isNotBlank(virtualHostKey)) {
|
||||
searchLog.setVirtualHost(virtualHostKey);
|
||||
} else {
|
||||
searchLog.setVirtualHost(StringUtil.EMPTY);
|
||||
}
|
||||
LaRequestUtil.getOptionalRequest().ifPresent(req -> {
|
||||
searchLog.setClientIp(StringUtils.abbreviate(ComponentUtil.getViewHelper().getClientIp(req), 100));
|
||||
searchLog.setReferer(StringUtils.abbreviate(req.getHeader("referer"), 1000));
|
||||
searchLog.setUserAgent(StringUtils.abbreviate(req.getHeader("user-agent"), 255));
|
||||
final Object accessType = req.getAttribute(Constants.SEARCH_LOG_ACCESS_TYPE);
|
||||
if (Constants.SEARCH_LOG_ACCESS_TYPE_JSON.equals(accessType)) {
|
||||
searchLog.setAccessType(Constants.SEARCH_LOG_ACCESS_TYPE_JSON);
|
||||
} else if (Constants.SEARCH_LOG_ACCESS_TYPE_GSA.equals(accessType)) {
|
||||
searchLog.setAccessType(Constants.SEARCH_LOG_ACCESS_TYPE_GSA);
|
||||
} else if (Constants.SEARCH_LOG_ACCESS_TYPE_OTHER.equals(accessType)) {
|
||||
searchLog.setAccessType(Constants.SEARCH_LOG_ACCESS_TYPE_OTHER);
|
||||
} else if (Constants.SEARCH_LOG_ACCESS_TYPE_ADMIN.equals(accessType)) {
|
||||
searchLog.setAccessType(Constants.SEARCH_LOG_ACCESS_TYPE_ADMIN);
|
||||
} else {
|
||||
searchLog.setAccessType(Constants.SEARCH_LOG_ACCESS_TYPE_WEB);
|
||||
}
|
||||
final Object languages = req.getAttribute(Constants.REQUEST_LANGUAGES);
|
||||
if (languages != null) {
|
||||
searchLog.setLanguages(StringUtils.join((String[]) languages, ","));
|
||||
} else {
|
||||
searchLog.setLanguages(StringUtil.EMPTY);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
final Map<String, List<String>> fieldLogMap = (Map<String, List<String>>) request.getAttribute(Constants.FIELD_LOGS);
|
||||
if (fieldLogMap != null) {
|
||||
final int queryMaxLength = fessConfig.getQueryMaxLengthAsInteger();
|
||||
for (final Map.Entry<String, List<String>> logEntry : fieldLogMap.entrySet()) {
|
||||
for (final String value : logEntry.getValue()) {
|
||||
searchLog.addSearchFieldLogValue(logEntry.getKey(), StringUtils.abbreviate(value, queryMaxLength));
|
||||
@SuppressWarnings("unchecked")
|
||||
final Map<String, List<String>> fieldLogMap = (Map<String, List<String>>) req.getAttribute(Constants.FIELD_LOGS);
|
||||
if (fieldLogMap != null) {
|
||||
final int queryMaxLength = fessConfig.getQueryMaxLengthAsInteger();
|
||||
for (final Map.Entry<String, List<String>> logEntry : fieldLogMap.entrySet()) {
|
||||
for (final String value : logEntry.getValue()) {
|
||||
searchLog.addSearchFieldLogValue(logEntry.getKey(), StringUtils.abbreviate(value, queryMaxLength));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LaRequestUtil.getOptionalRequest().ifPresent(req -> {
|
||||
for (final String s : fessConfig.getSearchlogRequestHeadersAsArray()) {
|
||||
final String key = s.replace('-', '_').toLowerCase(Locale.ENGLISH);
|
||||
Collections.list(req.getHeaders(s)).stream().forEach(v -> {
|
||||
|
@ -184,6 +176,13 @@ public class SearchLogHelper {
|
|||
}
|
||||
});
|
||||
|
||||
final String virtualHostKey = ComponentUtil.getVirtualHostHelper().getVirtualHostKey();
|
||||
if (StringUtil.isNotBlank(virtualHostKey)) {
|
||||
searchLog.setVirtualHost(virtualHostKey);
|
||||
} else {
|
||||
searchLog.setVirtualHost(StringUtil.EMPTY);
|
||||
}
|
||||
|
||||
addDocumentsInResponse(queryResponseList, searchLog);
|
||||
|
||||
searchLogQueue.add(searchLog);
|
||||
|
|
|
@ -53,34 +53,34 @@ public class UserInfoHelper {
|
|||
protected boolean httpOnly = true;
|
||||
|
||||
public String getUserCode() {
|
||||
final HttpServletRequest request = LaRequestUtil.getRequest();
|
||||
|
||||
String userCode = (String) request.getAttribute(Constants.USER_CODE);
|
||||
if (StringUtil.isNotBlank(userCode)) {
|
||||
return userCode;
|
||||
}
|
||||
|
||||
userCode = getUserCodeFromRequest(request);
|
||||
if (StringUtil.isNotBlank(userCode)) {
|
||||
return userCode;
|
||||
}
|
||||
|
||||
if (!request.isRequestedSessionIdValid()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
userCode = getUserCodeFromCookie(request);
|
||||
if (StringUtil.isBlank(userCode)) {
|
||||
userCode = getUserCodeFromUserBean(request);
|
||||
if (StringUtil.isBlank(userCode)) {
|
||||
userCode = getId();
|
||||
return LaRequestUtil.getOptionalRequest().map(request -> {
|
||||
String userCode = (String) request.getAttribute(Constants.USER_CODE);
|
||||
if (StringUtil.isNotBlank(userCode)) {
|
||||
return userCode;
|
||||
}
|
||||
}
|
||||
|
||||
if (StringUtil.isNotBlank(userCode)) {
|
||||
updateUserSessionId(userCode);
|
||||
}
|
||||
return userCode;
|
||||
userCode = getUserCodeFromRequest(request);
|
||||
if (StringUtil.isNotBlank(userCode)) {
|
||||
return userCode;
|
||||
}
|
||||
|
||||
if (!request.isRequestedSessionIdValid()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
userCode = getUserCodeFromCookie(request);
|
||||
if (StringUtil.isBlank(userCode)) {
|
||||
userCode = getUserCodeFromUserBean(request);
|
||||
if (StringUtil.isBlank(userCode)) {
|
||||
userCode = getId();
|
||||
}
|
||||
}
|
||||
|
||||
if (StringUtil.isNotBlank(userCode)) {
|
||||
updateUserSessionId(userCode);
|
||||
}
|
||||
return userCode;
|
||||
}).get();
|
||||
}
|
||||
|
||||
protected String getUserCodeFromUserBean(final HttpServletRequest request) {
|
||||
|
@ -135,8 +135,7 @@ public class UserInfoHelper {
|
|||
protected void updateUserSessionId(final String userCode) {
|
||||
ComponentUtil.getSearchLogHelper().getUserInfo(userCode);
|
||||
|
||||
final HttpServletRequest request = LaRequestUtil.getRequest();
|
||||
request.setAttribute(Constants.USER_CODE, userCode);
|
||||
LaRequestUtil.getOptionalRequest().ifPresent(req -> req.setAttribute(Constants.USER_CODE, userCode));
|
||||
|
||||
updateCookie(userCode, cookieMaxAge);
|
||||
}
|
||||
|
@ -171,8 +170,7 @@ public class UserInfoHelper {
|
|||
}
|
||||
|
||||
public void storeQueryId(final String queryId, final List<Map<String, Object>> documentItems) {
|
||||
final HttpSession session = LaRequestUtil.getRequest().getSession(false);
|
||||
if (session != null) {
|
||||
LaRequestUtil.getOptionalRequest().map(req -> req.getSession(false)).ifPresent(session -> {
|
||||
final FessConfig fessConfig = ComponentUtil.getFessConfig();
|
||||
|
||||
final List<String> docIdList = new ArrayList<>();
|
||||
|
@ -187,19 +185,18 @@ public class UserInfoHelper {
|
|||
final Map<String, String[]> resultDocIdsCache = getResultDocIdsCache(session);
|
||||
resultDocIdsCache.put(queryId, docIdList.toArray(new String[docIdList.size()]));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public String[] getResultDocIds(final String queryId) {
|
||||
final HttpSession session = LaRequestUtil.getRequest().getSession(false);
|
||||
if (session != null) {
|
||||
return LaRequestUtil.getOptionalRequest().map(req -> req.getSession(false)).map(session -> {
|
||||
final Map<String, String[]> resultUrlCache = getResultDocIdsCache(session);
|
||||
final String[] urls = resultUrlCache.get(queryId);
|
||||
if (urls != null) {
|
||||
return urls;
|
||||
}
|
||||
}
|
||||
return StringUtil.EMPTY_STRINGS;
|
||||
return StringUtil.EMPTY_STRINGS;
|
||||
}).orElse(StringUtil.EMPTY_STRINGS);
|
||||
}
|
||||
|
||||
private Map<String, String[]> getResultDocIdsCache(final HttpSession session) {
|
||||
|
|
|
@ -472,8 +472,7 @@ public class ViewHelper {
|
|||
}
|
||||
|
||||
protected String appendPDFSearchWord(final Map<String, Object> document, final String url) {
|
||||
final String queries = (String) LaRequestUtil.getRequest().getAttribute(Constants.REQUEST_QUERIES);
|
||||
if (queries != null) {
|
||||
return LaRequestUtil.getOptionalRequest().map(req -> (String) req.getAttribute(Constants.REQUEST_QUERIES)).map(queries -> {
|
||||
try {
|
||||
final StringBuilder buf = new StringBuilder(url.length() + 100);
|
||||
buf.append(url).append("#search=%22");
|
||||
|
@ -483,8 +482,8 @@ public class ViewHelper {
|
|||
} catch (final UnsupportedEncodingException e) {
|
||||
logger.warn("Unsupported encoding.", e);
|
||||
}
|
||||
}
|
||||
return url;
|
||||
return null;
|
||||
}).filter(StringUtil::isNotBlank).orElse(url);
|
||||
}
|
||||
|
||||
public String getPagePath(final String page) {
|
||||
|
|
|
@ -100,24 +100,25 @@ public class FessFunctions {
|
|||
}
|
||||
|
||||
public static Boolean labelExists(final String value) {
|
||||
@SuppressWarnings("unchecked")
|
||||
final Map<String, String> labelValueMap = (Map<String, String>) LaRequestUtil.getRequest().getAttribute(Constants.LABEL_VALUE_MAP);
|
||||
if (labelValueMap != null) {
|
||||
return labelValueMap.get(value) != null;
|
||||
}
|
||||
return false;
|
||||
return LaRequestUtil.getOptionalRequest().map(req -> {
|
||||
@SuppressWarnings("unchecked")
|
||||
final Map<String, String> labelValueMap = (Map<String, String>) req.getAttribute(Constants.LABEL_VALUE_MAP);
|
||||
if (labelValueMap != null) {
|
||||
return labelValueMap.get(value) != null;
|
||||
}
|
||||
return false;
|
||||
}).orElse(false);
|
||||
}
|
||||
|
||||
public static String label(final String value) {
|
||||
@SuppressWarnings("unchecked")
|
||||
final Map<String, String> labelValueMap = (Map<String, String>) LaRequestUtil.getRequest().getAttribute(Constants.LABEL_VALUE_MAP);
|
||||
if (labelValueMap != null) {
|
||||
final String name = labelValueMap.get(value);
|
||||
if (name != null) {
|
||||
return name;
|
||||
return LaRequestUtil.getOptionalRequest().map(req -> {
|
||||
@SuppressWarnings("unchecked")
|
||||
final Map<String, String> labelValueMap = (Map<String, String>) req.getAttribute(Constants.LABEL_VALUE_MAP);
|
||||
if (labelValueMap != null) {
|
||||
return labelValueMap.get(value);
|
||||
}
|
||||
}
|
||||
return value;
|
||||
return null;
|
||||
}).orElse(value);
|
||||
}
|
||||
|
||||
public static Date date(final Long value) {
|
||||
|
@ -223,20 +224,21 @@ public class FessFunctions {
|
|||
}
|
||||
|
||||
public static String pagingQuery(final String query) {
|
||||
final HttpServletRequest request = LaRequestUtil.getRequest();
|
||||
@SuppressWarnings("unchecked")
|
||||
final List<String> pagingQueryList = (List<String>) request.getAttribute(Constants.PAGING_QUERY_LIST);
|
||||
if (pagingQueryList != null) {
|
||||
final String prefix;
|
||||
if (query != null) {
|
||||
prefix = "ex_q=" + query.split(":")[0] + "%3A";
|
||||
} else {
|
||||
prefix = null;
|
||||
return LaRequestUtil.getOptionalRequest().map(req -> {
|
||||
@SuppressWarnings("unchecked")
|
||||
final List<String> pagingQueryList = (List<String>) req.getAttribute(Constants.PAGING_QUERY_LIST);
|
||||
if (pagingQueryList != null) {
|
||||
final String prefix;
|
||||
if (query != null) {
|
||||
prefix = "ex_q=" + query.split(":")[0] + "%3A";
|
||||
} else {
|
||||
prefix = null;
|
||||
}
|
||||
return pagingQueryList.stream().filter(s -> prefix == null || !s.startsWith(prefix))
|
||||
.collect(Collectors.joining("&", "&", StringUtil.EMPTY));
|
||||
}
|
||||
return pagingQueryList.stream().filter(s -> prefix == null || !s.startsWith(prefix))
|
||||
.collect(Collectors.joining("&", "&", StringUtil.EMPTY));
|
||||
}
|
||||
return StringUtil.EMPTY;
|
||||
return null;
|
||||
}).orElse(StringUtil.EMPTY);
|
||||
}
|
||||
|
||||
public static String facetQuery() {
|
||||
|
@ -261,56 +263,58 @@ public class FessFunctions {
|
|||
}
|
||||
|
||||
private static String createQuery(final String key, final String prefix) {
|
||||
final HttpServletRequest request = LaRequestUtil.getRequest();
|
||||
String query = (String) request.getAttribute(key);
|
||||
if (query == null) {
|
||||
final StringBuilder buf = new StringBuilder(100);
|
||||
final Enumeration<String> names = request.getParameterNames();
|
||||
while (names.hasMoreElements()) {
|
||||
final String name = names.nextElement();
|
||||
if (name.startsWith(prefix)) {
|
||||
final String[] values = request.getParameterValues(name);
|
||||
if (values != null) {
|
||||
for (final String value : values) {
|
||||
buf.append('&');
|
||||
buf.append(LdiURLUtil.encode(name, Constants.UTF_8));
|
||||
buf.append('=');
|
||||
buf.append(LdiURLUtil.encode(value, Constants.UTF_8));
|
||||
return LaRequestUtil.getOptionalRequest().map(request -> {
|
||||
String query = (String) request.getAttribute(key);
|
||||
if (query == null) {
|
||||
final StringBuilder buf = new StringBuilder(100);
|
||||
final Enumeration<String> names = request.getParameterNames();
|
||||
while (names.hasMoreElements()) {
|
||||
final String name = names.nextElement();
|
||||
if (name.startsWith(prefix)) {
|
||||
final String[] values = request.getParameterValues(name);
|
||||
if (values != null) {
|
||||
for (final String value : values) {
|
||||
buf.append('&');
|
||||
buf.append(LdiURLUtil.encode(name, Constants.UTF_8));
|
||||
buf.append('=');
|
||||
buf.append(LdiURLUtil.encode(value, Constants.UTF_8));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
query = buf.toString();
|
||||
request.setAttribute(key, query);
|
||||
}
|
||||
query = buf.toString();
|
||||
request.setAttribute(key, query);
|
||||
}
|
||||
return query;
|
||||
return query;
|
||||
}).get();
|
||||
}
|
||||
|
||||
private static String createForm(final String key, final String prefix) {
|
||||
final HttpServletRequest request = LaRequestUtil.getRequest();
|
||||
String query = (String) request.getAttribute(key);
|
||||
if (query == null) {
|
||||
final StringBuilder buf = new StringBuilder(100);
|
||||
final Enumeration<String> names = request.getParameterNames();
|
||||
while (names.hasMoreElements()) {
|
||||
final String name = names.nextElement();
|
||||
if (name.startsWith(prefix)) {
|
||||
final String[] values = request.getParameterValues(name);
|
||||
if (values != null) {
|
||||
for (final String value : values) {
|
||||
buf.append("<input type=\"hidden\" name=\"");
|
||||
buf.append(StringEscapeUtils.escapeHtml4(name));
|
||||
buf.append("\" value=\"");
|
||||
buf.append(StringEscapeUtils.escapeHtml4(value));
|
||||
buf.append("\"/>");
|
||||
return LaRequestUtil.getOptionalRequest().map(request -> {
|
||||
String query = (String) request.getAttribute(key);
|
||||
if (query == null) {
|
||||
final StringBuilder buf = new StringBuilder(100);
|
||||
final Enumeration<String> names = request.getParameterNames();
|
||||
while (names.hasMoreElements()) {
|
||||
final String name = names.nextElement();
|
||||
if (name.startsWith(prefix)) {
|
||||
final String[] values = request.getParameterValues(name);
|
||||
if (values != null) {
|
||||
for (final String value : values) {
|
||||
buf.append("<input type=\"hidden\" name=\"");
|
||||
buf.append(StringEscapeUtils.escapeHtml4(name));
|
||||
buf.append("\" value=\"");
|
||||
buf.append(StringEscapeUtils.escapeHtml4(value));
|
||||
buf.append("\"/>");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
query = buf.toString();
|
||||
request.setAttribute(key, query);
|
||||
}
|
||||
query = buf.toString();
|
||||
request.setAttribute(key, query);
|
||||
}
|
||||
return query;
|
||||
return query;
|
||||
}).get();
|
||||
}
|
||||
|
||||
public static String base64(final String value) {
|
||||
|
@ -334,11 +338,8 @@ public class FessFunctions {
|
|||
final String msg = "The argument 'input' should start with slash '/': " + input;
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
final String contextPath = LaRequestUtil.getRequest().getContextPath();
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
if (contextPath.length() > 1) {
|
||||
sb.append(contextPath);
|
||||
}
|
||||
LaRequestUtil.getOptionalRequest().map(req -> req.getContextPath()).filter(s -> s.length() > 1).ifPresent(s -> sb.append(s));
|
||||
sb.append(input);
|
||||
if (input.indexOf('?') == -1) {
|
||||
try {
|
||||
|
|
|
@ -26,26 +26,26 @@ public final class WebApiUtil {
|
|||
}
|
||||
|
||||
public static void setObject(final String name, final Object value) {
|
||||
LaRequestUtil.getRequest().setAttribute(name, value);
|
||||
LaRequestUtil.getOptionalRequest().ifPresent(req -> req.setAttribute(name, value));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T getObject(final String name) {
|
||||
return (T) LaRequestUtil.getRequest().getAttribute(name);
|
||||
return LaRequestUtil.getOptionalRequest().map(req -> (T) req.getAttribute(name)).get();
|
||||
}
|
||||
|
||||
public static void setError(final int statusCode, final String message) {
|
||||
LaRequestUtil.getRequest().setAttribute(WEB_API_EXCEPTION, new WebApiException(statusCode, message));
|
||||
LaRequestUtil.getOptionalRequest().ifPresent(req -> req.setAttribute(WEB_API_EXCEPTION, new WebApiException(statusCode, message)));
|
||||
}
|
||||
|
||||
public static void setError(final int statusCode, final Exception e) {
|
||||
LaRequestUtil.getRequest().setAttribute(WEB_API_EXCEPTION, new WebApiException(statusCode, e));
|
||||
LaRequestUtil.getOptionalRequest().ifPresent(req -> req.setAttribute(WEB_API_EXCEPTION, new WebApiException(statusCode, e)));
|
||||
}
|
||||
|
||||
public static void validate() {
|
||||
final WebApiException e = (WebApiException) LaRequestUtil.getRequest().getAttribute(WEB_API_EXCEPTION);
|
||||
if (e != null) {
|
||||
LaRequestUtil.getOptionalRequest().map(req -> (WebApiException) req.getAttribute(WEB_API_EXCEPTION)).ifPresent(e -> {
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue