Example usage for org.springframework.http HttpHeaders add

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

Introduction

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

Prototype

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

Source Link

Document

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

Usage

From source file:ch.ralscha.extdirectspring.controller.RouterControllerSimpleTest.java

@Test
public void methodMultipleHeaders2() throws Exception {
    HttpHeaders headers = new HttpHeaders();
    headers.add("last", "lastHeader");
    headers.add("header2", "2ndHeader");

    ControllerUtil.sendAndReceive(mockMvc, headers, "remoteProviderSimple", "method19",
            "100;default1;2ndHeader;lastHeader", 100);
}

From source file:ch.ralscha.extdirectspring.controller.RouterControllerSimpleTest.java

@Test
public void methodHeaderWithConversion() throws Exception {
    HttpHeaders headers = new HttpHeaders();
    headers.add("intHeader", "2");
    headers.add("booleanHeader", "true");

    ControllerUtil.sendAndReceive(mockMvc, headers, "remoteProviderSimple", "method20", "2;true");
    ControllerUtil.sendAndReceiveWithSession(mockMvc, headers, "remoteProviderSimple", "method20", "2;true");
}

From source file:ch.ralscha.extdirectspring.controller.RouterControllerSimpleTest.java

@Test
public void methodMultipleHeaders3() throws Exception {
    HttpHeaders headers = new HttpHeaders();
    headers.add("last", "last");
    headers.add("header1", "1st");
    headers.add("header2", "2nd");

    ControllerUtil.sendAndReceive(mockMvc, headers, "remoteProviderSimple", "method19", "100;1st;2nd;last",
            100);/* ww  w.j  a va  2 s . c  o  m*/
}

From source file:cn.org.once.cstack.cli.rest.RestUtils.java

/**
 * /*  ww  w.  ja  v  a 2s  .  c  o m*/
 * /** sendPostCommand
 *
 * @param url
 * @param parameters
 * @return
 * @throws ClientProtocolException
 */
public Map<String, Object> sendPostForUpload(String url, Map<String, Object> parameters) {
    SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
    requestFactory.setBufferRequestBody(false);

    RestTemplate restTemplate = new RestTemplate(requestFactory);
    List<HttpMessageConverter<?>> mc = restTemplate.getMessageConverters();
    mc.add(new MappingJackson2HttpMessageConverter());
    restTemplate.setMessageConverters(mc);

    MultiValueMap<String, Object> postParams = new LinkedMultiValueMap<String, Object>();
    postParams.setAll(parameters);
    Map<String, Object> response = new HashMap<String, Object>();
    HttpHeaders headers = new HttpHeaders();
    headers.set("Content-Type", "multipart/form-data");
    headers.set("Accept", "application/json");
    headers.add("Cookie", "JSESSIONID=" + localContext.getCookieStore().getCookies().get(0).getValue());
    HttpEntity<Object> request = new HttpEntity<Object>(postParams, headers);
    ResponseEntity<?> result = restTemplate.exchange(url, HttpMethod.POST, request, String.class);
    String body = result.getBody().toString();
    MediaType contentType = result.getHeaders().getContentType();
    HttpStatus statusCode = result.getStatusCode();
    response.put(CONTENT_TYPE, contentType);
    response.put(STATUS_CODE, statusCode);
    response.put(BODY, body);

    return response;

}

From source file:com.orange.ngsi.client.UpdateContextRequestTest.java

@Test
public void performPostWith200() throws Exception {

    protocolRegistry.unregisterHost(brokerUrl);

    HttpHeaders httpHeaders = ngsiClient.getRequestHeaders(brokerUrl);
    Assert.assertEquals("application/json", httpHeaders.getFirst("Content-Type"));
    Assert.assertEquals("application/json", httpHeaders.getFirst("Accept"));

    httpHeaders.add("Fiware-Service", serviceName);
    httpHeaders.add("Fiware-ServicePath", servicePath);

    String responseBody = json(jsonConverter, createUpdateContextResponseTempSensor());

    this.mockServer.expect(requestTo(brokerUrl + "/ngsi10/updateContext")).andExpect(method(HttpMethod.POST))
            .andExpect(header("Content-Type", MediaType.APPLICATION_JSON_VALUE))
            .andExpect(header("Accept", MediaType.APPLICATION_JSON_VALUE))
            .andExpect(header("Fiware-Service", serviceName))
            .andExpect(header("Fiware-ServicePath", servicePath))
            .andExpect(jsonPath("$.updateAction").value(UpdateAction.UPDATE.getLabel()))
            .andRespond(withSuccess(responseBody, MediaType.APPLICATION_JSON));

    ngsiClient.updateContext(brokerUrl, httpHeaders, createUpdateContextTempSensor(0)).get();

    this.mockServer.verify();
}

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

@SuppressWarnings("rawtypes")
private ResponseEntity<Map> deleteUser(String id, int version) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("If-Match", "\"" + version + "\"");
    return client.exchange(serverRunning.getUrl(userEndpoint + "/{id}"), HttpMethod.DELETE,
            new HttpEntity<Void>(headers), Map.class, id);
}

From source file:com.highcharts.export.controller.ExportController.java

@RequestMapping(value = "/files/{name}.{ext}", method = RequestMethod.GET)
public HttpEntity<byte[]> getFile(@PathVariable("name") String name, @PathVariable("ext") String extension)
        throws SVGConverterException, IOException {

    Path path = Paths.get(TempDir.getOutputDir().toString(), name + "." + extension);
    String filename = path.toString();
    MimeType mime = getMime(extension);

    ByteArrayOutputStream stream = writeFileToStream(filename);

    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", mime.getType() + "; charset=utf-8");
    headers.setContentLength(stream.size());

    return new HttpEntity<byte[]>(stream.toByteArray(), headers);
}

From source file:com.orange.ngsi.client.UpdateContextRequestTest.java

@Test
public void performPostWith200_XML() throws Exception {

    protocolRegistry.registerHost(brokerUrl);

    HttpHeaders httpHeaders = ngsiClient.getRequestHeaders(brokerUrl);
    Assert.assertEquals("application/xml", httpHeaders.getFirst("Content-Type"));
    Assert.assertEquals("application/xml", httpHeaders.getFirst("Accept"));

    httpHeaders.add("Fiware-Service", serviceName);
    httpHeaders.add("Fiware-ServicePath", servicePath);

    String responseBody = xml(xmlConverter, createUpdateContextResponseTempSensor());

    this.mockServer.expect(requestTo(brokerUrl + "/ngsi10/updateContext")).andExpect(method(HttpMethod.POST))
            .andExpect(header("Content-Type", MediaType.APPLICATION_XML_VALUE))
            .andExpect(header("Accept", MediaType.APPLICATION_XML_VALUE))
            .andExpect(header("Fiware-Service", serviceName))
            .andExpect(header("Fiware-ServicePath", servicePath))
            .andExpect(xpath("updateContextRequest/updateAction").string(UpdateAction.UPDATE.getLabel()))
            .andExpect(xpath("updateContextRequest/contextElementList/contextElement/entityId/id").string("S1"))
            .andExpect(xpath(// w  ww  . j  a v a 2  s  .c  om
                    "updateContextRequest/contextElementList/contextElement/contextAttributeList/contextAttribute/name")
                            .string("temp"))
            .andExpect(xpath(
                    "updateContextRequest/contextElementList/contextElement/contextAttributeList/contextAttribute/type")
                            .string("float"))
            .andExpect(xpath(
                    "updateContextRequest/contextElementList/contextElement/contextAttributeList/contextAttribute/contextValue")
                            .string("15.5"))
            .andRespond(withSuccess(responseBody, MediaType.APPLICATION_XML));

    ngsiClient.updateContext(brokerUrl, httpHeaders, createUpdateContextTempSensor(0)).get();

    this.mockServer.verify();
}

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

@Test
public void updateUserSucceeds() throws Exception {
    ResponseEntity<ScimUser> response = createUser(JOE, "Joe", "User", "joe@blah.com");
    ScimUser joe = response.getBody();//  w ww  .j  a  v  a  2  s.  c  om
    assertEquals(JOE, joe.getUserName());

    joe.setName(new ScimUser.Name("Joe", "Bloggs"));

    HttpHeaders headers = new HttpHeaders();
    headers.add("If-Match", "\"" + joe.getVersion() + "\"");
    response = client.exchange(serverRunning.getUrl(userEndpoint) + "/{id}", HttpMethod.PUT,
            new HttpEntity<ScimUser>(joe, headers), ScimUser.class, joe.getId());
    ScimUser joe1 = response.getBody();
    assertEquals(JOE, joe1.getUserName());

    assertEquals(joe.getId(), joe1.getId());

}

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

@Test
public void updateUserNameSucceeds() throws Exception {
    ResponseEntity<ScimUser> response = createUser(JOE, "Joe", "User", "joe@blah.com");
    ScimUser joe = response.getBody();/*from   w w w  .  ja va2s  .com*/
    assertEquals(JOE, joe.getUserName());

    joe.setUserName(JOE + "new");

    HttpHeaders headers = new HttpHeaders();
    headers.add("If-Match", "\"" + joe.getVersion() + "\"");
    response = client.exchange(serverRunning.getUrl(userEndpoint) + "/{id}", HttpMethod.PUT,
            new HttpEntity<ScimUser>(joe, headers), ScimUser.class, joe.getId());
    ScimUser joe1 = response.getBody();
    assertEquals(JOE + "new", joe1.getUserName());

    assertEquals(joe.getId(), joe1.getId());

}