Example usage for org.springframework.http HttpStatus I_AM_A_TEAPOT

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

Introduction

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

Prototype

HttpStatus I_AM_A_TEAPOT

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

Click Source Link

Document

418 I'm a teapot .

Usage

From source file:org.owasp.webgoat.service.BaseService.java

/**
 * <p>handleException.</p>/*from w w  w  .  j a  v a  2  s.com*/
 *
 * @param request a {@link javax.servlet.http.HttpServletRequest} object.
 * @param ex a {@link java.lang.Exception} object.
 * @return a {@link org.owasp.webgoat.service.ExceptionInfo} object.
 */
@ExceptionHandler(Exception.class)
@ResponseStatus(value = HttpStatus.I_AM_A_TEAPOT)
public @ResponseBody ExceptionInfo handleException(HttpServletRequest request, Exception ex) {
    String url = request.getRequestURL().toString();
    logger.error("Exception handler for service caught exception when processing: " + url, ex);
    ExceptionInfo response = new ExceptionInfo();
    response.setUrl(url);

    response.setMessage(getStringStackTrace(ex));

    return response;
}

From source file:org.openbaton.marketplace.api.exceptions.GlobalExceptionHandler.java

@ExceptionHandler({ InterruptedException.class, IOException.class })
@ResponseStatus(value = HttpStatus.NOT_FOUND)
protected ResponseEntity<Object> handleException(HttpServletRequest req, Exception e) {
    log.error("Exception with message " + e.getMessage() + " was thrown");
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    Map body = new HashMap<>();
    body.put("error", "Upload Error");
    body.put("exception", e.getClass().toString());
    body.put("message", e.getMessage());
    body.put("path", req.getRequestURI());
    body.put("status", HttpStatus.I_AM_A_TEAPOT.value());
    body.put("timestamp", new Date().getTime());
    ResponseEntity responseEntity = new ResponseEntity(body, headers, HttpStatus.I_AM_A_TEAPOT);
    return responseEntity;
}

From source file:org.osiam.resources.exceptions.OsiamExceptionHandler.java

private HttpStatus setStatus(Exception ex) {
    if (ex instanceof ResourceNotFoundException) {
        return HttpStatus.NOT_FOUND;
    }/*from   w  w w.  ja va 2s  .c o  m*/
    if (ex instanceof SchemaUnknownException) {
        return HttpStatus.I_AM_A_TEAPOT;
    }
    if (ex instanceof UnsupportedOperationException) {
        return HttpStatus.NOT_IMPLEMENTED;
    }

    return HttpStatus.CONFLICT;
}

From source file:fr.olympicinsa.riocognized.exception.MyExceptionHandler.java

@ExceptionHandler(NotRecognizedException.class)
@ResponseBody/*from   ww w  . j  av a2s  .co m*/
@ResponseStatus(HttpStatus.I_AM_A_TEAPOT)
public ErrorMessage handleNotRecognizedException(NotRecognizedException e, HttpServletRequest req) {
    return new ErrorMessage("NOT_RECOGNIZED");
}

From source file:com.hyphenated.card.controller.ExceptionController.java

/**
 * Catch all exception handler for any other exception thrown in the controller.
 * @param e Exception that was thrown.//from w w  w .j  a  v a 2  s  .  c om
 * @return A more generic error message that does not give away any implementation details
 */
@ExceptionHandler(Exception.class)
@ResponseStatus(HttpStatus.I_AM_A_TEAPOT)
public @ResponseBody Map<String, String> handleExcpetion(Exception e) {
    Map<String, String> error = new HashMap<String, String>();
    error.put("error", "There was an error on the server");
    error.put("errorDetails", "Make sure you request was formatted correctly, and all parameters were correct. "
            + "If you believe you received this message by mistake, you are probably out of luck.");
    log.error("Error: " + e.getMessage());
    log.error("Class? " + e.getClass());
    return error;
}

From source file:org.osiam.resources.exception.OsiamExceptionHandler.java

@ExceptionHandler(SchemaUnknownException.class)
@ResponseStatus(HttpStatus.I_AM_A_TEAPOT)
@ResponseBody//from w  w w. j  av a  2  s  . com
public ErrorResponse handleSchemaUnknown(SchemaUnknownException e) {
    return produceErrorResponse(e.getMessage(), HttpStatus.I_AM_A_TEAPOT);
}

From source file:org.openbaton.marketplace.api.exceptions.GlobalExceptionHandler.java

@ExceptionHandler({ FailedToUploadException.class })
@ResponseStatus(value = HttpStatus.I_AM_A_TEAPOT)
protected @ResponseBody ResponseEntity<Object> handleErrorRequest(Exception e, WebRequest request) {
    if (log.isDebugEnabled()) {
        log.error("Exception was thrown -> Return message: " + e.getMessage(), e);
    } else {//  ww w .j  a v  a  2s .c  o  m
        log.error("Exception was thrown -> Return message: " + e.getMessage());
    }
    ExceptionResource exc = new ExceptionResource("Bad Request", e.getMessage());
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    Map body = new HashMap<>();
    body.put("error", "Upload Error");
    body.put("exception", e.getClass().toString());
    body.put("message", e.getMessage());
    body.put("path", request.getContextPath());
    body.put("status", HttpStatus.I_AM_A_TEAPOT.value());
    body.put("timestamp", new Date().getTime());
    ResponseEntity responseEntity = new ResponseEntity(body, headers, HttpStatus.I_AM_A_TEAPOT);
    return responseEntity;
}

From source file:com.oneops.controller.cms.CMSClientTest.java

@SuppressWarnings("unchecked")
@Test(priority = 14)/*from  ww w  .  jav a 2s  .c  o m*/
/** again with http error */
public void getWorkOrdersHttpErrTest() {
    CmsDeployment cmsDeployment = mock(CmsDeployment.class);
    when(cmsDeployment.getDeploymentId()).thenReturn(DPLMNT_ID);

    DelegateExecution delegateExecution = mock(DelegateExecution.class);
    when(delegateExecution.getVariable("dpmt")).thenReturn(cmsDeployment);
    //we rely on mock of restTemplate to give error  answer 
    RestTemplate httpErrorTemplate = mock(RestTemplate.class);
    when(httpErrorTemplate.getForObject(anyString(), any(java.lang.Class.class), anyLong(), anyInt()))
            .thenThrow(new HttpClientErrorException(HttpStatus.I_AM_A_TEAPOT, "mocking"));
    cc.setRestTemplate(httpErrorTemplate);
    cc.getWorkOrderIds(delegateExecution);
    //it would be nice to assert the exec was updated, but for now we
    //just let the test pass if the client swallows the http error
}

From source file:com.oneops.controller.cms.CMSClientTest.java

@SuppressWarnings("unchecked")
@Test//from  www. java2  s.co m
public void updateWoStateTestHttperr() {
    DelegateExecution delegateExecution = mock(DelegateExecution.class);
    CmsDeployment cmsDeployment = mock(CmsDeployment.class);
    when(delegateExecution.getVariable("dpmt")).thenReturn(cmsDeployment);
    when(delegateExecution.getId()).thenReturn("Id11");
    when(delegateExecution.getVariable("error-message")).thenReturn("mocked-error");

    CmsWorkOrderSimple cmsWorkOrderSimple = new CmsWorkOrderSimple();
    cmsWorkOrderSimple.setDpmtRecordId(0);
    cmsWorkOrderSimple.setDeploymentId(66);
    cmsWorkOrderSimple.setComments("mockito-mock-comments");

    RestTemplate httpErrorTemplate = mock(RestTemplate.class);
    when(httpErrorTemplate.getForObject(anyString(), any(java.lang.Class.class), anyLong(), anyInt()))
            .thenThrow(new HttpClientErrorException(HttpStatus.I_AM_A_TEAPOT, "mocking"));
    cc.setRestTemplate(httpErrorTemplate);
    cc.updateWoState(delegateExecution, cmsWorkOrderSimple, "failed"); //also to do complete

}

From source file:org.talend.dataprep.command.GenericCommandTestService.java

@RequestMapping(value = "/command/test/fail_with_unknown", method = RequestMethod.GET, consumes = MediaType.ALL_VALUE, produces = MediaType.TEXT_PLAIN_VALUE)
public void fail_with_unknown() throws IOException {
    HttpResponseContext.status(HttpStatus.I_AM_A_TEAPOT);
}