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:io.github.howiefh.jeews.modules.sys.controller.RoleController.java

@RequiresPermissions("role:create")
@RequestMapping(value = "", method = RequestMethod.POST)
public ResponseEntity<RoleResource> create(HttpEntity<Role> entity, HttpServletRequest request)
        throws URISyntaxException {
    Role role = entity.getBody();
    roleService.save(role);//  w  w  w .j av  a2  s .c om
    HttpHeaders headers = new HttpHeaders();
    RoleResource roleResource = new RoleResourceAssembler().toResource(role);
    headers.setLocation(entityLinks.linkForSingleResource(Role.class, role.getId()).toUri());
    ResponseEntity<RoleResource> responseEntity = new ResponseEntity<RoleResource>(roleResource, headers,
            HttpStatus.CREATED);
    return responseEntity;
}

From source file:com.appleframework.monitor.action.UserAction.java

@RequestMapping(value = "/user/destroy", method = RequestMethod.POST)
public @ResponseBody WebResult delete(HttpEntity<User> entity) throws UnsupportedEncodingException {
    User user = entity.getBody();
    WebResult result = new WebResult();

    userManager.removeUser(user.getUsername());
    return result;
}

From source file:com.mtt.myapp.operation.LogMonitorControllerTest.java

private String getLastMessage() {
    HttpEntity<String> lastLog = logMonitorController.getLast();
    JsonParser parser = new JsonParser();
    JsonElement parse = parser.parse(lastLog.getBody());
    String message = parse.getAsJsonObject().get("log").getAsString();
    return message;
}

From source file:io.github.howiefh.jeews.modules.oauth2.controller.ClientController.java

@RequiresPermissions("clients:create")
@RequestMapping(value = "", method = RequestMethod.POST)
public ResponseEntity<ClientResource> create(HttpEntity<Client> entity, HttpServletRequest request)
        throws URISyntaxException {
    Client Client = entity.getBody();
    clientService.save(Client);//from  ww  w. j av a 2 s.com
    HttpHeaders headers = new HttpHeaders();
    ClientResource ClientResource = new ClientResourceAssembler().toResource(Client);
    headers.setLocation(entityLinks.linkForSingleResource(Client.class, Client.getId()).toUri());
    ResponseEntity<ClientResource> responseEntity = new ResponseEntity<ClientResource>(ClientResource, headers,
            HttpStatus.CREATED);
    return responseEntity;
}

From source file:org.openlmis.fulfillment.service.stockmanagement.ValidSourceDestinationsStockManagementServiceTest.java

@Test
public void shouldFindOne() {
    // given/*from  www.  ja  v a  2s.c om*/
    UUID facility = UUID.randomUUID();
    ValidSourceDestinationDto destination = new ValidSourceDestinationDtoDataBuilder().withNode(facility)
            .build();
    ResponseEntity<ValidSourceDestinationDto[]> response = new ResponseEntity<>(
            new ValidSourceDestinationDto[] { destination }, HttpStatus.OK);

    when(restTemplate.exchange(any(URI.class), eq(HttpMethod.GET), any(HttpEntity.class),
            eq(service.getArrayResultClass()))).thenReturn(response);

    // when
    UUID program = UUID.randomUUID();
    UUID facilityType = UUID.randomUUID();
    Optional<ValidSourceDestinationDto> validSourceDestination = service.search(program, facilityType,
            facility);

    // then
    assertThat(validSourceDestination.isPresent(), is(true));
    assertThat(validSourceDestination.get(), is(destination));

    verify(restTemplate).exchange(uriCaptor.capture(), eq(HttpMethod.GET), entityCaptor.capture(),
            eq(service.getArrayResultClass()));

    String uri = uriCaptor.getValue().toString();
    String url = service.getServiceUrl() + getUrl();

    assertThat(uri, allOf(startsWith(url), containsString("program=" + program),
            containsString("facilityType=" + facilityType)));

    HttpEntity<String> entity = entityCaptor.getValue();
    assertAuthHeader(entity);
    assertThat(entity.getBody(), is(nullValue()));
}

From source file:nl.flotsam.calendar.core.CalendarClient.java

public String getCalendarAsType(String key, String contentType) {
    String address = UriBuilder.fromUri(baseURI).path("calendars").build().toASCIIString() + "/{key}";
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("key", key);
    HttpHeaders headers = new HttpHeaders();
    headers.set("Accept", contentType);
    HttpEntity<?> request = new HttpEntity(headers);
    HttpEntity<String> response = template.exchange(address, HttpMethod.GET, request, String.class, params);
    return response.getBody();
}

From source file:com.consol.citrus.admin.connector.WebSocketPushMessageListenerTest.java

@Test
public void testNoContext() throws Exception {
    Message inbound = new DefaultMessage("Hello Citrus!");

    reset(restTemplate, context);/*from  w  w  w  . j a v  a2s . c  o  m*/
    when(restTemplate.exchange(eq("http://localhost:8080/connector/message/inbound?processId="),
            eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class))).thenAnswer(invocation -> {
                HttpEntity request = (HttpEntity) invocation.getArguments()[2];

                Assert.assertEquals(request.getBody().toString(), inbound.toString());

                return ResponseEntity.ok().build();
            });

    pushMessageListener.onInboundMessage(inbound, null);
    pushMessageListener.onInboundMessage(inbound, context);

    verify(restTemplate, times(2)).exchange(eq("http://localhost:8080/connector/message/inbound?processId="),
            eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class));
}

From source file:com.consol.citrus.admin.connector.WebSocketPushMessageListenerTest.java

@Test
public void testOnInboundMessage() throws Exception {
    Message inbound = new DefaultMessage("Hello Citrus!");

    reset(restTemplate, context);/*w w  w. j  ava  2s . c o  m*/
    when(restTemplate.exchange(eq("http://localhost:8080/connector/message/inbound?processId=MySampleTest"),
            eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class))).thenAnswer(invocation -> {
                HttpEntity request = (HttpEntity) invocation.getArguments()[2];

                Assert.assertEquals(request.getBody().toString(), inbound.toString());

                return ResponseEntity.ok().build();
            });

    when(context.getVariables())
            .thenReturn(Collections.singletonMap(Citrus.TEST_NAME_VARIABLE, "MySampleTest"));
    when(context.getVariable(Citrus.TEST_NAME_VARIABLE)).thenReturn("MySampleTest");

    pushMessageListener.onInboundMessage(inbound, context);
    verify(restTemplate).exchange(eq("http://localhost:8080/connector/message/inbound?processId=MySampleTest"),
            eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class));
}

From source file:com.consol.citrus.admin.connector.WebSocketPushMessageListenerTest.java

@Test
public void testOnOutboundMessage() throws Exception {
    Message outbound = new DefaultMessage("Hello Citrus!");

    reset(restTemplate, context);/*  w w  w  . j  a va  2 s  .c  o  m*/
    when(restTemplate.exchange(eq("http://localhost:8080/connector/message/outbound?processId=MySampleTest"),
            eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class))).thenAnswer(invocation -> {
                HttpEntity request = (HttpEntity) invocation.getArguments()[2];

                Assert.assertEquals(request.getBody().toString(), outbound.toString());

                return ResponseEntity.ok().build();
            });

    when(context.getVariables())
            .thenReturn(Collections.singletonMap(Citrus.TEST_NAME_VARIABLE, "MySampleTest"));
    when(context.getVariable(Citrus.TEST_NAME_VARIABLE)).thenReturn("MySampleTest");

    pushMessageListener.onOutboundMessage(outbound, context);
    verify(restTemplate).exchange(eq("http://localhost:8080/connector/message/outbound?processId=MySampleTest"),
            eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class));
}

From source file:io.github.howiefh.jeews.modules.sys.controller.OrganizationController.java

@RequiresPermissions("organization:create")
@RequestMapping(value = "", method = RequestMethod.POST)
public ResponseEntity<OrganizationResource> create(HttpEntity<Organization> entity, HttpServletRequest request)
        throws URISyntaxException {
    Organization organization = entity.getBody();
    organizationService.save(organization);
    HttpHeaders headers = new HttpHeaders();
    OrganizationResource organizationResource = new OrganizationResourceAssembler().toResource(organization);
    headers.setLocation(entityLinks.linkForSingleResource(Organization.class, organization.getId()).toUri());
    ResponseEntity<OrganizationResource> responseEntity = new ResponseEntity<OrganizationResource>(
            organizationResource, headers, HttpStatus.CREATED);
    return responseEntity;
}