Example usage for javax.servlet.http HttpServletResponse SC_NO_CONTENT

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

Introduction

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

Prototype

int SC_NO_CONTENT

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

Click Source Link

Document

Status code (204) indicating that the request succeeded but that there was no new information to return.

Usage

From source file:com.homesnap.webserver.LabelRestAPITest.java

@Test
public void test1DeleteLabelList() {
    // Test impossible to create label list
    JSONObject result = deleteRequestJSONObject(urn_labels, HttpServletResponse.SC_NO_CONTENT);
    Assert.assertNull(result);//from  ww  w.  jav a2 s.  c o m
}

From source file:com.homesnap.webserver.GroupRestAPITest.java

@Test
public void test0DeleteGroupList() {
    // Test impossible to create grouplist
    JSONObject jo = deleteRequestJSONObject(urn_groups, HttpServletResponse.SC_NO_CONTENT);
    Assert.assertNull(jo);/* ww w  . j  av  a 2  s . c  o  m*/

    // Test there is no more controllers
    JSONArray controllers = getRequestJSONArray(urn_groups);
    Assert.assertEquals(0, controllers.length());
}

From source file:com.nec.harvest.security.HarvestLoginUrlAuthenticationEntryPoint.java

@Override
public void commence(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException authException) throws IOException, ServletException {
    if (isPreflight(request)) {
        response.setStatus(HttpServletResponse.SC_NO_CONTENT);
    } else if (isRestRequest(request)) {
        response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized");
    } else {//from  ww w.j  av  a  2  s. co  m
        super.commence(request, response, authException);
    }
}

From source file:com.enonic.cms.core.tools.LivePortalTraceController.java

@Override
protected void doPost(final HttpServletRequest req, final HttpServletResponse res) throws Exception {
    final String command = req.getParameter("command");

    if ("clear-longestpagerequests".equals(command)) {
        livePortalTraceService.clearLongestPageRequestsTraces();
    } else if ("clear-longestattachmentrequests".equals(command)) {
        livePortalTraceService.clearLongestAttachmentRequestTraces();
    } else if ("clear-longestimagerequests".equals(command)) {
        livePortalTraceService.clearLongestImageRequestTraces();
    }/*w w  w  . j  a v  a 2  s  .co m*/

    res.setStatus(HttpServletResponse.SC_NO_CONTENT);
}

From source file:com.erudika.para.security.SimpleAuthenticationSuccessHandler.java

@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) throws IOException, ServletException {
    User u = SecurityUtils.getAuthenticatedUser(authentication);
    if (u != null) {
        if (!StringUtils.equals(request.getRemoteAddr(), u.getLastIp())) {
            u.setLastIp(request.getRemoteAddr());
            u.update();//from  ww  w.  j  a  v a 2 s .c om
        }
    }
    if (isRestRequest(request)) {
        RestUtils.returnStatusResponse(response, HttpServletResponse.SC_NO_CONTENT, "Authentication success.");
    } else {
        super.onAuthenticationSuccess(request, response, authentication);
    }
}

From source file:byps.http.HWriteResponseHelper.java

public void writeResponse(ByteBuffer obuf, Throwable e, HttpServletResponse resp, boolean isAsync)
        throws IOException {
    if (log.isDebugEnabled())
        log.debug("writeResponse(" + obuf + ", exception=" + e + ", resp=" + resp);

    if (resp == null) {
        if (log.isDebugEnabled())
            log.debug(")writeResponse timeout");
        return; // timeout
    }/*from  w  ww.  ja  v a  2  s .c  om*/

    if (listener != null) {
        if (log.isDebugEnabled())
            log.debug("call onBefore-listener");
        if (listener.onBeforeWriteHttpResponse(obuf, e, resp, isAsync)) {
            if (log.isDebugEnabled())
                log.debug(")writeResponse, onBefore-listener has written the response.");
        }
    }

    if (e != null) {

        int status = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
        if (e instanceof BException) {
            BException bex = (BException) e;
            if (bex.code == BExceptionC.CANCELLED) {
                status = HttpServletResponse.SC_NOT_ACCEPTABLE;
            } else if (bex.code == BExceptionC.RESEND_LONG_POLL) {
                status = HttpServletResponse.SC_NO_CONTENT;
            }
        }

        if (status == HttpServletResponse.SC_INTERNAL_SERVER_ERROR) {
            log.warn("Responding server error.", e);
        }

        resp.setStatus(status);

        PrintWriter wr = resp.getWriter();
        String errmsg = e.toString(); // (e instanceof BException) ?
                                      // ((BException)e).msg : e.toString();
        wr.print(errmsg);
        wr.close();

    } else {

        if (log.isDebugEnabled())
            log.debug("copy to servlet output");
        boolean isJson = BMessageHeader.detectProtocol(obuf) == BMessageHeader.MAGIC_JSON;
        resp.setContentType(isJson ? "application/json; charset=UTF-8" : "application/byps");
        resp.setContentLength(obuf.remaining());
        OutputStream os = resp.getOutputStream();

        if (log.isDebugEnabled()) {
            log.debug("buffer: \r\n" + BBuffer.toDetailString(obuf));
        }

        if (isAsync) {

            // Tomcat does not throw an IOException in asynchronous requests, if the
            // client
            // has closed the socket. Somewhere on stackoverflow.com I found a hack
            // to workaround this bug. The workaround splits the message into two
            // parts and calls flush() after each part. The second flush throws the
            // expected exception. But the author of this workaround mentioned, that
            // it does not work in all cases - and I confirm to him.
            // http://stackoverflow.com/questions/7124508/how-to-properly-detect-a-client-disconnect-in-servlet-spec-3
            int pos = obuf.position(), len = obuf.remaining() / 2;
            os.write(obuf.array(), pos, len);
            os.flush();
            os.write(obuf.array(), pos + len, obuf.remaining() - len);
            os.flush();
        } else {
            os.write(obuf.array(), obuf.position(), obuf.remaining());
        }

        os.close();

        if (listener != null) {
            if (log.isDebugEnabled())
                log.debug("call onAfter-listener");
            listener.onAfterWriteHttpResponse(obuf.remaining());
        }

    }
    if (log.isDebugEnabled())
        log.debug(")writeResponse");
}

From source file:org.cryptomator.frontend.webdav.DefaultServlet.java

@Override
protected void doOptions(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    resp.addHeader("DAV", "1, 2");
    resp.addHeader("MS-Author-Via", "DAV");
    resp.addHeader("Allow", "OPTIONS, GET, HEAD");
    resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
}

From source file:com.alzatezabala.fp.presentacion.controller.EntidadBancariaController.java

@RequestMapping(value = { "/EntidadBancaria/{id}" }, method = RequestMethod.DELETE)
public void delete(HttpServletRequest httpRequest, HttpServletResponse httpServletResponse,
        @PathVariable("id") int idEntidad) throws IOException {
    if (entidadBancariaDAO.delete(idEntidad)) {
        httpServletResponse.setStatus(HttpServletResponse.SC_ACCEPTED);
    } else {/*from  w w  w .ja  v a2 s.  c o  m*/
        httpServletResponse.setStatus(HttpServletResponse.SC_NO_CONTENT);
    }
}

From source file:org.eclipse.orion.server.cf.commands.GetOrgsCommand.java

@Override
protected ServerStatus _doIt() {
    try {//from  w w  w .  ja  v a 2 s  . com
        /* get available orgs */
        URI targetURI = URIUtil.toURI(target.getUrl());
        URI orgsURI = targetURI.resolve("/v2/organizations");

        GetMethod getDomainsMethod = new GetMethod(orgsURI.toString());
        HttpUtil.configureHttpMethod(getDomainsMethod, target);
        getDomainsMethod.setQueryString("inline-relations-depth=1"); //$NON-NLS-1$

        ServerStatus status = HttpUtil.executeMethod(getDomainsMethod);
        if (!status.isOK())
            return status;

        /* extract available orgs */
        JSONObject orgs = status.getJsonData();

        if (orgs == null || orgs.optInt(CFProtocolConstants.V2_KEY_TOTAL_RESULTS, 0) < 1) {
            return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NO_CONTENT,
                    "Server did not return any organizations.", null);
        }

        /* look if the domain is available */
        JSONObject result = new JSONObject();
        int resources = orgs.getJSONArray(CFProtocolConstants.V2_KEY_RESOURCES).length();
        for (int k = 0; k < resources; ++k) {
            JSONObject orgJSON = orgs.getJSONArray(CFProtocolConstants.V2_KEY_RESOURCES).getJSONObject(k);
            List<Space> spaces = new ArrayList<Space>();
            status = getSpaces(spaces, orgJSON);
            if (!status.isOK())
                return status;
            OrgWithSpaces orgWithSpaces = new OrgWithSpaces();
            orgWithSpaces.setCFJSON(orgJSON);
            orgWithSpaces.setSpaces(spaces);
            result.append("Orgs", orgWithSpaces.toJSON());
        }

        return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, result);
    } catch (Exception e) {
        String msg = NLS.bind("An error occurred when performing operation {0}", commandName); //$NON-NLS-1$
        logger.error(msg, e);
        return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e);
    }
}

From source file:com.homesnap.webserver.ControllerRestAPITest.java

@Test
public void test01CreateControllerByGroup() {
    // Test impossible to create an existing controller
    deleteRequestJSONObject("/house", HttpServletResponse.SC_NO_CONTENT);
    postRequestJSONObject(urn_groups + "/group?id=1", createGroup1(), HttpServletResponse.SC_CREATED);
    postRequestJSONObject(urn_groups + "/1/11", createJsonController11(), HttpServletResponse.SC_CREATED);
    postRequestJSONObject(urn_groups + "/1/12", createJsonController12(), HttpServletResponse.SC_CREATED);

    JSONObject jo = postRequestJSONObject(urn_groups + "/1/16", createJsonController16(),
            HttpServletResponse.SC_CREATED);
    testController16(jo);//from ww  w  .  j av a  2  s. c om
    postRequestJSONObject(urn_groups + "/1/16", createJsonController16(),
            HttpServletResponse.SC_NOT_ACCEPTABLE);

    jo = postRequestJSONObject(urn_groups + "/1/17", createJsonController17(), HttpServletResponse.SC_CREATED);
    testController17(jo);
}