Example usage for org.springframework.http HttpStatus METHOD_FAILURE

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

Introduction

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

Prototype

HttpStatus METHOD_FAILURE

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

Click Source Link

Usage

From source file:com.stormcloud.ide.api.BaseController.java

@ExceptionHandler(Exception.class)
@ResponseStatus(HttpStatus.METHOD_FAILURE)
@ResponseBody
public String handleServerErrors(Exception ex) {
    return ex.getMessage();
}

From source file:org.kuali.mobility.sakai.service.SakaiPrivateTopicServiceImpl.java

public ResponseEntity<String> postMessage(Message message, String siteId, String userId) {
    try {/*from  w w w  .j  a  va 2s  .c o m*/
        String jsonString = "{";
        jsonString += "\"attachments\": [],";
        jsonString += "\"authoredBy\":\"" + userId + "\", ";
        jsonString += "\"body\":\"" + message.getBody() + "\", ";
        jsonString += "\"label\":\"" + "" + "\", ";
        jsonString += "\"recipients\":\"" + message.getRecipients() + "\", ";
        jsonString += "\"replies\":" + "null" + ", ";
        jsonString += "\"replyTo\":" + message.getInReplyTo() + ", ";
        jsonString += "\"title\":\"" + message.getTitle() + "\", ";
        //         jsonString += "\"topicId\":\"" + null + "\", ";
        //         jsonString += "\"typeUuid\":\""+ "4d9593ed-aaee-4826-b74a-b3c3432b384c" + "\", ";
        jsonString += "\"siteId\":\"" + siteId + "\", ";
        jsonString += "\"read\":" + "false" + ", ";
        //         jsonString += "\"entityReference\":\"" + "\\/forum_message" + "\", ";
        //jsonString += "\"entityURL\":\"" + "http:\\/\\/localhost:8080\\/direct\\/forum_message" + "\", ";
        //jsonString += "\"entityTitle\":\"" + subject + "\"";

        jsonString += "}";

        String url = configParamService.findValueByName("Sakai.Url.Base") + "forum_message/new.json";
        ResponseEntity<InputStream> is = oncourseOAuthService.oAuthPostRequest(userId, url, "text/html",
                jsonString);
        return new ResponseEntity<String>(is.getStatusCode());
    } catch (OAuthException e) {
        BufferedReader br = new BufferedReader(new InputStreamReader(e.getResponseBody()));
        String body = "";
        try {
            body = br.readLine();
        } catch (IOException e1) {
        }
        LOG.error(e.getResponseCode() + ", " + body, e);
        return new ResponseEntity<String>(HttpStatus.valueOf(e.getResponseCode()));
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        return new ResponseEntity<String>(HttpStatus.METHOD_FAILURE);
    }
}

From source file:org.kuali.mobility.sakai.service.SakaiForumServiceImpl.java

@Override
public ResponseEntity<String> postMessage(Message message, String userId) {
    try {/*from w  w w.j  av a 2s .  c o  m*/
        String jsonString = "{";
        jsonString += "\"attachments\": [],";
        jsonString += "\"authoredBy\":\"" + userId + "\", ";
        jsonString += "\"body\":\"" + message.getBody() + "\", ";
        jsonString += "\"label\":\"" + "" + "\", ";
        jsonString += "\"recipients\":\"" + "" + "\", ";
        jsonString += "\"replies\":" + "null" + ", ";
        jsonString += "\"replyTo\":" + message.getInReplyTo() + ", ";
        jsonString += "\"title\":\"" + message.getTitle() + "\", ";
        jsonString += "\"topicId\":\"" + message.getTopicId() + "\", ";
        jsonString += "\"forumId\":\"" + message.getForumId() + "\", ";
        jsonString += "\"read\":" + "false" + ", ";
        jsonString += "\"entityReference\":\"" + "\\/forum_message" + "\"";
        //jsonString += "\"entityURL\":\"" + "http:\\/\\/localhost:8080\\/direct\\/forum_message" + "\", ";
        //jsonString += "\"entityTitle\":\"" + subject + "\"";

        jsonString += "}";

        String url = configParamService.findValueByName("Sakai.Url.Base") + "forum_message/new.json";
        ResponseEntity<InputStream> is = oncourseOAuthService.oAuthPostRequest(userId, url, "application/json",
                jsonString);
        return new ResponseEntity<String>(is.getStatusCode());
    } catch (OAuthException e) {
        BufferedReader br = new BufferedReader(new InputStreamReader(e.getResponseBody()));
        String body = "";
        try {
            body = br.readLine();
        } catch (IOException e1) {
        }
        LOG.error(e.getResponseCode() + ", " + body, e);
        return new ResponseEntity<String>(HttpStatus.valueOf(e.getResponseCode()));
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        return new ResponseEntity<String>(HttpStatus.METHOD_FAILURE);
    }
}

From source file:org.kuali.mobility.sakai.service.SakaiForumServiceImpl.java

@Override
public ResponseEntity<String> markMessageRead(String siteId, String messageId, String userId) {
    try {//from   ww w. j ava  2  s.c o m
        String url = configParamService.findValueByName("Sakai.Url.Base") + "forum_message/markread/"
                + messageId + "/site/" + siteId;
        ResponseEntity<InputStream> response = oncourseOAuthService.oAuthPostRequest(userId, url, "text/html",
                "");
        return new ResponseEntity<String>(response.getStatusCode());
    } catch (OAuthException e) {
        if (e.getResponseBody() != null) {
            BufferedReader br = new BufferedReader(new InputStreamReader(e.getResponseBody()));
            String body = "";
            try {
                body = br.readLine();
            } catch (IOException e1) {
            }
            LOG.error(e.getResponseCode() + ", " + body, e);
        } else {
            LOG.error(e.getMessage(), e);
        }
        return new ResponseEntity<String>(HttpStatus.valueOf(e.getResponseCode()));
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        return new ResponseEntity<String>(HttpStatus.METHOD_FAILURE);
    }
}

From source file:nl.strohalm.cyclos.webservices.rest.PaymentsRestController.java

/**
 * Handles {@link PaymentException}s//from w  w  w  . j  a va 2  s.  c  o m
 */
@ExceptionHandler(PaymentException.class)
@ResponseBody
@ResponseStatus(HttpStatus.METHOD_FAILURE)
public ServerErrorVO handlePaymentException(final PaymentException ex) {
    String errorCode = UNKNOWN_PAYMENT_ERROR;
    if (ex instanceof MaxAmountPerDayExceededException) {
        errorCode = MAX_AMOUNT_PER_DAY_EXCEEDED;
    } else if (ex instanceof NotEnoughCreditsException) {
        errorCode = NOT_ENOUGH_CREDITS;
    } else if (ex instanceof TransferMinimumPaymentException) {
        errorCode = TRANSFER_MINIMUM_PAYMENT;
    } else if (ex instanceof UpperCreditLimitReachedException) {
        errorCode = UPPER_CREDIT_LIMIT_REACHED;
    }
    return new ServerErrorVO(errorCode, null);
}

From source file:org.kuali.mobility.writer.controllers.WriterEditArticleController.java

@RequestMapping(value = "/mediaUpload", method = RequestMethod.POST)
public ResponseEntity<String> mediaUpload(HttpServletRequest request,
        @RequestParam(value = "file", required = false) MultipartFile mediaFile,
        @RequestParam(value = "mediaType") int mediaType,
        @RequestParam(value = "articleId", required = false) long articleId, Model uiModel) {

    Media media = service.uploadMediaData(mediaFile, mediaType);
    if (media == null) {
        return new ResponseEntity<String>(HttpStatus.METHOD_FAILURE);
    } else {/*  w  ww .  j a  v  a 2s  .c o m*/
        Article article = (Article) uiModel.asMap().get("article");
        boolean hadArticle = true;
        if (article == null) {
            article = this.service.getArticle(articleId);
            hadArticle = false;
        }

        article = service.updateMedia(article, media);
        if (hadArticle) {
            uiModel.addAttribute("article", article);
        }
    }
    return new ResponseEntity<String>(HttpStatus.OK);
}