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:com.googlesource.gerrit.plugins.gitblit.auth.GerritAuthFilter.java

public boolean doFilter(final Provider<WebSession> webSession, ServletRequest request, ServletResponse response,
        FilterChain chain) throws IOException, ServletException {
    HttpServletRequest httpRequest = (HttpServletRequest) request;

    String hdr = httpRequest.getHeader("Authorization");
    if (hdr != null) {
        return filterBasicAuth((HttpServletRequest) request, (HttpServletResponse) response, hdr);
    } else if (webSession.get().isSignedIn()) {
        return filterSessionAuth(webSession, (HttpServletRequest) request);
    } else {/*from   w  w  w.j a  v  a2s. co m*/
        return true;
    }
}

From source file:eu.hydrologis.stage.geopaparazzi.servlets.ProjectDownloadServiceHandler.java

@Override
public void service(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
    String authHeader = req.getHeader("Authorization");

    String[] userPwd = StageUtils.getUserPwdWithBasicAuthentication(authHeader);
    if (userPwd == null || !LoginChecker.isLoginOk(userPwd[0], userPwd[1])) {
        throw new ServletException("No permission!");
    }//ww  w  .  j  av a2s.  c o m

    // userPwd = new String[]{"testuser"};
    Object projectIdObj = req.getParameter("id");
    if (projectIdObj != null) {
        String projectId = (String) projectIdObj;
        File geopaparazziFolder = StageWorkspace.getInstance().getGeopaparazziFolder(userPwd[0]);
        File newGeopaparazziFile = new File(geopaparazziFolder, projectId);

        byte[] data = IOUtils.toByteArray(new FileInputStream(newGeopaparazziFile));
        DownloadService service = new DownloadService(data, newGeopaparazziFile.getName());
        service.register();
        resp.sendRedirect(resp.encodeRedirectURL(service.getURL()));
    } else {
        throw new ServletException("No project id provided.");
    }

}

From source file:com.google.ie.web.view.GsonView.java

/**
 * check whether gzip encoding is accepted by the browser
 * //from   www .j a  v a 2s. c o  m
 * @param request
 * @return a boolean whether gzip encoding is accepted by the browser
 */
private boolean isGzipInRequest(HttpServletRequest request) {
    String header = request.getHeader("Accept-Encoding");
    return header != null && header.indexOf("gzip") >= 0;
}

From source file:ar.com.zauber.commons.web.filter.webkit.WebKitContentTypeFilter.java

/**
 * @param request/*w  ww  .ja  v  a  2s  .  c om*/
 * @return todos los tipos de media types que acepta este request.
 */
private List<MediaType> getMediaTypes(final HttpServletRequest request) {
    Validate.notNull(request);
    String acceptHeader = request.getHeader(ACCEPT_HEADER);
    List<MediaType> mediaTypes = null;
    if (StringUtils.isNotBlank(acceptHeader)) {
        mediaTypes = MediaType.parseMediaTypes(acceptHeader);
    }
    return mediaTypes;
}

From source file:com.kurento.kmf.jsonrpcconnector.internal.server.config.OAuthFiWareFilter.java

/**
 * Obtains the access token from the request, either form the X-Auth-Header
 * or from the request parameters//  w w w  .  j av a  2s  .co  m
 * 
 * @param request
 * @return The access token. Null if none was found
 */
private String parseAccessToken(HttpServletRequest request) {
    String accessToken = request.getHeader(X_AUTH_HEADER);

    if (accessToken == null) {
        accessToken = request.getParameter(OAuthConstants.ACCESS_TOKEN);
    }

    return accessToken;
}

From source file:fr.mycellar.interfaces.web.security.SecurityContextTokenRepository.java

public void deleteToken(HttpServletRequest request) {
    securityContexts.remove(request.getHeader(SpringSecurityConfiguration.TOKEN_HEADER_NAME));
}

From source file:com.mirth.connect.server.servlets.MirthServlet.java

protected String getRequestIpAddress(HttpServletRequest request) {
    String address = request.getHeader("x-forwarded-for");

    if (address == null) {
        address = request.getRemoteAddr();
    }//from w w  w.j  av  a  2  s .co m

    return address;
}

From source file:com.esd.vs.controller.SMSController.java

/**
 * ?IP?/*from w  ww .jav a2s .  co  m*/
 * 
 * @param request
 * @return
 */
private String getRemoteAddress(HttpServletRequest request) {
    String ip = request.getHeader("x-forwarded-for");
    if (ip == null || ip.length() == 0 || ip.equalsIgnoreCase("unknown")) {
        ip = request.getHeader("Proxy-Client-IP");
    }
    if (ip == null || ip.length() == 0 || ip.equalsIgnoreCase("unknown")) {
        ip = request.getHeader("WL-Proxy-Client-IP");
    }
    if (ip == null || ip.length() == 0 || ip.equalsIgnoreCase("unknown")) {
        ip = request.getRemoteAddr();
    }
    return ip;
}

From source file:org.n52.web.BaseController.java

protected boolean isRequestingPngData(HttpServletRequest request) {
    return IMAGE_PNG.getMimeType().equals(request.getHeader("Accept"));
}

From source file:com.google.sampling.experiential.server.PubExperimentServlet.java

private void logPacoClientVersion(HttpServletRequest req) {
    String pacoVersion = req.getHeader("paco.version");
    if (pacoVersion != null) {
        log.info("Paco version of request = " + pacoVersion);
    }/*from ww  w.j a va2s.com*/
}