use of org.springframework.web.context.request.WebRequest in project uhgroupings by uhawaii-system-its-ti-iam.
the class ErrorControllerAdviceTest method illegalArgumentTest.
@Test
public void illegalArgumentTest() {
IllegalArgumentException IAE = new IllegalArgumentException();
WebRequest Req = new WebRequest() {
@Override
public String getHeader(String s) {
return null;
}
@Override
public String[] getHeaderValues(String s) {
return new String[0];
}
@Override
public Iterator<String> getHeaderNames() {
return null;
}
@Override
public String getParameter(String s) {
return null;
}
@Override
public String[] getParameterValues(String s) {
return new String[0];
}
@Override
public Iterator<String> getParameterNames() {
return null;
}
@Override
public Map<String, String[]> getParameterMap() {
return null;
}
@Override
public Locale getLocale() {
return null;
}
@Override
public String getContextPath() {
return null;
}
@Override
public String getRemoteUser() {
return null;
}
@Override
public Principal getUserPrincipal() {
return null;
}
@Override
public boolean isUserInRole(String s) {
return false;
}
@Override
public boolean isSecure() {
return false;
}
@Override
public boolean checkNotModified(long l) {
return false;
}
@Override
public boolean checkNotModified(String s) {
return false;
}
@Override
public boolean checkNotModified(String s, long l) {
return false;
}
@Override
public String getDescription(boolean b) {
return null;
}
@Override
public Object getAttribute(String s, int i) {
return null;
}
@Override
public void setAttribute(String s, Object o, int i) {
// intentionally empty
}
@Override
public void removeAttribute(String s, int i) {
// intentionally empty
}
@Override
public String[] getAttributeNames(int i) {
return new String[0];
}
@Override
public void registerDestructionCallback(String s, Runnable runnable, int i) {
// intentionally empty
}
@Override
public Object resolveReference(String s) {
return null;
}
@Override
public String getSessionId() {
return null;
}
@Override
public Object getSessionMutex() {
return null;
}
};
errorControllerAdvice.handleIllegalArgumentException(IAE, Req);
String IAException = "<404,edu.hawaii.its.api.type.GroupingsHTTPException: " + "Resource not available,[]>";
assertThat(errorControllerAdvice.handleIllegalArgumentException(IAE, Req).toString(), equalTo(IAException));
}
use of org.springframework.web.context.request.WebRequest in project BroadleafCommerce by BroadleafCommerce.
the class CustomerStateRefresher method onApplicationEvent.
/**
* Removes the complete {@link Customer} stored in session and adds a new session variable for just the customer ID. This
* should occur once the session-based {@link Customer} (all anonymous Customers start out this way) has been persisted.
*
* <p>Also updates {@link CustomerState} with the persisted {@link Customer} so that it will always represent the most
* up-to-date version that is in the database</p>
*
* @param request
* @param databaseCustomer
*/
@Override
public void onApplicationEvent(final CustomerPersistedEvent event) {
Customer dbCustomer = event.getCustomer();
// if there is an active request, remove the session-based customer if it exists and update CustomerState
WebRequest request = BroadleafRequestContext.getBroadleafRequestContext().getWebRequest();
if (request != null) {
String customerAttribute = CustomerStateRequestProcessor.getAnonymousCustomerSessionAttributeName();
String customerIdAttribute = CustomerStateRequestProcessor.getAnonymousCustomerIdSessionAttributeName();
if (BLCRequestUtils.isOKtoUseSession(request)) {
Customer sessionCustomer = (Customer) request.getAttribute(customerAttribute, WebRequest.SCOPE_GLOBAL_SESSION);
// persisted
if (sessionCustomer != null && sessionCustomer.getId().equals(dbCustomer.getId())) {
request.removeAttribute(customerAttribute, WebRequest.SCOPE_GLOBAL_SESSION);
request.setAttribute(customerIdAttribute, dbCustomer.getId(), WebRequest.SCOPE_GLOBAL_SESSION);
}
}
// Update CustomerState if the persisted Customer ID is the same
if (CustomerState.getCustomer() != null && CustomerState.getCustomer().getId().equals(dbCustomer.getId())) {
// Copy transient fields from the customer that existed in CustomerState, prior to the DB refresh,
// to the customer that has been saved (merged) in the DB....
Customer preMergedCustomer = CustomerState.getCustomer();
resetTransientFields(preMergedCustomer, dbCustomer);
CustomerState.setCustomer(dbCustomer);
}
}
}
use of org.springframework.web.context.request.WebRequest in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafContextUtil method establishThinRequestContextInternal.
/**
* Adds request and site to the BroadleafRequestContext
*
* If includeTheme is true then also adds the Theme.
* If includeSandBox is true then also adds the SandBox.
*
* @param includeTheme
* @param includeSandBox
*/
protected void establishThinRequestContextInternal(boolean includeTheme, boolean includeSandBox) {
BroadleafRequestContext brc = BroadleafRequestContext.getBroadleafRequestContext();
if (brc.getRequest() == null) {
HttpServletRequest req = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
HttpSession session = req.getSession(false);
SecurityContext ctx = readSecurityContextFromSession(session);
if (ctx != null) {
SecurityContextHolder.setContext(ctx);
}
brc.setRequest(req);
}
WebRequest wr = brc.getWebRequest();
if (brc.getNonPersistentSite() == null) {
brc.setNonPersistentSite(siteResolver.resolveSite(wr, true));
if (includeSandBox) {
brc.setSandBox(sbResolver.resolveSandBox(wr, brc.getNonPersistentSite()));
}
brc.setDeployBehavior(deployBehaviorUtil.isProductionSandBoxMode() ? DeployBehavior.CLONE_PARENT : DeployBehavior.OVERWRITE_PARENT);
}
if (includeTheme) {
if (brc.getTheme() == null) {
brc.setTheme(themeResolver.resolveTheme(wr));
}
}
}
use of org.springframework.web.context.request.WebRequest in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafRequestCustomerResolverImpl method setCustomer.
@Override
public void setCustomer(Object customer) {
WebRequest request = BroadleafRequestContext.getBroadleafRequestContext().getWebRequest();
request.setAttribute(getCustomerRequestAttributeName(), customer, WebRequest.SCOPE_REQUEST);
}
use of org.springframework.web.context.request.WebRequest in project Flare-event-calendar by PollubCafe.
the class GlobalExceptionHandler method handleMethodArgumentNotValid.
@Override
protected ResponseEntity<Object> handleMethodArgumentNotValid(MethodArgumentNotValidException ex, HttpHeaders headers, HttpStatus status, WebRequest request) {
BindingResult bindingResult = ex.getBindingResult();
List<ApiFieldError> apiFieldErrors = bindingResult.getFieldErrors().stream().map(fieldError -> new ApiFieldError(fieldError.getField(), fieldError.getDefaultMessage())).collect(toList());
ApiErrorsView apiErrorsView = new ApiErrorsView(apiFieldErrors);
return new ResponseEntity<>(apiErrorsView, HttpStatus.UNPROCESSABLE_ENTITY);
}
Aggregations