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:org.jboss.additional.testsuite.jdkall.present.clustering.cluster.web.ClusteredWebSimpleTestCase.java

@Test
@OperateOnDeployment(DEPLOYMENT_1)/* w  ww. j  a  v  a  2 s .c om*/
public void testSerialized(@ArquillianResource(SimpleServlet.class) URL baseURL)
        throws IOException, URISyntaxException {

    // returns the URL of the deployment (http://127.0.0.1:8180/distributable)
    URI uri = SimpleServlet.createURI(baseURL);

    try (CloseableHttpClient client = TestHttpClientUtils.promiscuousCookieHttpClient()) {
        HttpResponse response = client.execute(new HttpGet(uri));
        try {
            Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
            Assert.assertEquals(1, Integer.parseInt(response.getFirstHeader("value").getValue()));
            Assert.assertFalse(Boolean.valueOf(response.getFirstHeader("serialized").getValue()));
        } finally {
            HttpClientUtils.closeQuietly(response);
        }

        response = client.execute(new HttpGet(uri));
        try {
            Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
            Assert.assertEquals(2, Integer.parseInt(response.getFirstHeader("value").getValue()));
            // This won't be true unless we have somewhere to which to replicate
            Assert.assertTrue(Boolean.valueOf(response.getFirstHeader("serialized").getValue()));
        } finally {
            HttpClientUtils.closeQuietly(response);
        }
    }

}

From source file:hr.diskobolos.controller.MembershipCategoryController.java

/**
 * REST service responsible for deletion of the membership category data
 *
 * @param membershipCategory//ww w.  ja v a 2 s  .  c  o  m
 * @param request
 * @param response
 * @return
 * @throws JSONException
 */
@RequestMapping(value = "/delete", method = RequestMethod.POST)
@ResponseBody
@PreAuthorize("hasAnyRole('ROLE_USER','ROLE_ADMIN')")
public String deleteSportData(@RequestBody MembershipCategory membershipCategory, HttpServletRequest request,
        HttpServletResponse response) throws JSONException {
    try {
        membershipCategoryService.delete(membershipCategory);
        response.setStatus(HttpServletResponse.SC_OK);
        return new JSONObject().put("result", 200).toString();
    } catch (Exception e) {
        return ErrorHandlerUtils.handleAjaxError(request, response);
    }
}

From source file:com.alfaariss.oa.ManagerServlet.java

/**
 * Handles requests send by the system manager.
 * //from  ww w.  jav  a2  s  . c om
 * The following requests are supported at this moment:
 * <ul>
 * <li>do=restart</li>
 * <li>do=stop</li>
 * <li>do=start</li>
 * </ul>
 * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 */
@Override
public void service(HttpServletRequest oRequest, HttpServletResponse oResponse)
        throws ServletException, IOException {
    try {
        Properties pConfig = cloneConfigurationFromRequest(oRequest);
        String sDo = oRequest.getParameter("do");
        if (sDo == null) //No 'do' paramater
        {
            String sGet = oRequest.getParameter("get");
            if (sGet == null) //No 'get' and no 'do' paramater
            {
                _logger.error("Invalid request sent from IP: " + oRequest.getRemoteAddr());
                oResponse.sendError(HttpServletResponse.SC_BAD_REQUEST);
            } else {
                StringBuffer sbWarning = new StringBuffer("Invalid request with name: ");
                sbWarning.append(sGet);
                sbWarning.append(", sent from IP: ");
                sbWarning.append(oRequest.getRemoteAddr());
                _logger.error(sbWarning.toString());
                oResponse.sendError(HttpServletResponse.SC_BAD_REQUEST);
            }

        } else if (sDo.equals("restart")) {
            _logger.info("Performing restart request sent from IP: " + oRequest.getRemoteAddr());
            _oEngineLauncher.restart(pConfig);
        } else if (sDo.equals("stop")) {
            _logger.info("Performing stop request sent from IP: " + oRequest.getRemoteAddr());
            _oEngineLauncher.stop();
        } else if (sDo.equals("start")) {
            _logger.info("Performing start request sent from IP: " + oRequest.getRemoteAddr());
            _oEngineLauncher.start(pConfig);
        } else {
            StringBuffer sbWarning = new StringBuffer("Invalid request with name: ");
            sbWarning.append(sDo);
            sbWarning.append(", sent from IP: ");
            sbWarning.append(oRequest.getRemoteAddr());
            _logger.error(sbWarning.toString());
            oResponse.sendError(HttpServletResponse.SC_BAD_REQUEST);
        }

        if (!oResponse.isCommitted())
            oResponse.sendError(HttpServletResponse.SC_OK);
    } catch (OAException e) {
        _logger.error("Error processing request", e);

        _logger.debug("try stopping the server");
        _oEngineLauncher.stop();

        if (!oResponse.isCommitted())
            oResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    } catch (Exception e) {
        _logger.fatal("Internal error", e);

        _logger.debug("try stopping the server");
        _oEngineLauncher.stop();

        if (!oResponse.isCommitted())
            oResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
}

From source file:edu.indiana.d2i.htrc.oauth2.userinfo.OAuth2UserInfoEndpoint.java

@POST
@Path("/")
@Consumes("application/x-www-form-urlencoded")
@Produces("application/json")
public Response getUserInformation(@Context HttpServletRequest request, MultivaluedMap<String, String> paramMap)
        throws OAuthSystemException {

    HttpServletRequestWrapper httpRequest = new OAuthUserInfoRequestWrapper(request, paramMap);

    if (log.isDebugEnabled()) {
        logUserInfoRequest(httpRequest);
    }/*from w ww. j  av  a 2 s .  c o m*/

    boolean basicAuthUsed = false;
    if (request.getHeader(OAuthConstants.HTTP_REQ_HEADER_AUTHZ) != null) {
        try {
            String[] clientCredentials = OAuthUIUtil
                    .extractCredentialsFromAuthzHeader(request.getHeader(OAuthConstants.HTTP_REQ_HEADER_AUTHZ));

            if (paramMap.containsKey(OAuth.OAUTH_CLIENT_ID)
                    && paramMap.containsKey(OAuth.OAUTH_CLIENT_SECRET)) {

                return handleBasicAuthFailure();

            }

            paramMap.add(OAuth.OAUTH_CLIENT_ID, clientCredentials[0]);
            paramMap.add(OAuth.OAUTH_CLIENT_SECRET, clientCredentials[1]);

            basicAuthUsed = true;

            log.debug("HTTP Authorization Header is available which will take precedence "
                    + "over the client credentials available as request parameters.");

        } catch (OAuthClientException e) {
            return handleBasicAuthFailure();
        }
    }

    try {
        OAuthUserInfoRequest oauthRequest = new OAuthUserInfoRequest(httpRequest);
        OAuth2UserInfoClient userInfoClient = new OAuth2UserInfoClient();
        // exchange the user information for the Access token.
        OAuth2UserInfoRespDTO oAuth2UserInfoRespDTO = userInfoClient.getUserInfo(oauthRequest);
        // if there BE has returned an error
        if (oAuth2UserInfoRespDTO.getError()) {
            // if the client has used Basic Auth and if there is an auth failure, HTTP 401 Status
            // Code should be sent back to the client.
            if (basicAuthUsed && OAuth2ErrorCodes.INVALID_CLIENT.equals(oAuth2UserInfoRespDTO.getErrorCode())) {
                return handleBasicAuthFailure();
            }
            // Otherwise send back HTTP 400 Status Code
            OAuthResponse response = OAuthResponse.errorResponse(HttpServletResponse.SC_BAD_REQUEST)
                    .setError(oAuth2UserInfoRespDTO.getErrorCode())
                    .setErrorDescription(oAuth2UserInfoRespDTO.getErrorMsg()).buildJSONMessage();
            return Response.status(response.getResponseStatus()).entity(response.getBody()).build();
        } else {
            OAuthResponse response = OAuthUserInfoResponse.userInfoResponse(HttpServletResponse.SC_OK)
                    .setAuthroizedUser(oAuth2UserInfoRespDTO.getAuthorizedUser())
                    .setUserFullName(oAuth2UserInfoRespDTO.getUserFullName())
                    .setUserEmail(oAuth2UserInfoRespDTO.getUserEmail()).buildJSONMessage();

            Response.ResponseBuilder respBuilder = Response.status(response.getResponseStatus())
                    .header(OAuthConstants.HTTP_RESP_HEADER_CACHE_CONTROL,
                            OAuthConstants.HTTP_RESP_HEADER_VAL_CACHE_CONTROL_NO_STORE)
                    .header(OAuthConstants.HTTP_RESP_HEADER_PRAGMA,
                            OAuthConstants.HTTP_RESP_HEADER_VAL_PRAGMA_NO_CACHE);

            return respBuilder.entity(response.getBody()).build();
        }

    } catch (OAuthClientException e) {
        return handleOAuthClientException();
    } catch (OAuthProblemException e) {
        return handleOAuthProblemException();
    }
}

From source file:com.kysoft.cpsi.audit.controller.SelfCheckAjaxUploadController.java

/**
 * @param request//from   www .ja va 2  s.c o  m
 * @param files
 * @return
 */
@RequestMapping(value = "selfCheckUpload", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> ajaxUpload(HttpServletRequest request, HttpServletResponse response, String owner,
        String col, String ownerKey, String hcrwId, String hcclName, String hcsxmc, Integer nd) {

    Map<String, Object> result = new HashedMap();

    InputStream is = null;

    String filename = request.getHeader("X-File-Name");
    try {
        is = request.getInputStream();
        String mongoId = null;

        Map<String, Object> params = new HashedMap();
        params.put("dxnType", 2);
        Map<String, Object> dxnHccl2 = selfCheckService.getDXNHccl(params);
        params.put("dxnType", 1);
        Map<String, Object> dxnHccl1 = selfCheckService.getDXNHccl(params);
        if (hcclName.equals(dxnHccl2.get("NAME").toString())
                && hcsxmc.equals(dxnHccl2.get("HCSXMC").toString())) {
            //?
            ByteArrayOutputStream baos = new ByteArrayOutputStream();

            byte[] buffer = new byte[1024];
            int len;
            while ((len = is.read(buffer)) > -1) {
                baos.write(buffer, 0, len);
            }
            baos.flush();
            // ?
            InputStream is1 = new ByteArrayInputStream(baos.toByteArray());
            InputStream is2 = new ByteArrayInputStream(baos.toByteArray());
            //?
            selfCheckService.uploadSelfCheckData(is2, hcrwId, filename, nd);

            //?MONGODB
            mongoId = FileUploadUtils.mongoUpload(is1, filename, owner, ownerKey);
        } else if (hcclName.equals(dxnHccl1.get("NAME").toString())
                && hcsxmc.equals(dxnHccl1.get("HCSXMC").toString())) {
            //???
            ByteArrayOutputStream baos = new ByteArrayOutputStream();

            byte[] buffer = new byte[1024];
            int len;
            while ((len = is.read(buffer)) > -1) {
                baos.write(buffer, 0, len);
            }
            baos.flush();

            // ?
            InputStream is1 = new ByteArrayInputStream(baos.toByteArray());
            InputStream is2 = new ByteArrayInputStream(baos.toByteArray());

            //?
            if (filename.endsWith("xls") || filename.endsWith("xlsx")) {
                selfCheckService.judgeRepeatExcle(is2, 5, 2, filename);
            }

            //?MONGODB
            mongoId = FileUploadUtils.mongoUpload(is1, filename, owner, ownerKey);
        } else {
            mongoId = FileUploadUtils.mongoUpload(is, filename, owner, ownerKey);
        }

        FileUploadUtils.updateOwner(owner, col, ownerKey, mongoId);

        response.setStatus(HttpServletResponse.SC_OK);
        result.put("status", 1);
        result.put("mongoId", mongoId);
        result.put("message", "??");

    } catch (Exception ex) {
        response.setStatus(HttpServletResponse.SC_OK);
        ex.printStackTrace();
        result.put("status", -1);
        result.put("mongoId", "");
        result.put("message", "??" + ex.getMessage());
        MongoLogger.warn("??", ExceptionUtils.getStackTrace(ex), hcrwId);
    } finally {
        try {
            is.close();
        } catch (IOException ignored) {
        }
    }
    return result;
}

From source file:org.jboss.as.test.clustering.cluster.singleton.SingletonPolicyServiceTestCase.java

@Test
public void testSingletonService(
        @ArquillianResource(NodeServiceServlet.class) @OperateOnDeployment(DEPLOYMENT_1) URL baseURL1,
        @ArquillianResource(NodeServiceServlet.class) @OperateOnDeployment(DEPLOYMENT_2) URL baseURL2)
        throws IOException, URISyntaxException {

    // Needed to be able to inject ArquillianResource
    stop(CONTAINER_2);/* w ww  .j  a v a2 s  .  c om*/

    try (CloseableHttpClient client = TestHttpClientUtils.promiscuousCookieHttpClient()) {
        HttpResponse response = client.execute(new HttpGet(
                NodeServiceServlet.createURI(baseURL1, NodeServicePolicyActivator.SERVICE_NAME, NODE_1)));
        try {
            Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
            Assert.assertTrue(response.containsHeader(NodeServiceServlet.NODE_HEADER));
            Assert.assertEquals(NODE_1, response.getFirstHeader(NodeServiceServlet.NODE_HEADER).getValue());
        } finally {
            HttpClientUtils.closeQuietly(response);
        }

        start(CONTAINER_2);

        response = client.execute(new HttpGet(
                NodeServiceServlet.createURI(baseURL1, NodeServicePolicyActivator.SERVICE_NAME, NODE_1)));
        try {
            Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
            Assert.assertTrue(response.containsHeader(NodeServiceServlet.NODE_HEADER));
            Assert.assertEquals(NODE_1, response.getFirstHeader(NodeServiceServlet.NODE_HEADER).getValue());
        } finally {
            HttpClientUtils.closeQuietly(response);
        }

        response = client.execute(new HttpGet(
                NodeServiceServlet.createURI(baseURL2, NodeServicePolicyActivator.SERVICE_NAME, NODE_1)));
        try {
            Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
            Assert.assertTrue(response.containsHeader(NodeServiceServlet.NODE_HEADER));
            Assert.assertEquals(NODE_1, response.getFirstHeader(NodeServiceServlet.NODE_HEADER).getValue());
        } finally {
            HttpClientUtils.closeQuietly(response);
        }

        stop(CONTAINER_2);

        response = client.execute(new HttpGet(
                NodeServiceServlet.createURI(baseURL1, NodeServicePolicyActivator.SERVICE_NAME, NODE_1)));
        try {
            Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
            Assert.assertTrue(response.containsHeader(NodeServiceServlet.NODE_HEADER));
            Assert.assertEquals(NODE_1, response.getFirstHeader(NodeServiceServlet.NODE_HEADER).getValue());
        } finally {
            HttpClientUtils.closeQuietly(response);
        }

        start(CONTAINER_2);

        response = client.execute(new HttpGet(
                NodeServiceServlet.createURI(baseURL1, NodeServicePolicyActivator.SERVICE_NAME, NODE_1)));
        try {
            Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
            Assert.assertTrue(response.containsHeader(NodeServiceServlet.NODE_HEADER));
            Assert.assertEquals(NODE_1, response.getFirstHeader(NodeServiceServlet.NODE_HEADER).getValue());
        } finally {
            HttpClientUtils.closeQuietly(response);
        }

        response = client.execute(new HttpGet(
                NodeServiceServlet.createURI(baseURL2, NodeServicePolicyActivator.SERVICE_NAME, NODE_1)));
        try {
            Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
            Assert.assertTrue(response.containsHeader(NodeServiceServlet.NODE_HEADER));
            Assert.assertEquals(NODE_1, response.getFirstHeader(NodeServiceServlet.NODE_HEADER).getValue());
        } finally {
            HttpClientUtils.closeQuietly(response);
        }

        stop(CONTAINER_1);

        response = client.execute(new HttpGet(
                NodeServiceServlet.createURI(baseURL2, NodeServicePolicyActivator.SERVICE_NAME, NODE_2)));
        try {
            Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
            Assert.assertTrue(response.containsHeader(NodeServiceServlet.NODE_HEADER));
            Assert.assertEquals(NODE_2, response.getFirstHeader(NodeServiceServlet.NODE_HEADER).getValue());
        } finally {
            HttpClientUtils.closeQuietly(response);
        }

        start(CONTAINER_1);

        response = client.execute(new HttpGet(
                NodeServiceServlet.createURI(baseURL1, NodeServicePolicyActivator.SERVICE_NAME, NODE_2)));
        try {
            Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
            Assert.assertTrue(response.containsHeader(NodeServiceServlet.NODE_HEADER));
            Assert.assertEquals(NODE_2, response.getFirstHeader(NodeServiceServlet.NODE_HEADER).getValue());
        } finally {
            HttpClientUtils.closeQuietly(response);
        }

        response = client.execute(new HttpGet(
                NodeServiceServlet.createURI(baseURL2, NodeServicePolicyActivator.SERVICE_NAME, NODE_2)));
        try {
            Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
            Assert.assertTrue(response.containsHeader(NodeServiceServlet.NODE_HEADER));
            Assert.assertEquals(NODE_2, response.getFirstHeader(NodeServiceServlet.NODE_HEADER).getValue());
        } finally {
            HttpClientUtils.closeQuietly(response);
        }
    }
}

From source file:au.edu.uq.cmm.benny.Benny.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String user = req.getParameter("user");
    String password = req.getParameter("password");
    if (user == null && password == null) {
        String[] credentials = getBasicAuthCredentials(req);
        if (credentials == null) {
            resp.setHeader("WWW-Authenticate", "Basic realm=\"" + realm + "\"");
            respond(resp, HttpServletResponse.SC_UNAUTHORIZED, "No credentials provided");
            return;
        }//w w  w .j  a  v a 2  s.c o m
        user = credentials[0];
        password = credentials[1];
    }
    try {
        LOG.debug("checking user='" + user + "', password='XXXXXX'");
        boolean ok = authenticator.authenticate(user, password, null) != null;
        if (ok) {
            respond(resp, HttpServletResponse.SC_OK, "Credentials accepted");
        } else {
            respond(resp, HttpServletResponse.SC_FORBIDDEN, "Credentials rejected");
        }
    } catch (IOException ex) {
        throw ex;
    } catch (Exception ex) {
        LOG.error("Unexpected exception", ex);
        respond(resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Service error");
    }
}

From source file:com.liferay.arquillian.DeployerServlet.java

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

    try {/*from w ww .  ja  v a 2s .  c  o  m*/
        InputStream bundleInputStream = getUploadedBundleInputStream(request);

        BundleContext bundleContext = _bundle.getBundleContext();

        Bundle newBundle = bundleContext.installBundle(_deployerServletInstallLocation, bundleInputStream);

        newBundle.start();

        Filter bundleContextFilter = bundleContext
                .createFilter("(&(objectClass=com.liferay.httpservice.internal.servlet."
                        + "BundleServletContext)(bundle.id=" + newBundle.getBundleId() + "))");

        ServiceTracker servletContextServiceTracker = new ServiceTracker(bundleContext, bundleContextFilter,
                null);

        servletContextServiceTracker.open();

        ServletContext servletContext = (ServletContext) servletContextServiceTracker
                .waitForService(_installTimeout);

        Servlet arquillianServletRunner = waitForServlet(servletContext, "ArquillianServletRunner",
                _installTimeout);

        if (arquillianServletRunner == null) {
            throw new TimeoutException(
                    "The arquillian servlet runner is taking more than " + _installTimeout + " to deploy");
        }

        response.setStatus(HttpServletResponse.SC_OK);
        response.setContentType(TEXT);
        response.setHeader(_contextPathHeader, servletContext.getContextPath());
    } catch (Exception e) {
        signalError(e, response);
    } finally {
        ServletOutputStream outputStream = response.getOutputStream();

        outputStream.flush();
    }
}

From source file:org.jboss.as.test.clustering.cluster.web.shared.SharedSessionFailoverTestCase.java

@Test
public void test(@ArquillianResource(SimpleServlet.class) @OperateOnDeployment(DEPLOYMENT_1) URL baseURL1,
        @ArquillianResource(SimpleServlet.class) @OperateOnDeployment(DEPLOYMENT_2) URL baseURL2)
        throws URISyntaxException, IOException {

    URI uri11 = SimpleServlet.createURI(baseURL1.toURI().resolve(MODULE_1).toURL());
    URI uri12 = SimpleServlet.createURI(baseURL1.toURI().resolve(MODULE_2).toURL());
    URI uri21 = SimpleServlet.createURI(baseURL2.toURI().resolve(MODULE_1).toURL());
    URI uri22 = SimpleServlet.createURI(baseURL2.toURI().resolve(MODULE_2).toURL());

    try (CloseableHttpClient client = TestHttpClientUtils.promiscuousCookieHttpClient()) {
        HttpResponse response = client.execute(new HttpGet(uri11));
        try {/*w  w w .  j  av  a2  s .  c o  m*/
            Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
            Assert.assertEquals(1,
                    Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue()));
        } finally {
            HttpClientUtils.closeQuietly(response);
        }

        response = client.execute(new HttpGet(uri12));
        try {
            Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
            Assert.assertEquals(2,
                    Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue()));
        } finally {
            HttpClientUtils.closeQuietly(response);
        }

        response = client.execute(new HttpGet(uri21));
        try {
            Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
            Assert.assertEquals(3,
                    Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue()));
        } finally {
            HttpClientUtils.closeQuietly(response);
        }

        response = client.execute(new HttpGet(uri22));
        try {
            Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
            Assert.assertEquals(4,
                    Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue()));
        } finally {
            HttpClientUtils.closeQuietly(response);
        }
    }
}

From source file:com.sketchy.server.UpgradeUploadServlet.java

protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    JSONServletResult jsonServletResult = new JSONServletResult(Status.SUCCESS);
    try {/*from   w w  w.  j a  v  a  2s  .  co  m*/

        boolean isMultipart = ServletFileUpload.isMultipartContent(request);
        if (isMultipart) {

            DiskFileItemFactory factory = new DiskFileItemFactory();
            factory.setRepository(FileUtils.getTempDirectory());
            factory.setSizeThreshold(MAX_SIZE);

            ServletFileUpload servletFileUpload = new ServletFileUpload(factory);
            List<FileItem> files = servletFileUpload.parseRequest(request);
            String version = "";
            for (FileItem fileItem : files) {
                String uploadFileName = fileItem.getName();
                if (StringUtils.isNotBlank(uploadFileName)) {

                    JarInputStream jarInputStream = null;
                    try {
                        // check to make sure it's a Sketchy File with a Manifest File
                        jarInputStream = new JarInputStream(fileItem.getInputStream(), true);
                        Manifest manifest = jarInputStream.getManifest();
                        if (manifest == null) {
                            throw new Exception("Invalid Upgrade File!");
                        }
                        Attributes titleAttributes = manifest.getMainAttributes();
                        if ((titleAttributes == null) || (!StringUtils.containsIgnoreCase(
                                titleAttributes.getValue("Implementation-Title"), "Sketchy"))) {
                            throw new Exception("Invalid Upgrade File!");
                        }
                        version = titleAttributes.getValue("Implementation-Version");
                    } catch (Exception e) {
                        throw new Exception("Invalid Upgrade File!");
                    } finally {
                        IOUtils.closeQuietly(jarInputStream);
                    }
                    // save new .jar file as "ready"
                    fileItem.write(new File("Sketchy.jar.ready"));
                    jsonServletResult.put("version", version);
                }
            }
        }
    } catch (Exception e) {
        jsonServletResult = new JSONServletResult(Status.ERROR, e.getMessage());
    }
    response.setContentType("text/html");
    response.setStatus(HttpServletResponse.SC_OK);
    response.getWriter().print(jsonServletResult.toJSONString());
}