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.dd4t.core.util.HttpUtils.java

public static String getOriginalUri(final HttpServletRequest request) {
    String orgUri = (String) request.getAttribute(RequestDispatcher.FORWARD_REQUEST_URI);

    if (StringUtils.isNotEmpty(orgUri)) {
        return orgUri;
    } else {/*from   w ww.  jav  a 2  s.  c  om*/
        return request.getRequestURI();
    }
}

From source file:org.apache.ofbiz.passport.event.GitHubEvents.java

public static GenericValue getOAuth2GitHubConfig(HttpServletRequest request) {
    Delegator delegator = (Delegator) request.getAttribute("delegator");
    String productStoreId = ProductStoreWorker.getProductStoreId(request);
    try {//from  w  w w  .j  ava  2  s  . com
        return getOAuth2GitHubConfig(delegator, productStoreId);
    } catch (GenericEntityException e) {
        Map<String, String> messageMap = UtilMisc.toMap("errorMessage", e.toString());
        String errMsg = UtilProperties.getMessage(resource, "GetOAuth2GitHubError", messageMap,
                UtilHttp.getLocale(request));
        request.setAttribute("_ERROR_MESSAGE_", errMsg);
    }
    return null;
}

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

private static String getErrorMessage(HttpServletRequest req) {
    Object errorMessage = req.getAttribute(ErrorUtility.ERROR_MESSAGE);

    if (errorMessage != null && errorMessage instanceof String) {
        return ErrorUtility.encodeMessage((String) errorMessage);
    }/*  www. j  a  v  a2  s.c om*/

    return null;
}

From source file:org.motrice.bpm.hippo.util.ServletUserNameUtil.java

static String getAttributeShibboleth(String name, final HttpServletRequest request) {
    //Encoding issue. See 
    //https://wiki.shibboleth.net/confluence/display/SHIB2/NativeSPAttributeAccess
    String value = (String) request.getAttribute(name);
    if (value != null) {
        try {//from   w  w w.  ja  v a2 s.com
            value = new String(value.getBytes("ISO-8859-1"), "UTF-8");
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    return value;
}

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

private static String getMessageArray(HttpServletRequest req) {
    Object message = req.getAttribute(ErrorUtility.MESSAGE_ARRAY);

    if (message != null && message instanceof String[]) {
        StringBuffer buffer = new StringBuffer();

        for (String msg : (String[]) message) {
            buffer.append(msg + "\n");
        }/*  ww  w .  j a v a  2s .  c  o  m*/

        String compress = ErrorUtility.compress(buffer.toString());

        return ErrorUtility.encodeMessage(compress);
    }

    return null;
}

From source file:org.apache.ofbiz.passport.event.LinkedInEvents.java

public static GenericValue getOAuth2LinkedInConfig(HttpServletRequest request) {
    Delegator delegator = (Delegator) request.getAttribute("delegator");
    String productStoreId = ProductStoreWorker.getProductStoreId(request);
    try {/*from  w  w w. java2s . c o m*/
        return getOAuth2LinkedInConfig(delegator, productStoreId);
    } catch (GenericEntityException e) {
        Map<String, String> messageMap = UtilMisc.toMap("errorMessage", e.toString());
        String errMsg = UtilProperties.getMessage(resource, "GetOAuth2LinkedInError", messageMap,
                UtilHttp.getLocale(request));
        request.setAttribute("_ERROR_MESSAGE_", errMsg);
    }
    return null;
}

From source file:it.eng.spagobi.commons.utilities.PortletUtilities.java

/**
 * Creates the particular portlet URL for a resource, given its path.
 * //from  ww w .j  a v  a  2 s .c o m
 * @param aHttpServletRequest The request object at input
 * @param resourceAbsolutePath The resource Absolute path
 * 
 * @return The resource Portlet URL String
 */
public static String createPortletURLForResource(HttpServletRequest aHttpServletRequest,
        String resourceAbsolutePath) {
    RenderResponse renderResponse = (RenderResponse) aHttpServletRequest.getAttribute("javax.portlet.response");
    RenderRequest renderRequest = (RenderRequest) aHttpServletRequest.getAttribute("javax.portlet.request");

    return renderResponse.encodeURL(renderRequest.getContextPath() + resourceAbsolutePath).toString();
}

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

public static String getMessagesForJavascript(HttpServletRequest req) {
    Object object = req.getAttribute(ErrorUtility.MESSAGE_ARRAY);

    if (object != null && object instanceof String[]) {
        String[] messages = (String[]) object;
        List<String> list = new LinkedList<String>();

        for (String message : messages) {
            message = message.replaceAll("\\s", " ");
            message = message.replaceAll("'", "\'");
            message = message.replaceAll("\"", "\\\"");

            list.add(message);/*from   w  w w .j  ava2 s . c o  m*/
        }

        return "['" + StringUtils.join(list, "','") + "']";
    }

    return "null";
}

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

private static String getErrorMessageArray(HttpServletRequest req) {
    Object errorMessage = req.getAttribute(ErrorUtility.ERROR_MESSAGE_ARRAY);

    if (errorMessage != null && errorMessage instanceof String[]) {
        StringBuffer buffer = new StringBuffer();

        for (String msg : (String[]) errorMessage) {
            buffer.append(msg + "\n");
        }//from   ww  w .j a  va 2 s .  c o  m

        return ErrorUtility.encodeMessage(buffer.toString());
    }

    return null;
}

From source file:it.eng.spagobi.commons.utilities.PortletUtilities.java

/**
 * Starting from the original URL and the request, creates a string representing the
 * Portlet URL./*from  w w  w. jav  a 2  s  .com*/
 * 
 * @param aHttpServletRequest The request object at input
 * @param originalURL The starting original URL
 * 
 * @return A String representing the Portlet URL
 */
public static String createPortletURL(HttpServletRequest aHttpServletRequest, String originalURL) {

    RenderResponse renderResponse = (RenderResponse) aHttpServletRequest.getAttribute("javax.portlet.response");

    PortletURL aPortletURL = renderResponse.createActionURL();

    logger.debug("Original URL.... " + originalURL + "indexOf ? is " + originalURL.indexOf("?"));

    String parameters = originalURL.substring(originalURL.indexOf("?") + 1);

    StringTokenizer st = new StringTokenizer(parameters, "&", false);

    String parameterToken = null;
    String parameterName = null;
    String parameterValue = null;
    while (st.hasMoreTokens()) {
        parameterToken = st.nextToken();
        logger.debug("Parameter Token [" + parameterToken + "]");

        parameterName = parameterToken.substring(0, parameterToken.indexOf("="));
        parameterValue = parameterToken.substring(parameterToken.indexOf("=") + 1);

        logger.debug("Parameter Name [" + parameterName + "]");
        logger.debug("Parameter Value [" + parameterValue + "]");

        aPortletURL.setParameter(parameterName, parameterValue);
    }

    return aPortletURL.toString();
}