Example usage for javax.servlet.http HttpServletResponse SC_OK

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

Introduction

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

Prototype

int SC_OK

To view the source code for javax.servlet.http HttpServletResponse SC_OK.

Click Source Link

Document

Status code (200) indicating the request succeeded normally.

Usage

From source file:com.google.api.server.spi.handlers.CorsHandlerTest.java

@Test
public void handle() {
    initializeValidRequest(request);/*from w w  w. j  a v  a 2s . com*/

    handler.handle(request, response);

    assertThat(response.getStatus()).isEqualTo(HttpServletResponse.SC_OK);
    assertThat(response.getHeader("Access-Control-Allow-Origin")).isEqualTo(ORIGIN);
    assertThat(response.getHeader("Access-Control-Allow-Headers")).isEqualTo(TEST_HEADER);
    assertThat(response.getHeader("Access-Control-Max-Age")).isEqualTo("3600");
    assertThat(response.getHeader("Access-Control-Allow-Credentials")).isEqualTo("true");
    assertThat(COMMA_SPLITTER.split(response.getHeader("Access-Control-Allow-Methods"))).containsExactly("HEAD",
            "DELETE", "GET", "PATCH", "POST", "PUT");
}

From source file:com.blogspot.ryanfx.auth.GoogleUtil.java

/**
 * Sends the auth token to google and gets the json result.
 * @param token auth token/*from ww w.  j  a va  2  s .  co  m*/
 * @return json result if valid request, null if invalid.
 * @throws IOException
 * @throws LoginException
 */
private static String issueTokenGetRequest(String token) throws IOException, LoginException {
    int timeout = 2000;
    URL u = new URL("https://www.googleapis.com/oauth2/v2/userinfo");
    HttpURLConnection c = (HttpURLConnection) u.openConnection();
    c.setRequestMethod("GET");
    c.setRequestProperty("Content-length", "0");
    c.setRequestProperty("Authorization", "OAuth " + token);
    c.setUseCaches(false);
    c.setAllowUserInteraction(false);
    c.setConnectTimeout(timeout);
    c.setReadTimeout(timeout);
    c.connect();
    int status = c.getResponseCode();
    if (status == HttpServletResponse.SC_OK) {
        BufferedReader br = new BufferedReader(new InputStreamReader(c.getInputStream()));
        StringBuilder sb = new StringBuilder();
        String line;
        while ((line = br.readLine()) != null) {
            sb.append(line + "\n");
        }
        br.close();
        return sb.toString();
    } else if (status == HttpServletResponse.SC_UNAUTHORIZED) {
        Logger.getLogger(GoogleUtil.class.getName()).severe("Invalid token request: " + token);
    }
    return null;
}

From source file:com.fpmislata.banco.presentation.controladores.CuentaBancariaController.java

@RequestMapping(value = {
        "/cuentabancaria/{idCuentaBancaria}" }, method = RequestMethod.GET, produces = "application/json")
public void get(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
        @PathVariable("idCuentaBancaria") int idCuentaBancaria) {
    try {// w ww . j a v  a 2s . c  o  m
        CuentaBancaria cuentaBancaria = cuentaBancariaService.get(idCuentaBancaria);

        String jsonSalida = jsonTransformer.ObjectToJson(cuentaBancaria);

        httpServletResponse.setStatus(HttpServletResponse.SC_OK);
        httpServletResponse.setContentType("application/json");
        httpServletResponse.getWriter().println(jsonSalida);

    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}

From source file:com.sentinel.rest.handlers.AuthSuccessHandler.java

@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) throws ServletException, IOException {
    LOG.trace("Method: onAuthenticationSuccess called.");

    response.setStatus(HttpServletResponse.SC_OK);
    UserDetails userdetails = (UserDetails) authentication.getPrincipal();

    LOG.info(userdetails.getUsername() + " got is connected ");

    PrintWriter writer = response.getWriter();
    mapper.writeValue(writer, null);/*ww  w. j  a  v  a2  s . c  om*/
    writer.flush();
    LOG.trace("Method: onAuthenticationSuccess finished.");
}

From source file:com.fpmislata.banco.presentation.controladores.EntidadBancariaController.java

@RequestMapping(value = "/entidadbancaria/{identidadbancaria}", method = RequestMethod.GET, produces = "application/json")
public void read(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
        @PathVariable("identidadbancaria") int identidadbancaria) {
    try {//from  w w  w .j  a  va 2 s  . c o  m
        EntidadBancaria entidadBancaria = entidadBancariaService.get(identidadbancaria);
        String jsonSalida = jsonTransformer.ObjectToJson(entidadBancaria);
        httpServletResponse.setStatus(HttpServletResponse.SC_OK);
        httpServletResponse.setContentType("application/json; charset=UTF-8");
        httpServletResponse.getWriter().println(jsonSalida);
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}

From source file:com.fpmislata.banco.presentation.controladores.UsuarioController.java

@RequestMapping(value = "/usuario/{idUsuario}", method = RequestMethod.GET, produces = "application/json")
public void read(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
        @PathVariable("idUsuario") int idUsuario) {
    try {//from w  ww . ja  va  2s .  c  o m
        Usuario usuario = usuarioService.get(idUsuario);
        String jsonSalida = jsonTransformer.ObjectToJson(usuario);
        httpServletResponse.setStatus(HttpServletResponse.SC_OK);
        httpServletResponse.setContentType("application/json; charset=UTF-8");
        httpServletResponse.getWriter().println(jsonSalida);
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}

From source file:com.fpmislata.banco.presentation.controladores.SucursalBancariaController.java

@RequestMapping(value = "/sucursalbancaria/{idsucursalbancaria}", method = RequestMethod.GET, produces = "application/json")
public void read(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
        @PathVariable("idsucursalbancaria") int idsucursalbancaria) {
    try {/* w  w  w .  java  2s  .com*/
        SucursalBancaria sucursalBancaria = sucursalBancariaService.get(idsucursalbancaria);
        String jsonSalida = jsonTransformer.ObjectToJson(sucursalBancaria);
        httpServletResponse.setStatus(HttpServletResponse.SC_OK);
        httpServletResponse.setContentType("application/json; charset=UTF-8");
        httpServletResponse.getWriter().println(jsonSalida);
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}

From source file:ge.taxistgela.servlet.AdminServlet.java

public void login(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String username = request.getParameter("username");
    String password = request.getParameter("password");

    Admin admin = new Admin();

    if (admin.checkLogin(username, password)) {
        request.getSession().setAttribute(Admin.class.getName(), admin);

        response.setStatus(HttpServletResponse.SC_OK);
        response.sendRedirect("/admin.jsp");

        return;//from w  ww  .ja  v  a2s.co m
    }

    response.setStatus(HttpServletResponse.SC_FORBIDDEN);
}

From source file:com.enonic.cms.server.service.servlet.CmsDispatcherServlet.java

@Override
protected void doOptions(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setHeader("Allow", StringUtils.join(ALLOWED_HTTP_METHODS, ","));
    response.setStatus(HttpServletResponse.SC_OK);
}

From source file:io.wcm.devops.maven.nodejsproxy.health.NodeJsDistHealthCheck.java

@Override
protected Result check() throws Exception {
    String url = config.getNodeJsBinariesRootUrl();

    log.info("Validate file: {}", url);
    HttpGet get = new HttpGet(url);
    HttpResponse response = httpClient.execute(get);
    try {//from  w ww. j  a  va  2 s .c  o  m
        if (response.getStatusLine().getStatusCode() == HttpServletResponse.SC_OK) {
            return Result.healthy();
        } else {
            return Result.unhealthy("Got status code " + response.getStatusLine().getStatusCode()
                    + " when accessing URL " + url);
        }
    } finally {
        EntityUtils.consumeQuietly(response.getEntity());
    }
}