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:org.mitre.openid.connect.view.JsonEntityView.java

@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
        HttpServletResponse response) {/* w w w  .  j  a  v  a 2  s  .c  om*/

    response.setContentType(MediaType.APPLICATION_JSON_VALUE);
    response.setCharacterEncoding("UTF-8");

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

    response.setStatus(code.value());

    try {

        Writer out = response.getWriter();
        Object obj = model.get(ENTITY);
        gson.toJson(obj, out);

    } catch (IOException e) {

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

    }
}

From source file:io.openshift.booster.service.FruitController.java

@ResponseBody
@ResponseStatus(HttpStatus.CREATED)/* www  .  j  a v  a2  s  .  co  m*/
@PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public Fruit post(@RequestBody(required = false) Fruit fruit) {
    verifyCorrectPayload(fruit);

    return repository.save(fruit);
}

From source file:springfox.documentation.spring.web.scanners.MediaTypeReader.java

@Override
public void apply(OperationContext context) {

    Set<String> consumesList = toSet(context.consumes());
    Set<String> producesList = toSet(context.produces());

    if (handlerMethodHasFileParameter(context)) {
        consumesList = newHashSet(MediaType.MULTIPART_FORM_DATA_VALUE);
    }/* w w  w .j a  v a 2s . c o m*/

    if (producesList.isEmpty()) {
        producesList.add(MediaType.ALL_VALUE);
    }
    if (consumesList.isEmpty()) {
        consumesList.add(MediaType.APPLICATION_JSON_VALUE);
    }
    context.operationBuilder().consumes(consumesList);
    context.operationBuilder().produces(producesList);
}

From source file:org.callistasoftware.netcare.api.rest.ScheduleApi.java

@RequestMapping(value = "/{id}", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody/* w ww .j  ava  2 s.  co  m*/
public ServiceResult<ScheduledActivity> report(@RequestBody final ScheduledActivity report) {
    logAccessWithoutPdl("report", "activity");
    return schedule.reportReady(report);
}

From source file:com.todo.backend.web.rest.AuthenticationApi.java

@RequestMapping(value = "/change-password", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Timed//from   w ww .  java2s  .  co  m
@Transactional
@PreAuthorize("isAuthenticated()")
public ResponseEntity<ChangePasswordResponse> changePassword(@Valid @RequestBody ChangePasswordRequest request,
        @ApiIgnore @AuthenticationPrincipal Long principalId) {
    log.debug("POST /change-password {}", request);
    final User user = userService.changePassword(principalId, request.getOldPassword(),
            request.getNewPassword());
    return ResponseEntity.ok().body(convertToChangePasswordResponse(user));
}

From source file:org.ow2.proactive.procci.rest.MixinRest.java

@RequestMapping(value = "{mixinTitle}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<MixinRendering> getMixin(@PathVariable("mixinTitle") String mixinTitle) {
    logger.debug("Getting Mixin " + mixinTitle);

    try {/*from  ww w  . j a v a2s.com*/
        return new ResponseEntity(mixinService.getMixinByTitle(mixinTitle).getRendering(), HttpStatus.OK);
    } catch (ClientException ex) {
        return new ResponseEntity(ex.getJsonError(), HttpStatus.BAD_REQUEST);
    } catch (ServerException exception) {
        return new ResponseEntity(exception.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
    }
}

From source file:com.goSmarter.activiti.loanrequest.web.LoanRequestControllerTest.java

@Before
public void setUp() {
    requestMock = new MockHttpServletRequest();
    requestMock.setContentType(MediaType.APPLICATION_JSON_VALUE);
    requestMock.setAttribute(HandlerMapping.INTROSPECT_TYPE_LEVEL_MAPPING, Boolean.FALSE);

    responseMock = new MockHttpServletResponse();

    handlerAdapter = new AnnotationMethodHandlerAdapter();
    HttpMessageConverter[] messageConverters = { new MappingJacksonHttpMessageConverter() };
    handlerAdapter.setMessageConverters(messageConverters);

    mapper = new ObjectMapper();
    loanRequest = new LoanRequest();
}

From source file:com.orange.cepheus.mockorion.AdminController.java

@RequestMapping(value = "/update", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity update(@Valid @RequestBody final Update update)
        throws ExecutionException, InterruptedException {

    UpdateContext updateContext = new UpdateContext();
    updateContext.setUpdateAction(UpdateAction.UPDATE);
    ContextElement contextElement = new ContextElement();
    contextElement.setEntityId(new EntityId(update.getName(), update.getType(), update.getIsPattern()));
    ContextAttribute contextAttribute = new ContextAttribute();
    contextAttribute.setName(update.getAttributName());
    contextAttribute.setType(update.getAttributType());
    contextAttribute.setValue(update.getAttributValue());
    contextElement.setContextAttributeList(Collections.singletonList(contextAttribute));
    updateContext.setContextElements(Collections.singletonList(contextElement));

    UpdateContextResponse updateContextResponse = ngsiClient.updateContext(cepheusBroker, null, updateContext)
            .get();/*from   ww w. j  av  a  2 s.  com*/
    logger.info("=> UpdateContextResponse received from {}: {}", cepheusBroker,
            updateContextResponse.toString());
    if (updateContextResponse.getErrorCode() == null) {
        updateContextResponse.getContextElementResponses().forEach(contextElementResponse -> {
            logger.info("EntityId : {}", contextElementResponse.getContextElement().getEntityId().toString());
            logger.info("StatusCode : {}", contextElementResponse.getStatusCode().toString());
        });
    }
    return new ResponseEntity<>(HttpStatus.OK);
}

From source file:org.oncoblocks.centromere.web.controller.CrudApiController.java

/**
 * {@code POST /}//from   w  w w  .j a v  a  2s . co  m
 * Attempts to create a new record using the submitted entity. Throws an exception if the
 *   entity already exists.
 *
 * @param entity entity representation to be persisted
 * @return updated representation of the submitted entity
 */
@RequestMapping(value = "", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE,
        ApiMediaTypes.APPLICATION_HAL_JSON_VALUE, ApiMediaTypes.APPLICATION_HAL_XML_VALUE,
        MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_PLAIN_VALUE })
public HttpEntity<?> create(@RequestBody T entity, HttpServletRequest request) {
    T created = getRepository().insert(entity);
    if (created == null)
        throw new RequestFailureException(40003, "There was a problem creating the record.", "", "");
    if (ApiMediaTypes.isHalMediaType(request.getHeader("Accept"))) {
        FilterableResource resource = getAssembler().toResource(created);
        return new ResponseEntity<>(resource, HttpStatus.CREATED);
    } else {
        return new ResponseEntity<>(created, HttpStatus.CREATED);
    }
}

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

@RequestMapping(value = "", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity createUser(Authentication _authentication, @RequestBody @Valid UserCreationRequest _ucr,
        BindingResult _bindingResult) {/*w w w . j  av  a2 s. c  o m*/

    if (_bindingResult.hasErrors()) {
        ArrayList<String> errors = new ArrayList();
        _bindingResult.getFieldErrors().forEach((FieldError t) -> {
            errors.add(t.getField() + ": " + t.getDefaultMessage());
        });
        return new ErrorResponse(mapper, HttpStatus.BAD_REQUEST, errors.toString()).response();
    }

    User u = new User(_ucr);

    if (users.create(u)) {
        return ResponseEntity.ok(u);
    } else {
        return new ErrorResponse(mapper, HttpStatus.BAD_REQUEST, "User already exists").response();
    }
}