Example usage for org.springframework.http MediaType APPLICATION_JSON_VALUE

List of usage examples for org.springframework.http MediaType APPLICATION_JSON_VALUE

Introduction

In this page you can find the example usage for org.springframework.http MediaType APPLICATION_JSON_VALUE.

Prototype

String APPLICATION_JSON_VALUE

To view the source code for org.springframework.http MediaType APPLICATION_JSON_VALUE.

Click Source Link

Document

A String equivalent of MediaType#APPLICATION_JSON .

Usage

From source file:com.github.lynxdb.server.api.http.handlers.EpTree.java

@RequestMapping(path = "/rule", method = { RequestMethod.GET, RequestMethod.POST, RequestMethod.DELETE,
        RequestMethod.PUT }, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity rule() {
    return ResponseEntity.status(HttpStatus.NOT_IMPLEMENTED).build();
}

From source file:be.ehb.restservermetdatabase.webservice.AchievementController.java

@RequestMapping(value = "/create", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public void create(@RequestBody Achievement a) {
    a.setIcon(setImg(a.getIcon(), a.getName()));
    AchievementDao.addAchievement(a);/* ww w .j a  v  a2s  . c  o  m*/
}

From source file:br.upe.community.ui.ControllerDoacao.java

@RequestMapping(value = "/interessadoDoacao", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody ResponseEntity<?> interesseDoacao(String email, long id) {

    try {//from   w w  w. j av a2s. c  o m
        fachada.interesseDoacao(email, id);
        return new ResponseEntity<String>(HttpStatus.OK);
    } catch (UsuarioInexistenteException e) {
        return new ResponseEntity<UsuarioInexistenteException>(e, HttpStatus.BAD_REQUEST);
    } catch (ProprioUsuarioAnunciadorException ex) {
        return new ResponseEntity<ProprioUsuarioAnunciadorException>(ex, HttpStatus.BAD_REQUEST);
    } catch (DoacaoJaRealizadaException ex) {
        return new ResponseEntity<DoacaoJaRealizadaException>(ex, HttpStatus.BAD_REQUEST);
    }
}

From source file:org.mitre.openid.connect.view.JsonErrorView.java

@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
        HttpServletResponse response) {/*from   ww  w.j ava2 s .  c  o m*/

    response.setContentType(MediaType.APPLICATION_JSON_VALUE);

    HttpStatus code = (HttpStatus) model.get(HttpCodeView.CODE);
    if (code == null) {
        code = HttpStatus.INTERNAL_SERVER_ERROR; // default to 500
    }

    response.setStatus(code.value());

    try {

        Writer out = response.getWriter();

        String errorTitle = (String) model.get(ERROR);
        if (Strings.isNullOrEmpty(errorTitle)) {
            errorTitle = "mitreid_error";
        }
        String errorMessage = (String) model.get(ERROR_MESSAGE);
        JsonObject obj = new JsonObject();
        obj.addProperty("error", errorTitle);
        obj.addProperty("error_description", errorMessage);
        gson.toJson(obj, out);

    } catch (IOException e) {

        logger.error("IOException in JsonErrorView.java: ", e);

    }
}

From source file:se.skltp.cooperation.web.rest.v1.controller.InstalledContractController.java

/**
 * GET /installedContracts -> get all the installedContracts. Content type:
 * JSON/*from w  ww  .  jav a  2 s  .  c o m*/
 */
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public List<InstalledContractDTO> getAllAsJson(@RequestParam(required = false) Long connectionPointId,
        @RequestParam(required = false) Long serviceContractId,
        @RequestParam(required = false) Long serviceDomainId) {
    log.debug("REST request to get all InstalledContracts as json");

    return getAll(connectionPointId, serviceContractId, serviceDomainId);

}

From source file:com.nebhale.letsmakeadeal.web.GamesController.java

@RequestMapping(method = RequestMethod.GET, value = "/{gameId}", produces = { MediaType.APPLICATION_JSON_VALUE,
        MediaType.TEXT_XML_VALUE })/*  w  w w . ja  v  a2  s .co m*/
ResponseEntity<GameResource> showGame(@PathVariable Long gameId) throws GameDoesNotExistException {
    Game game = this.gameRepository.retrieve(gameId);
    GameResource resource = this.gameResourceAssembler.toResource(game);

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

From source file:io.ignitr.dispatchr.manager.controller.client.ClientsController.java

/**
 * Finds all clients in the system.//  w  ww  . j av a 2s.c o m
 *
 * @param offset starting offset when using pagination
 * @param limit number of records to return when using pagination
 * @param sortDir sort direction of records when using pagination
 * @param httpRequest http request
 * @return an HTTP 200 response containing a list of all clients defined in the system
 */
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public DeferredResult<ResponseEntity<?>> findAll(
        @RequestParam(value = "offset", defaultValue = "0") Long offset,
        @RequestParam(value = "limit", defaultValue = "25") Long limit,
        @RequestParam(value = "sort_dir", defaultValue = "asc") String sortDir,
        @RequestParam(value = "active", defaultValue = "true") Boolean active, HttpServletRequest httpRequest) {
    final DeferredResult<ResponseEntity<?>> deferredResult = new DeferredResult<>();

    Observable.fromCallable(() -> SortDirectionValidator.validate(sortDir))
            .lift(new RequestContextStashOperator<>())
            .flatMap(valid -> Observable.create(new Observable.OnSubscribe<List<Client>>() {
                List<Client> clients = new ArrayList<>();

                @Override
                public void call(Subscriber<? super List<Client>> subscriber) {
                    service.findAll(offset, limit, sortDir, active).collect(() -> clients, List::add)
                            .subscribe(clients -> {
                                subscriber.onNext(clients);
                                subscriber.onCompleted();
                            });
                }
            })).map(FindClientsResponse::from).subscribeOn(Schedulers.io()).subscribe(body -> {
                deferredResult.setResult(ResponseEntity.ok(body));
            }, error -> {
                deferredResult.setErrorResult(errorHandler.handleError(httpRequest, error));
            });

    return deferredResult;
}

From source file:org.agatom.springatom.webmvc.controllers.SVActionsController.java

@ResponseBody
@RequestMapping(value = "/model/{*.+actionModel}", method = RequestMethod.GET, produces = {
        MediaType.APPLICATION_JSON_VALUE })
public ActionModel onActionModelRequest(@PathVariable("*.+actionModel") final String actionModel)
        throws NotFoundException {
    return this.actionsModelReader.getActionModel(actionModel);
}

From source file:com.jiwhiz.rest.user.PostCommentRestController.java

@RequestMapping(method = RequestMethod.POST, value = URL_USER_BLOGS_BLOG_COMMENTS, consumes = MediaType.APPLICATION_JSON_VALUE)
@Transactional/*from ww w  .  j  av  a  2s.c om*/
public ResponseEntity<Void> postComment(@PathVariable("blogId") String blogId,
        @RequestBody CommentForm newComment) throws ResourceNotFoundException {
    UserAccount currentUser = getCurrentAuthenticatedUser();
    BlogPost blogPost = this.blogPostRepository.findOne(blogId);
    if (blogPost == null || !blogPost.isPublished()) {
        throw new ResourceNotFoundException("No published blog post with the id: " + blogId);
    }

    CommentPost commentPost = commentPostService.postComment(currentUser, blogPost, newComment.getContent());

    //send email to author if someone else posted a comment to blog.
    if (this.commentNotificationSender != null && !blogPost.getAuthor().equals(currentUser)) {
        this.commentNotificationSender.send(blogPost.getAuthor(), currentUser, commentPost, blogPost);
    }

    UserCommentResource resource = userCommentResourceAssembler.toResource(commentPost);
    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.setLocation(URI.create(resource.getLink(Link.REL_SELF).getHref()));

    return new ResponseEntity<>(httpHeaders, HttpStatus.CREATED);
}

From source file:com.boyuanitsm.fort.web.rest.AccountResource.java

/**
 * POST  /register : register the user.//www  .  ja va2s.c o  m
 *
 * @param managedUserDTO the managed user DTO
 * @param request the HTTP request
 * @return the ResponseEntity with status 201 (Created) if the user is registred or 400 (Bad Request) if the login or e-mail is already in use
 */
@RequestMapping(value = "/register", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE,
        MediaType.TEXT_PLAIN_VALUE })
@Timed
public ResponseEntity<?> registerAccount(@Valid @RequestBody ManagedUserDTO managedUserDTO,
        HttpServletRequest request) {

    HttpHeaders textPlainHeaders = new HttpHeaders();
    textPlainHeaders.setContentType(MediaType.TEXT_PLAIN);

    return userRepository.findOneByLogin(managedUserDTO.getLogin().toLowerCase())
            .map(user -> new ResponseEntity<>("login already in use", textPlainHeaders, HttpStatus.BAD_REQUEST))
            .orElseGet(() -> userRepository.findOneByEmail(managedUserDTO.getEmail())
                    .map(user -> new ResponseEntity<>("e-mail address already in use", textPlainHeaders,
                            HttpStatus.BAD_REQUEST))
                    .orElseGet(() -> {
                        User user = userService.createUserInformation(managedUserDTO.getLogin(),
                                managedUserDTO.getPassword(), managedUserDTO.getFirstName(),
                                managedUserDTO.getLastName(), managedUserDTO.getEmail().toLowerCase(),
                                managedUserDTO.getLangKey());
                        String baseUrl = request.getScheme() + // "http"
                        "://" + // "://"
                        request.getServerName() + // "myhost"
                        ":" + // ":"
                        request.getServerPort() + // "80"
                        request.getContextPath(); // "/myContextPath" or "" if deployed in root context

                        mailService.sendActivationEmail(user, baseUrl);
                        return new ResponseEntity<>(HttpStatus.CREATED);
                    }));
}