Example usage for javax.servlet.http HttpServletResponse addHeader

List of usage examples for javax.servlet.http HttpServletResponse addHeader

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse addHeader.

Prototype

public void addHeader(String name, String value);

Source Link

Document

Adds a response header with the given name and value.

Usage

From source file:cf.spring.HttpBasicAuthenticator.java

private void setUnathorizedResponse(HttpServletResponse response) {
    response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    response.addHeader("WWW-Authenticate", "Basic realm=\"" + realm + "\"");
}

From source file:org.mitre.oauth2.web.CorsFilter.java

@Override
public void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
        throws IOException, ServletException {

    response.addHeader("Access-Control-Allow-Origin", "*");
    if (request.getHeader("Access-Control-Request-Method") != null && "OPTIONS".equals(request.getMethod())) {
        // CORS "pre-flight" request
        response.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
        response.addHeader("Access-Control-Allow-Headers",
                "X-Requested-With,Origin,Content-Type, Accept, Authorization");
    }/*from   w  w  w.j  a  v  a  2s  .  com*/
    filterChain.doFilter(request, response);
}

From source file:com.rsginer.spring.filters.CORSFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {
    response.addHeader("Access-Control-Allow-Origin", "*");

    if (request.getHeader("Access-Control-Request-Method") != null && "OPTIONS".equals(request.getMethod())) {
        LOG.trace("Sending Header....");
        // CORS "pre-flight" request
        response.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
        //         response.addHeader("Access-Control-Allow-Headers", "Authorization");
        response.addHeader("Access-Control-Allow-Headers", "Content-Type");
        response.addHeader("Access-Control-Max-Age", "1");
    }/*from   w w  w . j  av a2  s .c  o m*/

    filterChain.doFilter(request, response);
}

From source file:es.galvarez.rest.config.CORSFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {
    response.addHeader("Access-Control-Allow-Origin", "*");
    response.addHeader("Access-Control-Allow-Credentials", "true");
    if (request.getHeader("Access-Control-Request-Method") != null && "OPTIONS".equals(request.getMethod())) {
        // CORS "pre-flight" request
        response.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
        response.addHeader("Access-Control-Allow-Headers",
                "Cache-Control, Pragma, Origin, Authorization, X-Requested-With, Content-Type, Accept");
    }/*from  ww  w.j  a v a2  s.c o  m*/
    filterChain.doFilter(request, response);
}

From source file:es.galvarez.rest.config.RestAuthenticationEntryPoint.java

@Override
public void commence(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException authException) throws IOException, ServletException {
    response.addHeader("Access-Control-Allow-Origin", "null");
    response.addHeader("WWW-Authenticate", "RestBasic realm=\"" + getRealmName() + "\"");
    response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    response.setContentLength(0);//from  www  .  j a v  a 2  s  .  co  m
}

From source file:io.dfox.junit.http.example.NoteServlet.java

private void addBasicHeaders(final HttpServletResponse response) {
    response.setCharacterEncoding(UTF_8);
    response.addHeader(ACCESS_CONTROL_ALLOW_ORIGIN, EXAMPLE_CLIENT_HOST);
}

From source file:org.keycloak.adapters.springsecurity.authentication.KeycloakAuthenticationEntryPoint.java

protected void commenceUnauthorizedResponse(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    response.addHeader(HttpHeaders.WWW_AUTHENTICATE, String.format("Bearer realm=\"%s\"", realm));
    response.sendError(HttpStatus.UNAUTHORIZED.value(), HttpStatus.UNAUTHORIZED.getReasonPhrase());
}

From source file:com.thoughtworks.go.server.web.FileView.java

void setContentLength(boolean needToZip, File file, HttpServletResponse response) {
    if (!needToZip) {
        response.addHeader("Content-Length", Long.toString(file.length()));
    }/*ww w .  jav  a  2 s .  c  o  m*/
}

From source file:de.otto.mongodb.profiler.web.CacheInterceptor.java

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {

    if (noCache(handler)) {
        response.addHeader("Cache-Control", "no-cache");
        response.addHeader("Cache-Control", "no-store");
        response.addHeader("Cache-Control", "must-revalidate");
        response.addHeader("Cache-Control", "max-age=0");
        response.addHeader("Cache-Control", "max-stale=0");
        response.addHeader("Cache-Control", "post-check=0");
        response.addHeader("Cache-Control", "pre-check=0");
        response.addHeader("Pragma", "no-cache");
    }//from   w w  w . j  av  a 2 s.co m

    return true;
}

From source file:org.openwms.common.location.LocationGroupController.java

@PatchMapping(value = CommonConstants.API_LOCATIONGROUPS + "/{id}")
public void save(@PathVariable String id,
        @RequestParam(name = "statein", required = false) LocationGroupState stateIn,
        @RequestParam(name = "stateout", required = false) LocationGroupState stateOut, HttpServletRequest req,
        HttpServletResponse res) {
    locationGroupService.changeGroupState(id, stateIn, stateOut);
    res.addHeader(HttpHeaders.LOCATION, getLocationForCreatedResource(req, id));
}