Example usage for org.springframework.http HttpEntity getBody

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

Introduction

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

Prototype

@Nullable
public T getBody() 

Source Link

Document

Returns the body of this entity.

Usage

From source file:com.logsniffer.web.controller.report.ElasticEventsController.java

@RequestMapping(value = "/reports/eventSearch", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public void eventSearch(final HttpEntity<String> httpEntity, final HttpServletResponse response)
        throws IOException {
    long start = System.currentTimeMillis();
    String jsonRequest = httpEntity.getBody();
    final SearchRequest searchRequest = new SearchRequest(indexName);
    try {// w  ww .ja v  a  2 s  .  com
        searchRequest.source(jsonRequest);
        searchRequest.types("event");
        SearchResponse r = clientTpl.executeWithClient(new ClientCallback<SearchResponse>() {
            @Override
            public SearchResponse execute(final Client client) {
                return client.search(searchRequest).actionGet();
            }
        });
        response.setContentType(MediaType.APPLICATION_JSON_VALUE);
        OutputStream responseStream = response.getOutputStream();
        XContentBuilder builder = XContentFactory.jsonBuilder(responseStream);
        builder.startObject();
        r.toXContent(builder, ToXContent.EMPTY_PARAMS);
        builder.endObject();
        builder.close();
        responseStream.close();
    } finally {
        logger.debug("Executed search in {}ms: {}", System.currentTimeMillis() - start, jsonRequest);
    }
}

From source file:org.ngrinder.user.controller.UserControllerTest.java

/**
 * Test method for/*from  w  w w.  ja v a  2 s.  c  o m*/
 * {@link UserController#checkDuplication(String)}
 * .
 */
@Test
public void testDuplication() {
    BaseController ngrinderBaseController = new BaseController();
    HttpEntity<String> rtnStr = userController.checkDuplication("not-exist");
    assertThat(rtnStr.getBody(), is(ngrinderBaseController.returnSuccess()));

    rtnStr = userController.checkDuplication(getTestUser().getUserId());
    assertThat(rtnStr.getBody(), is(ngrinderBaseController.returnError()));
}

From source file:org.ngrinder.user.controller.UserControllerTest.java

@Test
public void testSwitchOptions() {
    ModelMap model = new ModelMap();
    User currUser = getTestUser();/*from   ww w .j  av a2 s . c o m*/
    User temp = new User("temp1", "temp1", "temp1", "temp@nhn.com", Role.USER);
    User admin = getAdminUser();
    userController.save(admin, temp, model);
    currUser.setOwners(Lists.newArrayList(temp));
    currUser.setOwnerUser(temp);
    userController.save(currUser, currUser, model);
    HttpEntity<String> shareUsersStr = userController.switchOptions(currUser, "");
    assertTrue(shareUsersStr.getBody().contains("id"));
}

From source file:org.bozzo.ipplan.web.ZoneController.java

@RequestMapping(value = "/{zoneId}", method = RequestMethod.GET, produces = { MediaType.TEXT_HTML_VALUE })
@ApiIgnore// w  w  w.  j a v  a  2 s.  c  o  m
public ModelAndView getZoneView(@PathVariable @NotNull Integer infraId, @PathVariable Long zoneId,
        @RequestParam(required = false) RequestMode mode) {
    HttpEntity<ZoneResource> zone = this.getZone(infraId, zoneId, mode);
    ModelAndView view = new ModelAndView("zone");
    view.addObject("id", zoneId);
    view.addObject("object", zone.getBody());
    return view;
}

From source file:org.bozzo.ipplan.web.InfrastructureController.java

@RequestMapping(value = "/{infraId}", method = RequestMethod.GET, produces = { MediaType.TEXT_HTML_VALUE })
@ApiIgnore/*from   w w  w.  j  a  v  a 2s .  com*/
public ModelAndView getInfrastructureView(@PathVariable Integer infraId,
        @RequestParam(required = false) RequestMode mode) {
    HttpEntity<InfrastructureResource> infra = this.getInfrastructure(infraId, mode);
    ModelAndView view = new ModelAndView("infra");
    view.addObject("id", infraId);
    view.addObject("object", infra.getBody());
    return view;
}

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

/**
 * exchange()?Headers.//from   w w  w  .j  a v a 2  s.c o  m
 * 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.bozzo.ipplan.web.RangeController.java

@RequestMapping(value = "/{rangeId}", method = RequestMethod.GET, produces = { MediaType.TEXT_HTML_VALUE })
@ApiIgnore/*ww w  .  ja  va2 s. c o  m*/
public ModelAndView getRangeView(@PathVariable Integer infraId, @PathVariable Long zoneId,
        @PathVariable Long rangeId, @RequestParam(required = false) RequestMode mode) {
    HttpEntity<RangeResource> range = this.getRange(infraId, zoneId, rangeId, mode);
    ModelAndView view = new ModelAndView("range");
    view.addObject("id", rangeId);
    view.addObject("object", range.getBody());
    return view;
}

From source file:org.openlmis.fulfillment.service.request.RequestHelperTest.java

@Test
public void shouldCreateEntityWithAnAuthHeader() {
    String body = "test";
    String token = "token";

    HttpEntity<String> entity = RequestHelper.createEntity(body, RequestHeaders.init().setAuth(token));

    assertThat(entity.getHeaders().get(HttpHeaders.AUTHORIZATION), is(singletonList(BEARER + token)));
    assertThat(entity.getBody(), is(body));
}

From source file:org.bozzo.ipplan.web.AddressController.java

@RequestMapping(value = "/{ip}", method = RequestMethod.GET, produces = { MediaType.TEXT_HTML_VALUE })
@ApiIgnore//w  ww . j av  a2  s .c o m
public ModelAndView getAddressView(@PathVariable Integer infraId, @PathVariable Long subnetId,
        @PathVariable Long ip) {
    HttpEntity<AddressResource> address = this.getAddress(infraId, subnetId, ip);
    ModelAndView view = new ModelAndView("address");
    view.addObject("id", ip);
    view.addObject("object", address.getBody());
    return view;
}

From source file:com.smartystreets.spring.SmartyStreetsAPI.java

public ZipCodeResponse[] zipCode(String zipCode, String city, String state, String inputId) {

    URI uri = createURI(zipCodeUrl);
    HttpEntity<ZipCodeResponse[]> response = getRestTemplate().postForEntity(uri,
            new ZipCodeRequest[] { new ZipCodeRequest(city, state, zipCode, inputId) },
            ZipCodeResponse[].class);
    return response.getBody();
}