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.ar.dev.tierra.api.controller.UsuariosController.java

@PreAuthorize("hasAuthority('ROLE_ADMIN')")
@RequestMapping(value = "/list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getAllUsuarios() {
    List<Usuarios> listUsuarios = facadeService.getUsuariosDAO().allUsuarios();
    ResponseEntity responseEntity;/*from w ww.j a  v a  2s.c o m*/
    if (listUsuarios.isEmpty()) {
        responseEntity = new ResponseEntity(HttpStatus.BAD_REQUEST);
    } else {
        responseEntity = new ResponseEntity(listUsuarios, HttpStatus.OK);
    }
    return responseEntity;
}

From source file:org.cloudfoundry.identity.uaa.error.JsonAwareAuthenticationEntryPoint.java

@Override
public void commence(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException authException) throws IOException, ServletException {
    response.addHeader("WWW-Authenticate", String.format("%s realm=\"%s\"", typeName, realmName));
    String accept = request.getHeader("Accept");
    boolean json = false;
    if (StringUtils.hasText(accept)) {
        for (MediaType mediaType : MediaType.parseMediaTypes(accept)) {
            if (mediaType.includes(MediaType.APPLICATION_JSON)) {
                json = true;/*w  w w. j av a  2 s .  c  o  m*/
                break;
            }
        }
    }
    if (json) {
        response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
        response.setContentType(MediaType.APPLICATION_JSON_VALUE);
        response.getWriter().append(String.format("{\"error\":\"%s\"}", authException.getMessage()));
    } else {
        response.sendError(HttpServletResponse.SC_UNAUTHORIZED, authException.getMessage());
    }
}

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

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

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

@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Object> search(@RequestParam(value = "items", defaultValue = "") String items,
        @RequestParam(value = "lang") String lang) {
    // Example endpoint usage is bitly?items=Q24, Q30, Q23, Q16, Q20&lang=fr
    // Scrub the input, and output a string for the Bitly service similar to the following:
    // Q24,Q30,Q23,Q16,Q20
    String argStr = WikiBrowserUtils.scrubItemIds(items, false);
    log.info("argStr=" + argStr);

    BitlyResponseNear bitlyResponseNear = null;

    if (argStr.length() > 0) {
        String blat = wikiBrowserProperties.getBlat();
        String bitlyUrlPart = "https://api-ssl.bitly.com/v3/shorten?access_token=" + blat + "&longUrl=";

        String conceptMapUrlPart = null;

        try {/*  w  ww.j  a  v  a 2s . c om*/
            conceptMapUrlPart = URLEncoder.encode("http://conceptmap.io?items=" + argStr + "&lang=" + lang,
                    "UTF-8");
        } catch (UnsupportedEncodingException uee) {
            log.error("Exception whild encoding for bitly");
        }

        bitlyResponseNear = bitlyServiceResponse(bitlyUrlPart + conceptMapUrlPart);
    } else {
        log.warn("Invalid argument to WikiBitlyController /bitly endpoint: \"" + items + "\"");
    }

    return Optional.ofNullable(bitlyResponseNear).map(cr -> new ResponseEntity<>((Object) cr, HttpStatus.OK))
            .orElse(new ResponseEntity<>("Bitly request unsuccessful", HttpStatus.INTERNAL_SERVER_ERROR));
}

From source file:org.callistasoftware.netcare.web.mobile.controller.BankIdController.java

@RequestMapping(value = "/authenticate", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody/* w w  w  .j av a2s .com*/
public String authenticate(@RequestParam(value = "crn", required = true) String crn,
        HttpServletResponse response) throws IOException {

    log.info("Authenticating user {}", crn);

    final PatientEntity ent = repo.findByCivicRegistrationNumber(crn.trim());
    if (ent != null) {
        try {
            return service.authenticate(new CivicRegistrationNumber(crn));
        } catch (final Exception e) {
            log.error("Error in bank id service. Message: {}", e.getMessage());
            response.sendError(HttpServletResponse.SC_BAD_REQUEST, e.getMessage());
            return null;
        }
    }

    log.info("User {} does not have an account in the system", crn);
    response.sendError(HttpServletResponse.SC_NOT_FOUND, "The user does not have an account...");
    return null;
}

From source file:io.curly.tagger.controller.TagController.java

@Loggable
@RequestMapping(value = "/search", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public DeferredResult<ResponseEntity<SearchResult>> search(
        @RequestParam(value = "q", defaultValue = "") String query) {
    return defer(readerCommand.like(query).filter(Optional::isPresent).map(Optional::get).map(SearchResult::new)
            .map(ResponseEntity::ok).defaultIfEmpty(new ResponseEntity<>(NOT_FOUND)));
}

From source file:com.orange.ngsi.server.NgsiBaseController.java

@RequestMapping(value = "/updateContext", method = RequestMethod.POST, consumes = {
        MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
final public ResponseEntity<UpdateContextResponse> updateContextRequest(
        @RequestBody final UpdateContext updateContext, HttpServletRequest httpServletRequest)
        throws Exception {
    ngsiValidation.checkUpdateContext(updateContext);
    registerIntoDispatcher(httpServletRequest);
    return new ResponseEntity<>(updateContext(updateContext), HttpStatus.OK);
}

From source file:de.document.controller.UmlsController.java

@RequestMapping(value = "/relationGet", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public Collection<String> rel() throws Exception {
    String s = "relationGetrelationGet";
    checkRelation c = new checkRelation();
    System.out.println("relationGET" + c.check());
    List<String> l = new ArrayList();
    //l.add(c.check());

    //System.out.println("this the relation"+);
    //return c.check();
    return c.check();
}

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

@RequestMapping(path = "/{type}", method = { RequestMethod.GET,
        RequestMethod.POST }, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity type(@PathVariable("type") String _type) {
    return ResponseEntity.status(HttpStatus.NOT_IMPLEMENTED).build();
}

From source file:com.ar.dev.tierra.api.controller.ProductoController.java

@RequestMapping(value = "/advanced", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> advanced(
        @RequestParam(value = "descripcion", required = false, defaultValue = "") String descripcion,
        @RequestParam(value = "marca", required = false, defaultValue = "") String marca,
        @RequestParam(value = "talla", required = false, defaultValue = "") String talla,
        @RequestParam(value = "codigo", required = false, defaultValue = "") String codigo,
        @RequestParam(value = "categoria", required = false, defaultValue = "") String categoria,
        @RequestParam(value = "page", required = false, defaultValue = "") Integer page,
        @RequestParam(value = "size", required = false, defaultValue = "") Integer size) {
    Page paged = facadeService.getProductoService().getByParams(descripcion, marca, talla, codigo, categoria,
            page, size);//from   w  w  w.j  a  v a 2 s .  co m
    if (paged.getSize() != 0) {
        return new ResponseEntity<>(paged, HttpStatus.OK);
    } else {
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }
}