英文:
In SpringBoot web service endpoint, how do I access http headers?
问题
我有一个用 @Endpoint 注解的类和一个处理方法
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "getWeatherRequest")
@SoapAction("http://foo/domain/getWeatherRequest")
@ResponsePayload
public GetWeatherResponse getWeatherRequest(@RequestPayload GetWeatherRequest request) {
// 我想在这里获取 HTTP 头部(不是 SOAP 头部)
}
英文:
I have a class annotated with @Endpoint and a handler method
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "getWeatherRequest")
@SoapAction("http://foo/domain/getWeatherRequest")
@ResponsePayload
public GetWeatherResponse getWeatherRequest(@RequestPayload GetWeatherRequest request) {
// I want to get HTTP header (Not SOAP Header) here
}
答案1
得分: 1
@RequestHeader
注解用法示例:
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "getWeatherRequest")
@SoapAction("http://foo/domain/getWeatherRequest")
@ResponsePayload
public GetWeatherResponse getWeatherRequest(@RequestPayload GetWeatherRequest request,
@RequestHeader("header-name") String header) {
}
英文:
Try using the @RequestHeader annotation
@SoapAction("http://foo/domain/getWeatherRequest")
@ResponsePayload
public GetWeatherResponse getWeatherRequest(@RequestPayload GetWeatherRequest request,
@RequestHeader("header-name") String header) {
}
</details>
# 答案2
**得分**: 0
你可以在方法中使用`RequestHeader`注解来访问HTTP头部,你可以使用`required`属性来指定头部是必填还是可选的。
```java
@RequestHeader(value = "ConfigId", required = true) String configId
英文:
You can use RequestHeader
annotation in your method to access http headers, you can specify whether header is mandatory or optional using required
attribute
@RequestHeader(value = "ConfigId", required = true) String configId
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论