我正在尝试为DELETE创建一个简单的REST端点。 代码如下
@RequestMapping(value = "/api/chat/v1/user", produces =
MediaType.APPLICATION_JSON_VALUE)
public class UserApiController {
@DeleteMapping(value = "channels/{channelSid}")
@ResponseStatus(value = HttpStatus.NO_CONTENT)
public Map<String, String> deleteChannel(@RequestHeader(HttpHeaders.AUTHORIZATION) String authorization, @PathVariable String channelSid) {
UserInfo userInfo = userTokenDecryptor.parseAndValidate(authorization);
chatService.deleteChannel("", channelSid);
return Map.of(
"chat_channel_sid", channelSid
);
}
}
我正在尝试接收URL中传递的值,以代替channelSid
作为String channelSid
方法参数。据我了解,当两个名称相同时,Spring应该执行此映射。
以下是我正在播放的cURL:
curl -X DELETE \
http://localhost:8082/api/chat/v1/user/channels/123456789 \
-H 'Accept: */*' \
-H 'Authorization: kjhbdfakjhgsdhkj' \
-H 'Cache-Control: no-cache' \
-H 'Connection: keep-alive' \
-H 'Host: localhost:8082' \
-H 'content-length: '
现在,为了检查其他组件的功能,我需要调试此代码,但是在与IntelliJ Idea调试器一起运行时,我得到以下响应:
{
"timestamp": "2019-07-03T09:38:04.640+0000",
"status": 500,
"error": "Internal Server Error",
"message": "Invalid parameter name \"\"",
"path": "/api/chat/v1/user/channels/123456789/"
}
服务器上的异常如下:
java.lang.reflect.MalformedParametersException: Invalid parameter name ""
at java.base/java.lang.reflect.Executable.verifyParameters(Executable.java:382) ~[na:na]
at java.base/java.lang.reflect.Executable.privateGetParameters(Executable.java:412) ~[na:na]
at java.base/java.lang.reflect.Executable.getParameters(Executable.java:353) ~[na:na]
at org.springframework.core.StandardReflectionParameterNameDiscoverer.getParameterNames(StandardReflectionParameterNameDiscoverer.java:39) ~[spring-core-5.1.6.RELEASE.jar:5.1.6.RELEASE]
其他信息:当我运行服务器而不是调试时,不会发生这种情况。此问题特定于调试。