Announcement Announcement Module
Collapse
No announcement yet.
Exception using JndiTemplate Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Exception using JndiTemplate

    Hi All,

    I have a little problem using the JndiTemplate to access the Jndi EJB home interface references. My configuration is WLS 8.1 sp4 with Spring 2.0M2.

    The Exception causes the BeanContext not to load if the lookupOnStartup attribute is set to true or the same Exception happens on the EJB Home.create() method after the BeanContext is initialised if the lookupOnStartup property is set to false (Same exception both times).


    The Exception I receive is as follows:

    Code:
    log4j:WARN No appenders could be found for logger (org.springframework.beans.factory.xml.XmlBeanDefinitionReader).
    log4j:WARN Please initialize the log4j system properly.
    Error Initialising the Bean Context.
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'vdc0e_eSelfcareSoapBeanHome' defined in class path resource [applicationContext-WLS-Test.xml]: Invocation of init method failed; nested exception is javax.naming.CommunicationException: null
    javax.naming.CommunicationException [Root exception is java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
    	java.lang.ClassNotFoundException: org.springframework.beans.factory.support.ManagedProperties:  This error could indicate that a component was deployed on a  cluster member but not other members of that cluster. Make sure that any component deployed on a server that is part of a cluster is also deployed on all other members of that cluster]
    	at weblogic.jndi.internal.ExceptionTranslator.toNamingException(ExceptionTranslator.java:83)
    	at weblogic.jndi.internal.WLContextImpl.translateException(WLContextImpl.java:390)
    	at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:346)
    	at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:336)
    	at javax.naming.InitialContext.lookup(Unknown Source)
    	at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:123)
    	at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:85)
    	at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:121)
    	at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:146)
    	at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:86)
    
    etc...
    (Full stack trace available in attacment)
    As can be seen in the stack trace it seems that the org.springframework.beans.factory.support.ManagedP roperties cannot be found. However the Spring.jar is definately on the class path of the client as the context initialises correctly if the lookupOnStartup property is set to false.

    There is NO spring code on the server at all....

    I have 2 context files

    applicationContext.xml that just sets the test harness class

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
    
    	<!-- Declare the testHarness class and pass in all the backends to be tested -->
    	<bean id="testHarness" class="com.o2.germany.sm.ECRMTestHarness">
    	</bean>
    	
    </beans>

    and my applicationContext-WLS-Test.xml

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
    
    	<!-- provide the environment information for the JNDI lookup on vdc0e -->
    	<bean id="vdc0e_jndiTemplate" class="org.springframework.jndi.JndiTemplate">
    		<property name="environment">
    			<props>
    				<prop key="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory</prop>
    				<prop key="java.naming.provider.url">t3://vdc0e:50060</prop>
    			</props>
    		</property>
    	</bean>
    
    	<!-- Setup an abstract JNDI Lookup object for all eSelfcareSoapBean Home interfaces for all real ones to inherit -->
    	<bean id="eSelfcareSoapBeanHome" class="org.springframework.jndi.JndiObjectFactoryBean" abstract="true">
    		<property name="jndiName"><value>eSelfCare.ESelfcareSoapHome</value></property>
    		<property name="lookupOnStartup"><value>true</value></property>
    		<property name="proxyInterface"><value>de.viaginterkom.ca.ecrm.eselfcare.ejbserver.ejb.soap.ESelfcareSoapHome</value></property>
    	</bean>
    
    	<!-- JNDI Lookup for eSelfcareSoapBean Home interface on vdc0e -->	
    	<bean id="vdc0e_eSelfcareSoapBeanHome" parent="eSelfcareSoapBeanHome">
    		<property name="jndiTemplate">
    			<ref local="vdc0e_jndiTemplate"/>
    		</property>
    	</bean>
    	
    	<!-- declare the backend object to represent vdc0e -->
    	<bean id="vdc0e-WLS" class="com.o2.germany.sm.WLSBackend">
    		<property name="serverName"><value>vdc0e-WLS</value></property>
    		<property name="home"><ref local="vdc0e_eSelfcareSoapBeanHome"/></property>
    	</bean>	
    	
    
    </beans>
    The following are the required source files

    The TestHarness class


    Code:
    package com.o2.germany.sm;
    
    import java.util.Iterator;
    import java.util.Map;
    import java.util.TreeMap;
    
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    public class ECRMTestHarness {
    	
    	private Map backends;
    	
    	public void setBackends(Map backends) {
    		this.backends = new TreeMap(backends);
    	}	
    	
    	public static void main(String [] args) {
    		if(args.length < 1) {
    			System.out.println("Must provide context.xml file.");
    			System.exit(0);
    		}
    		ApplicationContext ctx = null;
    		try {
    			ctx = new ClassPathXmlApplicationContext(args);
    		}catch(Exception ex) {
    			System.out.println("Error Initialising the Bean Context.");
    			ex.printStackTrace();
    			System.exit(-1);
    		}
    		
    		ECRMTestHarness th = (ECRMTestHarness)ctx.getBean("testHarness");
    		Map backends = ctx.getBeansOfType(Backend.class);
    		th.setBackends(backends);
    		
    		th.testBackends();
    	}
    
    	
    	private void testBackends() {
    		System.out.println("**** Checking eCRM Backends ****");
    		for(Iterator it = backends.values().iterator(); it.hasNext();) {
    			System.out.println(testBackend(it.next()));
    		}
    		System.out.println("**** Finished Checking eCRM Backends ****");
    	}
    	
    	private String testBackend(Object obj) {
    		if(!(obj instanceof Backend)) {
    			return "Object " + obj + " is not of type Backend.";
    		}
    		
    		// test the backEnd
    		Backend backend = (Backend)obj;
    		return backend.test();
    	}
    }
    The interface for a backend to be tested

    Code:
    package com.o2.germany.sm;
    
    
    public interface Backend {
    	
    	public void setServerName(String name);
    	public String test();
    
    }
    And the actual Implementation for a backend test


    Code:
    package com.o2.germany.sm;
    
    import java.lang.reflect.UndeclaredThrowableException;
    import java.rmi.RemoteException;
    import java.util.Date;
    
    import javax.ejb.CreateException;
    
    import de.viaginterkom.ca.ecrm.eselfcare.ejbserver.ejb.soap.ESelfcareSoap;
    import de.viaginterkom.ca.ecrm.eselfcare.ejbserver.ejb.soap.ESelfcareSoapHome;
    
    
    public class WLSBackend implements Backend {
    	
    	private String serverName;
    	private ESelfcareSoapHome home; 
    	
    	
    	public void setHome(ESelfcareSoapHome home) {
    		this.home = home;
    	}
    	
    	public void setServerName(String serverName) {
    		this.serverName = serverName;
    	}
    	
    	public String test() {
    		ESelfcareSoap bean = null;
    		try {
    			bean = home.create();
    			bean.testDate(new Date());
    			return "Server [" + serverName + "] is working OK.";
    		}
    		catch (RemoteException re) {
    			return "Server [" + serverName + "] is NOT reachable. Could be down. [" + re.getMessage() + "]";			
    		}
    		catch (CreateException ce) {
    			return "Server [" + serverName + "] is RUNNING but ESelfcareSoap Object is not able to be created. [" + ce.getMessage() + "]";			
    		}
    		
    		catch (UndeclaredThrowableException ute) {
    			Throwable t = ute.getUndeclaredThrowable();
    			t.printStackTrace();
    			if(t == null)
    				return "Server [" + serverName + "] has a problem. UndeclaredThrowableException has no cause.";
    			else
    				return "Server [" + serverName + "] has a problem. [" + t + "]";
    		}
    		catch (Exception ex) {
    			ex.printStackTrace();
    			return "Server [" + serverName + "] has a problem. [" + ex.getMessage() + "]";			
    		}
    		
    		finally {
    			if(bean != null) {
    				try {
    					bean.remove();
    				}
    				catch(Exception ex) {
    					// ignore
    				}
    			}
    		}
    	}
    
    }
    Any ideas?

    Steve

  • #2
    Only affects 2.0M2

    Hi all again,

    OK, I tries this again using the 1.2.5 spring.jar and it works fine. This only seems to affect Property types i.e. the exception is caused by the following

    Code:
    	<!-- provide the environment information for the JNDI lookup on vdc0e -->
    	<bean id="vdc0e_jndiTemplate" class="org.springframework.jndi.JndiTemplate">
    		<property name="environment">
    			<props>
    				<prop key="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory</prop>
    				<prop key="java.naming.provider.url">t3://vdc0e:50060</prop>
    			</props>
    		</property>
    	</bean>
    
    	<!-- JNDI Lookup for eSelfcareSoapBean Home interface on vdc0e -->	
    	<bean id="vdc0e_eSelfcareSoapBean" parent="eSelfcareBean">
    		<property name="jndiTemplate">
    			<ref local="vdc0e_jndiTemplate"/>
    		</property>
    	</bean>
    If I comment out the property jndiTemplate in the bean with id="vdc0e_eSelfcareSoapBean" and set the InitialContext information as -D JVM options all works fine in 2.0M2 as well.

    P.S. I refactored the applicationContext file a bit as well as the WLSBackend class to use the business interface instead of the Home interface trying to narrow down the problem i.e. used the org.springframework.ejb.access.SimpleRemoteStatele ssSessionProxyFactoryBean class instead of the JndiObjectFactory (its the same problem both ways)


    Regards

    Steve

    Comment

    Working...
    X