Juh*_*älä 9 java spring spring-ws http-headers
如何在Spring-ws端点中访问HTTP头?
我的代码看起来像这样:
public class MyEndpoint extends AbstractMarshallingPayloadEndpoint {
protected Object invokeInternal(Object arg) throws Exception {
MyReq request = (MyReq) arg;
// need to access some HTTP headers here
return createMyResp();
}
}
Run Code Online (Sandbox Code Playgroud)
invokeInternal()
只获取未编组的JAXB对象作为参数.如何访问内部请求附带的HTTP标头invokeInternal()
?
一种可能有效的方法是创建一个Servlet过滤器,将头值存储到ThreadLocal
变量中,然后在内部访问invokeInternal()
,但是有更好的,更类似Spring的方法吗?
Juh*_*älä 16
您可以添加这些方法.在TransportContextHolder
将持有线程局部变量(在这种情况下HTTP)与交通有关的一些数据.你可以HttpServletRequest
从TransportContext
.访问.
protected HttpServletRequest getHttpServletRequest() {
TransportContext ctx = TransportContextHolder.getTransportContext();
return ( null != ctx ) ? ((HttpServletConnection ) ctx.getConnection()).getHttpServletRequest() : null;
}
protected String getHttpHeaderValue( final String headerName ) {
HttpServletRequest httpServletRequest = getHttpServletRequest();
return ( null != httpServletRequest ) ? httpServletRequest.getHeader( headerName ) : null;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10435 次 |
最近记录: |