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:info.magnolia.cms.util.Resource.java

/**
 * <p>//from   w  w w  .j a va 2  s .  c  o m
 * get ContentNode object as set by the "set" tag
 * </p>
 * @param req HttpServletRequest as received in JSP or servlet
 * @return ContentNode , global container specific to the current JSP/Servlet page
 */
public static Content getGlobalContentNode(HttpServletRequest req) {
    try {
        return (Content) req.getAttribute(Resource.GLOBAL_CONTENT_NODE);
    } catch (Exception e) {
        return null;
    }
}

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

public static RPCRequest getRpcRequest(HttpServletRequest request) {
    return ((RPCRequest) request.getAttribute(GWT_RPC_REQUEST_ATTR_NAME));
}

From source file:org.springjutsu.validation.util.RequestUtils.java

public static String getPathWithinHandlerMapping() {
    HttpServletRequest request = getCurrentRequest();
    String pathWithinHandlerMapping = request == null ? null
            : (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
    return removeLeadingAndTrailingSlashes(pathWithinHandlerMapping);
}

From source file:com.surevine.alfresco.audit.listeners.PostAuditEventListener.java

/**
 * Assumes that the post content was a JSON string.
 *
 * @param postContent/*from  ww w . ja va 2s. c  om*/
 *            from the request
 * @return valid JSONObject, otherwise null
 */
public static JSONObject parseJSONFromPostContent(final HttpServletRequest request) {

    if (request.getAttribute(REQUEST_ATTRIBUTE_JSON) != null) {
        return (JSONObject) request.getAttribute(REQUEST_ATTRIBUTE_JSON);
    }

    JSONObject retVal = null;

    InputStream inStream;
    try {
        inStream = request.getInputStream();
    } catch (IOException eIO) {
        logger.error("Error encountered while reading from the request stream", eIO);
        return null;
    }

    InputStreamReader reader = new InputStreamReader(inStream);
    JSONTokener tokenizer = new JSONTokener(reader);

    try {
        retVal = new JSONObject(tokenizer);
    } catch (JSONException e) {
        // We will only warn in the logs if it was supposed to be JSON
        if ("application/json".equals(request.getHeader("Content-Type"))) {
            try {
                logger.warn("Invalid JSON string parsed from post content "
                        + IOUtils.toString(request.getInputStream()), e);
            } catch (IOException e1) {
                logger.error("IOException caught parsing request stream", e1);
            }
        }
    }

    request.setAttribute(REQUEST_ATTRIBUTE_JSON, retVal);

    return retVal;
}

From source file:info.magnolia.cms.core.Path.java

public static String getOriginalURI(HttpServletRequest req) {
    return (String) req.getAttribute(JAVAX_FORWARD_SERVLET_PATH);
}

From source file:org.springjutsu.validation.util.RequestUtils.java

/**
 * Identifies the view name pattern which best matches
 * the current request URL (path within handler mapping).
 * @param candidateViewNames The view name patterns to test
 * @param controllerPaths Possible request mapping prefixes 
 * from a controller-level RequestMapping annotation 
 * @param request the current request/*from   w  w w .  jav a  2s  . c om*/
 * @return the best matching view name.
 */
public static String findFirstMatchingRestPath(String[] candidateViewNames, String[] controllerPaths,
        HttpServletRequest request) {

    String pathWithinHandlerMapping = removeLeadingAndTrailingSlashes(
            (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE));

    AntPathMatcher antPathMatcher = new AntPathMatcher();
    for (String candidatePath : candidateViewNames) {
        if ((controllerPaths == null || candidatePath.startsWith("/")) && antPathMatcher
                .match(removeLeadingAndTrailingSlashes(candidatePath), pathWithinHandlerMapping)) {
            return candidatePath;
        } else if (controllerPaths != null) {
            for (String controllerPath : controllerPaths) {
                String testPath = (controllerPath + "/" + candidatePath).replace("//", "/");
                if (antPathMatcher.match(removeLeadingAndTrailingSlashes(testPath), pathWithinHandlerMapping)) {
                    return candidatePath;
                }
            }
        }
    }
    return null;
}

From source file:arena.utils.ServletUtils.java

public static String canonicalizeURI(String uri, String webrootPath, HttpServletRequest request,
        boolean isPublicURI) {

    boolean isInclude = WebUtils.isIncludeRequest(request);
    boolean isForward = (request.getAttribute(WebUtils.FORWARD_PATH_INFO_ATTRIBUTE) != null);

    // Check it's not an illegal URL
    File webroot = new File(webrootPath);
    File configFile = new File(webroot, uri); // build a canonical version if we can
    String canonicalURI = FileUtils.constructOurCanonicalVersion(configFile, webroot);
    if (!FileUtils.isDescendant(webroot, configFile, webroot)) {
        return null; // illegal
    } else if (isPublicURI && !isInclude && !isForward
            && FileUtils.isDescendant(new File(webroot, "WEB-INF"), configFile, webroot)) {
        return null; // don't allow direct access to web-inf
    } else if (isPublicURI && !isInclude && !isForward
            && FileUtils.isDescendant(new File(webroot, "META-INF"), configFile, webroot)) {
        return null; // don't allow direct access to meta-inf
    } else {/*  w  w w.  j  a v  a  2s . c o m*/
        return canonicalURI;
    }
}

From source file:info.magnolia.cms.util.Resource.java

/**
 * <p>/*from  w  ww . j av a  2s .  co  m*/
 * get Content object as requested from the URI
 * </p>
 * @param req HttpServletRequest as received in JSP or servlet
 * @return currently active page, as requested from the URI
 */
public static Content getCurrentActivePage(HttpServletRequest req) {
    Content currentActpage;
    currentActpage = (Content) req.getAttribute(Aggregator.CURRENT_ACTPAGE);
    if (currentActpage == null) {
        currentActpage = (Content) req.getAttribute(Aggregator.ACTPAGE);
    }
    return currentActpage;
}

From source file:gov.nih.nci.cabig.ctms.web.WebTools.java

@SuppressWarnings({ "unchecked" })
public static SortedMap<String, Object> requestAttributesToMap(final HttpServletRequest request) {
    return namedAttributesToMap(request.getAttributeNames(), new AttributeAccessor() {
        public Object getAttribute(String name) {
            return request.getAttribute(name);
        }//w  w  w .  ja v  a2 s.co m
    });
}

From source file:net.sourceforge.fenixedu.util.InquiriesUtil.java

public static Object getFromRequest(final String name, final HttpServletRequest request) {
    final Object parameter = request.getParameter(name);
    return (parameter == null) ? request.getAttribute(name) : parameter;
}