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:cn.vlabs.duckling.vwb.VWBContext.java

public static VWBContext createContext(HttpServletRequest request, Command command, Resource vp) {
    SiteMetaInfo site = VWBContainerImpl.findSite(request);
    VWBContext context = new VWBContext(request, site, command, vp);
    request.setAttribute(CONTEXT_KEY, context);
    return context;
}

From source file:com.swiftcorp.portal.common.util.WebUtils.java

public static void setFailureMessages(HttpServletRequest request, String[] messageKeys) {
    if (messageKeys == null || messageKeys.length == 0) {
        theLogger.error("messageKeys cant null or empty");
        throw new RuntimeException("messageKeys cant null or empty");
    }/*from  w  w  w. j  a  v a2  s  .  co  m*/

    ActionMessages actionMessages = new ActionMessages();
    for (String messageKey : messageKeys) {
        ActionMessage actionMessage = new ActionMessage(messageKey);
        actionMessages.add(ActionMessages.GLOBAL_MESSAGE, actionMessage);
    }
    request.setAttribute(Globals.ERROR_KEY, actionMessages);
}

From source file:com.runwaysdk.controller.ErrorUtility.java

private static void prepareProblems(ProblemExceptionDTO e, HttpServletRequest req,
        boolean ignoreNotifications) {
    List<String> messages = new LinkedList<String>();

    for (ProblemDTOIF problem : e.getProblems()) {
        if ((!ignoreNotifications) && (problem instanceof AttributeNotificationDTO)) {
            String message = problem.getMessage();

            messages.add(message);/* w  w w  . j av  a2 s.c o  m*/
        }
    }

    if (messages.size() > 0) {
        req.setAttribute(ErrorUtility.ERROR_MESSAGE_ARRAY, messages.toArray(new String[messages.size()]));
    }
}

From source file:de.knowwe.core.kdom.rendering.RenderResult.java

private static String createMaskKey(HttpServletRequest request) {
    Object storedMaskKey = request.getAttribute(storeKey);
    if (storedMaskKey != null)
        return (String) storedMaskKey;

    int rnd = Math.abs(new Random().nextInt());
    String maskKey = Integer.toString(rnd, Character.MAX_RADIX);
    request.setAttribute(storeKey, maskKey);
    return maskKey;
}

From source file:cn.vlabs.duckling.vwb.VWBContext.java

public static VWBContext createContext(int siteId, HttpServletRequest request, Command command, Resource vp) {
    VWBContainer container = VWBContainerImpl.findContainer();
    SiteMetaInfo site = container.getSite(siteId);
    VWBContext context = new VWBContext(request, site, command, vp);
    request.setAttribute(CONTEXT_KEY, context);
    return context;
}

From source file:com.glaf.core.res.MessageUtils.java

/**
 * Adds the specified messages keys into the appropriate request attribute
 * for use by the &lt;html:messages&gt; tag (if messages="true" is set), if
 * any messages are required. Initialize the attribute if it has not already
 * been. Otherwise, ensure that the request attribute is not set.
 * /*from   ww  w .ja v a2 s. com*/
 * @param request
 *            The servlet request we are processing
 * @param messages
 *            Messages object
 * @since Struts 1.2.1
 */
public static void addMessages(HttpServletRequest request, ViewMessages messages) {
    if (messages == null) {
        // bad programmer! *slap*
        return;
    }

    // get any existing messages from the request, or make a new one
    ViewMessages viewMessages = (ViewMessages) request.getAttribute(Globals.MESSAGE_KEY);

    if (viewMessages == null) {
        viewMessages = new ViewMessages();
    }

    // add incoming messages
    viewMessages.add(messages);

    // if still empty, just wipe it out from the request
    if (viewMessages.isEmpty()) {
        request.removeAttribute(Globals.MESSAGE_KEY);
        return;
    }

    log.debug("save viewMessages...");

    // Save the messages
    request.setAttribute(Globals.MESSAGE_KEY, viewMessages);
}

From source file:de.itsvs.cwtrpc.core.CwtRpcUtils.java

public static String readContent(HttpServletRequest request)
        throws ServletException, IOException, SecurityException {
    String payload;//from w w w  .j av  a  2 s  .  c  o  m

    /*
     * Content can only be read once from servlet request. In order to
     * access it multiple times the content must be stored in request after
     * it has been read.
     */
    payload = (String) request.getAttribute(GWT_RPC_REQUEST_CONTENT_ATTR_NAME);
    if (payload == null) {
        if (!containsStrongName(request)) {
            throw new SecurityException("Request does not contain required strong name header");
        }
        payload = RPCServletUtils.readContentAsGwtRpc(request);
        request.setAttribute(GWT_RPC_REQUEST_CONTENT_ATTR_NAME, payload);
    }

    return payload;
}

From source file:de.itsvs.cwtrpc.security.RpcSessionManagementFilter.java

@SuppressWarnings("unchecked")
public static void saveAppliedSessionAuthenticationStrategy(HttpServletRequest request,
        SessionAuthenticationStrategy strategy) {
    List<Class<? extends SessionAuthenticationStrategy>> appliedStrategies;

    appliedStrategies = (List<Class<? extends SessionAuthenticationStrategy>>) request
            .getAttribute(APPLIED_SESSION_AUTHENTICATION_STRATEGIES_ATTR_NAME);
    if (appliedStrategies == null) {
        appliedStrategies = new ArrayList<Class<? extends SessionAuthenticationStrategy>>();
    }/* w  w w . j  a v a 2s  .  co m*/
    appliedStrategies.add(strategy.getClass());
    request.setAttribute(APPLIED_SESSION_AUTHENTICATION_STRATEGIES_ATTR_NAME, appliedStrategies);
}

From source file:com.redhat.rhn.frontend.struts.ActionChainHelper.java

/**
 * Adds parameters needed to display action chains in schedule-options.jspf
 * to request./*  w  ww.  j a  va  2  s  . c  om*/
 * @param request the request
 */
public static void prepopulateActionChains(HttpServletRequest request) {
    log.debug("Prepopulating Action Chains");
    List<Map<String, String>> result = new LinkedList<Map<String, String>>();
    User u = new RequestContext(request).getCurrentUser();
    List<ActionChain> actionChains = ActionChainFactory.getActionChainsByModificationDate(u);

    for (ActionChain actionChain : actionChains) {
        populateActionChain(result, actionChain.getLabel());
    }
    if (result.isEmpty()) {
        String placeholder = LocalizationService.getInstance().getMessage("schedule-options.placeholder");
        populateActionChain(result, placeholder);
    }

    String json = new JSONWriter().write(result);
    request.setAttribute(EXISTING_ACTION_CHAINS_PROPERTY_NAME, json);
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.publico.ShowDegreeSiteAction.java

public static Degree getDegree(HttpServletRequest request) {
    final DegreeSite site = SiteMapper.getSite(request);
    Degree degree = null;/*from   w w w  . j a  v a 2s. co  m*/
    if (site != null) {
        degree = site.getDegree();
    } else {
        String degreeId = FenixContextDispatchAction.getFromRequest("degreeID", request);
        degree = FenixFramework.getDomainObject(degreeId);
    }
    if (degree != null) {
        request.setAttribute("degreeID", degree.getExternalId());
        request.setAttribute("degree", degree);
        OldCmsSemanticURLHandler.selectSite(request, degree.getSite());
    }
    return degree;
}