Example usage for javax.servlet.http HttpServletRequest setAttribute

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

Introduction

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

Prototype

public void setAttribute(String name, Object o);

Source Link

Document

Stores an attribute in this request.

Usage

From source file:de.eiswind.magnolia.thymeleaf.base.AbstractMockMagnoliaTest.java

@Before
public void setUp() throws Exception {

    /** mock up magnolia */
    node = mock(Node.class);
    Session session = mock(Session.class);
    Workspace workspace = mock(Workspace.class);
    when(workspace.getName()).thenReturn("pages");
    when(session.getWorkspace()).thenReturn(workspace);
    when(session.hasPermission(any(), any())).thenReturn(true);
    when(node.getSession()).thenReturn(session);
    when(node.getPath()).thenReturn("/home");
    NodeIterator nodeIterator = mock(NodeIterator.class);
    when(nodeIterator.hasNext()).thenReturn(false);
    when(node.getNodes()).thenReturn(nodeIterator);

    HttpServletRequest request = new MockHttpServletRequest();
    request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, webApplicationContext);
    HttpServletResponse response = new MockHttpServletResponse();
    WebContext webCtx = mock(WebContext.class);
    when(webCtx.getRequest()).thenReturn(request);
    when(webCtx.getResponse()).thenReturn(response);
    AggregationState state = mock(AggregationState.class);
    when(state.getMainContentNode()).thenReturn(node);

    when(webCtx.getAggregationState()).thenReturn(state);

    AccessManager accessManager = mock(AccessManager.class);
    when(accessManager.isGranted(anyString(), anyLong())).thenReturn(true);
    when(webCtx.getAccessManager(anyString())).thenReturn(accessManager);
    when(webCtx.getLocale()).thenReturn(Locale.ENGLISH);
    MgnlContext.setInstance(webCtx);/*from www.  ja va 2s  .  c o  m*/

    config = mock(ServerConfiguration.class);
    when(config.isAdmin()).thenReturn(true);

    componentProvider = mock(ComponentProvider.class);
    when(componentProvider.getComponent(ServerConfiguration.class)).thenReturn(config);
    engine = mock(RenderingEngine.class);
    when(componentProvider.getComponent(RenderingEngine.class)).thenReturn(engine);
    Provider<AggregationState> provider = mock(Provider.class);
    TemplatingFunctions templatingFunctions = new TemplatingFunctions(provider);
    when(componentProvider.getComponent(TemplatingFunctions.class)).thenReturn(templatingFunctions);
    I18nContentSupport i18nContentSupport = mock(I18nContentSupport.class);
    when(i18nContentSupport.getDefaultLocale()).thenReturn(Locale.ENGLISH);
    when(componentProvider.getComponent(I18nContentSupport.class)).thenReturn(i18nContentSupport);

    Components.pushProvider(componentProvider);

    DefaultMessagesManager mgr = new DefaultMessagesManager();
    when(componentProvider.getComponent(MessagesManager.class)).thenReturn(mgr);

    RenderContext.push();
    RenderContext.get().setModel(new HashMap<>());

    ServletContext servletContext = mock(ServletContext.class);

    thymeEngine = new SpringTemplateEngine();
    thymeEngine.addTemplateResolver(new ClassLoaderTemplateResolver());
    thymeEngine.addDialect(new MagnoliaDialect());
    renderer = new ThymeleafRenderer();
    renderer.setApplicationContext(webApplicationContext);
    renderer.setServletContext(servletContext);
    renderer.setEngine(thymeEngine);

    renderableDefinition = mock(RenderableDefinition.class);
    renderingContext = mock(RenderingContext.class);
    when(engine.getRenderingContext()).thenReturn(renderingContext);
    RenderableVariationResolver variationResolver = mock(RenderableVariationResolver.class);
    AreaElement areaElement = new AreaElement(config, renderingContext, engine, variationResolver);
    areaElement.setContent(node);
    when(componentProvider.newInstance(eq(AreaElement.class), any())).thenReturn(areaElement);

    stringWriter = new StringWriter();
    AppendableWriter out = new AppendableWriter(stringWriter);
    when(renderingContext.getAppendable()).thenReturn(out);

    BlossomTemplateDefinition templateDefinition = mock(BlossomTemplateDefinition.class);
    when(templateDefinition.getDialog()).thenReturn(null);
    AreaDefinition areaDef = mock(AreaDefinition.class);
    when(areaDef.getName()).thenReturn("Area");
    when(areaDef.getEnabled()).thenReturn(true);
    Map<String, AreaDefinition> areaMap = new HashMap<>();
    areaMap.put("Area", areaDef);
    when(templateDefinition.getAreas()).thenReturn(areaMap);
    when(renderingContext.getRenderableDefinition()).thenReturn(templateDefinition);
}

From source file:edu.cornell.mannlib.vedit.controller.BaseEditController.java

protected void setRequestAttributes(HttpServletRequest request, EditProcessObject epo) {
    VitroRequest vreq = new VitroRequest(request);
    request.setAttribute("epoKey", epo.getKey());
    request.setAttribute("epo", epo);
    request.setAttribute("globalErrorMsg", epo.getAttribute("globalErrorMsg"));
    request.setAttribute("css", "<link rel=\"stylesheet\" type=\"text/css\" href=\""
            + vreq.getAppBean().getThemeDir() + "css/edit.css\"/>");
}

From source file:io.ignitr.springboot.common.error.IgnitionErrorAttributes.java

private void storeErrorAttributes(HttpServletRequest request, Exception ex) {
    request.setAttribute(ERROR_ATTRIBUTE, ex);
}

From source file:controller.ControlPembayaran.java

public void returnError(HttpServletRequest request, HttpServletResponse response, Exception e)
        throws ServletException, IOException {
    RequestDispatcher dispatcher;/*from   w  ww  . ja v  a 2s.  c  o  m*/
    request.setAttribute("error", e.getMessage());
    dispatcher = request.getRequestDispatcher("error.jsp");
    dispatcher.forward(request, response);
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.administrativeOffice.studentEnrolment.StudentExternalEnrolmentsDA.java

public ActionForward cancelExternalEnrolment(ActionMapping mapping, ActionForm actionForm,
        HttpServletRequest request, HttpServletResponse response) {
    request.setAttribute("registration", getRegistration(request, actionForm));
    return mapping.findForward("viewRegistrationDetails");
}

From source file:gallery.web.controller.wallpaper.WallpaperDimmensionsControllerCms.java

@Override
public ModelAndView handleRequest(HttpServletRequest req, HttpServletResponse arg1) throws Exception {
    String action_param = req.getParameter(Config.ACTION_PARAM_NAME);
    //String do_param = req.getParameter("do");

    req.setAttribute("title", "? ?? ? --> Resize");
    req.setAttribute(config.getNavigationUrlAttribute(), navigationUrl);
    boolean handled = false;

    long l = System.currentTimeMillis();
    if (RESIZE_VALUE.equals(action_param)) {
        req.setAttribute("top_header", "Resize");
        req.setAttribute(config.getContentUrlAttribute(), beforeUrl);
        String append_all = req.getParameter("append_all");
        wallpaper_service.reResizeWallpapers(Boolean.valueOf(append_all));
        handled = true;/*from   w w  w  . j  a  v  a 2  s  .com*/
        CommonAttributes.addHelpMessage("operation_succeed", req);
    }
    if (!handled) {
        req.setAttribute("top_header", " Resize");
        req.setAttribute(config.getContentUrlAttribute(), beforeUrl);
    }
    l = System.currentTimeMillis() - l;

    //DateFormat df = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss.S");
    req.setAttribute("time", l);

    return new ModelAndView(config.getTemplateUrl());
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.credits.ShowTeacherCreditsDispatchAction.java

private void setMasterDegreeServices(HttpServletRequest request, TeacherService teacherService) {
    if (!teacherService.getMasterDegreeServices().isEmpty()) {
        request.setAttribute("masterDegreeServices", teacherService.getMasterDegreeServices());
    }/*from  w  w w. j  a  v  a  2  s  .co m*/
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.administrativeOffice.studentEnrolment.StudentExternalEnrolmentsDA.java

public ActionForward manageExternalEnrolments(ActionMapping mapping, ActionForm actionForm,
        HttpServletRequest request, HttpServletResponse response) {

    request.setAttribute("registration", getRegistration(request, actionForm));
    return mapping.findForward("manageExternalEnrolments");
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.personnelSection.ManagePeople.java

public ActionForward prepareCreatePersonFillInformation(ActionMapping mapping, ActionForm actionForm,
        HttpServletRequest request, HttpServletResponse response) throws Exception {
    setRequestParametersToCreateInvitedPerson(request, new InternalPersonBean());
    request.setAttribute("initialUnit", UnitUtils.readInstitutionUnit());
    return mapping.findForward("createPersonFillInfo");
}

From source file:com.acc.storefront.controllers.pages.CategoryPageController.java

@ExceptionHandler(UnknownIdentifierException.class)
public String handleUnknownIdentifierException(final UnknownIdentifierException exception,
        final HttpServletRequest request) {
    request.setAttribute("message", exception.getMessage());
    return FORWARD_PREFIX + "/404";
}