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.orange.clara.pivotaltrackermirror.controllers.TaskStatusController.java

@ApiOperation(value = "Get information of all tasks.", response = TriggerResponse.class, responseContainer = "List")
@RequestMapping(method = RequestMethod.GET, value = "/", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getAll() throws SchedulerException {
    Iterable<MirrorReference> mirrorReferences = this.mirrorReferenceRepo.findAll();
    List<TriggerResponse> triggerResponseList = Lists.newArrayList();
    for (MirrorReference mirrorReference : mirrorReferences) {
        Trigger trigger = this.getTriggerFromId(mirrorReference.getId());
        triggerResponseList.add(new TriggerResponse(trigger, this.getTriggerState(mirrorReference.getId()),
                mirrorReference.getId()));
    }//from  w w w  .j  a  v  a  2s  .  c  om
    return ResponseEntity.ok(triggerResponseList);
}

From source file:com.biblio.web.rest.UserResource.java

@RequestMapping(value = "/register", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE,
        MediaType.TEXT_PLAIN_VALUE })//from   w w  w . j  a va2 s .  com

public Object createUser(@RequestBody @Valid ManagedUserVM managedUserVM, BindingResult bindingResult)
        throws MessagingException {
    Map<String, Object> modele = new HashMap<>();

    if (bindingResult.hasErrors()) {

        modele.put(Constants.ERROR, true);
        modele.put(Constants.MESSAGE, "Enregistrement chou");
        bindingResult.getFieldErrors().stream().forEach((f) -> {
            System.out.println("Field " + f.getField());
            System.out.println("error" + f.getDefaultMessage());
            modele.put(f.getField(), f.getDefaultMessage());
        });

        return modele;
    }

    if (userRepository.findOneByLogin(managedUserVM.getLogin()).isPresent()) {

        modele.put(Constants.ERROR, "true");
        modele.put(Constants.MESSAGE, "Enregistrement chou");
        modele.put("login", "Ce nom d'utilisateur existe deja");
        return modele;
    }

    if (userRepository.findOneByEmail(managedUserVM.getEmail()).isPresent()) {
        modele.put(Constants.ERROR, "true");
        modele.put(Constants.MESSAGE, "Enregistrement chou");
        modele.put("email", "Ce email est deja utilis");

        return modele;
    }

    managedUserVM.setPassword("123456");

    if (managedUserVM.getType() != null && managedUserVM.getType() == 2) {
        managedUserVM.getRoles().add(ConstantRole.ADMIN_ROLE);
    } else {
        managedUserVM.getRoles().add(ConstantRole.USER_ROLE);
    }

    managedUserVM.setPassword(RandomUtil.generateAlphaNumerique(8));
    User u = userService.createUser(managedUserVM);
    modele.put(Constants.MESSAGE, "Enregistrement russi");
    try {
        mailService.sendEmail(u.getEmail(), "Mot de passe", " Les parametre de compte\n Username : "
                + u.getLogin() + " \n password " + managedUserVM.getPassword(), true, true);
    } catch (Exception e) {
        System.out.println("ex");
        return modele;
    }
    return modele;
}

From source file:ui.controller.ItemDatabaseRestController.java

@RequestMapping(method = RequestMethod.DELETE, consumes = MediaType.APPLICATION_JSON_VALUE)
public void deleteTweet(@RequestParam String name) {
    getService().removeUser(name);
}

From source file:com.javafxpert.wikibrowser.WikiSearchController.java

@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Object> search(@RequestParam(value = "title", defaultValue = "") String title,
        @RequestParam(value = "nearmatch", defaultValue = "false") boolean nearmatch,
        @RequestParam(value = "lang") String lang) {

    String language = wikiBrowserProperties.computeLang(lang);

    //TODO: Implement better way of creating the query represented by the following variables

    String qa = "https://";
    String qb = ""; // Some language code e.g. en
    String qc = ".wikipedia.org/w/api.php?action=query&format=json&list=search&srlimit=10&redirects";
    String qd = ""; // Indication that only nearmatch is desired
    String qe = "&srsearch=";
    String qf = ""; // article title so search for

    qb = language;//  www .j a v a  2  s . c  o  m
    //qd = nearmatch.equalsIgnoreCase("true") ? "&srwhat=nearmatch" : "";
    qd = nearmatch ? "&srwhat=nearmatch" : "";
    qf = title;

    String searchQuery = qa + qb + qc + qd + qe + qf;

    SearchResponseNear searchResponseNear = queryProcessSearchResponse(searchQuery, language);

    return Optional.ofNullable(searchResponseNear).map(cr -> new ResponseEntity<>((Object) cr, HttpStatus.OK))
            .orElse(new ResponseEntity<>("Wikipedia title search unsuccessful",
                    HttpStatus.INTERNAL_SERVER_ERROR));
}

From source file:com.traffitruck.web.JsonController.java

@RequestMapping(value = "/load_for_truck_by_radius", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public List<Load> getLoadsForTruckByDistance(@RequestParam("licensePlateNumber") String licensePlateNumber,
        @RequestParam("sourceLat") Double sourceLat, @RequestParam("sourceLng") Double sourceLng,
        @RequestParam("destinationLat") Double destinationLat,
        @RequestParam("destinationLng") Double destinationLng,
        @RequestParam(value = "source_radius", required = false) Integer source_radius,
        @RequestParam(value = "destination_radius", required = false) Integer destination_radius) {
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    String username = authentication.getName();
    // verify the truck belongs to the logged-in user
    if (licensePlateNumber == null || licensePlateNumber.isEmpty() || licensePlateNumber.equals("NA")) {
        // set default value for radius if not set
        if (sourceLat != null && sourceLng != null && source_radius == null) {
            source_radius = DEFAULT_RADIUS_FOR_SEARCHES;
        }/*from   w ww  .j  ava 2s . c om*/
        if (destinationLat != null && destinationLng != null && destination_radius == null) {
            destination_radius = DEFAULT_RADIUS_FOR_SEARCHES;
        }
        return dao.getLoadsWithoutTruckByFilter(sourceLat, sourceLng, source_radius, destinationLat,
                destinationLng, destination_radius);
    } else {
        Truck truck = dao.getTruckByUserAndLicensePlate(username, licensePlateNumber);
        if (truck == null) { // the logged in user does not have a truck with this license plate number
            return Collections.emptyList();
        }
        // set default value for radius if not set
        if (sourceLat != null && sourceLng != null && source_radius == null) {
            source_radius = DEFAULT_RADIUS_FOR_SEARCHES;
        }
        if (destinationLat != null && destinationLng != null && destination_radius == null) {
            destination_radius = DEFAULT_RADIUS_FOR_SEARCHES;
        }

        return dao.getLoadsForTruckByFilter(truck, sourceLat, sourceLng, source_radius, destinationLat,
                destinationLng, destination_radius);
    }
}

From source file:com.expedia.seiso.web.controller.v1.NodeIpAddressControllerV1.java

@RequestMapping(value = NODE_IP_ADDRESS_URI_TEMPLATE, method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.NO_CONTENT)/*  ww  w. ja va2 s.  c  om*/
public void put(@PathVariable String nodeName, @PathVariable String ipAddress, PEResource nipResource) {
    val node = nodeRepo.findByName(nodeName);
    val serviceInstance = node.getServiceInstance();

    // Enrich the node IP address so we can save it. [WLW]
    val nipData = (NodeIpAddress) nipResource.getItem();
    nipData.setNode(node);
    nipData.setIpAddress(ipAddress);
    nipData.getIpAddressRole().setServiceInstance(serviceInstance);
    basicItemDelegate.put(nipData, true);
}

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

@RequestMapping(value = "/remover", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody ResponseEntity<?> removerDoacao(long id) {

    try {//from  ww w  .  j a va2 s  .  c o  m
        fachada.removerDoacao(id);
        return new ResponseEntity<String>(HttpStatus.OK);
    } catch (DoacaoInexistenteException e) {
        return new ResponseEntity<DoacaoInexistenteException>(e, HttpStatus.BAD_REQUEST);
    }
}

From source file:com.cami.web.controller.FileController.java

/**
 * *************************************************
 * URL: /appel-offre/file/upload upload(): receives files
 *
 * @param request : MultipartHttpServletRequest auto passed
 * @param response : HttpServletResponse auto passed
 * @param idAppelOffre//from  ww  w  . ja  v  a2  s  .c  o  m
 * @return LinkedList<FileMeta> as json format
 * **************************************************
 */
@RequestMapping(value = "/{idAppelOffre}/upload", method = RequestMethod.POST, produces = {
        MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody LinkedList<FileMeta> upload(MultipartHttpServletRequest request,
        HttpServletResponse response, @PathVariable String idAppelOffre) {

    //1. build an iterator
    Iterator<String> itr = request.getFileNames();
    MultipartFile mpf = null;
    AppelOffre appelOffre = appelOffreService.findOne(Long.valueOf(idAppelOffre));
    int i = 0;
    //2. get each file
    while (itr.hasNext()) {
        System.out.println("i = " + i);
        //2.1 get next MultipartFile
        mpf = request.getFile(itr.next());

        System.out.println(mpf.getOriginalFilename() + " uploaded! ");

        //2.2 if files > 10 remove the first from the list
        //             if(files.size() >= 10)
        //                 files.pop();
        //2.3 create new fileMeta
        //             fileMeta = new FileMeta();
        //             fileMeta.setFileName(saveName);
        //             fileMeta.setFileSize(mpf.getSize()/1024+" Kb");
        //             fileMeta.setFileType(mpf.getContentType());
        try {
            //fileMeta.setBytes(mpf.getBytes());

            // copy file to local disk (make sure the path "e.g. D:/temp/files" exists)            
            String saveName = getFileName(mpf, appelOffre);
            processFileData(mpf, SAVE_DIRECTORY, saveName);
            //FileCopyUtils.copy(mpf.getBytes(), new FileOutputStream("/home/gervais/" + saveName));
            appelOffre.addFile(saveName);
            appelOffre = appelOffreService.updateFiles(appelOffre);

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        //2.4 add to files
        // files.add(fileMeta);
    }
    // result will be like this
    // [{"fileName":"app_engine-85x77.png","fileSize":"8 Kb","fileType":"image/png"},...]
    files = new LinkedList<>();
    for (String file : appelOffre.getFiles()) {
        fileMeta = new FileMeta();
        fileMeta.setFileName(file);
        files.add(fileMeta);
    }
    return files;
}

From source file:com.app.TestServis.java

@Test
public void update_book() throws Exception {
    mockMvc.perform(MockMvcRequestBuilders.post("/update/" + test.getBookname()))
            .andExpect(MockMvcResultMatchers.status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.bookname").value("test")).andExpect(jsonPath("$.author").value("test"));

}

From source file:com.javafxpert.wikibrowser.WikiIdLocatorController.java

@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Object> locatorEndpoint(
        @RequestParam(value = "name", defaultValue = "") String articleName,
        @RequestParam(value = "lang") String lang) {

    String language = wikiBrowserProperties.computeLang(lang);

    ItemInfo itemInfo = null;/*from   www . j  a  va2  s .c  om*/
    if (!articleName.equals("")) {
        itemInfo = name2Id(articleName, language);
    }

    return Optional.ofNullable(itemInfo).map(cr -> new ResponseEntity<>((Object) cr, HttpStatus.OK))
            .orElse(new ResponseEntity<>("Wikipedia query unsuccessful", HttpStatus.INTERNAL_SERVER_ERROR));
}