Example usage for org.springframework.http HttpHeaders set

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

Introduction

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

Prototype

@Override
public void set(String headerName, @Nullable String headerValue) 

Source Link

Document

Set the given, single header value under the given name.

Usage

From source file:org.cloudfoundry.identity.uaa.api.group.impl.UaaGroupOperationsImpl.java

private ScimGroup updateGroup(ScimGroup group) {
    Assert.notNull(group);/*from   ww w.  jav  a  2 s .c  om*/

    HttpHeaders headers = new HttpHeaders();
    headers.set("if-match", String.valueOf(group.getMeta().getVersion()));

    return helper.putScimObject("/Groups/{id}", group, GROUP_REF, group.getId());
}

From source file:org.mifosplatform.mpesa.controller.MifosMpesaController.java

@RequestMapping(value = "/getunmappedtransactions", method = RequestMethod.GET)
public @ResponseBody ResponseEntity<Collection<Mpesa>> retriveUnmappedTransactions(
        @QueryParam("officeId") final Long officeId) {
    Collection<Mpesa> transactionDetails = null;
    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.set("Access-Control-Allow-Origin", "*");
    responseHeaders.set("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT, OPTIONS");
    //responseHeaders.setOrigin("*");
    try {/*  www.ja v  a 2s .c o  m*/
        this.mpesaBridgeService.retriveAllTransactions(officeId);
        transactionDetails = this.mpesaBridgeService.retriveUnmappedTransactions(officeId);
    } catch (Exception e) {
        logger.error("Exception " + e);
    }

    return new ResponseEntity<Collection<Mpesa>>(transactionDetails, HttpStatus.OK);
}

From source file:com.xyxy.platform.examples.showcase.functional.rest.UserRestFT.java

/**
 * exchange()?Headers.//ww w.  jav  a  2s .  com
 * xml??.
 * jdk connection.
 */
@Test
public void getUserAsXML() {
    // Http Basic?
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.set(com.google.common.net.HttpHeaders.AUTHORIZATION,
            Servlets.encodeHttpBasic("admin", "admin"));
    System.out.println("Http header is" + requestHeaders);
    HttpEntity<?> requestEntity = new HttpEntity(requestHeaders);

    try {
        HttpEntity<UserDTO> response = jdkTemplate.exchange(resourceUrl + "/{id}.xml", HttpMethod.GET,
                requestEntity, UserDTO.class, 1L);
        assertThat(response.getBody().getLoginName()).isEqualTo("admin");
        assertThat(response.getBody().getName()).isEqualTo("?");
        assertThat(response.getBody().getTeamId()).isEqualTo(1);

        // ?XML
        HttpEntity<String> xml = jdkTemplate.exchange(resourceUrl + "/{id}.xml", HttpMethod.GET, requestEntity,
                String.class, 1L);
        System.out.println("xml output is " + xml.getBody());
    } catch (HttpStatusCodeException e) {
        fail(e.getMessage());
    }
}

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

@Test
public void testGetClientInfo() throws Exception {

    HttpHeaders headers = new HttpHeaders();
    AuthorizationCodeResourceDetails app = testAccounts.getDefaultAuthorizationCodeResource();
    headers.set("Authorization", testAccounts.getAuthorizationHeader(app.getClientId(), app.getClientSecret()));
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));

    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> response = serverRunning.getForObject("/clientinfo", Map.class, headers);
    assertEquals(HttpStatus.OK, response.getStatusCode());
    assertEquals(app.getClientId(), response.getBody().get("client_id"));

}

From source file:org.kurento.repository.test.RangePutTests.java

private ResponseEntity<String> putContent(String url, byte[] info, int firstByte) {

    RestTemplate httpClient = getRestTemplate();

    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.set("Content-Range", "bytes " + firstByte + "-" + (firstByte + info.length) + "/*");
    requestHeaders.set("Content-Length", Integer.toString(info.length));

    HttpEntity<byte[]> requestEntity = new HttpEntity<byte[]>(info, requestHeaders);

    ResponseEntity<String> response = httpClient.exchange(url, HttpMethod.PUT, requestEntity, String.class);

    log.info("Put " + info.length + " bytes from " + firstByte + " to " + (firstByte + info.length));

    return response;

}

From source file:org.zalando.riptide.ActionsTest.java

@Test
public void shouldNormalizeContentLocation() {
    final HttpHeaders headers = new HttpHeaders();
    headers.set(CONTENT_LOCATION, "/accounts/456");
    server.expect(requestTo(url)).andRespond(withSuccess().headers(headers));

    final URI location = unit.execute(GET, url)
            .dispatch(series(), on(SUCCESSFUL).map(normalize(url).andThen(contentLocation())).capture())
            .to(URI.class);

    assertThat(location, hasToString("https://api.example.com/accounts/456"));

}

From source file:nl.surfnet.coin.api.AbstractApiController.java

/**
 * Handle CORS preflight request.//from  w  w w .  j a va  2  s .co  m
 * 
 * @param origin
 *          the Origin header
 * @param methods
 *          the "Access-Control-Request-Method" header
 * @param headers
 *          the "Access-Control-Request-Headers" header
 * @return a ResponseEntity with 204 (no content) and the right response
 *         headers
 */
@RequestMapping(method = RequestMethod.OPTIONS, value = "/**")
public ResponseEntity<String> preflightCORS(@RequestHeader("Origin") String origin,
        @RequestHeader(value = "Access-Control-Request-Method", required = false) String[] methods,
        @RequestHeader(value = "Access-Control-Request-Headers", required = false) String[] headers) {
    LOG.debug("Hitting CORS preflight handler. Origin header: {}, methods: {}, headers: {}",
            new Object[] { origin, methods, headers });

    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.set("Allow", "GET,OPTIONS,HEAD");
    responseHeaders.set("Access-Control-Allow-Methods", "GET,OPTIONS,HEAD");
    responseHeaders.set("Access-Control-Allow-Headers", "Authorization");
    responseHeaders.set("Access-Control-Max-Age", "86400"); // allow cache of 1
                                                            // day
    return new ResponseEntity<String>(null, responseHeaders, HttpStatus.OK);
}

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

@Test
public void testUnauthenticated() throws Exception {

    HttpHeaders headers = new HttpHeaders();
    ResourceOwnerPasswordResourceDetails app = testAccounts.getDefaultResourceOwnerPasswordResource();
    headers.set("Authorization", testAccounts.getAuthorizationHeader(app.getClientId(), "bogus"));
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));

    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> response = serverRunning.getForObject("/clientinfo", Map.class, headers);
    assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());
    assertEquals("unauthorized", response.getBody().get("error"));

}

From source file:org.obiba.mica.core.service.MailService.java

private synchronized void sendEmail(String subject, String text, String recipient) {
    try {//from w ww. j  ava  2 s.co  m
        RestTemplate template = newRestTemplate();
        HttpHeaders headers = new HttpHeaders();
        headers.set(APPLICATION_AUTH_HEADER, getApplicationAuth());
        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
        String form = (Strings.isNullOrEmpty(recipient) ? "" : recipient + "&") + "subject="
                + encode(subject, "UTF-8") + "&body=" + encode(text, "UTF-8");
        HttpEntity<String> entity = new HttpEntity<>(form, headers);

        ResponseEntity<String> response = template.exchange(getNotificationsUrl(), HttpMethod.POST, entity,
                String.class);

        if (response.getStatusCode().is2xxSuccessful()) {
            log.info("Email sent via Agate");
        } else {
            log.error("Sending email via Agate failed with status: {}", response.getStatusCode());
        }
    } catch (Exception e) {
        log.error("Agate connection failure: {}", e.getMessage());
    }
}

From source file:io.github.cdelmas.spike.springboot.car.CarsController.java

@RequestMapping(method = RequestMethod.POST, consumes = "application/json")
public ResponseEntity<CarRepresentation> create(@RequestBody Car car) {
    carRepository.save(car);//from  w  ww . j  a va  2  s.  co m
    HttpHeaders responseHeaders = new HttpHeaders();
    Link link = linkTo(methodOn(CarsController.class).byId(String.valueOf(car.getId()))).withSelfRel();
    responseHeaders.set("Location", link.getHref());
    return new ResponseEntity<>(responseHeaders, HttpStatus.CREATED);
}