2017-11-21 12 views
0

JAX-RS 프로젝트에서 이름이 지정된 ContainerRequestFilteron을 추가하려고합니다. 첫째, 내가 주석 만든 : 그럼

@NameBinding 
@Target({ElementType.METHOD, ElementType.TYPE}) 
@Retention(RetentionPolicy.RUNTIME) 
public @interface IsAuthenticated {} 

를, 내가 공급자 만든 : 그럼

@PreMatching 
@Provider 
@IsAuthenticated 
public class AuthenticationRequestFilter implements ContainerRequestFilter { 

    public void filter(ContainerRequestContext requestContext) throws IOException { 
     System.out.println("filter() on  ServerAuthenticationRequestFilter"); 
     Response.ResponseBuilder responseBuilder = Response.serverError(); 
     Response response = responseBuilder.status(Response.Status.BAD_REQUEST).build(); 
     requestContext.abortWith(response); 
    } 
} 

을, 나는 나의 JAX-RS 방법에 그것을 사용하고 있습니다 :

@GET 
@Path("/trial") 
@IsAuthenticated 
public String trial() { 
    return "Hello world"; 
} 

불행히도 다음 오류로 인해 충돌이 발생합니다.

StandardWrapperValve[SpringApplication]: Servlet.service() for servlet SpringApplication threw exception java.lang.NullPointerException at org.glassfish.jersey.server.spring.scope.RequestContextFilter$2.resetAttributes(RequestContextFilter.java:125) at org.glassfish.jersey.server.spring.scope.RequestContextFilter.filter(RequestContextFilter.java:138) at org.glassfish.jersey.server.ContainerFilteringStage$ResponseFilterStage.apply(ContainerFilteringStage.java:196) at org.glassfish.jersey.server.ContainerFilteringStage$ResponseFilterStage.apply(ContainerFilteringStage.java:163) at org.glassfish.jersey.process.internal.Stages.process(Stages.java:171) at org.glassfish.jersey.server.ServerRuntime$Responder.processResponse(ServerRuntime.java:393) at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:385) at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:280) at org.glassfish.jersey.internal.Errors$1.call(Errors.java:272) at org.glassfish.jersey.internal.Errors$1.call(Errors.java:268) at org.glassfish.jersey.internal.Errors.process(Errors.java:316) at org.glassfish.jersey.internal.Errors.process(Errors.java:298) at org.glassfish.jersey.internal.Errors.process(Errors.java:268) at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:289) at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:256) at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:703) at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:416) at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:370) at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:389) at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:342) at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:229) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1580) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:258) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:652) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:591) at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:371) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:238) at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:463) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:168) at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206) at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180) at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:242) at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201) at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133) at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112) at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77) at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:539) at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:593) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:573) at java.lang.Thread.run(Thread.java:748)

나는 프로 바이더로부터, 다음 줄을 제거하면

하지만, (예상대로 잘못된 요청이 반환되지 않습니다으로이 작동하지 않지만)

requestContext.abortWith(response); 

는 충돌이 사라집니다. 무슨 일

<init-param> 
    <param-name>jersey.config.server.provider.packages</param-name> 
    <param-value>com.trial.filters</param-value> 
</init-param> 
<init-param> 
    <param-name>jersey.config.server.provider.classnames</param-name> 
    <param-value>com.trial.filters.AuthenticationRequestFilter</param-value> 
</init-param> 

: 나는 web.xml을에 추가 한? 내가 도대체 ​​뭘 잘못하고있는 겁니까?

덕분에 나는 이유를 알고하지 않습니다하지만 문제는, @PreMatching에 의해 발생되고 있었다

답변

0

많은. 하지만 주석을 삭제했으며 이제 예상대로 작동합니다.