Example usage for org.springframework.http HttpStatus CREATED

List of usage examples for org.springframework.http HttpStatus CREATED

Introduction

In this page you can find the example usage for org.springframework.http HttpStatus CREATED.

Prototype

HttpStatus CREATED

To view the source code for org.springframework.http HttpStatus CREATED.

Click Source Link

Document

201 Created .

Usage

From source file:org.apigw.authserver.web.admin.v1.controller.CertifiedClientRestController.java

@RequestMapping(method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public CertifiedClientDTO create(@Valid @RequestBody CertifiedClientDTO client) {
    //TODO: Add more validations to DTO
    CertifiedClient mappedClient = mapper.map(client, CertifiedClient.class);
    CertifiedClient persisted = service.store(mappedClient);
    return mapper.map(persisted, CertifiedClientDTO.class);
}

From source file:com.alehuo.wepas2016projekti.controller.ImageController.java

/**
 * Hakee tietokannasta kuvan. Kuvan hakemisessa hydynnetn ETag
 * -otsaketta./*  w w  w .  j  a  v  a2s .c o  m*/
 *
 * @param a Autentikointi
 * @param imageUuid Kuvan UUID
 * @param ifNoneMatch If-None-Match -headeri vlimuistia varten
 * @return Kuva
 */
@RequestMapping(value = "/{imageUuid}", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<byte[]> getImage(Authentication a, @PathVariable String imageUuid,
        @RequestHeader(required = false, value = "If-None-Match") String ifNoneMatch) {
    if (ifNoneMatch != null) {
        //            LOG.log(Level.INFO, "Kuva ''{0}'' loytyy kayttajan selaimen valimuistista eika sita tarvitse ladata. Kuvaa pyysi kayttaja ''{1}''", new Object[]{imageUuid, a.getName()});
        //Jos If-None-Match -headeri lytyy, niin lhet NOT MODIFIED vastaus
        return new ResponseEntity<>(HttpStatus.NOT_MODIFIED);
    }
    Image i = imageService.findOneImageByUuid(imageUuid);
    if (i != null && i.isVisible()) {
        //Luodaan ETag kuvalle
        final HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.parseMediaType(i.getContentType()));
        headers.setContentLength(i.getImageData().length);
        headers.setCacheControl("public");
        headers.setExpires(Long.MAX_VALUE);
        headers.setETag("\"" + imageUuid + "\"");
        //            LOG.log(Level.INFO, "Kuva ''{0}'' loytyi tietokannasta, ja sita pyysi kayttaja ''{1}''", new Object[]{imageUuid, a.getName()});
        //Palautetaan kuva uutena resurssina
        return new ResponseEntity<>(i.getImageData(), headers, HttpStatus.CREATED);
    } else {
        //Jos kuvaa ei lydy tietokannasta
        LOG.log(Level.WARNING, "Kuvaa ''{0}'' ei loytynyt tietokannasta, ja sita pyysi kayttaja ''{1}''",
                new Object[] { imageUuid, a.getName() });
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }
}

From source file:com.fredhopper.core.connector.index.upload.impl.RestPublishingStrategy.java

@Override
public String uploadDataSet(final InstanceConfig config, final File file) throws ResponseStatusException {
    Preconditions.checkArgument(config != null);
    Preconditions.checkArgument(file != null);

    final RestTemplate restTemplate = restTemplateProvider.createTemplate(config.getHost(), config.getPort(),
            config.getUsername(), config.getPassword());
    final String checkSum = createCheckSum(file);

    final List<NameValuePair> params = Arrays
            .asList(new NameValuePair[] { new BasicNameValuePair("checksum", checkSum) });
    final URI url = createUri(config.getScheme(), config.getHost(), config.getPort(), config.getServername(),
            UPLOAD_PATH, params);//  w ww.  java  2  s. co  m

    final HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.valueOf("application/zip"));
    final HttpEntity<Resource> httpEntity = new HttpEntity<>(new FileSystemResource(file), headers);

    final ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.PUT, httpEntity,
            String.class);

    final HttpStatus status = response.getStatusCode();
    if (status.equals(HttpStatus.CREATED)) {
        return response.getBody().trim();
    } else {
        throw new ResponseStatusException(
                "HttpStatus " + status.toString() + " response received. File upload failed.");
    }
}

From source file:org.openwms.core.uaa.api.RolesController.java

/**
 * Documented here: https://openwms.atlassian.net/wiki/x/BIAWAQ
 *
 * @param role The {@link Role} instance to be created
 * @return An {@link Response} object to encapsulate the result of the creation operation
 * @status Reviewed [scherrer]/*from   ww  w.j a  v  a  2  s  .co m*/
 */
@PostMapping
@ResponseBody
public ResponseEntity<Response<RoleVO>> create(@RequestBody @Valid @NotNull RoleVO role, HttpServletRequest req,
        HttpServletResponse resp) {
    RoleVO createdRole = m.map(service.save(m.map(role, Role.class)), RoleVO.class);
    resp.addHeader(HttpHeaders.LOCATION, getLocationForCreatedResource(req, createdRole.getId().toString()));
    return buildResponse(HttpStatus.CREATED, translate(Messages.CREATED), Messages.CREATED);
}

From source file:org.openbaton.autoscaling.api.RestEventInterface.java

/**
 * Stops autoscaling for the passed NSR//from   w w  w.j av  a  2 s.  co m
 *
 * @param msg : NSR in payload to add for autoscaling
 */
@RequestMapping(value = "ERROR", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.CREATED)
public void stop(@RequestBody String msg) throws NotFoundException {
    log.debug("========================");
    log.debug("msg=" + msg);
    JsonParser jsonParser = new JsonParser();
    JsonObject json = jsonParser.parse(msg).getAsJsonObject();
    Gson mapper = new GsonBuilder().create();
    Action action = mapper.fromJson(json.get("action"), Action.class);
    log.debug("ACTION=" + action);
}

From source file:org.nekorp.workflow.backend.security.controller.imp.UsuarioClienteWebControllerImp.java

/**{@inheritDoc}*/
@Override/*from   www . java  2s . com*/
@RequestMapping(method = RequestMethod.POST)
public void crear(@Valid @RequestBody final UsuarioClienteWeb datos, final HttpServletResponse response) {
    datos.setAlias(StringUtils.lowerCase(datos.getAlias()));
    UsuarioClienteWeb resultado = usuarioClienteWebDAO.consultar(datos.getAlias());
    if (resultado != null) {
        response.setStatus(HttpStatus.BAD_REQUEST.value());
        return;
    }
    Cliente cliente = clienteDao.consultar(datos.getIdCliente());
    if (cliente == null) {
        response.setStatus(HttpStatus.BAD_REQUEST.value());
        return;
    }
    this.usuarioClienteWebDAO.guardar(datos);
    response.setStatus(HttpStatus.CREATED.value());
    response.setHeader("Location", "/cliente/web/usuarios/" + datos.getAlias());
}

From source file:com.onedrive.api.resource.support.UploadSession.java

public UploadSession uploadFragment(long startIndex, long endIndex, long totalSize, byte[] data) {
    Assert.notNull(uploadUrl, "UploadSession instance invalid. The uploadUrl is not defined.");
    Assert.notNull(data, "The data is required.");
    MultiValueMap<String, String> headers = new LinkedMultiValueMap<String, String>();
    headers.add("Content-Range", "bytes " + startIndex + "-" + endIndex + "/" + totalSize);
    ResponseEntity<UploadSession> response = getOneDrive().getRestTemplate().exchange(uploadUri(),
            HttpMethod.PUT, new HttpEntity<ByteArrayResource>(new ByteArrayResource(data), headers),
            UploadSession.class);
    UploadSession session = response.getBody();
    session.setUploadUrl(uploadUrl);//ww  w . ja  va 2 s.c  o  m
    session.complete = response.getStatusCode().equals(HttpStatus.CREATED)
            || response.getStatusCode().equals(HttpStatus.OK);
    return session;
}

From source file:com.wujiabo.opensource.feather.rest.controller.RbacRestController.java

@RequestMapping(value = "/group/create", method = RequestMethod.POST, consumes = MediaTypes.JSON)
public ResponseEntity<?> create(@RequestBody TGroup group, UriComponentsBuilder uriBuilder) {
    // JSR303 Bean Validator, RestExceptionHandler?.
    RestValidation.validateWithException(validator, group);

    // // ?/*from  w ww. j a v  a2  s .co  m*/
    // taskService.saveTask(group);
    //
    // // Restful?url, ?id.
    // Long id = task.getId();
    // URI uri = uriBuilder.path("/api/v1/task/" + id).build().toUri();
    HttpHeaders headers = new HttpHeaders();
    // headers.setLocation(uri);

    return new ResponseEntity(headers, HttpStatus.CREATED);
}

From source file:org.nekorp.workflow.backend.controller.imp.EventoControllerImp.java

@Override
@RequestMapping(method = RequestMethod.POST)
public void crearEvento(@PathVariable final Long idServicio, @Valid @RequestBody final Evento dato,
        final HttpServletResponse response) {
    dato.setId(null);/*from  ww  w  . java2 s  .  co m*/
    if (!idServicioValido(idServicio)) {
        response.setStatus(HttpStatus.NOT_FOUND.value());
        return;
    }
    this.eventoDAO.guardar(idServicio, dato);
    response.setStatus(HttpStatus.CREATED.value());
    response.setHeader("Location", "/servicios/" + idServicio + "/bitacora/eventos/" + dato.getId());

}

From source file:de.hska.ld.core.controller.UserControllerIntegrationTest.java

@Test
public void testUpdateUsernameUsesHttpConflictIfAlreadyExists() throws Exception {
    User user = newUser();/*from   w  ww .  j a  v  a  2s. com*/

    HttpResponse response = UserSession.admin().post(RESOURCE_USER, user);
    Assert.assertEquals(HttpStatus.CREATED, ResponseHelper.getStatusCode(response));

    HttpResponse response2 = UserSession.admin().post(RESOURCE_USER, user);
    Assert.assertEquals(HttpStatus.CONFLICT, ResponseHelper.getStatusCode(response2));
}