CXF 请求上下文过滤器
CXF RequestContextFilter
http://cxf.apache.org/docs/30-migration-guide.html
CXF RequestHandler and ResponseHandler filters have been removed,
please use JAX-RS 2.0 ContainerRequestFilter and
ContainerResponseFilter and also WriterInterceptor and
ReaderInterceptor when needed.
如何重写呢?我找不到任何将 org.apache.cxf.message.Message 作为参数并返回 Response.
的示例
我还应该使用 ContainerResponseFilter
public void filter(ContainerRequestContext containerRequestContext, ContainerResponseContext containerResponseContext) throws IOException {
而不是 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);
Spring
<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>
http://cxf.apache.org/docs/30-migration-guide.html
CXF RequestHandler and ResponseHandler filters have been removed, please use JAX-RS 2.0 ContainerRequestFilter and ContainerResponseFilter and also WriterInterceptor and ReaderInterceptor when needed.
如何重写呢?我找不到任何将 org.apache.cxf.message.Message 作为参数并返回 Response.
的示例我还应该使用 ContainerResponseFilter
public void filter(ContainerRequestContext containerRequestContext, ContainerResponseContext containerResponseContext) throws IOException {
而不是 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);
Spring
<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>