Example usage for javax.servlet.http HttpServletResponse SC_GONE

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

Introduction

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

Prototype

int SC_GONE

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

Click Source Link

Document

Status code (410) indicating that the resource is no longer available at the server and no forwarding address is known.

Usage

From source file:aiai.ai.launchpad.server.ServerController.java

@GetMapping("/rest-auth/payload/snippet-checksum/{name}")
public HttpEntity<String> snippetChecksum(HttpServletResponse response,
        @PathVariable("name") String snippetCode) throws IOException {

    SnippetVersion snippetVersion = SnippetVersion.from(snippetCode);
    Snippet snippet = snippetCache.findByNameAndSnippetVersion(snippetVersion.name, snippetVersion.version);
    if (snippet == null) {
        log.warn("Snippet wasn't found for name {}", snippetCode);
        return returnEmptyStringWithStatus(response, HttpServletResponse.SC_GONE);
    }//w w w  .  j  a  va 2s . c  o m
    /*
            File snippetFile;
            AssetFile assetFile = StationResourceUtils.prepareResourceFile(globals.launchpadResourcesDir, Enums.BinaryDataType.SNIPPET, snippetCode);
            if (assetFile==null) {
    log.warn("Snippet wasn't found for name {}", snippetCode);
    return returnEmptyStringWithStatus(response, HttpServletResponse.SC_GONE);
            }
            try {
    binaryDataService.storeToFile(snippetCode, assetFile.file);
            } catch (BinaryDataNotFoundException e) {
    log.error("Error store data to file", e);
    return returnEmptyStringWithStatus(response, HttpServletResponse.SC_GONE);
            }
            
            Checksum checksum = Checksum.fromJson(snippet.getChecksum());
            try (InputStream is = new FileInputStream(assetFile.file)) {
    CheckSumAndSignatureStatus status = checksumWithSignatureService.verifyChecksumAndSignature(
            checksum, snippetCode, is, false
    );
    if (!status.isOk) {
        return returnEmptyStringWithStatus(response, HttpServletResponse.SC_CONFLICT);
    }
            }*/
    final int length = snippet.getChecksum().length();
    log.info("Send checksum for snippet {}, length: {}", snippet.getSnippetCode(), length);

    return new HttpEntity<>(snippet.getChecksum(), getHeader(length));
}

From source file:com.rmn.qa.servlet.AutomationTestRunServlet.java

/**
 * Attempts to register a new run request with the server. Returns a 201 if the request can be fulfilled but AMIs
 * must be started Returns a 202 if the request can be fulfilled Returns a 400 if the required parameters are not
 * passed in. Returns a 409 if the server is at full node capacity
 *//*from w w w.j  a  v  a  2 s.  c  o  m*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html");
    response.setCharacterEncoding("UTF-8");

    String browserRequested = request.getParameter("browser");
    String browserVersion = request.getParameter("browserVersion");
    String osRequested = request.getParameter("os");
    String threadCount = request.getParameter("threadCount");
    String uuid = request.getParameter(AutomationConstants.UUID);
    BrowserPlatformPair browserPlatformPairRequest;
    Platform requestedPlatform;

    // Return a 400 if any of the required parameters are not passed in
    // Check for uuid first as this is the most important variable
    if (uuid == null) {
        String msg = "Parameter 'uuid' must be passed in as a query string parameter";
        log.error(msg);
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, msg);
        return;
    }
    if (browserRequested == null) {
        String msg = "Parameter 'browser' must be passed in as a query string parameter";
        log.error(msg);
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, msg);
        return;
    }
    if (threadCount == null) {
        String msg = "Parameter 'threadCount' must be passed in as a query string parameter";
        log.error(msg);
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, msg);
        return;
    }
    if (StringUtils.isEmpty(osRequested)) {
        requestedPlatform = Platform.ANY;
    } else {
        requestedPlatform = AutomationUtils.getPlatformFromObject(osRequested);
        if (requestedPlatform == null) {
            String msg = "Parameter 'os' does not have a valid Selenium Platform equivalent: " + osRequested;
            log.error(msg);
            response.sendError(HttpServletResponse.SC_BAD_REQUEST, msg);
            return;
        }
    }

    Integer threadCountRequested = Integer.valueOf(threadCount);

    AutomationRunRequest runRequest = new AutomationRunRequest(uuid, threadCountRequested, browserRequested,
            browserVersion, requestedPlatform);
    browserPlatformPairRequest = new BrowserPlatformPair(browserRequested, requestedPlatform);

    log.info(String.format("Server request [%s] received.", runRequest));
    boolean amisNeeded;
    int amiThreadsToStart = 0;
    int currentlyAvailableNodes;
    // Synchronize this block until we've added the run to our context for other potential threads to see
    synchronized (AutomationTestRunServlet.class) {
        int remainingNodesAvailable = AutomationContext.getContext().getTotalThreadsAvailable(getProxySet());
        // If the number of nodes this grid hub can actually run is less than the number requested, this hub can not
        // fulfill this run at this time
        if (remainingNodesAvailable < runRequest.getThreadCount()) {
            log.error(String.format(
                    "Requested node count of [%d] could not be fulfilled due to hub limit. [%d] nodes available - Request UUID [%s]",
                    threadCountRequested, remainingNodesAvailable, uuid));
            response.sendError(HttpServletResponse.SC_CONFLICT,
                    "Server cannot fulfill request due to configured node limit being reached.");
            return;
        }
        // Get the number of matching, free nodes to determine if we need to start up AMIs or not
        currentlyAvailableNodes = requestMatcher.getNumFreeThreadsForParameters(getProxySet(), runRequest);
        // If the number of available nodes is less than the total number requested, we will have to spin up AMIs in
        // order to fulfill the request
        amisNeeded = currentlyAvailableNodes < threadCountRequested;
        if (amisNeeded) {
            // Get the difference which will be the number of additional nodes we need to spin up to supplement
            // existing nodes
            amiThreadsToStart = threadCountRequested - currentlyAvailableNodes;
        }
        // If the browser requested is not supported by AMIs, we need to not unnecessarily spin up AMIs
        if (amisNeeded && !AutomationUtils.browserAndPlatformSupported(browserPlatformPairRequest)) {
            response.sendError(HttpServletResponse.SC_GONE,
                    "Request cannot be fulfilled and browser and platform is not supported by AMIs");
            return;
        }
        // Add the run to our context so we can track it
        AutomationRunRequest newRunRequest = new AutomationRunRequest(uuid, threadCountRequested,
                browserRequested, browserVersion, requestedPlatform);
        boolean addSuccessful = AutomationContext.getContext().addRun(newRunRequest);
        if (!addSuccessful) {
            log.warn(String.format("Test run already exists for the same UUID [%s]", uuid));
            //                response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Test run already exists with the same UUID.");
            response.setStatus(HttpServletResponse.SC_CREATED);
            return;
        }
    }
    if (amisNeeded) {
        // Start up AMIs as that will be required
        log.warn(String.format(
                "Insufficient nodes to fulfill request. New AMIs will be queued up. Requested [%s] - Available [%s] - Request UUID [%s]",
                threadCountRequested, currentlyAvailableNodes, uuid));
        try {
            AutomationTestRunServlet.startNodes(ec2, uuid, amiThreadsToStart, browserRequested,
                    requestedPlatform);
        } catch (NodesCouldNotBeStartedException e) {
            // Make sure and de-register the run if the AMI startup was not successful
            AutomationContext.getContext().deleteRun(uuid);
            String throwableMessage = e.getCause() != null ? e.getCause().getMessage() : e.getMessage();
            String msg = "Nodes could not be started: " + throwableMessage;
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg);
            return;
        }
        // Return a 201 to let the caller know AMIs will be started
        response.setStatus(HttpServletResponse.SC_CREATED);
        return;
    } else {
        // Otherwise just return a 202 letting the caller know the requested resources are available
        response.setStatus(HttpServletResponse.SC_ACCEPTED);
        return;
    }
}

From source file:net.oneandone.jasmin.main.Servlet.java

private void gone(HttpServletRequest request, HttpServletResponse response) throws IOException {
    LOG.warn("gone: " + request.getPathInfo());
    response.sendError(HttpServletResponse.SC_GONE);
}

From source file:org.apache.hadoop.hdfs.server.namenode.ImageServlet.java

@Override
protected void doPut(final HttpServletRequest request, final HttpServletResponse response)
        throws ServletException, IOException {
    try {/*from   ww w .  j av  a 2  s .  c  o m*/
        ServletContext context = getServletContext();
        final FSImage nnImage = NameNodeHttpServer.getFsImageFromContext(context);
        final Configuration conf = (Configuration) getServletContext().getAttribute(JspHelper.CURRENT_CONF);
        final PutImageParams parsedParams = new PutImageParams(request, response, conf);
        final NameNodeMetrics metrics = NameNode.getNameNodeMetrics();

        validateRequest(context, conf, request, response, nnImage, parsedParams.getStorageInfoString());

        UserGroupInformation.getCurrentUser().doAs(new PrivilegedExceptionAction<Void>() {

            @Override
            public Void run() throws Exception {

                final long txid = parsedParams.getTxId();

                final NameNodeFile nnf = parsedParams.getNameNodeFile();

                if (!nnImage.addToCheckpointing(txid)) {
                    response.sendError(HttpServletResponse.SC_CONFLICT,
                            "Either current namenode is checkpointing or another"
                                    + " checkpointer is already in the process of "
                                    + "uploading a checkpoint made at transaction ID " + txid);
                    return null;
                }
                try {
                    if (nnImage.getStorage().findImageFile(nnf, txid) != null) {
                        response.sendError(HttpServletResponse.SC_CONFLICT,
                                "Either current namenode has checkpointed or "
                                        + "another checkpointer already uploaded an " + "checkpoint for txid "
                                        + txid);
                        return null;
                    }

                    InputStream stream = request.getInputStream();
                    try {
                        long start = monotonicNow();
                        MD5Hash downloadImageDigest = TransferFsImage.handleUploadImageRequest(request, txid,
                                nnImage.getStorage(), stream, parsedParams.getFileSize(), getThrottler(conf));
                        nnImage.saveDigestAndRenameCheckpointImage(nnf, txid, downloadImageDigest);
                        // Metrics non-null only when used inside name node
                        if (metrics != null) {
                            long elapsed = monotonicNow() - start;
                            metrics.addPutImage(elapsed);
                        }
                        // Now that we have a new checkpoint, we might be able to
                        // remove some old ones.
                        nnImage.purgeOldStorage(nnf);
                    } finally {
                        stream.close();
                    }
                } finally {
                    nnImage.removeFromCheckpointing(txid);
                }
                return null;
            }

        });
    } catch (Throwable t) {
        String errMsg = "PutImage failed. " + StringUtils.stringifyException(t);
        response.sendError(HttpServletResponse.SC_GONE, errMsg);
        throw new IOException(errMsg);
    }
}