Example usage for org.apache.commons.httpclient HttpStatus SC_INTERNAL_SERVER_ERROR

List of usage examples for org.apache.commons.httpclient HttpStatus SC_INTERNAL_SERVER_ERROR

Introduction

In this page you can find the example usage for org.apache.commons.httpclient HttpStatus SC_INTERNAL_SERVER_ERROR.

Prototype

int SC_INTERNAL_SERVER_ERROR

To view the source code for org.apache.commons.httpclient HttpStatus SC_INTERNAL_SERVER_ERROR.

Click Source Link

Document

<tt>500 Server Error</tt> (HTTP/1.0 - RFC 1945)

Usage

From source file:com.thoughtworks.go.server.service.PipelinePauseServiceTest.java

@Test
public void shouldPopulateHttpResult500WhenPipelineUnPauseResultsInAnError() throws Exception {

    setUpValidPipelineWithAuth();/*from w  w w .j av a2  s .  com*/

    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();

    doThrow(new RuntimeException("Failed to unpause")).when(pipelineDao).unpause(VALID_PIPELINE);

    pipelinePauseService.unpause(VALID_PIPELINE, VALID_USER, result);

    assertThat(result.isSuccessful(), is(false));
    assertThat(result.httpCode(), is(HttpStatus.SC_INTERNAL_SERVER_ERROR));

    verify(pipelineDao).unpause(VALID_PIPELINE);
}

From source file:com.bigdata.rdf.sail.remoting.GraphRepositoryServlet.java

/**
 * Perform an HTTP-POST, which corresponds to the basic CRUD operation
 * "create" according to the generic interaction semantics of HTTP REST.
 * <p>/*from  w ww  .ja v  a2  s  . c om*/
 * BODY contains the new RDF/XML content
 * if ( body == null ) -> noop 
 * RANGE ignored for POST
 */
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    // CREATE
    String body = IOUtils.readString(request.getReader());
    try {
        if (body != null && body.length() > 0) {
            create(body);
        }
        response.setStatus(HttpStatus.SC_OK);
    } catch (Exception ex) {
        ex.printStackTrace();
        response.sendError(HttpStatus.SC_INTERNAL_SERVER_ERROR, ex.getMessage());
    }

}

From source file:com.google.collide.server.fe.WebFE.java

private void doAuthAndWriteHostPage(final HttpServerRequest req, String authCookie) {
    String[] cookieParts = authCookie.split("__");
    if (cookieParts.length != 2) {
        sendRedirect(req, "/static/login.html");
        return;//from   www . j  av  a2  s  .c  o m
    }

    final String sessionId = cookieParts[0];
    String username = cookieParts[1];
    final HttpServerResponse response = req.response;
    vertx.eventBus()
            .send("participants.authorise", new JsonObject().putString("sessionID", sessionId)
                    .putString("username", username).putBoolean("createClient", true),
                    new Handler<Message<JsonObject>>() {
                        @Override
                        public void handle(Message<JsonObject> event) {
                            if ("ok".equals(event.body.getString("status"))) {
                                String activeClientId = event.body.getString("activeClient");
                                String username = event.body.getString("username");
                                if (activeClientId == null || username == null) {
                                    sendStatusCode(req, HttpStatus.SC_INTERNAL_SERVER_ERROR);
                                    return;
                                }

                                String responseText = getHostPage(sessionId, username, activeClientId);
                                response.statusCode = HttpStatus.SC_OK;
                                byte[] page = responseText.getBytes(Charset.forName("UTF-8"));
                                response.putHeader("Content-Length", page.length);
                                response.putHeader("Content-Type", "text/html");
                                response.end(new Buffer(page));
                            } else {
                                sendRedirect(req, "/static/login.html");
                            }
                        }
                    });
}

From source file:domderrien.wrapper.UrlFetch.UrlFetchHttpConnection.java

@Override
public String readLine(String charset) throws IOException, IllegalStateException {
    if (waitForHttpStatus) {
        // Dom Derrien: called only once to get the HTTP status, other information being read from the response output stream
        int responseCode = getResponse().getResponseCode();
        String line = "HTTP/1.1 " + responseCode;
        switch (responseCode) {
        case HttpStatus.SC_OK:
            line += " OK";
            break;
        case HttpStatus.SC_BAD_REQUEST:
            line += " BAD REQUEST";
            break;
        case HttpStatus.SC_UNAUTHORIZED:
            line += " UNAUTHORIZED";
            break;
        case HttpStatus.SC_FORBIDDEN:
            line += " FORBIDDEN";
            break;
        case HttpStatus.SC_NOT_FOUND:
            line += " NOT FOUND";
            break;
        case HttpStatus.SC_INTERNAL_SERVER_ERROR:
            line += " INTERNAL SERVER ERROR";
            break;
        case HttpStatus.SC_SERVICE_UNAVAILABLE:
            line += " SERVICE UNAVAILABLE";
            break;
        default:/*from   w ww  . j a  va2  s.c  om*/
            line = "HTTP/1.1 " + HttpStatus.SC_BAD_REQUEST + " BAD REQUEST";
        }
        waitForHttpStatus = false;
        return line;
    }
    throw new RuntimeException("readLine(String)");
}

From source file:ai.grakn.engine.controller.TasksController.java

@POST
@Path("/")
@ApiOperation(value = "Schedule a set of tasks.")
@ApiImplicitParams({//  w  ww . j  a  v a  2  s  .com
        @ApiImplicitParam(name = REST.Request.TASKS_PARAM, value = "JSON Array containing an ordered list of task parameters and comfigurations.", required = true, dataType = "List", paramType = "body") })
private Json createTasks(Request request, Response response) {
    Json requestBodyAsJson = bodyAsJson(request);
    // This covers the previous behaviour. It looks like a quirk of the testing
    // client library we are using. Consider deprecating it.
    if (requestBodyAsJson.has("value")) {
        requestBodyAsJson = requestBodyAsJson.at("value");
    }
    if (!requestBodyAsJson.has(REST.Request.TASKS_PARAM)) {
        LOG.error("Malformed request body: {}", requestBodyAsJson);
        throw GraknServerException.requestMissingBodyParameters(REST.Request.TASKS_PARAM);
    }
    LOG.debug("Received request {}", request);
    List<Json> taskJsonList = requestBodyAsJson.at(REST.Request.TASKS_PARAM).asJsonList();
    Json responseJson = Json.array();
    response.type(ContentType.APPLICATION_JSON.getMimeType());
    // We need to return the list of taskStates in order
    // so the client can relate the state to each element in the request.
    final Timer.Context context = createTasksTimer.time();
    try {
        List<TaskStateWithConfiguration> taskStates = parseTasks(taskJsonList);
        CompletableFuture<List<Json>> completableFuture = saveTasksInQueue(taskStates);
        try {
            return buildResponseForTasks(response, responseJson, completableFuture);
        } catch (TimeoutException | InterruptedException e) {
            LOG.error("Task interrupted", e);
            response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
            return Json.object();
        } catch (Exception e) {
            LOG.error("Exception while processing batch of tasks", e);
            response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
            return Json.object();
        }
    } finally {
        context.stop();
    }
}

From source file:com.bigdata.rdf.sail.remoting.GraphRepositoryServlet.java

/**
 * Perform an HTTP-DELETE, which corresponds to the basic CRUD operation
 * "delete" according to the generic interaction semantics of HTTP REST.
 * <p>/*ww w. j  a v a2 s.com*/
 * BODY ignored for DELETE 
 * RANGE of null clears the entire graph
 * RANGE(triples[<rdf/xml>]) deletes the selection specified by the serialized triples
 * RANGE(query[<query language>[<query string>]]) deletes the selection specified by the query
 */
protected void doDelete(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // DELETE
    String range = request.getHeader("RANGE");

    if (log.isInfoEnabled()) {
        log.info("range header: " + range);
    }

    try {
        if (range == null || range.length() == 0) {
            clear();
        } else if (range.startsWith("triples[")) {
            // chop off the "triples[" at the beginning
            // and the "]" at the end
            final String rdfXml = range.substring(8, range.length() - 1);
            delete(rdfXml);
        } else if (range.startsWith("query[")) {
            // chop off the "query[" at the beginning
            // and the "]" at the end
            range = range.substring(6, range.length() - 1);
            final int i = range.indexOf('[');
            final QueryLanguage ql = QueryLanguage.valueOf(range.substring(0, i));
            if (ql == null) {
                throw new RuntimeException("unrecognized query language: " + range);
            }
            final String query = range.substring(i + 1, range.length() - 1);
            deleteByQuery(query, ql);
        } else {
            response.sendError(HttpStatus.SC_REQUESTED_RANGE_NOT_SATISFIABLE,
                    "unrecognized subgraph selection scheme in range header");
            return;
        }
        response.setStatus(HttpStatus.SC_OK);
    } catch (Exception ex) {
        ex.printStackTrace();
        response.sendError(HttpStatus.SC_INTERNAL_SERVER_ERROR, ex.getMessage());
    }
}

From source file:com.sdm.core.resource.RestResource.java

@Override
public IBaseResponse getStructure() {
    DefaultResponse response = this.validateCache();
    // Cache validation
    if (response != null) {
        return response;
    }/*from w  ww. j  av a2 s.  c  o m*/

    try {
        T instance = getEntityClass().newInstance();
        List<UIProperty> properties = instance.getStructure();
        ListModel<UIProperty> content = new ListModel<UIProperty>(properties);

        response = new DefaultResponse<>(HttpStatus.SC_OK, ResponseType.SUCCESS, content);
        // Cache will hold a year of entity structure
        response.setHeaders(this.buildCache(3600 * 24 * 365));
        return response;
    } catch (InstantiationException | IllegalAccessException e) {
        throw new WebApplicationException(e.getLocalizedMessage(), HttpStatus.SC_INTERNAL_SERVER_ERROR);
    }
}

From source file:ai.grakn.engine.controller.TasksController.java

private Json buildResponseForTasks(Response response, Json responseJson,
        CompletableFuture<List<Json>> completableFuture)
        throws InterruptedException, java.util.concurrent.ExecutionException, TimeoutException {
    List<Json> results = completableFuture.get(MAX_EXECUTION_TIME.getSeconds(), TimeUnit.SECONDS);
    boolean hasFailures = false;
    for (Json resultForTask : results) {
        responseJson.add(resultForTask);
        if (resultForTask.at("code").asInteger() != HttpStatus.SC_OK) {
            LOG.error("Could not add task {}", resultForTask);
            hasFailures = true;//from w w  w .ja v  a  2 s  . c o  m
        }
    }
    if (!hasFailures) {
        response.status(HttpStatus.SC_OK);
    } else if (responseJson.asJsonList().size() > 0) {
        response.status(HttpStatus.SC_ACCEPTED);
    } else {
        response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
    }
    return responseJson;
}

From source file:$.ManagerService.java

/**
     * This will give link to generated agent
     *// w w  w  .jav a2 s  .  co m
     * @param deviceName name of the device which is to be created
     * @param sketchType name of sketch type
     * @return link to generated agent
     */
    @Path("manager/device/{sketch_type}/generate_link")
    @GET
    public Response generateSketchLink(@QueryParam("deviceName") String deviceName,
            @PathParam("sketch_type") String sketchType) {

        try {
            ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), deviceName, sketchType);
            ResponsePayload responsePayload = new ResponsePayload();
            responsePayload.setStatusCode(HttpStatus.SC_OK);
            responsePayload.setMessageFromServer(
                    "Sending Requested sketch by type: " + sketchType + " and id: " + zipFile.getDeviceId() + ".");
            responsePayload.setResponseContent(zipFile.getDeviceId());
            return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
        } catch (IllegalArgumentException ex) {
            return Response.status(HttpStatus.SC_BAD_REQUEST).entity(ex.getMessage()).build();
        } catch (DeviceManagementException ex) {
            log.error("Error occurred while creating device with name " + deviceName + "\n", ex);
            return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(ex.getMessage()).build();
        } catch (AccessTokenException ex) {
            log.error(ex.getMessage(), ex);
            return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(ex.getMessage()).build();
        } catch (DeviceControllerException ex) {
            log.error(ex.getMessage(), ex);
            return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(ex.getMessage()).build();
        }
    }

From source file:com.cerema.cloud2.lib.common.operations.RemoteOperationResult.java

public boolean isServerFail() {
    return (mHttpCode >= HttpStatus.SC_INTERNAL_SERVER_ERROR);
}