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.haulmont.restapi.controllers.FileUploadController.java

/**
 * Method for multipart file upload. It expects the file contents to be passed in the part called 'file'
 */// www  .j  a v a  2  s .  com
@PostMapping(consumes = "multipart/form-data")
public ResponseEntity<FileInfo> uploadFile(@RequestParam("file") MultipartFile file,
        @RequestParam(required = false) String name, HttpServletRequest request) {
    try {
        if (Strings.isNullOrEmpty(name)) {
            name = file.getOriginalFilename();
        }

        long size = file.getSize();
        FileDescriptor fd = createFileDescriptor(name, size);

        InputStream is = file.getInputStream();
        uploadToMiddleware(is, fd);
        saveFileDescriptor(fd);

        return createFileInfoResponseEntity(request, fd);
    } catch (Exception e) {
        log.error("File upload failed", e);
        throw new RestAPIException("File upload failed", "File upload failed",
                HttpStatus.INTERNAL_SERVER_ERROR);
    }
}

From source file:org.trustedanalytics.servicebroker.h2o.service.H2oProvisionerClientTest.java

@Test
public void deprovisionInstance_provisionerEndsWith500_exceptionThrown() throws Exception {
    // arrange//from   w  w  w .  j a  va 2s.  c om
    expectedException.expect(ServiceBrokerException.class);
    expectedException.expectMessage("Unable to deprovision h2o for: " + INSTANCE_ID);
    when(h2oRestMock.deleteH2oInstance(INSTANCE_ID, YARN_CONF))
            .thenReturn(new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR));

    // act
    h2oProvisioner.deprovisionInstance(INSTANCE_ID);
}

From source file:com.indeed.iupload.web.controller.AppController.java

@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler(Exception.class)
public @ResponseBody BasicResponse handleGeneralException(IOException e) {
    log.error(e.getMessage());/*from w w  w .  j  a  v  a  2 s  .c  o  m*/
    return BasicResponse.error(e.getMessage());
}

From source file:com.hp.autonomy.frontend.find.idol.view.IdolViewController.java

@ExceptionHandler
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public ModelAndView handleViewServerErrorException(final ViewServerErrorException e,
        final HttpServletRequest request, final ServletResponse response) {
    response.reset();/*from w  w  w .jav  a2s  . c  om*/

    final String reference = e.getReference();

    log.info(Markers.AUDIT, "TRIED TO VIEW DOCUMENT WITH REFERENCE {} BUT VIEW SERVER RETURNED AN ERROR PAGE",
            reference);

    return controllerUtils.buildErrorModelAndView(new ErrorModelAndViewInfo.Builder().setRequest(request)
            .setMainMessageCode("error.viewServerErrorMain").setSubMessageCode("error.viewServerErrorSub")
            .setSubMessageArguments(new Object[] { reference })
            .setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR.value()).setContactSupport(true).setException(e)
            .build());
}

From source file:org.cloudfoundry.identity.uaa.login.RemoteUaaAuthenticationManager.java

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    String username = authentication.getName();
    String password = (String) authentication.getCredentials();

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));

    MultiValueMap<String, Object> parameters = new LinkedMultiValueMap<String, Object>();
    parameters.set("username", username);
    parameters.set("password", password);

    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> response = restTemplate.exchange(loginUrl, HttpMethod.POST,
            new HttpEntity<MultiValueMap<String, Object>>(parameters, headers), Map.class);

    if (response.getStatusCode() == HttpStatus.OK) {
        String userFromUaa = (String) response.getBody().get("username");

        if (userFromUaa.equals(userFromUaa)) {
            logger.info("Successful authentication request for " + authentication.getName());
            return new UsernamePasswordAuthenticationToken(username, null, UaaAuthority.USER_AUTHORITIES);
        }//from   w ww .  j  a v  a2s  .c o m
    } else if (response.getStatusCode() == HttpStatus.UNAUTHORIZED) {
        logger.info("Failed authentication request");
        throw new BadCredentialsException("Authentication failed");
    } else if (response.getStatusCode() == HttpStatus.INTERNAL_SERVER_ERROR) {
        logger.info("Internal error from UAA. Please Check the UAA logs.");
    } else {
        logger.error("Unexpected status code " + response.getStatusCode() + " from the UAA."
                + " Is a compatible version running?");
    }
    throw new RuntimeException("Could not authenticate with remote server");
}

From source file:com.hp.autonomy.frontend.find.hod.view.HodViewController.java

@ExceptionHandler
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public ModelAndView handleGeneralException(final Exception e, final HttpServletRequest request,
        final ServletResponse response) {
    response.reset();//  w w w . j  a  v a  2s  .  c  o  m

    return controllerUtils.buildErrorModelAndView(new ErrorModelAndViewInfo.Builder().setRequest(request)
            .setMainMessageCode(HOD_ERROR_MESSAGE_CODE_INTERNAL_MAIN)
            .setSubMessageCode(HOD_ERROR_MESSAGE_CODE_INTERNAL_SUB)
            .setStatusCode(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).setContactSupport(true).setException(e)
            .build());
}

From source file:org.venice.piazza.servicecontroller.controller.TaskManagedController.java

/**
 * Pulls the next job off of the Service Queue.
 * /*ww w . java  2s  . c  o  m*/
 * @param userName
 *            The name of the user. Used for verification.
 * @param serviceId
 *            The ID of the Service
 * @return The information for the next Job, if one is present.
 */
@RequestMapping(value = {
        "/service/{serviceId}/task" }, method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<PiazzaResponse> getNextServiceJobFromQueue(
        @RequestParam(value = "userName", required = true) String userName,
        @PathVariable(value = "serviceId") String serviceId) {
    try {
        // Log the Request
        piazzaLogger.log(String.format("User %s Requesting to perform Work on Next Job for %s Service Queue.",
                userName, serviceId), Severity.INFORMATIONAL);

        // Check for Access
        boolean canAccess = mongoAccessor.canUserAccessServiceQueue(serviceId, userName);
        if (!canAccess) {
            throw new ResourceAccessException("Service does not allow this user to access.");
        }

        // Get the Job. This will mark the Job as being processed.
        ExecuteServiceJob serviceJob = serviceTaskManager.getNextJobFromQueue(serviceId);
        // Return
        if (serviceJob != null) {
            // Return Job Information
            return new ResponseEntity<>(new ServiceJobResponse(serviceJob, serviceJob.getJobId()),
                    HttpStatus.OK);
        } else {
            // No Job Found. Return Null in the Response.
            return new ResponseEntity<>(new ServiceJobResponse(), HttpStatus.OK);
        }

    } catch (Exception exception) {
        String error = String.format("Error Getting next Service Job for Service %s by User %s: %s", serviceId,
                userName, exception.getMessage());
        LOGGER.error(error, exception);
        piazzaLogger.log(error, Severity.ERROR,
                new AuditElement(userName, "errorGettingServiceJob", serviceId));
        HttpStatus status = HttpStatus.INTERNAL_SERVER_ERROR;
        if (exception instanceof ResourceAccessException) {
            status = HttpStatus.UNAUTHORIZED;
        } else if (exception instanceof InvalidInputException) {
            status = HttpStatus.NOT_FOUND;
        }
        return new ResponseEntity<>(new ErrorResponse(error, "ServiceController"), status);
    }
}

From source file:at.ac.tuwien.dsg.cloud.utilities.gateway.registry.UserController.java

@RequestMapping(method = RequestMethod.DELETE, value = REST_USER_PATH_VARIABLE)
public ResponseEntity<String> remove(@PathVariable String user) {
    boolean res = this.kongUsers.getUsers().removeIf((KongUser u) -> {
        if (u.getUserName().equals(user)) {
            RequestEntity<Void> request = RequestEntity
                    .delete(URI.create(this.kongUris.getKongConsumerIdUri(u.getId()))).accept(MediaType.ALL)
                    .build();//from  www.j a  va 2 s.co m

            ResponseEntity<String> resp = restUtilities.simpleRestExchange(request, String.class);

            if (resp == null || resp.getStatusCode() != HttpStatus.NO_CONTENT) {
                return false;
            }

            return true;
        }
        return false;
    });

    if (!res) {
        return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
    }

    return new ResponseEntity<>(HttpStatus.OK);
}

From source file:be.bittich.quote.controller.impl.DefaultExceptionHandler.java

@RequestMapping(produces = APPLICATION_JSON)
@ExceptionHandler(DataAccessException.class)
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
public @ResponseBody Map<String, Object> handleDataAccessException(DataAccessException ex) throws IOException {
    Map<String, Object> map = newHashMap();
    map.put("error", "Data Error");
    map.put("cause", ex.getCause().getMessage());
    return map;/* w  w w .  j  a  v a 2s.com*/
}

From source file:de.steilerdev.myVerein.server.controller.user.EventController.java

@RequestMapping(produces = "application/json", params = "id", method = RequestMethod.GET)
public ResponseEntity<Event> getEvent(@RequestParam(value = "id") String eventID,
        @CurrentUser User currentUser) {
    logger.debug("[{}] Gathering event with id {}", currentUser, eventID);
    if (eventID.isEmpty()) {
        logger.warn("[{}] The id is not allowed to be empty", currentUser);
        return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
    } else {/*from w  w  w.  j  a v a2  s.  com*/
        Event event = eventRepository.findEventById(eventID);
        if (event == null) {
            logger.warn("[{}] Unable to find event with id {}", currentUser, eventID);
            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
        } else {
            logger.info("[{}] Returning event {}", currentUser, event);
            return new ResponseEntity<>(event.getSendingObjectInternalSync(currentUser), HttpStatus.OK);
        }
    }
}