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:fr.epsi.controllers.rest.LoginController.java

/**
 * Methode qui permet de connecter un utilisateur
 * @param username le username de l'utilisateur
 * @param password le password de l'utilisateur
 * @return Un message statut de la connexion
 *///from  w  w  w .  j  a  v a  2  s  .  c o m
@RequestMapping(value = "/connect", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody User connect(@RequestParam("username") String username,
        @RequestParam("password") String password, HttpServletResponse resp) {

    try {
        Users userModel = Users.getInstance();
        //On recuoere le user
        User user = userModel.findByUsername(username);

        // On retourne le guuid de l'utilisateur
        if (user.getPassword().equals(password)) {
            user.generateGUID();
            return user;
        }

        resp.setStatus(HttpServletResponse.SC_FORBIDDEN);
        return null;

    } catch (Exception e) {
        resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        return null;
    }
}

From source file:ip.ip.rest.controller.BookRestController.java

@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public List<Book> getBooks() {
    return service.getAllBooks();
}

From source file:com.gong.illidan.rest.controller.UserController.java

/**
 * GET /users -> get all the users//from  w  w  w.j  a  va  2 s  .  c om
 */
@RequestMapping(value = "/test", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<User> test() {
    log.info("REST request to test");
    return new ResponseEntity<>(userService.getUser(1), HttpStatus.OK);
}

From source file:com.github.prajan.feign.SampleFeignClient.java

@RequestMapping(value = "/test", produces = { MediaType.APPLICATION_JSON_VALUE }, method = RequestMethod.GET)
public String testUrl();

From source file:com.jayway.restassured.scala.GreetingController.java

@RequestMapping(value = "/greeting", method = GET, produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody String greeting(
        @RequestParam(value = "name", required = false, defaultValue = "World") String name) {
    return "{ \"greetings\" : \"" + name + "\"}";
}

From source file:ip.ip.rest.controller.AuthorRestController.java

@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public List<Author> getAuthors() {
    return service.getAllAuthors();
}

From source file:com._8x8.presentation.restfulController.GCMRestController.java

@RequestMapping(value = "/gcm/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<GCM>> getAllGCM() {
    List<GCM> GCMs = _gcmService.GetGCMs();

    if (GCMs.isEmpty()) {
        return new ResponseEntity<List<GCM>>(HttpStatus.NO_CONTENT);//You many decide to return HttpStatus.NOT_FOUND
    }/*from   w w w .j a  v  a 2s. c om*/
    return new ResponseEntity<List<GCM>>(GCMs, HttpStatus.OK);
}

From source file:aka.pirana.springsecurity.web.controllers.UserResource.java

@RequestMapping(value = "", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody/*  www .  j a v a 2 s.  c o m*/
public List<User> findAll() {
    System.out.println("aka.pirana.springsecurity.web.controllers.UserResource.findAll()");
    return userService.findAll();
}

From source file:fr.epsi.controllers.rest.OrderController.java

/**
 * Methode pour les commandes//  www . jav  a 2s  .co  m
 * @param reference la reference du produit
 * @param quantity la quantite voulue
 * @param guid l'identifiant de l'utilisateur
 * @return Un message selon le statut de la commande
 */
@RequestMapping(value = "/order", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody Product order(@RequestParam("reference") String reference,
        @RequestParam("quantity") int quantity, @RequestParam("token") String token, HttpServletResponse resp) {

    Users userModel = Users.getInstance(); //Recupere l'instance de user

    try {
        // Si on trouve un user correspondant au guid
        if (userModel.findByGUID(token) != null) {
            Products productModel = Products.getInstance();

            // On recupere le produit par reference
            Product product = productModel.findByRef(reference);

            if (product == null || quantity <= 0 || product.getQuantity() == 0
                    || product.getQuantity() < quantity) {
                resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
            } else {
                //On decremente la quantite du produit
                product.setQuantity(product.getQuantity() - quantity);

                return new Product(product.getReference(), product.getName(), quantity);
            }
        } else {
            resp.setStatus(HttpServletResponse.SC_FORBIDDEN);
        }
        return null;
    } catch (Exception e) {
        resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        return null;
    }
}

From source file:com.softcrylic.dockeryamlcatalog.controller.tomcat7jdk7.java

@RequestMapping(value = "/tm7jd7", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody ResponseEntity<String> post_Tomcat7Jdk7_Yml(@RequestBody String inputJson) {

    FigCommandClassDef fccd = new FigCommandClassDef();

    StringBuilder sb = new StringBuilder();

    try {//  w w w  .j ava  2  s. c om
        /**
         * Get the Json and Assigned to class definition
         */
        fccd = gson.fromJson(inputJson, FigCommandClassDef.class);

        /**
         * Check parent should be present
         */
        if (fccd.getContainer_id().equals("") || fccd.getContainer_id().equals(null)) {
            return new ResponseEntity<String>("Container_Id can't be null or left blank",
                    HttpStatus.BAD_REQUEST);
        }

        /**
         * Generate the Yaml
         */

        sb = YmlBuilder.buildYaml(fccd);

    } catch (Exception e) {
        return new ResponseEntity<String>(e.getMessage(), HttpStatus.BAD_REQUEST);
    }
    return new ResponseEntity<String>(sb.toString(), HttpStatus.OK);
}