本文介绍了CXF RequestContextFilter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
http://cxf.apache.org/docs/30-migration-guide.html
如何重写?我找不到任何以org.apache.cxf.message.Message作为参数并返回Response的示例.
我也应该使用ContainerResponseFilter
Also I should use the ContainerResponseFilter
public void filter(ContainerRequestContext containerRequestContext, ContainerResponseContext containerResponseContext) throws IOException {
代替RequestHandler
instead of RequestHandler
Response handleRequest(Message m, ClassResourceInfo resourceClass)
推荐答案
替换 RequestHandler
public class CustomRequestHandler implements RequestHandler {
public Response handleRequest(Message m, ClassResourceInfo resourceClass) {
带有 ContainerRequestFilter
public class CustomRequestFilter implements ContainerRequestFilter {
public void filter(ContainerRequestContext context) {
Message m = JAXRSUtils.getCurrentMessage();
OperationResourceInfo m = message.getExchange().get(OperationResourceInfo.class);
ClassResourceInfo resourceClass = operation.getClassResourceInfo();
// finally use context.abortWith(Response) if you need to block the request
替换 ResponseHandler
public class CustomResponseHandler implements ResponseHandler {
public Response handleResponse(Message m, OperationResourceInfo operation, Response response) {
带有 ContainerResponseFilter
public class CustomResponseFilter implements ContainerResponseFilter {
public void filter(ContainerRequestContext inContext, ContainerResponseContext outContext) throws IOException{
Message m = JAXRSUtils.getCurrentMessage();
OperationResourceInfo operation = m.getExchange().get(OperationResourceInfo.class);
//outContext has the capabilites of javax.ws.rs.Response. For example outContext.setStatus(201);
春天
<bean id="customRequestFilter" class="com.CustomRequestFilter" />
<bean id="customResponseFilter" class="com.CustomResponseFilter" />
<!-- Add filters to provider zone in JAX-RS server-->
<bean id="myRestServer" class="org.apache.cxf.jaxrs.JAXRSServerFactoryBean" lazy-init="false" init-method="create">
...
<property name="providers">
<list>
<ref bean="customRequestFilter" />
<ref bean="customResponseFilter" />
</list>
</property>
这篇关于CXF RequestContextFilter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!