Example usage for org.springframework.http HttpHeaders HttpHeaders

List of usage examples for org.springframework.http HttpHeaders HttpHeaders

Introduction

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

Prototype

public HttpHeaders() 

Source Link

Document

Construct a new, empty instance of the HttpHeaders object.

Usage

From source file:org.projecthdata.social.api.impl.HDataTemplateTest.java

@Test
public void test() {
    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.setContentType(MediaType.APPLICATION_XML);

    mockServer.expect(requestTo("http://hstore.com/1234/root.xml")).andExpect(method(GET)).andRespond(
            withResponse(new ClassPathResource("../../resources/root.xml", getClass()), responseHeaders));

    Root root = hDataTemplate.getRootOperations().getRoot();
    assertEquals(5, root.getExtensions().size());
}

From source file:com.w3ma.m3u8web.controller.DownloadPlaylistController.java

@RequestMapping(value = "/playlist", method = RequestMethod.GET, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public ResponseEntity<ByteArrayResource> getPlaylist(final HttpServletResponse response) throws IOException {
    logger.debug("getPlaylist called");
    final HttpHeaders headers = new HttpHeaders();
    response.setHeader("Content-Disposition", "attachment; filename=playlist.m3u");
    return new ResponseEntity<>(
            new ByteArrayResource(playlistGeneratorService.getPlaylistByteArrayOutputStream().toByteArray()),
            headers, HttpStatus.OK);/* w  w  w.  ja v  a  2  s  .c om*/
}

From source file:com.aspose.showcase.qrcodegen.web.api.controller.RestResponseEntityExceptionHandler.java

@ExceptionHandler(value = { BarCodeException.class })
protected ResponseEntity<Object> handleConflict(RuntimeException ex, WebRequest request) {

    String bodyOfResponse = "Internal Server Error";
    HttpStatus httpStatus = HttpStatus.INTERNAL_SERVER_ERROR;

    String detailMessage = ex.getLocalizedMessage();

    if (detailMessage == null) {
        bodyOfResponse = "Internal Server Error";
        httpStatus = HttpStatus.INTERNAL_SERVER_ERROR;

    } else if (detailMessage.contains("evaluation version")) {

        bodyOfResponse = "Please upgrade to paid license to avail this feature. \n Internal Error - "
                + ex.getMessage();/* w w w.j  a  v  a  2s .c  o  m*/
        httpStatus = HttpStatus.PAYMENT_REQUIRED;

    } else {
        bodyOfResponse = ex.getMessage();
        httpStatus = HttpStatus.INTERNAL_SERVER_ERROR;

    }

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.TEXT_PLAIN);

    return handleExceptionInternal(ex, bodyOfResponse, headers, httpStatus, request);
}

From source file:sample.RestTests.java

@Test(expected = HttpClientErrorException.class)
public void unauthenticatedUserSentToLogInPage() {
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
    ResponseEntity<String> entity = getForUser(this.baseUrl + "/", headers, String.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
}

From source file:org.cloudfoundry.identity.uaa.integration.LoginInfoEndpointIntegrationTests.java

/**
 * tests a happy-day flow of the <code>/login</code> endpoint
 *//*from  ww  w  . j a v a 2  s.  co  m*/
@Test
public void testHappyDayHtml() throws Exception {

    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));

    HttpStatus status = HttpStatus.FOUND;
    String location = "/login";
    ResponseEntity<Void> response = null;
    while (status == HttpStatus.FOUND) {
        response = serverRunning.getForResponse(location, headers);
        status = response.getStatusCode();
        if (status == HttpStatus.FOUND) {
            location = response.getHeaders().getLocation().toString();
            System.err.println("Redirected to " + location);
        }
    }

    ResponseEntity<String> finalResponse = serverRunning.getForString(location, headers);
    String body = finalResponse.getBody().toString();
    // System.err.println(body);
    assertNotNull(body);
    assertTrue("Wrong body: " + body, body.contains("<form id="));

}

From source file:monkeys.web.MonkeysController.java

@RequestMapping(method = RequestMethod.DELETE, value = "/{id}")
public ResponseEntity<Void> deleteMonkey(@PathVariable Long id) {
    monkeyRepository.delete(id);// www  .j  a  v a  2  s  .  c om
    HttpHeaders headers = new HttpHeaders();
    return new ResponseEntity<>(headers, HttpStatus.OK);
}

From source file:cz.muni.fi.mushroomhunter.restclient.MushroomUpdateSwingWorker.java

@Override
protected Integer doInBackground() throws Exception {
    DefaultTableModel model = (DefaultTableModel) restClient.getTblMushroom().getModel();
    int selectedRow = restClient.getTblMushroom().getSelectedRow();

    RestTemplate restTemplate = new RestTemplate();

    String plainCreds = RestClient.USER_NAME + ":" + RestClient.PASSWORD;
    byte[] plainCredsBytes = plainCreds.getBytes();
    byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes);
    String base64Creds = new String(base64CredsBytes);

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    List<MediaType> mediaTypeList = new ArrayList<>();
    mediaTypeList.add(MediaType.ALL);/*from  ww w .j  a  v  a2  s . c o  m*/
    headers.setAccept(mediaTypeList);

    headers.add("Authorization", "Basic " + base64Creds);

    HttpEntity request = new HttpEntity<>(headers);

    ResponseEntity<MushroomDto> responseEntity = restTemplate.exchange(
            RestClient.SERVER_URL + "pa165/rest/mushroom/" + RestClient.getMushroomIDs().get(selectedRow),
            HttpMethod.GET, request, MushroomDto.class);

    MushroomDto mushroomDto = responseEntity.getBody();

    mushroomDto.setName(restClient.getTfMushroomName().getText());

    SimpleDateFormat formatter = new SimpleDateFormat("dd-MMMM-yyyy", new Locale("en_US"));

    //to create date object only month is used, day and year are fixed values
    String dateInString = "01-" + restClient.getComboBoxMushroomStartOfOccurence().getSelectedItem().toString()
            + "-2000";
    mushroomDto.setStartOfOccurence(formatter.parse(dateInString));

    //to create date object only month is used, day and year are fixed values
    dateInString = "01-" + restClient.getComboBoxMushroomEndOfOccurence().getSelectedItem().toString()
            + "-2000";
    mushroomDto.setEndOfOccurence(formatter.parse(dateInString));

    ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
    String json = ow.writeValueAsString(mushroomDto);
    request = new HttpEntity(json, headers);

    restTemplate.exchange(RestClient.SERVER_URL + "pa165/rest/mushroom", HttpMethod.PUT, request,
            MushroomDto.class);
    return selectedRow;
}

From source file:com.appglu.impl.AbstractAppGluApiTest.java

@Before
public void setup() {
    /* Setting time zone to GMT+0 avoiding time zone issues in tests */
    TimeZone gmt = TimeZone.getTimeZone("GMT");
    TimeZone.setDefault(gmt);//from  w ww  .jav  a2  s  .  c o  m

    appGluTemplate = createAppGluTemplate();

    mockServer = MockRestServiceServer.createServer(appGluTemplate.getRestTemplate());

    responseHeaders = new HttpHeaders();
    responseHeaders.setContentType(jsonMediaType);
}

From source file:org.cloudfoundry.identity.batch.integration.BatchEndpointIntegrationTests.java

/**
 * tests a unauthorized flow of the <code>/batch</code> endpoint
 *///from  w  w  w.  j ava  2  s  .c o m
@Test
public void testUnauthorized() throws Exception {

    HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization",
            String.format("Basic %s", new String(Base64.encode("batch:bogus".getBytes()))));
    ResponseEntity<String> response = serverRunning.getForString("/batch/", headers);
    assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());

    String map = response.getBody();
    // System.err.println(map);
    assertTrue(map.contains("{\"error\""));

}

From source file:io.getlime.push.service.fcm.FcmClient.java

/**
 * Create a new FCM service client.// www.  j  a  v  a 2 s .  com
 * @param serverKey Server key tp be used.
 */
public FcmClient(String serverKey) {
    headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    headers.set("Authorization", "key=" + serverKey);
    restTemplate = new AsyncRestTemplate();
}