我正在将springboot 2.1.7应用程序部署为对wlp-javaee8-18.0.0.4的战争,并从邮递员呼叫我的其余端点时获得406 httpstatus
我的服务:
@PostMapping(path = "/authentication/schema", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> hello(@RequestHeader("key") String key) {
HttpHeaders headers = new HttpHeaders();
headers.add("X-KEY", schemaPair.getValue());
headers.SetContentType(MediaType.APPLICATION_JSON);
return new ResponseEntity<>("hello", headers, HttpStatus.OK);
}
来自邮递员,我指定ContentType和Accept标头,如下所示:-内容类型:application / json-接受:application / json
我也尝试过:-内容类型:/-接受:/
调试springboot显示问题来自Java servlet。确切地说,在这里:
package org.springframework.http.server;
import javax.servlet.http.HttpServletResponse;
public class ServletServerHttpResponse implements ServerHttpResponse {
private final HttpServletResponse servletResponse;
// after code
@Override
@Nullable
public String getFirst(String headerName) {
String value = servletResponse.getHeader(headerName); // problem here
/*
* this method servletResponse.getHeader(headerName)
* returns text/html while my contenttype is application/json
*/
if (value != null) {
return value;
}
else {
return super.getFirst(headerName);
}
}
// after code
}
任何想法请
非常感谢
问题是一个过滤器,该过滤器覆盖了Websphere自由servlet中的contentType。我移除了过滤器,一切正常[]
在tomcat上我的过滤器起作用