如何在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();
}
}
invokeInternal()
仅获取未编组的JAXB对象作为参数。如何访问请求内部附带的HTTP标头invokeInternal()
?
一种可能可行的方法是创建一个Servlet过滤器,该过滤器将标头值存储到ThreadLocal
变量中,然后在内部访问该变量invokeInternal()
,但是有没有更好的,更像弹簧的方法来做到这一点?
您可以添加这些方法。在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;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句