Search in sources :

Example 1 with HttpHeaders

use of org.springframework.http.HttpHeaders in project spring-boot-admin by codecentric.

the class HipchatNotifier method createHipChatNotification.

protected HttpEntity<Map<String, Object>> createHipChatNotification(ClientApplicationEvent event) {
    Map<String, Object> body = new HashMap<>();
    body.put("color", getColor(event));
    body.put("message", getMessage(event));
    body.put("notify", getNotify());
    body.put("message_format", "html");
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    return new HttpEntity<>(body, headers);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) HashMap(java.util.HashMap)

Example 2 with HttpHeaders

use of org.springframework.http.HttpHeaders in project spring-boot-admin by codecentric.

the class ApplicationOperations method doGet.

protected <T> ResponseEntity<T> doGet(Application application, URI uri, Class<T> responseType) {
    LOGGER.debug("Fetching '{}' for {}", uri, application);
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(asList(MediaType.APPLICATION_JSON));
    headers.putAll(httpHeadersProvider.getHeaders(application));
    ResponseEntity<T> response = restTemplate.exchange(uri, HttpMethod.GET, new HttpEntity<Void>(headers), responseType);
    LOGGER.debug("'{}' responded with {}", uri, response);
    return response;
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders)

Example 3 with HttpHeaders

use of org.springframework.http.HttpHeaders in project spring-boot-admin by codecentric.

the class ApplicationRegistratorTest method setup.

@Before
public void setup() {
    restTemplate = mock(RestTemplate.class);
    adminProps = new AdminProperties();
    adminProps.setUrl(new String[] { "http://sba:8080", "http://sba2:8080" });
    ApplicationFactory factory = mock(ApplicationFactory.class);
    when(factory.createApplication()).thenReturn(Application.create("AppName").withManagementUrl("http://localhost:8080/mgmt").withHealthUrl("http://localhost:8080/health").withServiceUrl("http://localhost:8080").build());
    registrator = new ApplicationRegistrator(restTemplate, adminProps, factory);
    headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
}
Also used : AdminProperties(de.codecentric.boot.admin.client.config.AdminProperties) HttpHeaders(org.springframework.http.HttpHeaders) ApplicationRegistrator(de.codecentric.boot.admin.client.registration.ApplicationRegistrator) RestTemplate(org.springframework.web.client.RestTemplate) ApplicationFactory(de.codecentric.boot.admin.client.registration.ApplicationFactory) Before(org.junit.Before)

Example 4 with HttpHeaders

use of org.springframework.http.HttpHeaders in project spring-boot-admin by codecentric.

the class ApplicationOperationsTest method test_getHealth.

@Test
@SuppressWarnings("rawtypes")
public void test_getHealth() {
    Application app = Application.create("test").withHealthUrl("http://health").withManagementUrl("http://mgmt").build();
    ArgumentCaptor<HttpEntity> requestEntity = ArgumentCaptor.forClass(HttpEntity.class);
    HttpHeaders headers = new HttpHeaders();
    headers.add("auth", "foo:bar");
    when(headersProvider.getHeaders(eq(app))).thenReturn(headers);
    when(restTemplate.exchange(eq(URI.create("http://health")), eq(HttpMethod.GET), requestEntity.capture(), eq(Map.class))).thenReturn(ResponseEntity.ok().body((Map) singletonMap("foo", "bar")));
    ResponseEntity<Map<String, Serializable>> response = ops.getHealth(app);
    assertThat(response.getBody()).containsEntry("foo", "bar");
    assertThat(requestEntity.getValue().getHeaders()).containsEntry("auth", asList("foo:bar"));
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) Application(de.codecentric.boot.admin.model.Application) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Test(org.junit.Test)

Example 5 with HttpHeaders

use of org.springframework.http.HttpHeaders in project spring-boot-admin by codecentric.

the class ApplicationOperationsTest method test_getInfo.

@Test
@SuppressWarnings("rawtypes")
public void test_getInfo() {
    Application app = Application.create("test").withHealthUrl("http://health").withManagementUrl("http://mgmt").build();
    ArgumentCaptor<HttpEntity> requestEntity = ArgumentCaptor.forClass(HttpEntity.class);
    HttpHeaders headers = new HttpHeaders();
    headers.add("auth", "foo:bar");
    when(headersProvider.getHeaders(eq(app))).thenReturn(headers);
    when(restTemplate.exchange(eq(URI.create("http://mgmt/info")), eq(HttpMethod.GET), requestEntity.capture(), eq(Map.class))).thenReturn(ResponseEntity.ok().body((Map) singletonMap("foo", "bar")));
    ResponseEntity<Map<String, Serializable>> response = ops.getInfo(app);
    assertThat(response.getBody()).containsEntry("foo", "bar");
    assertThat(requestEntity.getValue().getHeaders()).containsEntry("auth", asList("foo:bar"));
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) Application(de.codecentric.boot.admin.model.Application) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Test(org.junit.Test)

Aggregations

HttpHeaders (org.springframework.http.HttpHeaders)1676 Test (org.junit.Test)426 ResponseEntity (org.springframework.http.ResponseEntity)383 HttpEntity (org.springframework.http.HttpEntity)345 Test (org.junit.jupiter.api.Test)273 HashMap (java.util.HashMap)184 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)154 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)127 MediaType (org.springframework.http.MediaType)121 URI (java.net.URI)111 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)102 Map (java.util.Map)97 IOException (java.io.IOException)83 RestTemplate (org.springframework.web.client.RestTemplate)78 ArrayList (java.util.ArrayList)75 MessageHeaders (org.springframework.messaging.MessageHeaders)74 MultiValueMap (org.springframework.util.MultiValueMap)74 HttpStatus (org.springframework.http.HttpStatus)71 List (java.util.List)65 Timed (com.codahale.metrics.annotation.Timed)54