简体   繁体   中英

Spring service return content empty when using feign client

Created an ui application to test my services. UI has relation with FooServiceUI. FooServiceUI sending request to BarServiceAccessor ( has implementation as interface at fooserviceui) with using feign client. But feign client returns response like this;

{"datas": [PagedResource { content: [], metadata: Metadata { number: 0, total pages: 1, total elements: 3, size: 200 }, links: [] }]}

When i sending request directly to BarService, i can see all of these datas.

FooService getAll method;

@RequestMapping(method = RequestMethod.GET, path = "/api/datas/")
public ResponseEntity<String> getAllDatas()
{
    PagedResources<DataResource> responseEntity = null;

    try
    {
        responseEntity = dataManagementAccessor.getAll(0, 200);
    }
    catch (Exception e)
    {
        LOG.error("Exception " + e.toString());
    }
    return ResponseEntity.ok()
            .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
            .body("{\"datas\": [" + responseEntity + "]}");
}

Accessor;

@FeignClient("https://datamanagement")
public interface DataManagementAccessor{
@RequestMapping(value = "/api/datas/", method = GET)
    PagedResources<DataResource> getAll(@RequestParam("page") final Integer page,
        @RequestParam("size") final Integer size);
}

BarService Code looks like;

@RequestMapping(method = GET)
@ResponseStatus(OK)
@ApiOperation(value = "Get all datas")
@ApiResponses(value = {@ApiResponse(code = SC_OK, message = "OK", response = DataPageResponse.class),
        @ApiResponse(code = SC_BAD_REQUEST, message = BAD_REQUEST_MESSAGE, response = String.class),
        @ApiResponse(code = SC_UNAUTHORIZED, message = UNAUTHORIZED_MESSAGE, response = String.class),
        @ApiResponse(code = SC_FORBIDDEN, message = FORBIDDEN_MESSAGE, response = String.class),
        @ApiResponse(code = SC_NOT_FOUND, message = NOT_FOUND_MESSAGE, response = String.class)})
    public PagedResources<Resource<DataResource>> getAll(@PageableDefault(sort = {"name"}) final Pageable pageable,
        final PagedResourcesAssembler<DataResource> pagedAssembler)
{
    final Page<DataData> allDatas = dataService.getAllDatas(pageable);

    final Page<DataResource> pagedResources = allDatas.map(
            d-> conversionService.convert(d, DataResource.class));
    pagedResources.forEach(resource -> controllerLinkHandler.addDataResourceLink(resource));
    return pagedAssembler.toResource(pagedResources);
}

I already tried to add spring jpa to client service's gradle and also tried to change mapping according to use stream api collections but still doesnt work.

Maybe something not working correctly when serializing with _embedded lines in response?

@EnableHypermediaSupport(type = EnableHypermediaSupport.HypermediaType.HAL)

i forgot to add this lines at main method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM