4 Replies Latest reply on Oct 12, 2010 4:24 AM by ceene

    Problem with InitialContext.lookup

    ceene

      Hey guys

       

      I have a little problem with my web-application. I'd like to call a method from an deployed *.jar-file.

      I tried with the following code:

       

      [Code]

      Context context = new InitialContext();
      test = context.getNameInNamespace();
      manager = (DataProtection) context.lookup("DataProtectionBean/remote");

      [/Code]

       

      But I get the follwing error-Message

       

      13:50:27,763 ERROR [STDERR] java.lang.ClassCastException: $Proxy333 cannot be cast to src.interfaces.DataProtection
      13:50:27,763 ERROR [STDERR]     at src.ejb.DataProtectionService.<init>(DataProtectionService.java:32)
      ......

       

      But I don't understand the problem. My Interface in the *.jar-file and my Interface in the web-application are the same.

      Here the interface of the *.jar-file

      [Code]

      package com;

       

      import java.util.List;

       

      public interface DataProtection {

       

          List<RecipientData> getRecipients(String country, AdressIdType type, long id);

       

      }

      [/Code]

       

      Here the interface of the application

      [Code]

      package src.interfaces;

       

      import java.util.List;

       

      import javax.ejb.Remote;

       

      import src.entity.RecipientData;
      import src.klassen.AdressIdType;

       

      @Remote
      public interface DataProtection {
         
          List<RecipientData> getRecipients(String country, AdressIdType type, long id);
      }

      [/Code]

       

      I hope somebody can help me I try to solve the problem since three days........if you need more code or other information tell me.

        • 1. Re: Problem with InitialContext.lookup
          wdfink

          Hi Sascha,

          you have the same look of the interface, but one is com.DataProtection and one is src.interfaces.DataProtection.

           

          This is for me and for Java not the same interface!

          You should use the same source or interface.jar file for your Web-App!!

           

          Also your code new InitialContext() ....

          might be easier if you use

          @EJB DataProtection manager

          and let do the container the work for you

          • 2. Re: Problem with InitialContext.lookup
            ceene

            thanks wolf-dieter

             

            the annotation is not good because the variable is null.

             

            i changed my packagenaming in the bean and now the constructor is ok, but i get another error if i try to call the method.

            error-message:

            15:56:54,122 ERROR [STDERR] java.lang.RuntimeException: Could not resolve beanClass method from proxy call
            15:56:54,122 ERROR [STDERR]     at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:274)
            15:56:54,122 ERROR [STDERR]     at org.jboss.ejb3.remoting.IsLocalInterceptor.invokeLocal(IsLocalInterceptor.java:81)
            15:56:54,122 ERROR [STDERR]     at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:72)
            15:56:54,122 ERROR [STDERR]     at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)

            .......

             

            Can you eventually solve this problem too? :-)

            • 3. Re: Problem with InitialContext.lookup
              wdfink

              Sounds like a similar problem.

              The method will be found by the signature, could it be that your AdressIdType is also different?

               

              I recommend that you use the interface.jar file for your application.

              Two choices, pack the jar into your WAR file or copy to the server/.../lib directory.

              Also it is possible to use the default JBoss classloader (no loder-repository tag in your app), in this case all classes are shared between different deployment files.

              • 4. Re: Problem with InitialContext.lookup
                ceene

                Thanks a lot. Now everthing is fine.