1 Reply Latest reply on Oct 14, 2014 11:19 PM by jaikiran pai

    WriterInterceptorContext.proceed - NullPointerException

    Emre SINDIR Newbie

      Hi everybody,

       

      I'm migrating my JavaEE 7 application Glassfish 4.0 to Wildfly 8.1. I configured Wildfly App. Server according to this guide. My project based on maven and it's have some dependencies. (javaee-api-7.0.jar, eclipselink-2.5.1 ect.)  This project includes JAX-RS(Jersey) and EJB technologies. And it's works perfect on GlassFish 4.0. I'm not using jersey spesific class or method.

       

      I'm getting NullPointerException in my WriterInterceptor implementation when i proceed context object. My code is something like that.

       

      Header 1

      import java.io.ByteArrayOutputStream;

      import java.io.FilterOutputStream;

      import java.io.IOException;

      import javax.ejb.EJB;

      import javax.ws.rs.WebApplicationException;

      import javax.ws.rs.core.MultivaluedMap;

      import javax.ws.rs.ext.Provider;

      import javax.ws.rs.ext.WriterInterceptor;

      import javax.ws.rs.ext.WriterInterceptorContext;

      import tr.com.emre.core.ejb.log.ServiceAccesLogBean;

       

      @Provider

      public class ResponseDataWriterInterceptor implements WriterInterceptor {

       

       

          @EJB

          ServiceAccesLogBean logBean;

       

       

          @Override

          public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {

              System.out.println("#DataWriterInterceptor->OK");

              final Object requestUidObj = context.getProperty("requestUid");

             

              final MultivaluedMap<String, Object> headers = context.getHeaders();

              if (requestUidObj != null) {

                  context.setOutputStream(new FilterOutputStream(context.getOutputStream()) {

       

       

                      final ByteArrayOutputStream baos = new ByteArrayOutputStream();

       

       

                      @Override

                      public void write(int b) throws IOException {

                          baos.write(b);

                          super.write(b);

                      }

       

       

                      @Override

                      public void close() throws IOException {

                          if (requestUidObj != null) {

                              logBean.addResponseDetailToExistingLog(requestUidObj.toString(), headers, baos.toString());

                          }

                          super.close();

                      }

                  });

                  context.proceed();

              }else{

                  if(!context.getPropertyNames().isEmpty()){

                      for (String name : context.getPropertyNames()) {

                          System.out.println("#Property: " + name);

                      }

                  }

                  System.out.println("#DataWriterInterceptor->Proceed,Before");

                  context.proceed();

                  System.out.println("#DataWriterInterceptor->Proceed, After");

              }

          }

       

      and i'm getting this exception;

       

       

      Header 1

      2014-10-14 14:41:59,257 INFO  [stdout] (default task-10) #DataWriterInterceptor->OK

      2014-10-14 14:41:59,257 INFO  [stdout] (default task-10) #DataWriterInterceptor->Proceed, Before

      2014-10-14 14:41:59,258 INFO  [stdout] (default task-10) #Property: org.jboss.weld.servlet.ConversationContextActivatorCONTEXT_ACTIVATED_IN_REQUEST

      2014-10-14 14:41:59,259 INFO  [stdout] (default task-10) #Property: org.jboss.weld.context.http.HttpRequestContext#WELD|ManagedBean|myproject-ear-1.0-SNAPSHOT.ear-/content/myproject-ear-1.0-SNAPSHOT.ear/myproject-rs-1.0-SNAPSHOT.war/WEB-INF/lib/core-ejb-1.0-SNAPSHOT.jar-tr.com.emre.core.ejb.organization.OrganizationRs-null-true

      2014-10-14 14:41:59,259 INFO  [stdout] (default task-10) #Property: RESTEASY_CHOSEN_ACCEPT

      2014-10-14 14:41:59,259 INFO  [stdout] (default task-10) #Property: org.jboss.weld.context.conversation.ConversationIdGenerator

      2014-10-14 14:41:59,259 INFO  [stdout] (default task-10) #Property: org.jboss.weld.context.ConversationContext.conversations

      2014-10-14 14:41:59,259 INFO  [stdout] (default task-10) #Property: org.jboss.resteasy.plugins.providers.validation.ViolationsContainer

      2014-10-14 14:41:59,259 INFO  [stdout] (default task-10) #Property: org.jboss.resteasy.core.ResourceMethodInvoker

      2014-10-14 14:41:59,261 WARN  [org.jboss.resteasy.core.ExceptionHandler] (default task-10) Unknown exception while executing GET /Management/Organization/getLoginOrgazisationList: java.lang.NullPointerException

        at org.jboss.resteasy.plugins.server.servlet.HttpServletResponseHeaders.addResponseHeader(HttpServletResponseHeaders.java:87) [resteasy-jaxrs-3.0.8.Final.jar:]

        at org.jboss.resteasy.plugins.server.servlet.HttpServletResponseHeaders.add(HttpServletResponseHeaders.java:82) [resteasy-jaxrs-3.0.8.Final.jar:]

        at org.jboss.resteasy.plugins.server.servlet.HttpServletResponseHeaders.putAll(HttpServletResponseHeaders.java:151) [resteasy-jaxrs-3.0.8.Final.jar:]

        at org.jboss.resteasy.core.ServerResponseWriter.commitHeaders(ServerResponseWriter.java:235) [resteasy-jaxrs-3.0.8.Final.jar:]

        at org.jboss.resteasy.core.ServerResponseWriter$1.commit(ServerResponseWriter.java:81) [resteasy-jaxrs-3.0.8.Final.jar:]

        at org.jboss.resteasy.util.CommitHeaderOutputStream.commit(CommitHeaderOutputStream.java:50) [resteasy-jaxrs-3.0.8.Final.jar:]

        at org.jboss.resteasy.util.CommitHeaderOutputStream.write(CommitHeaderOutputStream.java:63) [resteasy-jaxrs-3.0.8.Final.jar:]

        at org.jboss.resteasy.plugins.providers.StringTextStar.writeTo(StringTextStar.java:64) [resteasy-jaxrs-3.0.8.Final.jar:]

        at org.jboss.resteasy.plugins.providers.StringTextStar.writeTo(StringTextStar.java:22) [resteasy-jaxrs-3.0.8.Final.jar:]

        at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.writeTo(AbstractWriterInterceptorContext.java:129) [resteasy-jaxrs-3.0.8.Final.jar:]

        at org.jboss.resteasy.core.interception.ServerWriterInterceptorContext.writeTo(ServerWriterInterceptorContext.java:62) [resteasy-jaxrs-3.0.8.Final.jar:]

        at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.proceed(AbstractWriterInterceptorContext.java:118) [resteasy-jaxrs-3.0.8.Final.jar:]

        at tr.com.emre.myproject.rs.interceptors.ResponseDataWriterInterceptor.aroundWriteTo(ResponseDataWriterInterceptor.java:65) [classes:]

        at tr.com.emre.myproject.rs.interceptors.ResponseDataWriterInterceptor$Proxy$_$$_WeldClientProxy.aroundWriteTo(Unknown Source) [classes:]

        at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.proceed(AbstractWriterInterceptorContext.java:122) [resteasy-jaxrs-3.0.8.Final.jar:]

        at org.jboss.resteasy.security.doseta.DigitalSigningInterceptor.aroundWriteTo(DigitalSigningInterceptor.java:143) [resteasy-crypto-3.0.8.Final.jar:]

        at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.proceed(AbstractWriterInterceptorContext.java:122) [resteasy-jaxrs-3.0.8.Final.jar:]

        at org.jboss.resteasy.plugins.interceptors.encoding.GZIPEncodingInterceptor.aroundWriteTo(GZIPEncodingInterceptor.java:100) [resteasy-jaxrs-3.0.8.Final.jar:]

        at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.proceed(AbstractWriterInterceptorContext.java:122) [resteasy-jaxrs-3.0.8.Final.jar:]

        at org.jboss.resteasy.core.ServerResponseWriter.writeNomapResponse(ServerResponseWriter.java:99) [resteasy-jaxrs-3.0.8.Final.jar:]

        at org.jboss.resteasy.core.SynchronousDispatcher.writeResponse(SynchronousDispatcher.java:427) [resteasy-jaxrs-3.0.8.Final.jar:]

        at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:376) [resteasy-jaxrs-3.0.8.Final.jar:]

        at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179) [resteasy-jaxrs-3.0.8.Final.jar:]

        at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220) [resteasy-jaxrs-3.0.8.Final.jar:]

        at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56) [resteasy-jaxrs-3.0.8.Final.jar:]

        at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51) [resteasy-jaxrs-3.0.8.Final.jar:]

        at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final]

        at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]

        at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]

        at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]

        at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)

        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]

        at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:113) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]

        at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]

        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]

        at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45) [undertow-core-1.0.15.Final.jar:1.0.15.Final]

        at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:61) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]

        at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58) [undertow-core-1.0.15.Final.jar:1.0.15.Final]

        at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]

        at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) [undertow-core-1.0.15.Final.jar:1.0.15.Final]

        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]

        at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)

        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]

        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]

        at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:240) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]

        at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:227) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]

        at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:73) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]

        at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:146) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]

        at io.undertow.server.Connectors.executeRootHandler(Connectors.java:177) [undertow-core-1.0.15.Final.jar:1.0.15.Final]

        at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:727) [undertow-core-1.0.15.Final.jar:1.0.15.Final]

        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_60]

        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_60]

        at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_60]

       

      I'm trying to understand to couse of this exception. Anybody have any idea about this? Thanx.