Bugs item #697254, was opened at 2003-03-04 13:56
Message generated for change (Comment added) made by oravecz
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=376685&aid=697254&group_id=22866

Category: JBossServer
Group: v3.2
Status: Closed
Resolution: Invalid
Priority: 5
Submitted By: Marcus Eriksson (marcuseriksson)
Assigned to: Scott M Stark (starksm)
Summary: ClassCastException when using EAR based scoping

Initial Comment:
I'm not sure if this behaviour is by design or a bug...

Two EARs with a bean in the first EAR calling a bean in 
the second EAR.
Is this not possible if I use EAR based scoping?
I get a ClassCastException when I narrow the home of 
the called bean:

Object o = ctx.lookup(jndiName);
TestBeanHome home = (TestBeanHome)
PortableRemoteObject.narrow(o,
TestBeanHome.class);

(JBoss 3.2.0RC2, J2SE1.4.1)




----------------------------------------------------------------------

Comment By: Jim Cook (oravecz)
Date: 2003-08-11 17:56

Message:
Logged In: YES 
user_id=6215

I was going to post this on the forums (Pay Documentation), 
since there is a TODO in the docs to expound upon this topic, 
but the forums appear to be down.

Document Pass-By-Value semantics

Our project team has developed a number of general-purpose 
EJBs, and these have evolved over time. Many of these EJBs 
depend on shared class libraries that also evolve over time. 
Now imagine that we have two general-purpose EJBs (called 
EJB1 and EJB2) that are deploed into jBoss and utilized by our 
application. EJB1 and EJB2 both use the library SHARED1.

Now, SHARED1 has evolved over time. In fact, EJB1 uses an 
older version of SHARED1, while EJB2 uses a version that has 
a few more methods available in it. Also, EJB2 has an ejb-ref 
to EJB1, indicating that EJB2 depends on EJB1.

Given the current jBoss deployment scenario, we have three 
options when it comes to the UnifiedClassloaders:

1. Deploy EJB1 and EJB2 in the same scope.

This is the default jBoss 3.2 behavior, and is easily achieved 
by adding nothing extra to the deployment desciptors in the 
EAR. It can also be achieved using the jboss-app.xml 
descriptor specifiying the same name for the <loader-
repository> tag.

This approach will limit any duplicate class definitions (such as 
all of the classes in SHARED1) to the first one encountered by 
the classloader. If the SHARED1 (older version) in EJB1 gets 
loaded first, then EJB2 will not have access to the newer 
methods in its copy of SHARED1. This will manifest by 
receiving the NoSuchMethodError exception.

2. Deploy EJB1 and EJB2 in separate scopes.

This is achieved by adding a META-INF/jboss-app.xml 
descriptor to the ear files and specifying different values for 
the <loader-repository> tag. With this approach, EJB1 and 
EJB2 will use their own individual classloaders.

This approach gives each EJB access to their own SHARED1 
library. However, EJB2 will eventually need to invoke a method 
on EJB1, and when it goes to lookup the Home interface in 
JNDI it can run into casting problems. Specifically, it attempts 
to cast the JNDI embedded value (UCL1->EJB1Home) as EJB2-
>EJB1Home. This causes the ClassCastException since these 
classes cannot be directly cast to each other.

3. Change the packaging of the EJB's HOME interfaces

By using scoped classloaders, it should be possible to move 
the Home interfaces for EJB1 into the base UnifiedClassloader 
(system classloader), but this seems mucho intrusive. This 
can be further complicated when third-party EJBs are involved.

-------------

Apparently, the PortableRemoteObject.lookup behavior can be 
changed to use Pass-By-Value semantics rather than the 
default Pass-By-Reference approach, and this should solve 
the only shortcoming in scenario #2 above.

Scott documented in a bug report (see reference) that pass-
by-value is activated by editing the client interceptors and 
alluded to changing the way InitialContext is initiated. 
Perhaps the change he mentions regarding InitialContext 
lookups are necessary, but this would kill our portability and 
seems way too intrusive.

Nevertheless, I have made changes to the interceptors and 
the InitialContext in a small testcase without any affect. I still 
continue to get ClassCastExceptions. Please provide the 
complete docs on how to implement pass-by-value.


Questions:

1. Can the jBoss team provide complete documentation on 
how to get scenario #2 above working on jBoss 3.2 RC2?
2. Does pass-by-value limit the application developer or 
performance of the app server in any way? (other than the 
cost of the lookup which I assume will now require some 
serialization as opposed to a simple cast. at least we are in 
the same VM.)
3. Does the pass-by-value behavior require all of the 
InitialContext creation in our code to be affected? If so, this 
seems like a really bad idea. Perhaps it can be made 
dependent on a server config option?


----------------------------------------------------------------------

Comment By: Scott M Stark (starksm)
Date: 2003-03-05 07:54

Message:
Logged In: YES 
user_id=175228

Yes, this violates the point of scoping which is to isolate
the deployment classes. The TestBeanHome seen in ear1 will
not match the corresponding class bound into JNDI. You can
disable the call by reference mode which is causing the
class cast exception by creating a custom container
configuration that uses the ByValueInvokerInterceptor in the
client proxy. An example from the testsuite is shown below.
There still may be a problem with the JNDI lookup also using
a by reference semantic as well that needs to be turned off.
The only way to do this is to create an InitialContext with
the  java.naming.provider.url=localhost:1099 property
defined. This causes the lookup to go through RMI and will
isolate the version of TestBeanHome bound into JNDI from the
one available in the second ear.


<?xml version="1.0" encoding="UTF-8"?>

<jboss>
   <invoker-proxy-bindings>
      <invoker-proxy-binding>
         <name>by-value-stateless-rmi-invoker</name>
        
<invoker-mbean>jboss:service=invoker,type=jrmp</invoker-mbean>
        
<proxy-factory>org.jboss.proxy.ejb.ProxyFactory</proxy-factory>
         <proxy-factory-config>
            <client-interceptors>
               <home>
                 
<interceptor>org.jboss.proxy.ejb.HomeInterceptor</interceptor>
                 
<interceptor>org.jboss.proxy.SecurityInterceptor</interceptor>
                 
<interceptor>org.jboss.proxy.TransactionInterceptor</interceptor>
                 
<interceptor>org.jboss.invocation.ByValueInvokerInterceptor</interceptor>
               </home>
               <bean>
                 
<interceptor>org.jboss.proxy.ejb.StatelessSessionInterceptor</interceptor>
                 
<interceptor>org.jboss.proxy.SecurityInterceptor</interceptor>
                 
<interceptor>org.jboss.proxy.TransactionInterceptor</interceptor>
                 
<interceptor>org.jboss.invocation.ByValueInvokerInterceptor</interceptor>
               </bean>
            </client-interceptors>
         </proxy-factory-config>
      </invoker-proxy-binding>
   </invoker-proxy-bindings>

   <enterprise-beans>
      <session>
         <ejb-name>ENCBean1</ejb-name>
        
<local-jndi-name>jbosstest/ejbs/local/ENCBean1</local-jndi-name>
      </session>
      <session>
         <ejb-name>SecuredEJB</ejb-name>
         <jndi-name>jbosstest/ejbs/SecuredEJB</jndi-name>
         <configuration-name>Secure Stateless
SessionBean</configuration-name>
      </session>
      <session>
         <ejb-name>UnsecuredEJB</ejb-name>
         <jndi-name>jbosstest/ejbs/UnsecuredEJB</jndi-name>
         <ejb-ref>
            <ejb-ref-name>ejb/Session</ejb-ref-name>
            <jndi-name>jbosstest/ejbs/SecuredEJB</jndi-name>
         </ejb-ref>
      </session>
      <session>
         <ejb-name>NotOptimizedEJB</ejb-name>
         <jndi-name>jbosstest/ejbs/NotOptimizedEJB</jndi-name>
         <invoker-bindings>
            <invoker>
              
<invoker-proxy-binding-name>by-value-stateless-rmi-invoker</invoker-proxy-binding-name>
            </invoker>
         </invoker-bindings>
      </session>
   </enterprise-beans>

   <container-configurations>
      <container-configuration extends="Standard Stateless
SessionBean">
         <container-name>Secure Stateless
SessionBean</container-name>
         <security-domain>java:/jaas/other</security-domain>
      </container-configuration>
   </container-configurations>

</jboss>


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=376685&aid=697254&group_id=22866


-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
_______________________________________________
JBoss-Development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to