必需,请求正文丢失:当我尝试加载 Swagger 时公开

问题描述 投票:0回答:1

我正在尝试使用

post
请求从我的 Spring-Boot 应用程序访问 swagger URL。但是得到一个
400-Bad request
并显示 请求正文丢失。但同样的请求在 Postman 中工作得很好。 控制器:

@RestController
public class IdVController {

    @Autowired
    private IdService idService;

    @Autowired
    protected FileUtility util;

    /** The Constant STATUS. */
    private static final String STATUS = "status";

    /** The Constant SUCCESS. */
    private static final String SUCCESS = "success";

    /** The Constant SYSTEM. */
    private static final String SYSTEM = "SYSTEM";

    @RequestMapping(value ="/idApi")
    public ResponseEntity<MarketPlaceResponse> 
    validateIdData(@RequestBody  VerifyIdDTO verifyIdDTO) throws Exception {
        JSONObject rawResponse = idService.validateId(verifyIdDTO);

        IdVerifyEntity DTOResponse = (IdVerifyEntity)util.convertToEntity(rawResponse.toString(), IdVerifyEntity.class);
        if (rawResponse.get(STATUS).equals(SUCCESS)) {
            DTOResponse.setCreated_by(SYSTEM);
            DTOResponse.setCreated_date(new 
            java.sql.Date(System.currentTimeMillis()).toString());
        }
        
        //return ResponseBuilder.buildResponse(DTOResponse);
        MarketPlaceResponse response = new MarketPlaceResponse();
        response.setResponse(DTOResponse);

        return new ResponseEntity<MarketPlaceResponse>(response,HttpStatus.OK);
    }
}

请求DTO:

public class VerifyIdDTO {

    @NotBlank(message="Owner ID should not be empty")
    private String id;
    private String citizenship;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getCitizenship() {
        return citizenship;
    }

    public void setCitizenship(String citizenship) {
        this.citizenship = citizenship;
    }
}

我通过构建 URL 并使用此 POST 方法中的 GET 来联系外部服务 这是 swagger 的 URL

localhost:8080/idvalidationservice/swagger-ui.html

您可以在此屏幕截图中看到错误消息。

java spring-boot swagger swagger-ui http-status-code-400
1个回答
0
投票

你解决了吗? 如果是的话怎么办?

© www.soinside.com 2019 - 2024. All rights reserved.