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.energyos.espi.thirdparty.repository.impl.ResourceRESTRepositoryImpl.java

public IdentifiedObject get(Authorization authorization, String url) {
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.set("Authorization", "Bearer " + authorization.getAccessToken());
    @SuppressWarnings({ "rawtypes", "unchecked" })
    HttpEntity<?> requestEntity = new HttpEntity(requestHeaders);

    HttpEntity<String> response = template.exchange(url, HttpMethod.GET, requestEntity, String.class);

    return (IdentifiedObject) marshaller.unmarshal(new StreamSource(response.getBody()));
}

From source file:com.codeabovelab.dm.gateway.filestorage.GetResponseExtractor.java

@Override
public Object extractData(ClientHttpResponse response) throws IOException {
    HttpHeaders headers = new HttpHeaders();
    headers.putAll(response.getHeaders());
    for (Map.Entry<String, List<String>> e : headers.entrySet()) {
        List<String> values = e.getValue();
        for (int i = 0; i < values.size(); i++) {
            final String key = e.getKey();
            if (FORBIDDEN_HEADERS.contains(key)) {
                continue;
            }//from w  ww  .  j a  va2s.  c  om
            servletResponse.setHeader(key, values.get(i));
        }
    }
    try (InputStream is = response.getBody(); ServletOutputStream os = servletResponse.getOutputStream()) {
        IOUtils.copy(is, os);
        servletResponse.flushBuffer();

    }
    return null;
}

From source file:org.devefx.httpmapper.http.HttpEntity.java

/**
 * Create a new {@code HttpEntity} with the given body and headers.
 * @param body the entity body//from  w  w  w .  jav a 2s  . c  om
 * @param headers the entity headers
 */
public HttpEntity(T body, MultiValueMap<String, String> headers) {
    this.body = body;
    HttpHeaders tempHeaders = new HttpHeaders();
    if (headers != null) {
        tempHeaders.putAll(headers);
    }
    this.headers = tempHeaders;
}

From source file:edu.fing.tagsi.db4o.business.TrackingController.java

public List<Tracking> getTracking(UUID id) {
    RestTemplate restTemplate = new RestTemplate();
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    HttpEntity entity = new HttpEntity(headers);

    ResponseEntity<RequestTrackingAddPackage[]> tracking = restTemplate.exchange(
            ConfigController.getInstance().getURLFindTracking() + "/" + id.toString(), GET, entity,
            RequestTrackingAddPackage[].class);

    if (tracking != null) {
        List<Tracking> resultado = new ArrayList<>(tracking.getBody().length);
        for (RequestTrackingAddPackage r : tracking.getBody()) {

            resultado.add(new Tracking(UUID.fromString(r.getIdpaquete()), UUID.fromString(r.getIdcliente()),
                    UUID.fromString(r.getIdlugar()), r.getFecha(), r.isEsdestino()));
        }/*from w ww  .j a v a2  s. co  m*/
        return resultado;
    } else {
        return null;
    }

}

From source file:net.eusashead.hateoas.conditional.interceptor.SyncTestController.java

@RequestMapping(method = RequestMethod.PUT)
public ResponseEntity<Void> put() {
    HttpHeaders headers = new HttpHeaders();
    headers.setETag("\"123456\"");
    return new ResponseEntity<Void>(headers, HttpStatus.NO_CONTENT);
}

From source file:org.schedoscope.metascope.controller.MetascopeAdminControllerTest.java

@Test
public void sometest() throws Exception {
    HttpHeaders headers = new HttpHeaders();
    headers.set("Referer", "/test");
    HttpEntity<String> entity = new HttpEntity<String>("parameters", headers);

    ResponseEntity<String> response = this.restTemplate.exchange("/admin/sync", HttpMethod.POST, entity,
            String.class);
    assertEquals(302, response.getStatusCodeValue());
    assertTrue(response.getHeaders().get("Location").get(0).endsWith("/test"));
}

From source file:com.alcatel.hello.actuator.ui.SampleActuatorUIApplicationTests.java

@Test
public void testHome() throws Exception {
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
    ResponseEntity<String> entity = new TestRestTemplate().exchange("http://localhost:" + this.port,
            HttpMethod.GET, new HttpEntity<Void>(headers), String.class);

    assertEquals(HttpStatus.OK, entity.getStatusCode());
    assertTrue("Wrong body (title doesn't match):\n" + entity.getBody(),
            entity.getBody().contains("<title>Hello"));
}

From source file:com.neu.controller.APIController.java

@RequestMapping(value = "/apicall.htm", method = RequestMethod.POST, headers = "Accept=*/*", produces = "application/json")
@ResponseStatus(HttpStatus.OK)/*w  w  w  .jav  a2 s  .  c  o  m*/
public @ResponseBody String searchresult(HttpServletRequest request) throws Exception {
    Map pmap = request.getParameterMap();
    System.out.println("in drugsearch controller");
    String action = request.getParameter("action");
    String urlRestWebService = "https://ussouthcentral.services.azureml.net/workspaces/168eb4a3d72e4b078160213fcdaa4333/services/ee080088b48141e0af10c9913067689d/execute?api-version=2.0&details=true";
    HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization",
            "Bearer AJacooh+WG4WeJTntLNn/E3A3E4yQELYY8S6/2sbpcsBvNFSCabuopvuiqlnrd47a0qBf4Coj1LMcEhBUm0Ujw==");
    headers.add("Content-Length", "100000");
    headers.add("Content-Type", "application/json");

    String requestJson = "{'Inputs': {'input1': {'ColumnNames': [ 'drugname','route','dose_amt','dose_unit','dose_form', 'dose_freq','mfr_sndr','pt'],'Values':[['"
            + pmap.get("drugname") + "','" + pmap.get("reactionlist") + "','" + pmap.get("doseform") + "','"
            + pmap.get("doseunit") + "','" + pmap.get("dosefreq") + "','" + pmap.get("mfndetails") + "','"
            + pmap.get("route") + "','" + pmap.get("doseamt") + "']]}},'GlobalParameters': {}}";

    HttpEntity<String> entity = new HttpEntity<String>(requestJson, headers);
    System.out.println("entity" + entity);
    RestTemplate restTemplate = new RestTemplate();

    String restData = restTemplate.postForObject(urlRestWebService, entity, String.class);

    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(SerializationConfig.Feature.INDENT_OUTPUT);
    mapper.writeValue(System.out, restData);

    //            Drugs drug=new Drugs("AZ","sn");
    return mapper.writeValueAsString(restData);
}

From source file:com.joseph.california.test.restapi.PersonRestControllerTest.java

private HttpEntity<?> getHttpEntity() {
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.setAccept(Collections.singletonList(new MediaType("application", "json")));
    HttpEntity<?> requestEntity = new HttpEntity<Object>(requestHeaders);
    restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
    return requestEntity;
}