REST调用中未传递参数。但是在邮递员中工作得很好

时间:2018-08-14 03:02:20

标签: java rest spring-boot controller endpoint

我正在以下getPlanPreferenceRules端点中执行集成测试,并且参数值未传递到preferences-admin-service。但是,当我尝试在邮递员中测试相同功能时,效果很好。

下面是执行REST调用的代码。

@Override
    public ServiceClientResponse<GetPlanPrefRulesResponse> getPlanPrefereneRules(GetPlanPrefRulesRequest parameters,
            String currentUserId, String correlationId, String requestorApp) {

        RequestEntity<?> targetRequest = 
                createGetPlanPrefRulesRequest(parameters, currentUserId, correlationId, requestorApp);

        return this.restClientService.exchangeAndParse(
                this.getRulesRestTemplate, targetRequest, new TypeReference<GetPlanPrefRulesResponse>(){});
    }

以下是Spring控制器服务:

@GetMapping(value = PATH_PLAN_PREF_RULES)
    public ResponseEntity<?> getPlanPrefRules(
            @Valid  final GetPlanPrefRulesRequest request )
    {
        log.info("getPlanPrefRulesDataRequest: Entering: GetPlanPrefRulesRequest={}", request); 
        return ResponseEntity.ok(this.getPlanPreferenceRulesService.getPlanPrefRules(request));
    }

下面是创建REST调用请求的代码:

protected RequestEntity<?> createGetPlanPrefRulesRequest(
            final GetPlanPrefRulesRequest parameters,
            final String currentUserId,
            final String correlationId,
            final String requestorApp)
    {
        URI targetUri = UriComponentsBuilder.fromUri(this.preferencesServiceUri)
                .path(this.rulesPath).build().toUri();

        HttpHeaders targetHeaders = createHeaders(
                currentUserId,
                correlationId,
                requestorApp);

        return new RequestEntity<>(
                parameters,
                targetHeaders,
                HttpMethod.GET,
                targetUri);
    }

我不确定我缺少什么。任何输入表示赞赏!

1 个答案:

答案 0 :(得分:0)

更新此方法

@GetMapping(value = PATH_PLAN_PREF_RULES)
    public ResponseEntity<?> getPlanPrefRules(
            @RequestBody @Valid  final GetPlanPrefRulesRequest request )
    {
        log.info("getPlanPrefRulesDataRequest: Entering: GetPlanPrefRulesRequest={}", request); 
        return ResponseEntity.ok(this.getPlanPreferenceRulesService.getPlanPrefRules(request));
    }