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:de.onyxbits.raccoon.net.AppListHandler.java

@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    if (target.equals("/" + index)) {
        response.setContentType("text/html;charset=utf-8");
        response.setStatus(HttpServletResponse.SC_OK);
        printIndex(response.getWriter());
        baseRequest.setHandled(true);/*  w  ww  .j  a v a  2  s . c o  m*/
        return;
    }

    String[] components = target.split("/");
    if (components.length != 3) {
        // components[0] is the empty root path.
        return;
    }

    AndroidApp app = mappings.lookup(components[1]);
    if (app == null) {
        return;
    }

    AppInstallerNode ain = new AppInstallerNode(layout, app.getPackageName(), app.getVersionCode());
    AppExpansionPatchNode patch = new AppExpansionPatchNode(layout, app.getPackageName(),
            app.getPatchVersion());
    AppExpansionMainNode main = new AppExpansionMainNode(layout, app.getPackageName(), app.getVersionCode());

    if (ain.toIcon().getFileName().equals(components[2])) {
        response.setContentType("image/png");
        response.setStatus(HttpServletResponse.SC_OK);
        OutputStream out = response.getOutputStream();
        FileInputStream in = new FileInputStream(ain.toIcon().resolve());
        try {
            IOUtils.copy(in, out);
        } catch (IOException e) {
            throw e;
        }
        in.close();
        out.flush();
        baseRequest.setHandled(true);
        return;
    }

    Object obj = getServer().getAttribute(Traits.class.getName());
    if (obj instanceof Traits) {
        if (!((Traits) obj).isAvailable("4.0.x")) {
            lm.sendBusMessage(new JTextField());
            response.setContentType("text/html");
            baseRequest.setHandled(true);
            return;
        }
    }

    if (components[2].equals(ain.getFileName())) {
        File file = ain.resolve();
        response.setHeader("Content-Length", new Long(file.length()).toString());

        response.setContentType("application/vnd.android.package-archive");
        String s = MessageFormat.format(Messages.getString("destination"), baseRequest.getRemoteAddr());
        NetWorker nw = new NetWorker(file, response, s);
        lm.sendBusMessage(nw);
        blockTillTransferred(nw);
        baseRequest.setHandled(true);
        return;
    }

    if (components[2].equals(main.getFileName())) {
        File file = main.resolve();
        response.setHeader("Content-Length", new Long(file.length()).toString());

        response.setContentType("application/octet-stream");
        String s = MessageFormat.format(Messages.getString("destination"), baseRequest.getRemoteAddr());
        NetWorker nw = new NetWorker(file, response, s);
        lm.sendBusMessage(nw);
        blockTillTransferred(nw);
        baseRequest.setHandled(true);
        return;
    }

    if (components[2].equals(patch.getFileName())) {
        File file = main.resolve();
        response.setHeader("Content-Length", new Long(file.length()).toString());

        response.setContentType("application/octet-stream");
        String s = MessageFormat.format(Messages.getString("destination"), baseRequest.getRemoteAddr());
        NetWorker nw = new NetWorker(file, response, s);
        lm.sendBusMessage(nw);
        blockTillTransferred(nw);
        baseRequest.setHandled(true);
        return;
    }
}

From source file:fr.paris.lutece.plugins.mylutece.modules.openam.web.NotifyLuteceUserFilter.java

/**
 *
 * {@inheritDoc}/*from   w w w . j  av  a2s.co m*/
 */
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) servletRequest;
    HttpServletResponse response = (HttpServletResponse) servletResponse;

    String strGuidParameter = request.getParameter(PARAMETER_UID);

    if (!StringUtils.isEmpty(strGuidParameter)) {
        OpenamLuteceUserSessionService.getInstance().notifyLuteceUserUpdating(strGuidParameter);
    }

    response.setStatus(HttpServletResponse.SC_OK);
}

From source file:com.surevine.alfresco.audit.integration.MoveDocumentTest.java

/**
 * Test sunny day scenario. This test should also assert the contents of returned item.
 */// w  ww  .ja  va  2 s.c o  m
@Test
public void testSuccess() {

    try {

        // Create an empty JSON string for the post data.
        JSONObject json = new JSONObject();
        JSONArray arr = new JSONArray();
        arr.put(TEST_FILENODEREF_STRING);
        json.put(AlfrescoJSONKeys.NODEREFS, arr);

        mockRequest.setRequestURI(REQUEST_URI_FIXTURE);
        mockRequest.setContent(json.toString().getBytes());

        // Initialise the response.
        JSONObject responseJSON = new JSONObject();
        responseJSON.put("totalResults", 2);
        responseJSON.put("overallSuccess", true);

        ResponseModifiableMockFilterChain modifiableFilterChain = new ResponseModifiableMockFilterChain(
                responseJSON.toString(), HttpServletResponse.SC_OK);

        springAuditFilterBean.doFilter(mockRequest, mockResponse, modifiableFilterChain);

        Auditable audited = getSingleAuditedEvent();

        assertEquals(TEST_REMOTE_ADDR, audited.getRemoteAddress());

        assertEquals(TEST_SITE, audited.getSite());
        verifyGenericAuditMetadata(audited);
        assertEquals(TEST_FILE, audited.getSource());
        assertEquals(TEST_FILENODEREF_STRING, audited.getNodeRef());
        assertEquals(NESTED_TEST_FOLDER, audited.getDetails());

    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }

}

From source file:com.surevine.alfresco.audit.integration.SafeMoveDocumentTest.java

/**
 * Test sunny day scenario. This test should also assert the contents of returned item.
 *///from ww w  .j  av  a2s.  c  o  m
@Test
public void testSuccess() {

    try {

        // Create an empty JSON string for the post data.
        JSONObject json = new JSONObject();
        JSONArray arr = new JSONArray();
        arr.put(TEST_FILENODEREF_STRING);
        json.put(AlfrescoJSONKeys.NODEREFS, arr);

        mockRequest.setRequestURI(REQUEST_URI_FIXTURE);
        mockRequest.setContent(json.toString().getBytes());

        // Initialise the response.
        JSONObject responseJSON = new JSONObject();
        responseJSON.put("totalResults", 2);
        responseJSON.put("overallSuccess", true);

        ResponseModifiableMockFilterChain modifiableFilterChain = new ResponseModifiableMockFilterChain(
                responseJSON.toString(), HttpServletResponse.SC_OK);

        springAuditFilterBean.doFilter(mockRequest, mockResponse, modifiableFilterChain);

        Auditable audited = getSingleAuditedEvent();

        assertEquals(TEST_REMOTE_ADDR, audited.getRemoteAddress());

        assertEquals(TEST_SITE, audited.getSite());
        verifyGenericAuditMetadata(audited);
        assertEquals(TEST_FILE, audited.getSource());
        assertEquals(TEST_FILENODEREF_STRING, audited.getNodeRef());
        assertEquals(TEST_FOLDER_PATH, audited.getDetails());

    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }

}

From source file:org.jboss.as.test.integration.web.response.DefaultResponseCodeTestCase.java

@Test
public void testNormalOpMode() throws Exception {
    HttpGet httpget = new HttpGet(url.toString() + URL_PATTERN);
    HttpResponse response = this.httpclient.execute(httpget);
    Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
    httpget = new HttpGet(url.toString() + URL_PATTERN + "/xxx");
    response = this.httpclient.execute(httpget);
    Assert.assertEquals(HttpServletResponse.SC_NOT_FOUND, response.getStatusLine().getStatusCode());
}

From source file:net.thewaffleshop.passwd.security.AuthenticationHandler.java

/**
 * Unsuccessful login; send error//w w w  .  ja va 2  s.c o  m
 *
 * @param request
 * @param response
 * @param exception
 * @throws IOException
 * @throws ServletException
 */
@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException exception) throws IOException, ServletException {
    String msg = exception.getMessage();

    response.setStatus(HttpServletResponse.SC_OK);
    response.setContentType("application/json");
    response.getWriter().write("{\"success\": false, \"msg\": \"" + StringEscapeUtils.escapeJson(msg) + "\"}");
}

From source file:com.nec.harvest.security.handler.HarvestLogoutSuccessHandler.java

/**
 * Causes a logout to be completed. The method must complete successfully
 * /*from w ww. ja  v a 2s.com*/
 * @param request
 * @param response
 * @param authentication
 * @throws IOException
 * @throws ServletException
 */
protected void onLogout(HttpServletRequest request, HttpServletResponse response, Authentication authentication)
        throws IOException, ServletException {
    final HttpSession session = request.getSession();
    if (session != null) {
        // ??????????
        session.invalidate();

        // Invalidates this session then unbinds any objects bound to it
        logger.info(
                "??????????");
    }

    // Remove from LRU Cache
    AuthenticatedUserDetails.removeUserPrincipal();

    // The {} successfully logged out...
    String username = authentication != null ? authentication.getName() : "HARVEST SYSTEM";
    logger.info("The {} successfully logged out...", username);

    // Empty authentication
    SecurityContextHolder.getContext().setAuthentication(null);

    // Redirect to LOGIN
    response.setStatus(HttpServletResponse.SC_OK);
    response.setContentType(HttpServletContentType.PLAN_TEXT);
    response.sendRedirect(request.getContextPath() + "/login");
    response.flushBuffer();
}

From source file:biz.taoconsulting.dominodav.methods.LOCK.java

/**
 * (non-Javadoc)/*from   ww  w  .j a v a 2  s  .co m*/
 * 
 * @see biz.taoconsulting.dominodav.methods.AbstractDAVMethod#action()
 */
protected void action() {
    // uri is the unique identifier on the host includes servlet and
    // repository but not server
    LockInfo li = null;
    int status = HttpServletResponse.SC_OK; // We presume success
    String curURI = (String) this.getHeaderValues().get("uri");
    LockManager lm = this.getLockManager();
    HttpServletRequest req = this.getReq();
    HttpServletResponse res = this.getResp();
    String lockrequestorName = this.getOwnerFromXMLLockRequest(req);

    IDAVResource resource = null;
    Long TimeOutValue = this.getTimeOutValue(req);
    String relockToken = this.getRelockToken(req);

    // Get the resource to lock
    // Populates the resource and set status
    resource = this.getResourceToLock(curURI);
    try {
        curURI = java.net.URLDecoder.decode(curURI, "UTF-8");
    } catch (Exception e) {
    }
    // One can't lock a readonly resource
    if (resource == null || resource.isReadOnly()) {
        status = HttpServletResponse.SC_FORBIDDEN; // Client can't lock this
    } else if (relockToken != null) {
        li = lm.relock(resource, relockToken, TimeOutValue);
        if (li == null) {
            String eString = "Relock failed for " + relockToken + " for " + lockrequestorName;
            LOGGER.debug(eString);
            this.setErrorMessage(eString, 412); // Precondition failed
            status = 412;
        } else {
            LOGGER.debug("successful relock for " + relockToken + ", new Token:" + li.getToken());
            status = HttpServletResponse.SC_OK;
        }
    } else {
        li = lm.lock(resource, lockrequestorName, TimeOutValue);
        if (li == null) {
            String eString = "Lock failed for " + lockrequestorName + " and " + curURI;
            LOGGER.debug(eString); // Locked by someone else
            this.setErrorMessage(eString, 423); // Locked by someone else
            status = 423;
        } else {
            LOGGER.debug("Lock successful:" + curURI + " for " + lockrequestorName);
            status = HttpServletResponse.SC_OK;
        }
    }

    // Status of the request
    this.setHTTPStatus(status);

    if (status < 400) { // 400 and 500 determine failure!
        res.addHeader("Lock-Token", "<" + li.getToken() + ">");
        // Render the XML response
        this.writeLockResponseXML(res, li);
    }
}

From source file:edu.ucla.loni.pipeline.server.Upload.Uploaders.FileUploadServlet.java

/**
 * Handles HTTP POST Request/Response//  ww w  .j av a 2 s  .co m
 * 
 * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse)
 */
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    // set response status
    resp.setStatus(HttpServletResponse.SC_OK);

    // reset response message
    ResponseBuilder respBuilder = new ResponseBuilder();

    // handle file upload
    handleFileUpload(req, respBuilder);

    // get response message
    String message = respBuilder.getRespMessage();

    resp.getWriter().print(message);

    // flush response buffer
    resp.flushBuffer();
}

From source file:com.androgogic.AikauLoginController.java

/**
 * Overrides the default behaviour to return a simple JSON response. 
 * /*from   w w  w  . jav  a 2s  .c o  m*/
 * @param request The {@link HttpServletRequest}
 * @param response The {@link HttpServletResponse}
 * @throws Exception
 */
@Override
protected void onSuccess(HttpServletRequest request, HttpServletResponse response) throws Exception {
    this.beforeSuccess(request, response);
    response.setStatus(HttpServletResponse.SC_OK);
}