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:com.manydesigns.portofino.dispatcher.DispatcherUtil.java

public static Dispatcher get(HttpServletRequest request) {
    if (request == null) {
        return null;
    }//from ww w .  j  a v  a2  s . co  m
    return (Dispatcher) request.getAttribute(RequestAttributes.DISPATCHER);
}

From source file:org.keycloak.example.AdminClient.java

public static List<RoleRepresentation> getRealmRoles(HttpServletRequest req) throws Failure {
    KeycloakSecurityContext session = (KeycloakSecurityContext) req
            .getAttribute(KeycloakSecurityContext.class.getName());

    HttpClient client = new DefaultHttpClient();
    try {//from ww w .  jav  a 2  s  .  c  o  m
        HttpGet get = new HttpGet(
                UriUtils.getOrigin(req.getRequestURL().toString()) + "/auth/admin/realms/demo/roles");
        get.addHeader("Authorization", "Bearer " + session.getTokenString());
        try {
            HttpResponse response = client.execute(get);
            if (response.getStatusLine().getStatusCode() != 200) {
                throw new Failure(response.getStatusLine().getStatusCode());
            }
            HttpEntity entity = response.getEntity();
            InputStream is = entity.getContent();
            try {
                return JsonSerialization.readValue(is, TypedList.class);
            } finally {
                is.close();
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    } finally {
        client.getConnectionManager().shutdown();
    }
}

From source file:architecture.ee.web.util.ServletUtils.java

public static Map getModelMap(HttpServletRequest request, HttpServletResponse response) {
    ModelMap modelMap = (ModelMap) request.getAttribute(WebApplicatioinConstants.MODEL_ATTRIBUTE);
    if (modelMap == null) {
        modelMap = new ModelMap();
    }/*from  w  w  w.  j av a2s.co m*/
    return modelMap;
}

From source file:org.keycloak.example.CxfRsClient.java

public static List<String> getCustomers(HttpServletRequest req) throws Failure {
    KeycloakSecurityContext session = (KeycloakSecurityContext) req
            .getAttribute(KeycloakSecurityContext.class.getName());

    HttpClient client = new HttpClientBuilder().disableTrustManager().build();
    try {/* w  w w . j ava  2s  . com*/
        HttpGet get = new HttpGet(
                UriUtils.getOrigin(req.getRequestURL().toString()) + "/cxf/customerservice/customers");
        get.addHeader("Authorization", "Bearer " + session.getTokenString());
        try {
            HttpResponse response = client.execute(get);
            if (response.getStatusLine().getStatusCode() != 200) {
                throw new Failure(response.getStatusLine().getStatusCode());
            }
            HttpEntity entity = response.getEntity();
            InputStream is = entity.getContent();
            try {
                return JsonSerialization.readValue(is, TypedList.class);
            } finally {
                is.close();
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    } finally {
        client.getConnectionManager().shutdown();
    }
}

From source file:org.keycloak.example.CustomerDatabaseClient.java

public static List<String> getCustomers(HttpServletRequest req) throws Failure {
    KeycloakSecurityContext session = (KeycloakSecurityContext) req
            .getAttribute(KeycloakSecurityContext.class.getName());

    HttpClient client = new DefaultHttpClient();
    try {/* w  w w  .  ja v a 2  s  . c o  m*/
        HttpGet get = new HttpGet(UriUtils.getOrigin(req.getRequestURL().toString()) + "/database/customers");
        get.addHeader("Authorization", "Bearer " + session.getTokenString());
        try {
            HttpResponse response = client.execute(get);
            if (response.getStatusLine().getStatusCode() != 200) {
                throw new Failure(response.getStatusLine().getStatusCode());
            }
            HttpEntity entity = response.getEntity();
            InputStream is = entity.getContent();
            try {
                return JsonSerialization.readValue(is, TypedList.class);
            } finally {
                is.close();
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    } finally {
        client.getConnectionManager().shutdown();
    }
}

From source file:com.bennavetta.appsite.webapi.ContentController.java

/**
 * Given a request that was matched against a @RequestMapping method, extract a trailing path from it.
 * For example, given a mapping of '/foo/**' and a request of '/foo/bar/baz', this would return 'bar/baz'.
 * @param request the matched request// w w  w  .  j a  va2s  . com
 * @return the final path component
 * @see http://stackoverflow.com/questions/3686808/spring-3-requestmapping-get-path-value
 */
public static String extractPathFromPattern(HttpServletRequest request) {
    String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
    String bestMatchPattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);

    AntPathMatcher apm = new AntPathMatcher();
    String finalPath = apm.extractPathWithinPattern(bestMatchPattern, path);

    return finalPath;
}

From source file:ee.ria.xroad.proxy.serverproxy.ServerProxyHandler.java

private static X509Certificate[] getClientSslCertChain(HttpServletRequest request) throws Exception {
    Object attribute = request.getAttribute("javax.servlet.request.X509Certificate");

    if (attribute != null) {
        return (X509Certificate[]) attribute;
    } else {// www  .j  a  v  a 2 s .  co  m
        return null;
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.java

public static boolean isPresent(HttpServletRequest req) {
    return (req.getAttribute(ATTRIBUTE_NAME) instanceof RequestModelAccess);
}

From source file:io.wcm.wcm.ui.granite.util.GraniteUi.java

/**
 * Current content resource/*from   w ww .j av  a  2 s .c om*/
 * @param request Request
 * @return Current content resource or null
 */
public static Resource getContentResource(HttpServletRequest request) {
    SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request;
    String contentPath = (String) request.getAttribute(Value.CONTENTPATH_ATTRIBUTE);
    if (contentPath != null) {
        return slingRequest.getResourceResolver().getResource(contentPath);
    }
    // fallback to suffix if CONTENTPATH_ATTRIBUTE is not set
    // (e.g. in inside a /libs/granite/ui/components/foundation/form/multifield component)
    contentPath = ((SlingHttpServletRequest) request).getRequestPathInfo().getSuffix();
    if (StringUtils.isNotEmpty(contentPath)) {
        return slingRequest.getResourceResolver().getResource(contentPath);
    }
    return null;
}

From source file:de.micromata.genome.gwiki.page.impl.i18n.GWikiMessageTag.java

@SuppressWarnings("unchecked")
public static String getDomId4I18N(HttpServletRequest req, String key) {
    Map<String, String> m = (Map<String, String>) req.getAttribute(GWIKI_MESSAGE_KEYM);
    if (m == null) {
        return null;
    }//from  w w  w  .  j av a 2  s.co  m
    return m.get(key);
}