Example usage for javax.servlet.http HttpServletRequest getAttribute

List of usage examples for javax.servlet.http HttpServletRequest getAttribute

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getAttribute.

Prototype

public Object getAttribute(String name);

Source Link

Document

Returns the value of the named attribute as an Object, or null if no attribute of the given name exists.

Usage

From source file:com.example.spring.controller.AppErrorController.java

private HttpStatus getStatus(HttpServletRequest request) {
    Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
    if (statusCode != null) {
        try {// ww  w. java 2s  .  c o  m
            return HttpStatus.valueOf(statusCode);
        } catch (Exception ex) {
        }
    }
    return HttpStatus.INTERNAL_SERVER_ERROR;
}

From source file:ru.org.linux.exception.ExceptionController.java

@RequestMapping("/ExceptionResolver")
public ModelAndView defaultExceptionHandler(HttpServletRequest request, HttpServletResponse response,
        Object handler) {/*from   ww w .ja v  a2  s  .co m*/
    Throwable ex = (Throwable) request.getAttribute("javax.servlet.error.exception");
    if (ex == null) {
        return new ModelAndView(new RedirectView("/"));
    }

    if (!(ex instanceof Exception)) {
        return exceptionResolver.resolveException(request, response, handler, new RuntimeException(ex));
    } else {
        return exceptionResolver.resolveException(request, response, handler, (Exception) ex);
    }
}

From source file:com.hp.autonomy.frontend.find.core.web.ControllerUtilsImpl.java

private String getBaseUrl(final HttpServletRequest request) {
    final String originalUri = (String) request.getAttribute(RequestDispatcher.FORWARD_REQUEST_URI);
    final String requestUri = originalUri != null ? originalUri : request.getRequestURI();
    final String path = requestUri.replaceFirst(request.getContextPath(), "");
    final int depth = StringUtils.countMatches(path, "/") - 1;

    return depth <= 0 ? "." : StringUtils.repeat("../", depth);
}

From source file:org.hdiv.web.servlet.support.ThymeleafHdivRequestDataValueProcessor.java

public Map<String, String> getExtraHiddenFields(HttpServletRequest request) {

    IDataComposer dataComposer = (IDataComposer) request.getAttribute(HDIVUtil.DATACOMPOSER_REQUEST_KEY);
    Map<String, String> extraFields = new HashMap<String, String>();

    if (this.innerRequestDataValueProcessor != null) {
        Map<String, String> innerExtras = this.innerRequestDataValueProcessor.getExtraHiddenFields(request);
        if (innerExtras != null) {
            extraFields.putAll(innerExtras);
        }/*from   ww w.  j  a v a  2  s  .  c  o  m*/
    }

    if (dataComposer == null || dataComposer.isRequestStarted() == false) {
        return extraFields;
    }

    // Use the state id generated by the form action processing
    String formStateId = (String) request.getAttribute(FormUrlProcessor.FORM_STATE_ID);

    if (formStateId != null && formStateId.length() > 0) {
        String hdivStateParam = (String) request.getSession().getAttribute(Constants.HDIV_PARAMETER);
        extraFields.put(hdivStateParam, formStateId);
    }
    return extraFields;
}

From source file:org.jboss.arquillian.warp.extension.spring.container.provider.ProviderBaseTestCase.java

/**
 * <p>Sets the {@link SpringMvcResult} on instance of the test object.</p>
 *
 * @throws Exception if any error occurs
 *///ww w  .j  a  v  a 2 s.c  o  m
@SuppressWarnings("unchecked")
protected void setSpringMvcResult() throws Exception {

    HttpServletRequest mockServletRequest = mock(HttpServletRequest.class);
    when(mockServletRequest.getAttribute(Commons.SPRING_MVC_RESULT_ATTRIBUTE_NAME)).thenReturn(springMvcResult);

    Instance<HttpServletRequest> mockServletRequestInstance = mock(Instance.class);
    TestReflectionHelper.setFieldValue(instance, "servletRequestInstance", mockServletRequestInstance);
    when(mockServletRequestInstance.get()).thenReturn(mockServletRequest);
}

From source file:com.github.fedorchuck.webstore.web.controllers.HomeController.java

@RequestMapping(value = "/error", method = GET)
public String error(HttpServletRequest request, Model model) {
    model.addAttribute("errorCode", request.getAttribute("javax.servlet.error.status_code"));
    Throwable throwable = (Throwable) request.getAttribute("javax.servlet.error.exception");
    String errorMessage = null;//ww w.  j  ava 2 s.c  o  m
    if (throwable != null) {
        errorMessage = throwable.getMessage();
    }
    model.addAttribute("errorMessage", errorMessage);
    return "error";
}

From source file:com.sshdemo.common.web.AccessDeniedAction.java

@Override
public String execute() {

    HttpServletRequest request = ServletActionContext.getRequest();
    AccessDeniedException exception = (AccessDeniedException) request
            .getAttribute(WebAttributes.ACCESS_DENIED_403);

    this.errorDetails = exception.getMessage();
    this.errorTrace = exception.toString();

    return SUCCESS;
}

From source file:edu.usu.sdl.opencatalog.web.extension.OpenCatalogExceptionHandler.java

public Resolution handleAll(Throwable error, HttpServletRequest request, HttpServletResponse response) {
    ActionBean action = (ActionBean) request.getAttribute(StripesConstants.REQ_ATTR_ACTION_BEAN);

    //TODO: Generate Error Ticket
    // Capture all request information, stacktraces, user info
    if (action != null) {

    }//from w  w  w  .  j a  v  a  2  s . c  o  m

    //Strip and senstive info (See Checklist Q: 410)

    systemErrorModel.setMessage(error.getLocalizedMessage());

    final ObjectMapper objectMapper = new ObjectMapper();
    return new StreamingResolution(MediaType.APPLICATION_JSON) {

        @Override
        protected void stream(HttpServletResponse response) throws Exception {
            objectMapper.writeValue(response.getOutputStream(), systemErrorModel);
        }
    };
}

From source file:org.hdiv.web.multipart.HdivStandardServletMultipartResolver.java

@Override
public boolean isMultipart(HttpServletRequest request) {

    HdivMultipartException multipartException = (HdivMultipartException) request
            .getAttribute(IMultipartConfig.FILEUPLOAD_EXCEPTION);
    if (multipartException != null) {
        Exception orig = multipartException.getOriginal();
        if (orig instanceof MultipartException) {
            throw (MultipartException) orig;
        } else {/*ww w.j  a  v a2 s .co  m*/
            throw new MultipartException("Could not parse multipart servlet request", orig);
        }
    }

    return super.isMultipart(request);
}

From source file:edu.usu.sdl.openstorefront.web.extension.OpenStorefrontExceptionHandler.java

public Resolution handleAll(Throwable error, HttpServletRequest request, HttpServletResponse response) {
    ActionBean action = (ActionBean) request.getAttribute(StripesConstants.REQ_ATTR_ACTION_BEAN);

    //TODO: Generate Error Ticket
    // Capture all request information, stacktraces, user info
    if (action != null) {

    }//from   w  w w. j  a va  2  s .c  o m

    //Strip and senstive info (See Checklist Q: 410)

    systemErrorModel.setMessage(error.getLocalizedMessage());

    final ObjectMapper objectMapper = ServiceUtil.defaultObjectMapper();
    return new StreamingResolution(MediaType.APPLICATION_JSON) {

        @Override
        protected void stream(HttpServletResponse response) throws Exception {
            objectMapper.writeValue(response.getOutputStream(), systemErrorModel);
        }
    };
}