Example usage for org.springframework.http HttpStatus INTERNAL_SERVER_ERROR

List of usage examples for org.springframework.http HttpStatus INTERNAL_SERVER_ERROR

Introduction

In this page you can find the example usage for org.springframework.http HttpStatus INTERNAL_SERVER_ERROR.

Prototype

HttpStatus INTERNAL_SERVER_ERROR

To view the source code for org.springframework.http HttpStatus INTERNAL_SERVER_ERROR.

Click Source Link

Document

500 Internal Server Error .

Usage

From source file:com.sms.server.controller.AdminController.java

@RequestMapping(value = "/user", method = RequestMethod.PUT, headers = { "Content-type=application/json" })
@ResponseBody//from   ww  w .  ja v  a2 s  .  c o m
public ResponseEntity<String> updateDefaultUser(@RequestBody User update) {
    User user = userDao.getUserByUsername("admin");

    if (user == null) {
        return new ResponseEntity<>("Default user does not exist.", HttpStatus.BAD_REQUEST);
    }

    if (update.getPassword() != null) {
        user.setPassword(update.getPassword());
    }

    // Update database
    if (!userDao.updateUser(user, "admin")) {
        LogService.getInstance().addLogEntry(Level.ERROR, CLASS_NAME,
                "Error updating user '" + user.getUsername() + "'.", null);
        return new ResponseEntity<>("Error updating user details.", HttpStatus.INTERNAL_SERVER_ERROR);
    }

    LogService.getInstance().addLogEntry(Level.INFO, CLASS_NAME,
            "User '" + user.getUsername() + "' updated successfully.", null);
    return new ResponseEntity<>("User details updated successfully.", HttpStatus.ACCEPTED);
}

From source file:org.ow2.proactive.procci.rest.ComputeRest.java

@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<ResourceRendering> createCompute(@RequestBody ResourceRendering computeRendering)
        throws InterruptedException, NumberFormatException {
    logger.debug("Creating Compute " + computeRendering.toString());
    try {/*from ww w. ja  v a2s.co m*/
        computeRendering.checkAttributes(Compute.getAttributes(), "Compute", mixinService);

        Resource response = instanceService.create(new ComputeBuilder(mixinService, computeRendering).build(),
                transformerManager.getTransformerProvider(TransformerType.COMPUTE), mixinService);
        return new ResponseEntity<>(response.getRendering(), HttpStatus.CREATED);
    } catch (ClientException e) {
        logger.error(this.getClass().getName(), e);
        return new ResponseEntity(e.getJsonError(), HttpStatus.BAD_REQUEST);
    } catch (ServerException e) {
        logger.error(this.getClass().getName(), e);
        return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR);
    }
}

From source file:de.zib.gndms.GORFX.service.GORFXServiceImpl.java

@RequestMapping(value = "/config/_{actionName:[a-zA-Z._0-9]+}", method = RequestMethod.POST)
@Secured("ROLE_ADMIN")
public ResponseEntity<String> callConfigAction(@PathVariable String actionName, @RequestBody String args,
        @RequestHeader("DN") String dn) {
    GNDMSResponseHeader responseHeaders = new GNDMSResponseHeader(gorfxFacets.findFacet("config").getUrl(),
            null, gorfxBaseUrl, dn, null);
    HttpStatus httpStatus = HttpStatus.INTERNAL_SERVER_ERROR;
    String result = null;/*from w  w  w .  j  ava 2 s.  c o  m*/
    try {
        result = configActionProvider.callConfigAction(actionName, args);
        httpStatus = HttpStatus.OK;
    } catch (Exception e) {
        logger.warn("config action exception on: " + actionName + ": " + args, e);
    }

    return new ResponseEntity<String>(result, responseHeaders, httpStatus);
}

From source file:gateway.test.DataTests.java

/**
 * Test GET /data endpoint//from w w w. ja  v a  2s  .c o  m
 */
@Test
public void testGetData() {
    // When the Gateway asks Access for a List of Data, Mock that
    // response here.
    DataResourceListResponse mockResponse = new DataResourceListResponse();
    mockResponse.data = new ArrayList<DataResource>();
    mockResponse.getData().add(mockData);
    mockResponse.pagination = new Pagination(1, 0, 10, "test", "asc");
    when(restTemplate.getForEntity(anyString(), eq(DataResourceListResponse.class)))
            .thenReturn(new ResponseEntity<DataResourceListResponse>(mockResponse, HttpStatus.OK));

    // Get the data
    ResponseEntity<PiazzaResponse> entity = dataController.getData(null, null, 0, 10, null, "asc", null, user);
    PiazzaResponse response = entity.getBody();

    // Verify the results
    assertTrue(response instanceof DataResourceListResponse);
    DataResourceListResponse dataList = (DataResourceListResponse) response;
    assertTrue(dataList.getData().size() == 1);
    assertTrue(dataList.getPagination().getCount() == 1);
    assertTrue(entity.getStatusCode().equals(HttpStatus.OK));

    // Mock an Exception being thrown and handled.
    when(restTemplate.getForEntity(anyString(), eq(DataResourceListResponse.class)))
            .thenThrow(new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR));

    // Get the data
    entity = dataController.getData(null, null, 0, 10, null, "asc", null, user);
    response = entity.getBody();

    // Verify that a proper exception was thrown.
    assertTrue(response instanceof ErrorResponse);
    assertTrue(entity.getStatusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR));
}

From source file:org.openlmis.fulfillment.web.errorhandler.ServiceErrorHandling.java

@ExceptionHandler(OrderStorageException.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ResponseBody// w ww .  j a  va2 s.co m
public Message.LocalizedMessage handleOrderStorageException(OrderStorageException ex) {
    return logErrorAndRespond("Unable to store the order", ex);
}

From source file:com.esri.geoportal.harvester.rest.ProcessController.java

/**
 * Removes completed processes from the list of processes.
 * @return process info array//from  w  ww .j  a  va 2s .co m
 */
@RequestMapping(value = "/rest/harvester/processes", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<ProcessResponse[]> purge() {
    try {
        LOG.debug(String.format("DELETE /rest/harvester/processes"));
        List<Map.Entry<UUID, ProcessInstance>> completed = engine.getProcessesService().removeCompleted();
        return new ResponseEntity<>(completed.stream()
                .map(e -> new ProcessResponse(e.getKey(), e.getValue().getTask().getTaskDefinition(),
                        e.getValue().getStatus()))
                .collect(Collectors.toList()).toArray(new ProcessResponse[0]), HttpStatus.OK);
    } catch (DataProcessorException ex) {
        LOG.error(String.format("Error purging processes"), ex);
        return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
    }
}

From source file:gateway.controller.JobController.java

/**
 * Returns the Status of a Job.//from  w  w  w.j  a  va 2s.  co  m
 * 
 * @see http://pz-swagger.stage.geointservices.io/#!/Job/get_job_jobId
 * 
 * @param jobId
 *            The Id of the Job.
 * @param user
 *            User information
 * @return Contains Job Status, or an appropriate Error.
 */
@RequestMapping(value = "/job/{jobId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "Get Job Status", notes = "Gets the Status for a Piazza Job by its Id.", tags = "Job")
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "Information regarding the requested Job. At bare minimum, this will contain the Job Id of the Job that has been spawned as a result of the POSTed message. If more information is available, such as Status, it will also be included.", response = JobStatusResponse.class),
        @ApiResponse(code = 401, message = "Unauthorized", response = ErrorResponse.class),
        @ApiResponse(code = 404, message = "Not Found", response = ErrorResponse.class),
        @ApiResponse(code = 500, message = "Internal Error", response = JobErrorResponse.class) })
public ResponseEntity<PiazzaResponse> getJobStatus(
        @ApiParam(value = "Id of the Job to Fetch", required = true) @PathVariable(value = "jobId") String jobId,
        Principal user) {
    try {
        // Log the request
        logger.log(String.format("User %s requested Job Status for %s.", gatewayUtil.getPrincipalName(user),
                jobId), PiazzaLogger.INFO);
        // Proxy the request to the Job Manager
        try {
            return new ResponseEntity<PiazzaResponse>(
                    restTemplate.getForEntity(String.format("%s/%s/%s", JOBMANAGER_URL, "job", jobId),
                            JobStatusResponse.class).getBody(),
                    HttpStatus.OK);
        } catch (HttpClientErrorException | HttpServerErrorException hee) {
            LOGGER.error("Error Requesting Job Status", hee);
            return new ResponseEntity<PiazzaResponse>(
                    gatewayUtil.getErrorResponse(hee.getResponseBodyAsString()), hee.getStatusCode());
        }
    } catch (Exception exception) {
        String error = String.format("Error requesting Job Status for Id %s: %s", jobId,
                exception.getMessage());
        LOGGER.error(error, exception);
        logger.log(error, PiazzaLogger.ERROR);
        return new ResponseEntity<PiazzaResponse>(new JobErrorResponse(jobId, error, "Gateway"),
                HttpStatus.INTERNAL_SERVER_ERROR);
    }
}

From source file:cn.org.once.cstack.config.RestHandlerException.java

@ExceptionHandler(value = { IllegalStateException.class })
protected ResponseEntity<Object> handleIllegalStateException(Exception ex, WebRequest request) {
    ex.printStackTrace();//from   ww  w. j  a v a2  s.com
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    return handleExceptionInternal(ex,
            new HttpErrorServer("An unkown error has occured! Server response : IllegalStateException"),
            headers, HttpStatus.INTERNAL_SERVER_ERROR, request);
}

From source file:org.cloudifysource.rest.controllers.AdminAPIController.java

@ExceptionHandler(Exception.class)
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
public void resolveInternalServerError(Writer writer, Exception e) throws IOException {
    logger.log(Level.WARNING, "caught exception", e);
    writer.write("{\"status\":\"error\", \"error\":\"" + e.getMessage() + "\"}");
}

From source file:com.esri.geoportal.harvester.rest.BrokerController.java

/**
 * Deletes a broker.//from   ww  w  . ja v  a 2 s .c  om
 * @param brokerId broker id
 * @return broker info
 */
@RequestMapping(value = "/rest/harvester/brokers/{brokerId}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<BrokerResponse> deleteBroker(@PathVariable UUID brokerId) {
    try {
        LOG.debug(formatForLog("DELETE /rest/harvester/brokers/%s", brokerId));
        engine.getBrokersService().deleteBroker(brokerId);
        return new ResponseEntity<>(
                BrokerResponse.createFrom(
                        engine.getBrokersService().findBroker(brokerId, LocaleContextHolder.getLocale())),
                HttpStatus.OK);
    } catch (DataProcessorException ex) {
        LOG.error(formatForLog("Error deleting broker: %s", brokerId), ex);
        return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
    }
}