休息功能在开始之前失败

时间:2017-12-07 08:27:55

标签: java spring rest api debugging

进行API Rest测试,有时我遇到一种情况,当Rest函数失败时,甚至连其中的第一个断点都没有到达。显然,一些初步设置失败了。但具体到底是什么?

这是函数的标题:

@RequestMapping(value = { "/export" }, method = RequestMethod.POST, produces = "text/plain;charset=UTF-8")
public Object exportConfiguration(@RequestBody ConfigurationExport configurationExport) {
    try {
        // at return here stands the breakpoint that is never reached:
        return configurationExporterProvider.export(configurationExport);

请求的主体是:

{}

作为回应我得到了:

            <td>HTTP ERROR: 415 Unsupported Media Type
                <p>Problem accessing /cc/api/configuration/export
                    <pre id="message">Unsupported Media Type</pre>

好吧,我想 - 在尝试将主体加载到configurationExport时会发生一些事情。但是在该类构造函数中没有抛出错误:

private ConfigurationExport() {
    documentTypes = new ArrayList<>();
    valueSets = new ArrayList<>();
    configuration = new Configuration();
}

由龙目岛创建的setter和getter。当然,龙目岛对任何媒体类型都不了解。

我同意应用程序通过错误消息将响应返回给我。但它出现在哪里?我应该在哪里以及如何寻找它?

1 个答案:

答案 0 :(得分:1)

在调用方法之前,Spring会对请求和请求标头执行多次验证。如果需要,可以在Spring类方法org.springframework.web.servlet.DispatcherServlet.doDispatch()中设置断点来调试它。