14 Replies Latest reply on Oct 6, 2006 12:09 PM by fakeer

    Interceptor medasata issue

    tterm

      Hello,

      I'm not sure if this is the right forum for my question. If not sorry and please point me to the right one.

      I get allways a class cast exception if I put some values into the metadate from the invocation object in the invoke method of an interceptor. It works fine with JBoss until version 4.0.3SP1. But with later versions I run allways in this issue.

      In a client side interceptor I do the following:

      SimpleMetaData metaData = invocation.getMetaData();
      
      metaData.addMetaData(InterceptorConstants.ARM_TAG,
       InterceptorConstants.ARM_CORR_KEY, corr.getBytes());
      
      


      corr.getBytes(); is a simple byte array


      If I do an EJB request I get allways this exception:

      java.lang.ClassCastException: org.jboss.serial.objectmetamodel.DataContainer$DataContainerOutput
       org.jboss.aop.util.MarshalledValue.writeExternal(MarshalledValue.java:190)
       org.jboss.serial.persister.ExternalizePersister.writeData(ExternalizePersister.java:58)
       org.jboss.serial.objectmetamodel.ObjectDescriptorFactory.describeObject(ObjectDescriptorFactory.java:275)
       org.jboss.serial.objectmetamodel.DataContainer$DataContainerOutput.writeObject(DataContainer.java:386)
       org.jboss.aop.metadata.SimpleMetaData.writeExternal(SimpleMetaData.java:226)
       org.jboss.serial.persister.ExternalizePersister.writeData(ExternalizePersister.java:58)
       org.jboss.serial.objectmetamodel.ObjectDescriptorFactory.describeObject(ObjectDescriptorFactory.java:275)
       org.jboss.serial.objectmetamodel.DataContainer$DataContainerOutput.writeObject(DataContainer.java:386)
       org.jboss.aop.joinpoint.MethodInvocation.writeExternal(MethodInvocation.java:321)
       org.jboss.serial.persister.ExternalizePersister.writeData(ExternalizePersister.java:58)
       org.jboss.serial.objectmetamodel.ObjectDescriptorFactory.describeObject(ObjectDescriptorFactory.java:275)
       org.jboss.serial.objectmetamodel.DataContainer$DataContainerOutput.writeObject(DataContainer.java:386)
       org.jboss.serial.io.MarshalledObjectForLocalCalls.<init>(MarshalledObjectForLocalCalls.java:38)
       org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:53)
       org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       de.fh_wiesbaden.cs.vs.jboss_ejb3_instrumentation.interceptor.client.ARMRunningClient.invoke(ARMRunningClient.java:248)
       de.fh_wiesbaden.cs.vs.jboss_ejb3_instrumentation.interceptor.client.ClientARMInterceptor.invoke(ClientARMInterceptor.java:94)
       org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       de.fh_wiesbaden.cs.vs.jboss_ejb3_instrumentation.interceptor.client.ClientGetCorrelatorFromThreadLocalInterceptor.invoke(ClientGetCorrelatorFromThreadLocalInterceptor.java:43)
       org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       org.jboss.ejb3.stateless.StatelessClusteredProxy.invoke(StatelessClusteredProxy.java:100)
       $Proxy92.getCategory(Unknown Source)
       de.fh_wiesbaden.cs.vs.xpetstore.web.struts.action.category.CategoryAction.doExecute(CategoryAction.java:48)
       de.fh_wiesbaden.cs.vs.xpetstore.web.struts.action.BaseAction.execute(BaseAction.java:78)
       org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:446)
       org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:266)
       org.apache.struts.action.ActionServlet.process(ActionServlet.java:1292)
       org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:492)
       javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
       javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
       de.fh_wiesbaden.cs.vs.xpetstore.web.filter.SignOnFilter.doFilter(SignOnFilter.java:128)
       com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(Unknown Source)
       com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(Unknown Source)
       org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      


      I tried to debug this thing but I couldn't get it why it occurs.

      I appreciate any help and thanks in advance. If more information is required I'll post it.

      Regards,
      Thomas Termin

        • 1. Re: Interceptor medasata issue
          clebert.suconic

          Can you provide more details on how this happens?

          It looks an issue with EJB3 invocation layer.

          If you provide a testcase, we might be able to identify the issue.

          If this turns to be a EJB3 thread I can move this to the right forum later, but I just need more context. For example, how you're getting SimpleMetaData. What's the context... that kind of thing.


          Clebert

          • 2. Re: Interceptor medasata issue
            tterm

            Hello clebert,

            I will provide you the complete information and a sample on the weekend.

            Regards,
            Thomas Termin

            • 3. Re: Interceptor medasata issue
              tterm

              Hello Clebert,

              so now let's come to the details and sorry for the long response time. I have a lot to do at the moment.

              The interceptors are requested during an ejb3 method call. The client side interceptor code is the following:

              public class ExampleClientInterceptor implements Interceptor, Serializable {
               private static Logger logger = Logger.getLogger(ExampleClientInterceptor.class);
              
               public String getName() {
               return "ExampleClientInterceptor";
               }
              
               public Object invoke(Invocation invocation) throws Throwable {
               logger.debug("Client: request");
               SimpleMetaData metaData = invocation.getMetaData();
               metaData.addMetaData("tag", "attr", "Hello JBoss;-)");
               Object obj = invocation.invokeNext();
               logger.debug("Client: response");
               return obj;
               }
              }


              You can see I just add a simple string to the metadata which should be read later from the server side interceptor. The server side interceptor has the following code:

              public class ExampleServerInterceptor implements Interceptor{
               private static Logger logger = Logger.getLogger(ExampleServerInterceptor.class);
              
               public String getName(){
               return "ExampleServerInterceptor";
               }
              
               public Object invoke(Invocation invocation) throws Throwable{
               logger.debug("Server: request");
               SimpleMetaData metaData = invocation.getMetaData();
               String str = (String)metaData.getMetaData("tag", "attr");
               logger.debug("Output from metaData: " + str);
               Object obj = invocation.invokeNext();
               logger.debug("Server: response");
               return obj;
               }
              }


              The interceptors are both registerded in the ejb3-interceptors-aop.xml which looks like the following:
              <aop>
               <interceptor class="de.example.ExampleClientInterceptor" scope="PER_VM"/>
               <interceptor class="de.example.ExampleServerInterceptor" scope="PER_VM"/>
              
              ....
              
              <stack name="StatelessSessionClientInterceptors">
               <interceptor-ref name="de.example.ExampleClientInterceptor"/>
              ...
              </stack>
              ... the same for the other client side stacks like stateful and so on
              
               server side stuff
              
               <domain name="Stateless Bean">
               <bind pointcut="execution(public * *->*(..))">
               <interceptor-ref name="de.example.ExampleServerInterceptor"/>
               ...
               </domain>
              
              ... the same for the other session bean stuff
              
              </aop>
              

              So if you invoke an ejb3 method then you get allways the exception I described before and you will never come to the server side interceptor. I don't know if I do something wrong here but as I said before it works fine until JBoss4.0.3SP1.

              It would be very nice if we could sorting out this things because I need it to finish an performance instrumentation project.

              You can download the test project described before from http://www.strace.org/~tterm/jboss-testcase.zip (You can contact me private if you use this domain and put the username before the @ sign). If you need an ejb project for testing this things I can give you also an test project. Just let me know.

              Thanks in advance.
              Thomas Termin

              • 4. Re: Interceptor medasata issue
                tterm

                Ok I tried the test again and I solved the problem for me.

                If I set the last parameter (Payload.KEY) for the addMetaData() method to 'AS_IS' then it works fine in jboss-4.0.4 and also 4.0.5. If the default payload key is MARSAHLLED (not sure if the syntax is correct) then it crashes with the ClassCastException.

                Can somebody explain me the difference between AS_IS and MARSHALLED or rather why it crashes with the default payload type?

                Regards,
                Thomas Termin

                • 5. Re: Interceptor medasata issue
                  clebert.suconic

                  AS_IS is always sent by parameter, and MARSHALLED will be serialized during the invocationLayer guaranteeing classLoader isolation. You probably had or a classPath issue or you found a ClassLoaderIsolation bug somewhere on the layer you were working. (EJB3?)

                  If your data is correctly serializable, I think it would worth to provide a testcase to EJB3 team.

                  • 6. Re: Interceptor medasata issue
                    tterm

                    Yes the whole thing is just for EJB. The testcase which I added above is for EJB3. That are two interceptors one for the clientside and one for the serverside. I added a String to the metadata so there should be no classpath conflict, right?
                    If I understood you right then it should also work with the default MARSHALLED but it doesn't!

                    If I have CallByValue enabled then all the parameter should be of type MARSAHLLED. Is this right?

                    • 7. Re: Interceptor medasata issue
                      clebert.suconic

                       

                      "tterm" wrote:

                      If I have CallByValue enabled then all the parameter should be of type MARSAHLLED. Is this right?



                      If you are using a RemoteInterface you always have a call-by-value on EJB3.


                      Now I don't understand if you are using EJB2 (with our regular Interceptors) or EJB3 with EJB interceptors.

                      One thing you should try is using MarshalledValues. They will provide you lazy serialization. Most of the sutff we set on Marshalled are using MarshalledValues.


                      But if you use AS_IS you won't serialize the data.

                      • 8. Re: Interceptor medasata issue
                        tterm

                        I use EJB3 with the org.jboss.aop.advice.Interceptor. Has nothing to do with ejb2. Sorry was my mistake.

                        I debugged an EJB3 method call and I saw that all the values in SimpleMetaData have the type AS_IS. So I did just the same for my values. Before I never used the Payload parameter as you can see in the code snippet above. So the default was then MarshalledValue and the ClassCastException happend.

                        As far as I know there are only three payload types: MARSHALLED, AS_IS and TRANSIENT. So you mean I should use MARSHALLED but that's exactly where the ClassCastException occurs.


                        • 9. Re: Interceptor medasata issue
                          clebert.suconic

                          Open a thread on EJB3 forum explaining how you set the MARSHALLED payload, and that a ClassCastException on MarshalledValue is happening.

                          I'm not sure what's the semantic on EJB3 for Interceptors and Payloads. I was just telling you what was happening.

                          Based on the correct semantic someone from EJB3 will have a better understanding in how to help you.

                          Also, maybe you could explain what's your use case for them. Most of usecases we found for Interceptors and MARSHALLED until now were JBoss internals oriented. I don 't know if the spec treats PAYLOAD on invocation or not.


                          Clebert

                          • 10. Re: Interceptor medasata issue
                            clebert.suconic

                            If you could... please provide a link on this forum when you open the thread on EJB3 user forum.

                            • 11. Re: Interceptor medasata issue
                              tterm

                              Hello Clebert,

                              I did the post in the EJB3 forum but I guess it is not that important for the ejb3 people. Nobody is answering!

                              Regards,
                              Thomas Termin

                              • 12. Re: Interceptor medasata issue
                                clebert.suconic

                                Can you place the link for the forum post?

                                When you open the message... copy that address and place it here please. I' m not finding your message

                                • 13. Re: Interceptor medasata issue
                                  tterm

                                  Hello Clebert,

                                  this is the link: http://www.jboss.org/index.html?module=bb&op=viewtopic&t=91671

                                  Regards,
                                  Thomas Termin

                                  • 14. Re: Interceptor medasata issue
                                    fakeer

                                    hey thomas, can you tell me how you configured your client and server side interceptors to work with ejb3? did you start another thread elsewhere regarding this problem?

                                    or clebert can you point me to any documentation on how to configure this stuff (what xmls etc.)

                                    thanks