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:eu.stratosphere.nephele.jobmanager.web.SetupInfoServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    resp.setStatus(HttpServletResponse.SC_OK);
    resp.setContentType("application/json");

    if ("globalConfiguration".equals(req.getParameter("get"))) {
        writeGlobalConfiguration(resp);/*from  w ww.  java 2  s . com*/
    } else if ("taskmanagers".equals(req.getParameter("get"))) {
        writeTaskmanagers(resp);
    }

}

From source file:controller.TemasNivel1RestController.java

@RequestMapping(method = RequestMethod.GET, produces = "application/json")
public String getJSON(HttpServletRequest request, HttpServletResponse response) {
    TemasNivel1DAO tabla = new TemasNivel1DAO();
    Gson JSON;/*from  w w w  .  j a  v  a 2 s  .c  om*/
    List<TemasNivel1> lista;
    try {
        lista = tabla.selectAll();
        if (lista.isEmpty()) {
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
            Error e = new Error();
            e.setTypeAndDescription("Warning", "No existen elementos");
            JSON = new Gson();
            return JSON.toJson(e);
        }
    } catch (HibernateException ex) {
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        Error e = new Error();
        e.setTypeAndDescription("errorServer", ex.getMessage());
        JSON = new Gson();
        return JSON.toJson(e);
    }

    Datos<TemasNivel1> datos = new Datos<>();
    datos.setDatos(lista);
    JSON = new Gson();
    response.setStatus(HttpServletResponse.SC_OK);
    return JSON.toJson(datos);
}

From source file:controller.TemasNivel2RestController.java

@RequestMapping(method = RequestMethod.GET, produces = "application/json")
public String getJSON(HttpServletRequest request, HttpServletResponse response) {
    TemasNivel2DAO tabla = new TemasNivel2DAO();
    Gson JSON;/*from w  w w .  ja  v  a2 s . c om*/
    List<TemasNivel2> lista;
    try {
        lista = tabla.selectAll();
        if (lista.isEmpty()) {
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
            Error e = new Error();
            e.setTypeAndDescription("Warning", "No existen elementos");
            JSON = new Gson();
            return JSON.toJson(e);
        }
    } catch (HibernateException ex) {
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        Error e = new Error();
        e.setTypeAndDescription("errorServer", ex.getMessage());
        JSON = new Gson();
        return JSON.toJson(e);
    }

    Datos<TemasNivel2> datos = new Datos<>();
    datos.setDatos(lista);
    JSON = new Gson();
    response.setStatus(HttpServletResponse.SC_OK);
    return JSON.toJson(datos);
}

From source file:controller.TemasNivel3RestController.java

@RequestMapping(method = RequestMethod.GET, produces = "application/json")
public String getJSON(HttpServletRequest request, HttpServletResponse response) {
    TemasNivel3DAO tabla = new TemasNivel3DAO();
    Gson JSON;//  ww w .  ja  v  a  2 s.  c o  m
    List<TemasNivel3> lista;
    try {
        lista = tabla.selectAll();
        if (lista.isEmpty()) {
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
            Error e = new Error();
            e.setTypeAndDescription("Warning", "No existen elementos");
            JSON = new Gson();
            return JSON.toJson(e);
        }
    } catch (HibernateException ex) {
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        Error e = new Error();
        e.setTypeAndDescription("errorServer", ex.getMessage());
        JSON = new Gson();
        return JSON.toJson(e);
    }

    Datos<TemasNivel3> datos = new Datos<>();
    datos.setDatos(lista);
    JSON = new Gson();
    response.setStatus(HttpServletResponse.SC_OK);
    return JSON.toJson(datos);
}

From source file:com.datatorrent.lib.io.HttpJsonChunksInputOperatorTest.java

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test/*w  w w .  j a  va 2s .com*/
public void testHttpInputModule() throws Exception {

    final List<String> receivedMessages = new ArrayList<String>();
    Handler handler = new AbstractHandler() {
        int responseCount = 0;

        @Override
        public void handle(String string, Request rq, HttpServletRequest request, HttpServletResponse response)
                throws IOException, ServletException {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            IOUtils.copy(request.getInputStream(), bos);
            receivedMessages.add(new String(bos.toByteArray()));
            response.setContentType("application/json");
            response.setStatus(HttpServletResponse.SC_OK);
            response.setHeader("Transfer-Encoding", "chunked");
            try {
                JSONObject json = new JSONObject();
                json.put("responseId", "response" + ++responseCount);
                byte[] bytes = json.toString().getBytes();
                response.getOutputStream().println(bytes.length);
                response.getOutputStream().write(bytes);
                response.getOutputStream().println();
                response.getOutputStream().println(0);
                response.getOutputStream().flush();
            } catch (JSONException e) {
                response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                        "Error generating response: " + e.toString());
            }

            ((Request) request).setHandled(true);
        }
    };

    Server server = new Server(0);
    server.setHandler(handler);
    server.start();

    String url = "http://localhost:" + server.getConnectors()[0].getLocalPort() + "/somecontext";
    final AbstractHttpInputOperator operator = new HttpJsonChunksInputOperator();

    CollectorTestSink sink = new CollectorTestSink();

    operator.outputPort.setSink(sink);
    operator.setUrl(new URI(url));

    operator.setup(null);
    operator.activate(null);

    int timeoutMillis = 3000;
    while (sink.collectedTuples.isEmpty() && timeoutMillis > 0) {
        operator.emitTuples();
        timeoutMillis -= 20;
        Thread.sleep(20);
    }

    Assert.assertTrue("tuple emitted", sink.collectedTuples.size() > 0);

    Map<String, String> tuple = (Map<String, String>) sink.collectedTuples.get(0);
    Assert.assertEquals("", tuple.get("responseId"), "response1");

    operator.deactivate();
    operator.teardown();
    server.stop();

}

From source file:edu.umn.msi.tropix.transfer.http.server.HttpTransferControllerImpl.java

private void doGet(final HttpServletRequest request, final HttpServletResponse response)
        throws ServletException {
    LOG.info("doGet called");
    final String downloadKey = request.getParameter(ServerConstants.KEY_PARAMETER_NAME);
    LOG.info("Key is " + downloadKey);
    try {//from   w w  w  .  java  2 s  .  c om
        response.setStatus(HttpServletResponse.SC_OK);
        response.flushBuffer();
        fileKeyResolver.handleDownload(downloadKey, response.getOutputStream());
    } catch (final Exception e) {
        LOG.info("handleDownload threw exception", e);
        throw new ServletException(e);
    }
}

From source file:com.cisco.ctao.sparkapi.webhookserver.HttpEventProcessor.java

@Override
public void handle(String target, Request baseRequest, HttpServletRequest httpRequest,
        HttpServletResponse httpResponse) throws IOException, ServletException {
    response = null;//from w  w  w  .j a v a  2 s.  com
    httpRSC = HttpServletResponse.SC_OK;
    final String method = baseRequest.getMethod().toLowerCase();
    final String uri = baseRequest.getRequestURI().trim();
    final String payload = IOUtils.toString(baseRequest.getInputStream()).trim();

    LOG.debug(">>>> handle: received http message: start");
    LOG.debug("Method: {}, URI: '{}', RemoteAddr: {}", method, uri, baseRequest.getRemoteAddr());

    if (method.compareToIgnoreCase("POST") == 0 || method.compareToIgnoreCase("PUT") == 0) {
        processHttpMessage(baseRequest, uri, payload);
    }

    sendHttpResponse(httpResponse);
    baseRequest.setHandled(true);
    LOG.debug("<<<< handle: received http message: end");
}

From source file:byps.http.HIncomingStreamAsync.java

@Override
public void close() throws IOException {
    if (log.isDebugEnabled())
        log.debug("close(targetId=" + targetId);

    boolean alreadyClosed = closed.getAndSet(true);
    if (log.isDebugEnabled())
        log.debug("alreadyClosed=" + alreadyClosed);
    if (!alreadyClosed) {

        if (log.isDebugEnabled())
            log.debug("complete AsyncContext of targetId=" + targetId + " with status="
                    + HttpServletResponse.SC_OK);

        // The stream data must be completely read.
        // Otherwise the data remains in the socket and 
        // disturbs the next request.
        while (is.read() != -1) {
            //if (log.isDebugEnabled()) log.debug("read before close, " + (char)c);
        }//from ww  w .j a va2  s. c o m
        is.close();

        HttpServletResponse response = (HttpServletResponse) rctxt.getResponse();
        response.getOutputStream().close();
        response.setStatus(HttpServletResponse.SC_OK);
        rctxt.complete();

        super.close();
    }
    if (log.isDebugEnabled())
        log.debug(")close");
}

From source file:com.jslsolucoes.tagria.lib.servlet.Tagria.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    String uri = request.getRequestURI().replaceAll(";jsessionid=.*", "");
    String etag = DigestUtils.sha256Hex(uri);

    if (uri.endsWith("blank")) {
        response.setStatus(HttpServletResponse.SC_OK);
        return;/*from  w ww  .  j a  va  2 s  .  c  o  m*/
    }

    if (uri.endsWith("locale")) {
        Config.set(request.getSession(), Config.FMT_LOCALE,
                Locale.forLanguageTag(request.getParameter("locale")));
        response.setStatus(HttpServletResponse.SC_OK);
        return;
    }

    if (request.getHeader("If-None-Match") != null && etag.equals(request.getHeader("If-None-Match"))) {
        response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        return;
    }

    String charset = "utf-8";
    if (TagUtil.getInitParam(TagriaConfigParameter.ENCODING) != null) {
        charset = TagUtil.getInitParam(TagriaConfigParameter.ENCODING);
    }
    response.setCharacterEncoding(charset);
    try {

        DateTime today = new DateTime();
        DateTime expires = new DateTime().plusDays(CACHE_EXPIRES_DAY);

        if (uri.endsWith(".css")) {
            response.setContentType("text/css");
        } else if (uri.endsWith(".js")) {
            response.setContentType("text/javascript");
        } else if (uri.endsWith(".png")) {
            response.setContentType("image/png");
        }

        SimpleDateFormat sdf = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss 'GMT'", Locale.ENGLISH);

        if (Boolean.valueOf(TagUtil.getInitParam(TagriaConfigParameter.CDN_ENABLED))) {
            response.setHeader(HttpHeaderParameter.ACCESS_CONTROL_ALLOW_ORIGIN.getName(), "*");
        }

        response.setHeader(HttpHeaderParameter.ETAG.getName(), etag);
        response.setHeader(HttpHeaderParameter.EXPIRES.getName(), sdf.format(expires.toDate()));
        response.setHeader(HttpHeaderParameter.CACHE_CONTROL.getName(),
                "public,max-age=" + Seconds.secondsBetween(today, expires).getSeconds());

        String url = "/com/jslsolucoes"
                + uri.replaceFirst(request.getContextPath(), "").replaceAll(";jsessionid=.*", "");
        InputStream in = getClass().getResourceAsStream(url);
        IOUtils.copy(in, response.getOutputStream());
        in.close();

    } catch (Exception exception) {
        logger.error("Could not load resource", exception);
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
}

From source file:com.magnet.mmx.server.plugin.mmxmgmt.servlet.ConfigServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse response)
        throws ServletException, IOException {
    LOGGER.trace("doGet : Getting MMX Configuration");
    response.setContentType(CONTENT_TYPE_JSON);
    PrintWriter out = response.getWriter();
    SerializableConfig sconfig = new SerializableConfig(MMXConfiguration.getConfiguration());
    GsonData.getGson().toJson(sconfig, out);
    out.flush();//from ww  w . j a  v a 2 s  . co  m
    response.setStatus(HttpServletResponse.SC_OK);
    return;
}