Example usage for java.net HttpURLConnection HTTP_INTERNAL_ERROR

List of usage examples for java.net HttpURLConnection HTTP_INTERNAL_ERROR

Introduction

In this page you can find the example usage for java.net HttpURLConnection HTTP_INTERNAL_ERROR.

Prototype

int HTTP_INTERNAL_ERROR

To view the source code for java.net HttpURLConnection HTTP_INTERNAL_ERROR.

Click Source Link

Document

HTTP Status-Code 500: Internal Server Error.

Usage

From source file:com.netflix.genie.server.resources.CommandConfigResource.java

/**
 * Remove the application from a given command.
 *
 * @param id The id of the command to delete the application from. Not
 *           null/empty/blank.//from   w  w w .j  a  v a  2  s.co  m
 * @return The active set of applications for the command.
 * @throws GenieException For any error
 */
@DELETE
@Path("/{id}/application")
@ApiOperation(value = "Remove an application from a command", notes = "Remove the application from the command with given id.", response = Application.class)
@ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Command not found"),
        @ApiResponse(code = HttpURLConnection.HTTP_PRECON_FAILED, message = "Invalid required parameter supplied"),
        @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Genie Server Error due to Unknown Exception") })
public Application removeApplicationForCommand(
        @ApiParam(value = "Id of the command to delete from.", required = true) @PathParam("id") final String id)
        throws GenieException {
    LOG.info("Called with id '" + id + "'.");
    return this.commandConfigService.removeApplicationForCommand(id);
}

From source file:com.netflix.genie.server.resources.ClusterConfigResource.java

/**
 * Get all the tags for a given cluster.
 *
 * @param id The id of the cluster to get the tags for. Not
 *           NULL/empty/blank.//from  w  w  w.  j a  v  a 2s  . c o m
 * @return The active set of tags.
 * @throws GenieException For any error
 */
@GET
@Path("/{id}/tags")
@ApiOperation(value = "Get the tags for a cluster", notes = "Get the tags for the cluster with the supplied id.", response = String.class, responseContainer = "List")
@ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Cluster not found"),
        @ApiResponse(code = HttpURLConnection.HTTP_PRECON_FAILED, message = "Invalid required parameter supplied"),
        @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Genie Server Error due to Unknown Exception") })
public Set<String> getTagsForCluster(
        @ApiParam(value = "Id of the cluster to get tags for.", required = true) @PathParam("id") final String id)
        throws GenieException {
    LOG.info("Called with id " + id);
    return this.clusterConfigService.getTagsForCluster(id);
}

From source file:org.eclipse.orion.server.docker.server.DockerServer.java

private DockerResponse.StatusCode getDockerResponse(DockerResponse dockerResponse,
        HttpURLConnection httpURLConnection) {
    try {//from w w w.j a v  a2  s  .c om
        int responseCode = httpURLConnection.getResponseCode();
        if (responseCode == HttpURLConnection.HTTP_OK) {
            dockerResponse.setStatusCode(DockerResponse.StatusCode.OK);
            return DockerResponse.StatusCode.OK;
        } else if (responseCode == HttpURLConnection.HTTP_CREATED) {
            dockerResponse.setStatusCode(DockerResponse.StatusCode.CREATED);
            return DockerResponse.StatusCode.CREATED;
        } else if (responseCode == HttpURLConnection.HTTP_NO_CONTENT) {
            dockerResponse.setStatusCode(DockerResponse.StatusCode.STARTED);
            return DockerResponse.StatusCode.STARTED;
        } else if (responseCode == HttpURLConnection.HTTP_BAD_REQUEST) {
            dockerResponse.setStatusCode(DockerResponse.StatusCode.BAD_PARAMETER);
            dockerResponse.setStatusMessage(httpURLConnection.getResponseMessage());
            return DockerResponse.StatusCode.BAD_PARAMETER;
        } else if (responseCode == HttpURLConnection.HTTP_NOT_FOUND) {
            dockerResponse.setStatusCode(DockerResponse.StatusCode.NO_SUCH_CONTAINER);
            dockerResponse.setStatusMessage(httpURLConnection.getResponseMessage());
            return DockerResponse.StatusCode.NO_SUCH_CONTAINER;
        } else if (responseCode == HttpURLConnection.HTTP_INTERNAL_ERROR) {
            dockerResponse.setStatusCode(DockerResponse.StatusCode.SERVER_ERROR);
            dockerResponse.setStatusMessage(httpURLConnection.getResponseMessage());
            return DockerResponse.StatusCode.SERVER_ERROR;
        } else {
            throw new RuntimeException("Unknown status code :" + responseCode);
        }
    } catch (IOException e) {
        setDockerResponse(dockerResponse, e);
        if (e instanceof ConnectException && e.getLocalizedMessage().contains("Connection refused")) {
            // connection refused means the docker server is not running.
            dockerResponse.setStatusCode(DockerResponse.StatusCode.CONNECTION_REFUSED);
            return DockerResponse.StatusCode.CONNECTION_REFUSED;
        }
    }
    return DockerResponse.StatusCode.SERVER_ERROR;
}

From source file:com.netflix.genie.server.services.impl.GenieExecutionServiceImpl.java

private <T extends BaseResponse> T executeRequest(Verb method, String restURI, BaseRequest request,
        Class<T> responseClass) throws CloudServiceException {
    HttpResponse clientResponse = null;//  w  w w  . j a v a2  s . c o m
    T response;
    try {
        RestClient genieClient = (RestClient) ClientFactory.getNamedClient("genie");
        HttpRequest req = HttpRequest.newBuilder().verb(method).header("Accept", "application/json")
                .uri(new URI(restURI)).entity(request).build();
        clientResponse = genieClient.execute(req);
        if (clientResponse != null) {
            int status = clientResponse.getStatus();
            logger.info("Response Status:" + status);
            response = clientResponse.getEntity(responseClass);
            return response;
        } else {
            String msg = "Received null response while auto-forwarding request to Genie instance";
            logger.error(msg);
            throw new CloudServiceException(HttpURLConnection.HTTP_INTERNAL_ERROR, msg);
        }
    } catch (CloudServiceException e) {
        // just raise it rightaway
        throw e;
    } catch (Exception e) {
        String msg = "Error while trying to auto-forward request: " + e.getMessage();
        logger.error(msg, e);
        throw new CloudServiceException(HttpURLConnection.HTTP_INTERNAL_ERROR, msg);
    } finally {
        if (clientResponse != null) {
            // this is really really important
            clientResponse.close();
        }
    }
}

From source file:com.netflix.genie.server.resources.ApplicationConfigResource.java

/**
 * Update the tags for a given application.
 *
 * @param id   The id of the application to update the tags for.
 *             Not null/empty/blank./*from w  w w .  j  a v  a 2  s. c  om*/
 * @param tags The tags to replace existing configuration
 *             files with. Not null/empty/blank.
 * @return The new set of application tags.
 * @throws GenieException For any error
 */
@PUT
@Path("/{id}/tags")
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update tags for a application", notes = "Replace the existing tags for application with given id.", response = String.class, responseContainer = "List")
@ApiResponses(value = {
        @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Application not found"),
        @ApiResponse(code = HttpURLConnection.HTTP_PRECON_FAILED, message = "Invalid ID supplied"),
        @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Genie Server Error due to Unknown Exception") })
public Set<String> updateTagsForApplication(
        @ApiParam(value = "Id of the application to update tags for.", required = true) @PathParam("id") final String id,
        @ApiParam(value = "The tags to replace existing with.", required = true) final Set<String> tags)
        throws GenieException {
    LOG.info("Called with id " + id + " and tags " + tags);
    return this.applicationConfigService.updateTagsForApplication(id, tags);
}

From source file:i5.las2peer.services.servicePackage.TemplateService.java

@GET
@Path("/users/{userID}")
@Produces(MediaType.APPLICATION_JSON)//from   ww w. j  a va 2 s  . c  om
public HttpResponse getUserContent(@PathParam("userID") String userID) {
    Connection conn = null;
    PreparedStatement stmnt = null;
    ResultSet rs = null;
    ToJSON converter = new ToJSON();
    JSONArray json = new JSONArray();

    try {
        // get connection from connection pool
        conn = dbm.getConnection();

        // prepare statement
        stmnt = conn.prepareStatement("SELECT id,content,author FROM urch where author = ?;");
        stmnt.setString(1, userID);

        // retrieve result set
        rs = stmnt.executeQuery();

        json = converter.toJSONArray(rs);

        return new HttpResponse(json.toString(), HttpURLConnection.HTTP_OK);

    } catch (Exception e) {

        return new HttpResponse("Internal error: " + e.getMessage(), HttpURLConnection.HTTP_INTERNAL_ERROR);

    } finally {
        // free resources if exception or not
        if (rs != null) {
            try {
                rs.close();
            } catch (Exception e) {
                Context.logError(this, e.getMessage());

                // return HTTP Response on error
                return new HttpResponse("Internal error: " + e.getMessage(),
                        HttpURLConnection.HTTP_INTERNAL_ERROR);
            }
        }
        if (stmnt != null) {
            try {
                stmnt.close();
            } catch (Exception e) {
                Context.logError(this, e.getMessage());

                // return HTTP Response on error
                return new HttpResponse("Internal error: " + e.getMessage(),
                        HttpURLConnection.HTTP_INTERNAL_ERROR);
            }
        }
        if (conn != null) {
            try {
                conn.close();
            } catch (Exception e) {
                Context.logError(this, e.getMessage());

                // return HTTP Response on error
                return new HttpResponse("Internal error: " + e.getMessage(),
                        HttpURLConnection.HTTP_INTERNAL_ERROR);
            }
        }
    }

}

From source file:org.wso2.carbon.registry.app.RegistryAdapter.java

private ResponseContext processImportRequest(RequestContext request, String path) {
    String slug = request.getSlug();

    String suggestedPath = path + getGoodSlug(path, slug, request);

    Resource resource = new ResourceImpl();
    Document<Entry> doc;/*  w w  w .  jav a  2  s. c  o m*/
    try {
        doc = request.getDocument();
    } catch (IOException e) {
        return new StackTraceResponseContext(e);
    }
    org.wso2.carbon.registry.app.Properties properties = doc.getRoot()
            .getExtension(PropertyExtensionFactory.PROPERTIES);
    RemoteRegistry.createPropertiesFromExtensionElement(properties, resource);
    resource.setMediaType(request.getContentType().toString());

    //        The resource can come with a UUID. Hence retrieving it here
    if (doc.getRoot().getSimpleExtension(APPConstants.QN_UUID_TYPE) != null) {
        resource.setUUID(doc.getRoot().getSimpleExtension(APPConstants.QN_UUID_TYPE));
    }

    String location;
    try {
        //            InputStream is = request.getInputStream();
        //            String importURL = readToString(is);
        //            if (importURL.contains("=")) {
        //                importURL = importURL.substring(importURL.indexOf('=') + 1);
        //            }
        //            importURL = importURL.substring(0, importURL.lastIndexOf(';'));
        // removes the "application/resource-import" string from incoming path 
        String importURL = request.getParameter("importURL");
        if (importURL.endsWith(";application/resource-import")) {
            importURL = importURL.substring(0, importURL.length() - ";application/resource-import".length());
        }
        location = getSecureRegistry(request).importResource(suggestedPath, importURL, resource);
    } catch (Exception e) {
        return new StringResponseContext(e, HttpURLConnection.HTTP_INTERNAL_ERROR);
    }
    ResponseContext rc = new EmptyResponseContext(HttpURLConnection.HTTP_OK);
    try {
        rc.setLocation(
                URLDecoder.decode(getAtomURI(location, request), RegistryConstants.DEFAULT_CHARSET_ENCODING)
                        .replaceAll(" ", "+"));
    } catch (UnsupportedEncodingException e) {
        // no action
    }

    return rc;
}

From source file:com.netflix.genie.server.resources.CommandConfigResource.java

/**
 * Get all the clusters this command is associated with.
 *
 * @param id       The id of the command to get the clusters for. Not
 *                 NULL/empty/blank.//ww w  .ja v  a  2s . c om
 * @param statuses The statuses of the clusters to get
 * @return The list of clusters.
 * @throws GenieException For any error
 */
@GET
@Path("/{id}/clusters")
@ApiOperation(value = "Get the clusters this command is associated with", notes = "Get the clusters which this command exists on supports.", response = Cluster.class, responseContainer = "List")
@ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Command not found"),
        @ApiResponse(code = HttpURLConnection.HTTP_PRECON_FAILED, message = "Invalid required parameter supplied"),
        @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Genie Server Error due to Unknown Exception") })
public List<Cluster> getClustersForCommand(
        @ApiParam(value = "Id of the command to get the clusters for.", required = true) @PathParam("id") final String id,
        @ApiParam(value = "Status of the cluster.", allowableValues = "UP, OUT_OF_SERVICE, TERMINATED") @QueryParam("status") final Set<String> statuses)
        throws GenieException {
    LOG.info("Called with id " + id + " and statuses " + statuses);

    Set<ClusterStatus> enumStatuses = null;
    if (!statuses.isEmpty()) {
        enumStatuses = EnumSet.noneOf(ClusterStatus.class);
        for (final String status : statuses) {
            if (StringUtils.isNotBlank(status)) {
                enumStatuses.add(ClusterStatus.parse(status));
            }
        }
    }

    return this.commandConfigService.getClustersForCommand(id, enumStatuses);
}

From source file:com.netflix.genie.server.resources.ClusterConfigResource.java

/**
 * Update the tags for a given cluster./*from  w  w  w .j  a  va  2 s .c  o m*/
 *
 * @param id   The id of the cluster to update the tags for.
 *             Not null/empty/blank.
 * @param tags The tags to replace existing configuration
 *             files with. Not null/empty/blank.
 * @return The new set of cluster tags.
 * @throws GenieException For any error
 */
@PUT
@Path("/{id}/tags")
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update tags for a cluster", notes = "Replace the existing tags for cluster with given id.", response = String.class, responseContainer = "List")
@ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Cluster not found"),
        @ApiResponse(code = HttpURLConnection.HTTP_PRECON_FAILED, message = "Invalid required parameter supplied"),
        @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Genie Server Error due to Unknown Exception") })
public Set<String> updateTagsForCluster(
        @ApiParam(value = "Id of the cluster to update tags for.", required = true) @PathParam("id") final String id,
        @ApiParam(value = "The tags to replace existing with.", required = true) final Set<String> tags)
        throws GenieException {
    LOG.info("Called with id " + id + " and tags " + tags);
    return this.clusterConfigService.updateTagsForCluster(id, tags);
}

From source file:com.netflix.genie.server.resources.ApplicationConfigResource.java

/**
 * Delete the all tags from a given application.
 *
 * @param id The id of the application to delete the tags from.
 *           Not null/empty/blank./*w  w w  .  j  av  a  2 s.co m*/
 * @return Empty set if successful
 * @throws GenieException For any error
 */
@DELETE
@Path("/{id}/tags")
@ApiOperation(value = "Remove all tags from a application", notes = "Remove all the tags from the application with given id.  Note that the genie name space tags"
        + "prefixed with genie.id and genie.name cannot be deleted.", response = String.class, responseContainer = "List")
@ApiResponses(value = {
        @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Application not found"),
        @ApiResponse(code = HttpURLConnection.HTTP_PRECON_FAILED, message = "Invalid ID supplied"),
        @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Genie Server Error due to Unknown Exception") })
public Set<String> removeAllTagsForApplication(
        @ApiParam(value = "Id of the application to delete from.", required = true) @PathParam("id") final String id)
        throws GenieException {
    LOG.info("Called with id " + id);
    return this.applicationConfigService.removeAllTagsForApplication(id);
}