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:controllers.ImageController.java

@RequestMapping("/")
public ResponseEntity<byte[]> getImage(@RequestParam(value = "name", required = false) String name,
        @RequestParam(value = "id", required = false) String id) throws IOException {
    File file = new File("/usr/local/seller/preview/" + id + "/" + name);
    if (!file.exists()) {
        return null;
    }/*from  w  w w.  java  2  s.c o  m*/
    InputStream in = new FileInputStream(file);
    //new File("/usr/local/seller/preview/"+id+"/"+name).;
    //servletContext.getResourceAsStream("/usr/local/seller/preview/"+id+"/"+name);

    final HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.IMAGE_PNG);

    return new ResponseEntity<>(IOUtils.toByteArray(in), headers, HttpStatus.CREATED);
}

From source file:com.opensearchserver.hadse.index.IndexCatalog.java

public final static ResponseEntity<?> create(String indexName, int shards, int replicas)
        throws HadseIndexException, JsonGenerationException, JsonMappingException, IOException {
    File indexDirectory = new File(Hadse.data_dir, indexName);
    if (indexDirectory.exists())
        return new ResponseEntity<Object>(HttpStatus.CONFLICT);
    if (!indexDirectory.mkdir())
        return new ResponseEntity<String>("Unable to create the index directory",
                HttpStatus.INTERNAL_SERVER_ERROR);
    IndexItem indexItem = IndexItem.get(indexName);
    for (int shard = 1; shard <= shards; shard++) {
        String shardName = Integer.toString(shard);
        ShardDef shardDef = ShardDef.write(indexDirectory, shardName, ClusterCatalog.nextShardCandidate());
        indexItem.add(ShardItem.load(shardDef, indexDirectory));
    }// w w w .j ava  2s. c o m
    return new ResponseEntity<String>("Index created: " + indexName, HttpStatus.CREATED);
}

From source file:technology.tikal.ventas.service.envio.EnvioService.java

@RequestMapping(method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public void crear(@PathVariable final Long pedidoId, @Valid @RequestBody final Envio request,
        final BindingResult result, final HttpServletRequest httpRequest,
        final HttpServletResponse httpResponse) {
    if (result.hasErrors()) {
        throw new NotValidException(result);
    }/*from www.  j a  v a  2  s .c  om*/
    Envio nuevo = envioController.crear(pedidoId, request);
    httpResponse.setHeader("Location", httpRequest.getRequestURI() + "/" + nuevo.getId());
}

From source file:com.bennavetta.appsite.webapi.ContentController.java

@RequestMapping(value = "/upload/**", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public void uploadFile(HttpServletRequest request) throws IOException {
    MediaType type = MediaType.parse(request.getContentType());
    String path = extractPathFromPattern(request);
    log.trace("Uploading resource {} with type {}", path, type);

    Resource old = Resource.get(path);
    if (old != null) {
        log.trace("Deleting prior resource: {}", old);
        old.delete();/* w  w w .  j a v  a2 s  .co  m*/
    }

    try (InputStream in = request.getInputStream()) {
        ReadableByteChannel channel = Channels.newChannel(in);
        resources.create(path, type, channel);
    }
}

From source file:technology.tikal.ventas.service.pedido.PedidoRaizService.java

@RequestMapping(method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public void crear(@Valid @RequestBody final PedidoRaiz request, final BindingResult result,
        final HttpServletRequest httpRequest, final HttpServletResponse httpResponse) {
    if (result.hasErrors()) {
        throw new NotValidException(result);
    }/*from  w  w w.  j a  v a2 s.c om*/
    PedidoRaiz nuevo = pedidoRaizController.crear(request);
    httpResponse.setHeader("Location", httpRequest.getRequestURI() + "/" + nuevo.getId());
}

From source file:technology.tikal.ventas.service.catalogo.CatalogoService.java

@RequestMapping(method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public void crearCatalogoProducto(@Valid @RequestBody final Catalogo request, final BindingResult result,
        final HttpServletRequest httpRequest, final HttpServletResponse httpResponse) {
    if (result.hasErrors()) {
        throw new NotValidException(result);
    }/*from  ww w  .j a  v  a2s.  c o  m*/
    Catalogo nuevo = catalogoController.crear(request);
    httpResponse.setHeader("Location", httpRequest.getRequestURI() + "/" + nuevo.getId());
}

From source file:technology.tikal.ventas.service.pedido.PartidaService.java

@RequestMapping(method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public void crear(@PathVariable final Long pedidoId, @Valid @RequestBody final Partida request,
        final BindingResult result, final HttpServletRequest httpRequest,
        final HttpServletResponse httpResponse) {
    if (result.hasErrors()) {
        throw new NotValidException(result);
    }/*from   w  ww. j av a  2s . com*/
    Partida nuevo = partidaController.crear(pedidoId, request);
    httpResponse.setHeader("Location", httpRequest.getRequestURI() + "/" + nuevo.getId());
}

From source file:com.trenako.web.images.WebImageServiceTests.java

@Test
public void shouldRenderImages() {
    GridFSDBFile mockFile = mock(GridFSDBFile.class);
    when(mockFile.getContentType()).thenReturn(MediaType.IMAGE_JPEG.toString());
    when(mockFile.getInputStream()).thenReturn(new ByteArrayInputStream(new byte[] {}));

    when(repo.findFileBySlug(eq("img-slug"))).thenReturn(mockFile);

    ResponseEntity<byte[]> resp = service.renderImage("img-slug");

    assertNotNull(resp);//  w  ww . java  2s.  com
    assertTrue(resp.hasBody());
    assertEquals(HttpStatus.CREATED, resp.getStatusCode());
    assertEquals(MediaType.IMAGE_JPEG, resp.getHeaders().getContentType());
}

From source file:de.codecentric.boot.admin.controller.RegistryControllerTest.java

@Test
public void register_twice() {
    controller.register(new Application("http://localhost", "test"));
    Application app = new Application("http://localhost", "test");
    ResponseEntity<Application> response = controller.register(app);

    assertEquals(HttpStatus.CREATED, response.getStatusCode());
    assertEquals("http://localhost", response.getBody().getUrl());
    assertEquals("test", response.getBody().getName());
}

From source file:de.sainth.recipe.backend.rest.controller.UnitController.java

@Secured("ROLE_ADMIN")
@RequestMapping(method = RequestMethod.POST)
HttpEntity<Unit> add(@Valid @RequestBody Unit unit) {
    Unit u = repository.save(unit);//w ww  .jav  a 2 s  .  c om
    return new ResponseEntity<>(u, HttpStatus.CREATED);
}