Example usage for org.springframework.http HttpEntity HttpEntity

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

Introduction

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

Prototype

public HttpEntity(MultiValueMap<String, String> headers) 

Source Link

Document

Create a new HttpEntity with the given headers and no body.

Usage

From source file:com.borabora.ui.secure.SampleSecureApplicationTests.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>Login"));
}

From source file:com.mc.printer.model.StartTask.java

@Override
public Object doBackgrounp() {

    //        File file = new File(ClientConstants.GUIDE_DOWNLOAD_DIR);
    //        if (file.exists() && file.isDirectory()) {
    //            try {
    //                logger.debug("clean download directory.");
    //                FileUtils.deleteDirectory(file);
    //            } catch (IOException ex) {
    //                logger.error("ex");
    //            }
    //        }//from  w w w  . j a  v  a  2s.c  o  m
    try {

        TbBranch branch = new TbBranch();
        branch.setAddress(IPHelper.getCurrentIP());
        branch.setName(ClientConstants.LOCAL_NAME);
        branch.setStatus(1);
        ComResponse<TbBranch> response = restTemplate.exchange(
                ClientConstants.WS_HTTP + ClientConstants.WS_ISREGISTER, HttpMethod.POST,
                new HttpEntity<TbBranch>(branch), new ParameterizedTypeReference<ComResponse<TbBranch>>() {
                }).getBody();

        if (response.getResponseStatus() == ComResponse.STATUS_OK) {
            logger.info("checked successfully. client is existing.");
            AutoPrinterApp.isRegister = true;
        } else {
            logger.error(response.getErrorMessage());
        }

    } catch (Exception e) {
        logger.error(e.getMessage());
    }

    return null;
}

From source file:comsat.sample.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.acc.test.UserWebServiceTest.java

@Test()
public void testGetUserReviews_Success_XML() {
    final HttpEntity<String> requestEntity = new HttpEntity<String>(getXMLHeaders());
    final ResponseEntity<String> response = template.exchange(
            "http://localhost:9001/rest/v1/users/{userid}/reviews", HttpMethod.GET, requestEntity, String.class,
            TestConstants.USERNAME);/*  w  w w . j  ava  2 s  .co  m*/
    assertEquals("application/xml;charset=UTF-8", response.getHeaders().getContentType().toString());
}

From source file:pl.hycom.jira.plugins.gitlab.integration.dao.CommitRepository.java

@Override
public Commit getOneCommit(ConfigEntity configEntity, String shaSum) {
    HttpEntity<?> requestEntity = new HttpEntity<>(
            new TemplateFactory().getHttpHeaders().setAuth(configEntity.getClientId()).build());
    ResponseEntity<Commit> response = new TemplateFactory().getRestTemplate().exchange(
            configEntity.getLink() + COMMIT_SINGLE_URL, HttpMethod.GET, requestEntity,
            new ParameterizedTypeReference<Commit>() {
            }, shaSum);/*www. ja  va  2s.com*/

    return response.getBody();
}

From source file:example.helloworld.CubbyholeAuthenticationTests.java

/**
 * Write some data to Vault before Vault can be used as {@link VaultPropertySource}.
 *///from  w w w  .java 2s.com
@BeforeClass
public static void beforeClass() {

    VaultOperations vaultOperations = new VaultTestConfiguration().vaultTemplate();
    vaultOperations.write("secret/myapp/configuration", Collections.singletonMap("configuration.key", "value"));

    VaultResponse response = vaultOperations.doWithSession(new RestOperationsCallback<VaultResponse>() {

        @Override
        public VaultResponse doWithRestOperations(RestOperations restOperations) {

            HttpHeaders headers = new HttpHeaders();
            headers.add("X-Vault-Wrap-TTL", "10m");

            return restOperations.postForObject("auth/token/create", new HttpEntity<Object>(headers),
                    VaultResponse.class);
        }
    });

    // Response Wrapping requires Vault 0.6.0+
    Map<String, String> wrapInfo = response.getWrapInfo();
    initialToken = VaultToken.of(wrapInfo.get("token"));
}

From source file:io.spring.initializr.web.project.LegacyStsControllerIntegrationTests.java

@Override
protected String htmlHome() {
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Collections.singletonList(MediaType.TEXT_HTML));
    return getRestTemplate()
            .exchange(createUrl("/sts"), HttpMethod.GET, new HttpEntity<Void>(headers), String.class).getBody();
}

From source file:sample.jetty.SampleJettyApplicationTests.java

@Test
public void testCompression() throws Exception {
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.set("Accept-Encoding", "gzip");
    HttpEntity<?> requestEntity = new HttpEntity<Object>(requestHeaders);

    ResponseEntity<byte[]> entity = this.restTemplate.exchange("/", HttpMethod.GET, requestEntity,
            byte[].class);

    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);

    GZIPInputStream inflater = new GZIPInputStream(new ByteArrayInputStream(entity.getBody()));
    try {//www.  j  a  v a2s  . c om
        //         assertThat(StreamUtils.copyToString(inflater, Charset.forName("UTF-8"))).isEqualTo("Hello World");
    } finally {
        inflater.close();
    }
}

From source file:com.capitalone.dashboard.collector.DefaultNexusIQClient.java

@Autowired
public DefaultNexusIQClient(Supplier<RestOperations> restOperationsSupplier, NexusIQSettings settings) {
    this.httpHeaders = new HttpEntity<>(this.createHeaders(settings.getUsername(), settings.getPassword()));
    this.rest = restOperationsSupplier.get();
    this.nexusIQSettings = settings;
}

From source file:com.tce.oauth2.spring.client.services.TodoService.java

public List<Todo> findAll(String accessToken) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization", "Bearer " + accessToken);
    HttpEntity<String> entity = new HttpEntity<String>(headers);
    ResponseEntity<Todo[]> response = restTemplate.exchange(OAUTH_RESOURCE_SERVER_URL + "/rest/todos",
            HttpMethod.GET, entity, Todo[].class);
    Todo[] todos = response.getBody();/*  w  w w.  j  a v  a  2  s . c  om*/

    return Arrays.asList(todos);
}