Example usage for org.springframework.http HttpStatus SEE_OTHER

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

Introduction

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

Prototype

HttpStatus SEE_OTHER

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

Click Source Link

Document

303 See Other .

Usage

From source file:com.nebhale.gpxconverter.ApplicationController.java

@RequestMapping(method = RequestMethod.POST, value = "", consumes = MediaType.APPLICATION_XML_VALUE, produces = MediaType.IMAGE_PNG_VALUE)
ResponseEntity<Void> image(@RequestBody DOMSource source,
        @RequestParam(defaultValue = "roadmap") String maptype,
        @RequestParam(defaultValue = "500") Integer width, @RequestParam(defaultValue = "500") Integer height) {
    this.logger.info("Rendering existing GPX file");
    List<Point> points = this.parser.parsePoints((Document) source.getNode());

    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(this.mapBuilder.build(points, maptype, width, height));

    return new ResponseEntity<>(headers, HttpStatus.SEE_OTHER);
}

From source file:com.nebhale.cyclinglibrary.web.PointControllerTest.java

@Test
public void readImage() {
    List<Point> points = Arrays.asList(new Point(Double.valueOf(0), Double.valueOf(1), Double.valueOf(2)));
    Item item = new Item(Long.valueOf(0), Long.valueOf(1), Long.valueOf(2), "test-name", "test-short-name",
            points);//from w w  w. ja  va2 s .co m
    when(this.itemRepository.read(Long.valueOf(2))).thenReturn(item);
    when(this.polylineEncoder.encodeSingle(1850, points)).thenReturn("encoded-polyline");

    ResponseEntity<Void> result = this.controller.read(Long.valueOf(2), "test-map-type", 100, 200,
            "test-user-ip");

    assertEquals(HttpStatus.SEE_OTHER, result.getStatusCode());
    assertEquals(URI.create(
            "http://maps.googleapis.com/maps/api/staticmap?key=test-google-api-key&sensor=false&userIp=test-user-ip&size=100x200&maptype=test-map-type&scale=2&path=color:0xff0000ff%7Cweight:2%7Cencoded-polyline"),
            result.getHeaders().getLocation());
}

From source file:org.hobsoft.contacts.server.controller.ContactsController.java

@RequestMapping(value = "/contacts", method = RequestMethod.POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public ResponseEntity<Object> create(Contact contact) {
    contactRepository.create(contact);/*from  www  .  j  av  a 2s  .c o m*/

    Link link = contactResourceAssembler.toResource(contact).getId();
    URI location = UriComponentsBuilder.fromUriString(link.getHref()).build().toUri();

    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(location);
    return new ResponseEntity<>(headers, HttpStatus.SEE_OTHER);
}

From source file:org.hobsoft.contacts.server.controller.ContactsControllerTest.java

@Test
public void createReturnsSeeOtherAndLocation() throws URISyntaxException {
    Contact contact = new Contact();
    Resource<Contact> resource = new Resource<>(contact, new Link("x"));
    when(contactResourceAssembler.toResource(contact)).thenReturn(resource);

    ResponseEntity<Object> actual = controller.create(contact);

    assertEquals(HttpStatus.SEE_OTHER, actual.getStatusCode());
    assertEquals(new URI("x"), actual.getHeaders().getLocation());
}

From source file:com.nebhale.cyclinglibrary.web.PointController.java

@RequestMapping(method = RequestMethod.GET, produces = ApplicationMediaType.POINTS_PNG_VALUE)
@ResponseBody/* ww  w  . ja va  2 s .  c o  m*/
ResponseEntity<Void> read(@PathVariable Long itemId,
        @RequestParam(value = "maptype", defaultValue = "roadmap") String mapType,
        @RequestParam(defaultValue = "250") Integer width, @RequestParam(defaultValue = "250") Integer height,
        @Value("#{request.getRemoteAddr()}") String userIp) {

    Item item = this.itemRepository.read(itemId);

    URI uri = UriComponentsBuilder.newInstance() //
            .scheme("http") //
            .host("maps.googleapis.com") //
            .path("/maps/api/staticmap") //
            .queryParam("key", this.apiKey) //
            .queryParam("sensor", false) //
            .queryParam("userIp", userIp) //
            .queryParam("size", String.format("%dx%d", width, height)) //
            .queryParam("maptype", mapType) //
            .queryParam("scale", 2) //
            .queryParam("path",
                    String.format("color:0xff0000ff|weight:2|%s",
                            this.polylineEncoder.encodeSingle(MAX_ENCODED_LENGTH, item.getPoints()))) //
            .build().toUri();

    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(uri);

    return new ResponseEntity<>(headers, HttpStatus.SEE_OTHER);
}

From source file:org.hobsoft.contacts.server.controller.ContactsController.java

@RequestMapping(value = "/contact/{id}", method = RequestMethod.DELETE)
public ResponseEntity<Object> delete(@PathVariable long id) {
    Contact contact = contactRepository.get(id);

    contactRepository.delete(contact);//from  w w w.  ja  v a  2s  .  com

    Link link = contactResourceAssembler.toResource(contact).getLink(Relation.COLLECTION.rel());
    URI location = UriComponentsBuilder.fromUriString(link.getHref()).build().toUri();

    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(location);
    return new ResponseEntity<>(headers, HttpStatus.SEE_OTHER);
}

From source file:org.hobsoft.contacts.server.controller.ContactsControllerTest.java

@Test
public void deleteReturnsSeeOtherAndLocation() throws URISyntaxException {
    Contact contact = new Contact();
    when(contactRepository.get(1)).thenReturn(contact);

    Resource<Contact> resource = new Resource<>(contact, new Link("x", Relation.COLLECTION.rel()));
    when(contactResourceAssembler.toResource(contact)).thenReturn(resource);

    ResponseEntity<Object> actual = controller.delete(1);

    assertEquals(HttpStatus.SEE_OTHER, actual.getStatusCode());
    assertEquals(new URI("x"), actual.getHeaders().getLocation());
}