Example usage for javax.servlet.http HttpServletRequest getHeader

List of usage examples for javax.servlet.http HttpServletRequest getHeader

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getHeader.

Prototype

public String getHeader(String name);

Source Link

Document

Returns the value of the specified request header as a String.

Usage

From source file:org.openmrs.module.openhmis.inventory.web.controller.ItemConceptSuggestionPageController.java

private String getReturnUrl(HttpServletRequest request) {
    String returnUrl = ModuleWebConstants.INVENTORY_PAGE;
    String referer = request.getHeader("referer");
    if (!referer.contains(ITEM_CONCEPT_SUGGESTION_PAGE)) {
        int refererWithoutHostPrefixStartIndex = referer.indexOf('/', 8);
        String refererWithoutHostPrefix = referer.substring(refererWithoutHostPrefixStartIndex);
        returnUrl = refererWithoutHostPrefix;
    }//from ww  w .  j av a  2  s.co m
    return returnUrl;
}

From source file:ch.ge.ve.protopoc.jwt.JwtAuthenticationTokenFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    HttpServletRequest httpRequest = (HttpServletRequest) request;
    String authToken = httpRequest.getHeader(this.tokenHeader);
    String username = jwtTokenUtil.getUsernameFromToken(authToken);

    if (username != null && SecurityContextHolder.getContext().getAuthentication() == null) {
        UserDetails userDetails = this.userDetailsService.loadUserByUsername(username);
        if (jwtTokenUtil.validateToken(authToken, userDetails)) {
            UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(
                    userDetails, null, userDetails.getAuthorities());
            authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(httpRequest));
            SecurityContextHolder.getContext().setAuthentication(authentication);
        }//from   w w  w .  j a va  2 s .  c o  m
    }

    chain.doFilter(request, response);
}

From source file:ch.rasc.extclassgenerator.ModelGenerator.java

public static void writeModel(HttpServletRequest request, HttpServletResponse response, ModelBean model,
        OutputConfig outputConfig) throws IOException {

    byte[] data = generateJavascript(model, outputConfig).getBytes(UTF8_CHARSET);
    String ifNoneMatch = request.getHeader("If-None-Match");
    String etag = "\"0" + DigestUtils.md5DigestAsHex(data) + "\"";

    if (etag.equals(ifNoneMatch)) {
        response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        return;/*from ww  w  .j  a v a  2s . c  o m*/
    }

    response.setContentType("application/javascript");
    response.setCharacterEncoding(UTF8_CHARSET.name());
    response.setContentLength(data.length);

    response.setHeader("ETag", etag);

    @SuppressWarnings("resource")
    ServletOutputStream out = response.getOutputStream();
    out.write(data);
    out.flush();

}

From source file:com.netflix.spinnaker.gate.ratelimit.RateLimitingInterceptor.java

private String sourceIpAddress(HttpServletRequest request) {
    String ip = request.getHeader("X-FORWARDED-FOR");
    if (ip == null) {
        return request.getRemoteAddr();
    }//from  ww  w  .  j  av a  2 s. co m
    return ip;
}

From source file:com.sun.socialsite.web.rest.core.XrdsFilter.java

public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) req;
    if ("application/xrds+xml".equals(request.getHeader("Accepts"))) {
        RequestDispatcher rd = request.getRequestDispatcher("/WEB-INF/jsps/xrds.jsp");
        rd.include(req, res);/*w  ww. j a va  2 s  .c  o  m*/
    } else {
        chain.doFilter(req, res);
    }
}

From source file:com.sfs.beans.DetectBrowserBean.java

/**
 * Sets the request./*from w  w  w .j a  v  a2  s .  c om*/
 *
 * @param req the new request
 */
public void setRequest(final HttpServletRequest req) {
    final String ua = req.getHeader("User-Agent");

    final UserAgent userAgent = UserAgent.parseUserAgentString(ua);
    this.browserName = userAgent.getBrowser().getName();

    if (StringUtils.contains(this.browserName, "Safari")) {
        this.version = "safari";
    }
    if (StringUtils.contains(this.browserName, "Chrome")) {
        this.version = "chrome";
    }
    if (StringUtils.contains(this.browserName, "Internet Explorer")) {
        // Assume IE8 unless proven otherwise later
        this.version = "ie8";
    }
    if (StringUtils.contains(this.browserName, "Internet Explorer 7")) {
        this.version = "ie7";
    }
    if (StringUtils.contains(this.browserName, "Internet Explorer 6")
            || StringUtils.contains(this.browserName, "Internet Explorer 5")) {
        this.version = "ie6";
    }
}

From source file:com.ram.topup.api.ws.security.filter.AuthenticationTokenProcessingFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    if (!(request instanceof HttpServletRequest)) {
        throw new RuntimeException("Expecting a HTTP request");
    }/*w  w w . j a  va2  s.  co m*/

    HttpServletRequest httpRequest = (HttpServletRequest) request;
    String authToken = httpRequest.getHeader("X-Auth-Token");

    String userName = TokenUtils.getUserNameFromToken(authToken);

    if (userName != null) {
        UserDetails userDetails = this.userService.loadUserByUsername(userName);
        if (TokenUtils.validateToken(authToken, userDetails.getUsername(), userDetails.getPassword())) {
            UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(
                    userDetails, null, userDetails.getAuthorities());
            authentication.setDetails(
                    new WebAuthenticationDetailsSource().buildDetails((HttpServletRequest) request));
            SecurityContextHolder.getContext().setAuthentication(authentication);
        }
    }

    chain.doFilter(request, response);
}

From source file:eu.openanalytics.rsb.security.X509AuthenticationFilter.java

@Override
protected Object getPreAuthenticatedCredentials(final HttpServletRequest request) {
    if (!StringUtils.equals(request.getHeader(SSL_VERIFIED_HEADER), "SUCCESS")) {
        return null;
    }/*from w  w w .  j ava 2  s. c  o m*/

    return StringUtils.trimToNull(request.getHeader(SSL_CLIENT_DN_HEADER));
}

From source file:biz.taoconsulting.dominodav.methods.UNLOCK.java

/**
 * @see biz.taoconsulting.dominodav.methods.AbstractDAVMethod#action()
 *//*  w ww . j ava  2s.  c  o  m*/
protected void action() throws Exception {
    // Resource-Path is stripped by the repository name!
    String curPath = (String) this.getHeaderValues().get("resource-path");
    LOGGER.debug("Unlocking for " + curPath);
    String curURI = (String) this.getHeaderValues().get("uri");
    IDAVRepository rep = this.getRepository();
    IDAVResource resource = rep.getResource(curURI);
    try {
        curURI = java.net.URLDecoder.decode(curURI, "UTF-8");
    } catch (Exception e) {
    }
    LockManager lm = this.getLockManager();
    HttpServletRequest req = this.getReq();

    try {
        String lockToken = req.getHeader("Lock-Token");
        LOGGER.debug("Lock-Token:" + lockToken);
        lm.unlock(((IDAVAddressInformation) resource).getInternalAddress(), lockToken);
    } catch (Exception e) {
        LOGGER.error(e);
    }

}

From source file:com.qq.common.WrappedController.java

private boolean isAjaxRequest(HttpServletRequest request) {
    String requestedWith = request.getHeader("X-Requested-With");
    return requestedWith != null && "XMLHttpRequest".equals(requestedWith);
}