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:org.kmnet.com.fw.web.token.transaction.TransactionTokenTag.java

/**
 * Renders the transaction token string in a hidden tag with {@code name} and {@code value} attributes <br>
 * The value of {@code name} attribute is {@code _TRANSACTION_TOKEN}. {@code value} attribute is the transaction token
 * string <br>//w w  w  .  j a v a  2s .com
 * @see org.springframework.web.servlet.tags.form.AbstractFormTag#writeTagContent(org.springframework.web.servlet.tags.form.TagWriter)
 */
@Override
protected int writeTagContent(final TagWriter tagWriter) throws JspException {
    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();

    TransactionToken nextToken = (TransactionToken) request
            .getAttribute(TransactionTokenInterceptor.NEXT_TOKEN_REQUEST_ATTRIBUTE_NAME);

    if (nextToken != null) {
        tagWriter.startTag("input");
        tagWriter.writeAttribute("type", "hidden");
        tagWriter.writeAttribute("name", TransactionTokenInterceptor.TOKEN_REQUEST_PARAMETER);
        tagWriter.writeAttribute("value", nextToken.getTokenString());
        tagWriter.endTag();
    }
    return SKIP_BODY;
}

From source file:com.liferay.portal.util.PortalUtil.java

public static PortletPreferences getPreferences(HttpServletRequest req) {
    RenderRequest renderRequest = (RenderRequest) req.getAttribute(WebKeys.JAVAX_PORTLET_REQUEST);

    PortletPreferences prefs = null;/* www  . j  a v  a  2 s .  c o m*/

    if (renderRequest != null) {
        PortletPreferencesWrapper prefsWrapper = (PortletPreferencesWrapper) renderRequest.getPreferences();

        prefs = prefsWrapper.getPreferencesImpl();
    }

    return prefs;
}

From source file:com.acc.storefront.web.i18n.StoreSessionLocaleResolver.java

@Override
public Locale resolveLocale(final HttpServletRequest request) {
    // Lookup the cached locale in the request
    Locale locale = (Locale) request.getAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME);

    if (locale == null) {
        // Get the locale from the hybris session
        locale = getHybrisSessionLocale();

        // Cache the locale in the request attributes
        if (locale != null) {
            request.setAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME, locale);
        }//  w ww  .  j a  v a  2  s .c o  m
    }

    return locale;
}

From source file:com.netflix.genie.web.controllers.UIControllerUnitTests.java

/**
 * Make sure the getFile method returns the right forward command.
 * @throws Exception if an error occurs/*from   w w  w.  ja v  a 2 s .co m*/
 */
@Test
public void canGetFile() throws Exception {
    final String id = UUID.randomUUID().toString();
    final HttpServletRequest request = Mockito.mock(HttpServletRequest.class);

    Mockito.when(request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE))
            .thenReturn("/file/" + id + "/output/genie/log.out");
    Mockito.when(request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE))
            .thenReturn("/file/{id}/**");

    final String encodedId = URLEncoder.encode(id, "UTF-8");
    final String expectedPath = "/api/v3/jobs/" + encodedId + "/output/genie/log.out";

    Assert.assertThat(this.controller.getFile(id, request), Matchers.is("forward:" + expectedPath));
}

From source file:org.fornax.cartridges.sculptor.framework.web.hibernate.DisconnectHibernateInterceptor.java

@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler,
        Exception exc) {/*from   ww  w.  j  a v a2 s . c om*/
    Session hibernateSession = (Session) request.getAttribute(HIBERNATE_SESSION_ATTRIBUTE);
    if (hibernateSession != null) {
        request.removeAttribute(HIBERNATE_SESSION_ATTRIBUTE);
        if (hibernateSession.isConnected()) {
            hibernateSession.disconnect();
        }
    }
}

From source file:org.jasig.portlet.calendar.util.MockView.java

@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    this.model = model;

    System.out.println(request.getAttribute(ViewRendererServlet.MODEL_ATTRIBUTE));
}

From source file:com.pkrete.locationservice.admin.controller.rest.v1.StatisticsRestController.java

@RequestMapping(method = RequestMethod.GET, produces = "application/json; charset=utf-8")
@ResponseBody/*ww  w.  jav  a  2 s .co  m*/
public Map get(HttpServletRequest request) {
    // Get Owner object related to the user
    Owner owner = (Owner) request.getAttribute("owner");
    // Parse StatisticalGroup
    StatisticsGroup group = StatisticsUtil.parseGroup(request.getParameter("group"));
    // Parse SearchEventType
    SearchEventType type = StatisticsUtil.parseType(request.getParameter("type"));
    // Get begin date of the date range
    String from = StatisticsUtil.parseFromDate(request.getParameter("from"));
    // Get end date of the date range
    String to = StatisticsUtil.parseToDate(request.getParameter("to"));
    // Get order of the results (ASC / DESC)
    String order = request.getParameter("order");
    // Get statistics matching the given conditions
    StatisticsSearchResult results = service.getStatistics(owner.getCode(), group, type, from, to, order);
    // Return the statistics
    return this.mapConverter.convert(results);
}

From source file:org.lareferencia.xoai.services.impl.context.LRContextService.java

@Override
public Context getContext() throws ContextServiceException {
    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes())
            .getRequest();/*from   w w w. ja  v  a2s. c  o  m*/
    Object value = request.getAttribute(OAI_CONTEXT);
    if (value == null || !(value instanceof Context)) {
        try {
            request.setAttribute(OAI_CONTEXT, new Context());
        } catch (SQLException e) {
            throw new ContextServiceException(e);
        }
    }
    return (Context) request.getAttribute(OAI_CONTEXT);
}

From source file:org.zalando.zmon.actuator.metrics.MetricsWrapper.java

private String getFinalStatus(final HttpServletRequest request) {
    Object bestMatchingPattern = request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
    if (bestMatchingPattern != null) {
        return fixSpecialCharacters(bestMatchingPattern.toString());
    }//www  .  ja v a 2  s.c  om

    // always return unknown, using the full path leads to an explosion of metrics due to path variables
    return UNKNOWN_PATH_SUFFIX;
}

From source file:net.shopxx.plugin.weiboLogin.WeiboLoginPlugin.java

@Override
public String getOpenId(HttpServletRequest request) {
    String uid = (String) request.getAttribute("uid");
    if (StringUtils.isNotEmpty(uid)) {
        return uid;
    }/*from   w  w  w  .  j  a  v  a 2 s.c  om*/
    return null;
}