1

我正在开发 Jersey 实现,其中我的要求是验证和验证请求正文并将其转发到 REST 资源。

验证和验证在注册过滤器中工作正常,但用于转发。请求未转发到 REST 资源。我无法弄清楚我错过了什么。这是我的配置和代码

web.xml

<init-param>
    <param-name>com.sun.jersey.spi.container.ResourceFilters</param-name>
    <param-value>com.level3.messaging.producer.auth.PubRequestFilterFactory</param-value>
</init-param>

我的资源过滤器工厂

@Component
@Provider
public class PubRequestFilterFactory implements
    ResourceFilterFactory {

    @Autowired
    PublisherRequestFilter publisherRequestFilter;

    @Override
    public List<ResourceFilter> create(AbstractMethod am) {
    return Collections
        .<ResourceFilter> singletonList(publisherRequestFilter);
    }

}

我的资源过滤器实现

@Component
@Provider
public class PublisherRequestFilter implements ResourceFilter {      

    @Override
    public ContainerRequestFilter getRequestFilter() {

    return new ContainerRequestFilter() {
        /**
         * Checks if the incoming request is appropriate for the request
         * body. If not throws a web application exception
         */
        @Override
        public ContainerRequest filter(ContainerRequest request) {
         // returned request is not gettting forwared.
                            // I was able to debug thru request
        return request;
        }
    };
    }

    @Override
    public ContainerResponseFilter getResponseFilter() {
    return null;
    }

}

我的 REST 资源实现

@Component
@Produces("application/xml")
@Path("publish")
@Scope("singleton")
public class Publisher extends MessageResource {     

    @POST
    @Path("event")
    @Consumes("application/xml")
    @Produces("application/xml")
    public ProducerResourceResponseWrapper publishEvent(Event event) {
        super.message = event;
        final Long startTime = System.currentTimeMillis();
        init(MessagePattern.Event.name());
        publishMessage(startTime);
        return responseWrapper;
    }


    private void publishMessage(Long startTime) {
    String errorMessage = null;
    try {
        final MessageDelegator eventDelegator = new MessageDelegator(
            publisherResourcesDO);
        eventDelegator.delegate();
        if (publisherResourcesDO.getErrorDO() != null) {
        throw new ErrorHandler(publisherResourcesDO.getErrorDO());
        }
        buildResponse(startTime);
    } catch (final Exception e) {
        errorMessage = e.getMessage();
        handleException(e);
    } finally {
        auditMessage(startTime, errorMessage);
    }

    } 
}
4

0 回答 0