Announcement Announcement Module
Collapse
No announcement yet.
Access to Remote EJB : org.springframework.remoting.RemoteLookupFailureEx ception Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Access to Remote EJB : org.springframework.remoting.RemoteLookupFailureEx ception

    Hi everyone,

    I'm facing a small configuration problem within my Spring Batch calls.

    My batch is currently just an EJB connectivity test. I'm deploying my EAR application on a JBoss 5.1.0 GA server. Here is what I first made, which completely succeeded :

    PersonReader.java

    Code:
    	private PersonApplicationService personApplicationService;
    	private int readIndex = 1;
    
    	@Override
    	public PersonDTO read() throws Exception, UnexpectedInputException, ParseException {
    		Properties p = new Properties();
    		p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
    		p.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
    		p.put(Context.PROVIDER_URL, "jnp://localhost:1099");
    		InitialContext context = new InitialContext(p);
    		personApplicationService = (PersonApplicationService) context.lookup("test/PersonApplicationServiceBean/remote");
    		
    		List<PersonDTO> persons = personApplicationService.findList(readIndex, 1);
    		readIndex++;
    		if(persons.size() > 0) return persons.get(0);
    		else return null;
    	}
    batch-sample-context.xml

    Code:
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:aop="http://www.springframework.org/schema/aop"
    	xmlns:p="http://www.springframework.org/schema/p"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
    		http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd
    		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    		
    	<bean id="PersonReader" class="test.batch.PersonReader">
    	</bean>
    	<bean id="PersonWriter" class="test.batch.PersonWriter"></bean>
    	
    	<bean id="jobLauncher"
    		class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
    		<property name="jobRepository" ref="jobRepository" />
    	</bean>
    	
    	<bean id="jobRepository"
    		class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean">
    		<property name="transactionManager" ref="transactionManager" />
    	</bean>
    	
    	<bean id="transactionManager"
    		class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" >
    	</bean>
    
    	<bean id="minimal"
    		class="org.springframework.batch.core.job.SimpleJob">
    		<property name="jobRepository" ref="jobRepository" />
    		<property name="steps">
    			<bean id="simpleStep"
    				class="org.springframework.batch.core.step.item.SimpleStepFactoryBean">
    				<property name="transactionManager" ref="transactionManager" />
    				<property name="jobRepository" ref="jobRepository" />
    				<property name="itemReader" ref="PersonReader" />
    				<property name="itemWriter" ref="PersonWriter" />
    			</bean>
    		</property>
    	</bean>
    
    </beans>
    I do run the batch in Eclipse with a "Run as..." configuration which do call the main class org.springframework.batch.core.launch.support.Comm andLineJobRunner with "batch-sample-context.xml minimal" as arguments

    My findList() function do return a list of persons, but my second parameter make it return only one element for each call.

    The writer just System.out.println the PersonDTO object, which is completely correctly printed in my Spring Batch console.

    Now, this is not optimal as JNDI call is performed at each read() call to get the remote EJB. This has a large performance overhead (I suppose). Here is my second test, trying to use Spring configuration file to initialise it correctly :

    PersonReader.java

    Code:
    	private PersonApplicationService personApplicationService;
    	private int readIndex = 1;
    	
    	@Override
    	public PersonDTO read() throws Exception, UnexpectedInputException, ParseException {
    		List<PersonDTO> persons= personApplicationService.findList(readIndex, 1);
    		readIndex++;
    		if(persons.size() > 0) return persons.get(0);
    		else return null;
    	}
    batch-sample-context.xml

    Code:
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:aop="http://www.springframework.org/schema/aop"
    	xmlns:p="http://www.springframework.org/schema/p"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
    		http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd
    		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    		
    	<bean id="PersonApplicationServiceBean" class="org.springframework.ejb.access.SimpleRemoteStatelessSessionProxyFactoryBean">
    		<property name="jndiName" value="test/PersonApplicationServiceBean/remote" />
    		<property name="businessInterface" value="test.common.application.PersonApplicationService" />
    		<property name="jndiEnvironment">
    			<props>
    				<prop key="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory</prop>
    				<prop key="java.naming.factory.url.pkgs">org.jboss.naming:org.jnp.interfaces</prop>
    				<prop key="java.naming.provider.url">jnp://localhost:1099</prop>
    			</props>
    		</property>
    	</bean>
    		
    	<bean id="PersonReader" class="test.batch.PersonReader">
    		<property name="personApplicationService" ref="PersonApplicationServiceBean" />
    	</bean>
    	<bean id="PersonWriter" class="test.batch.PersonWriter"></bean>
    	
    	<bean id="jobLauncher"
    		class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
    		<property name="jobRepository" ref="jobRepository" />
    	</bean>
    	
    	<bean id="jobRepository"
    		class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean">
    		<property name="transactionManager" ref="transactionManager" />
    	</bean>
    	
    	<bean id="transactionManager"
    		class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" >
    	</bean>
    
    	<bean id="minimal"
    		class="org.springframework.batch.core.job.SimpleJob">
    		<property name="jobRepository" ref="jobRepository" />
    		<property name="steps">
    			<bean id="simpleStep"
    				class="org.springframework.batch.core.step.item.SimpleStepFactoryBean">
    				<property name="transactionManager" ref="transactionManager" />
    				<property name="jobRepository" ref="jobRepository" />
    				<property name="itemReader" ref="PersonReader" />
    				<property name="itemWriter" ref="PersonWriter" />
    			</bean>
    		</property>
    	</bean>
    
    </beans>
    But, at execution time, I do receive this exception :

    Code:
    org.springframework.remoting.RemoteLookupFailureException: EJB instance [Proxy to jboss.j2ee:ear=test.ear,jar=test_ejb.jar,name=PersonApplicationServiceBean,service=EJB3 implementing [interface test.common.application.PersonApplicationService]] is not a Remote Stateless Session Bean
    The deploy version is strictly the same on JBoss server. I don't understand why the Spring configuration keeps saying this EJB is not a Remote Stateles Session Bean, as I can access it through the manual JNDI initialization in read().

    The stacktrace (if it helps) is :

    Code:
    at org.springframework.ejb.access.AbstractRemoteSlsbInvokerInterceptor.newSessionBeanInstance(AbstractRemoteSlsbInvokerInterceptor.java:228)
    	at org.springframework.ejb.access.SimpleRemoteSlsbInvokerInterceptor.getSessionBeanInstance(SimpleRemoteSlsbInvokerInterceptor.java:141)
    	at org.springframework.ejb.access.SimpleRemoteSlsbInvokerInterceptor.doInvoke(SimpleRemoteSlsbInvokerInterceptor.java:97)
    	at org.springframework.ejb.access.AbstractRemoteSlsbInvokerInterceptor.invoke(AbstractRemoteSlsbInvokerInterceptor.java:140)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    	at $Proxy3.findList(Unknown Source)
    	at test.batch.PersonReader.read(PersonReader.java:42)
    	at test.batch.PersonReader.read(PersonReader.java:1)
    	at org.springframework.batch.core.step.item.SimpleChunkProvider.doRead(SimpleChunkProvider.java:90)
    	at org.springframework.batch.core.step.item.SimpleChunkProvider.read(SimpleChunkProvider.java:127)
    	at org.springframework.batch.core.step.item.SimpleChunkProvider$1.doInIteration(SimpleChunkProvider.java:106)
    	at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:367)
    	at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:214)
    	at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:143)
    	at org.springframework.batch.core.step.item.SimpleChunkProvider.provide(SimpleChunkProvider.java:103)
    	at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:68)
    	at 
    ...... (I did need to remove a few of the stacktrace, as forum limit to 10'000 caracters)
    	at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:114)
    	at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:300)
    	at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:464)
    The JNDI configuration in the XML really looks the same as the manual EJB lookup, I could not figure out any difference.

    Any suggest to try to figure out the problem will be appreciated.

  • #2
    You'd better put a complete stack trace that would help a lot.

    Comment


    • #3
      Here is the complete execution log :

      Code:
      2011-04-14 09:10:56,528 INFO  [org.springframework.context.support.ClassPathXmlApplicationContext] (main) Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@19bd03e: display name [org.springframework.context.support.ClassPathXmlApplicationContext@19bd03e]; startup date [Thu Apr 14 09:10:56 CEST 2011]; root of context hierarchy
      2011-04-14 09:10:56,607 INFO  [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] (main) Loading XML bean definitions from class path resource [batch-sample-context.xml]
      2011-04-14 09:10:56,778 INFO  [org.springframework.context.support.ClassPathXmlApplicationContext] (main) Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext@19bd03e]: org.springframework.beans.factory.support.DefaultListableBeanFactory@c2ff5
      2011-04-14 09:10:56,888 INFO  [org.springframework.beans.factory.support.DefaultListableBeanFactory] (main) Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@c2ff5: defining beans [PersonApplicationServiceBean,PersonReader,PersonWriter,jobLauncher,jobRepository,transactionManager,minimal]; root of factory hierarchy
      2011-04-14 09:10:57,560 INFO  [org.springframework.batch.core.launch.support.SimpleJobLauncher] (main) No TaskExecutor has been set, defaulting to synchronous executor.
      2011-04-14 09:10:57,591 INFO  [org.springframework.batch.core.step.item.SimpleStepFactoryBean] (main) Setting commit interval to default value (1)
      2011-04-14 09:10:57,669 INFO  [org.springframework.batch.core.launch.support.SimpleJobLauncher] (main) Job: [SimpleJob: [name=minimal]] launched with the following parameters: [{}]
      2011-04-14 09:10:57,700 INFO  [org.springframework.batch.core.job.SimpleStepHandler] (main) Executing step: [TaskletStep: [name=simpleStep]]
      2011-04-14 09:10:57,716 ERROR [org.springframework.batch.core.step.AbstractStep] (main) Encountered an error executing the step
      org.springframework.remoting.RemoteLookupFailureException: EJB instance [Proxy to jboss.j2ee:ear=test.ear,jar=test_ejb.jar,name=PersonApplicationServiceBean,service=EJB3 implementing [interface test.common.application.PersonApplicationService]] is not a Remote Stateless Session Bean
      	at org.springframework.ejb.access.AbstractRemoteSlsbInvokerInterceptor.newSessionBeanInstance(AbstractRemoteSlsbInvokerInterceptor.java:228)
      	at org.springframework.ejb.access.SimpleRemoteSlsbInvokerInterceptor.getSessionBeanInstance(SimpleRemoteSlsbInvokerInterceptor.java:141)
      	at org.springframework.ejb.access.SimpleRemoteSlsbInvokerInterceptor.doInvoke(SimpleRemoteSlsbInvokerInterceptor.java:97)
      	at org.springframework.ejb.access.AbstractRemoteSlsbInvokerInterceptor.invoke(AbstractRemoteSlsbInvokerInterceptor.java:140)
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
      	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
      	at $Proxy3.findList(Unknown Source)
      	at test.batch.PersonReader.read(PersonReader.java:47)
      	at test.batch.PersonReader.read(PersonReader.java:1)
      	at org.springframework.batch.core.step.item.SimpleChunkProvider.doRead(SimpleChunkProvider.java:90)
      	at org.springframework.batch.core.step.item.SimpleChunkProvider.read(SimpleChunkProvider.java:127)
      	at org.springframework.batch.core.step.item.SimpleChunkProvider$1.doInIteration(SimpleChunkProvider.java:106)
      	at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:367)
      	at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:214)
      	at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:143)
      	at org.springframework.batch.core.step.item.SimpleChunkProvider.provide(SimpleChunkProvider.java:103)
      	at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:68)
      	at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:347)
      	at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:128)
      	at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:261)
      	at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:76)
      	at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:367)
      	at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:214)
      	at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:143)
      	at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:247)
      	at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:196)
      	at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:115)
      	at org.springframework.batch.core.job.AbstractJob.handleStep(AbstractJob.java:356)
      	at org.springframework.batch.core.job.SimpleJob.doExecute(SimpleJob.java:121)
      	at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:281)
      	at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:120)
      	at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:49)
      	at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:114)
      	at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:300)
      	at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:464)
      2011-04-14 09:10:57,732 INFO  [org.springframework.batch.core.launch.support.SimpleJobLauncher] (main) Job: [SimpleJob: [name=minimal]] completed with the following parameters: [{}] and the following status: [FAILED]
      2011-04-14 09:10:57,732 INFO  [org.springframework.context.support.ClassPathXmlApplicationContext] (main) Closing org.springframework.context.support.ClassPathXmlApplicationContext@19bd03e: display name [org.springframework.context.support.ClassPathXmlApplicationContext@19bd03e]; startup date [Thu Apr 14 09:10:56 CEST 2011]; root of context hierarchy
      2011-04-14 09:10:57,732 INFO  [org.springframework.beans.factory.support.DefaultListableBeanFactory] (main) Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@c2ff5: defining beans [PersonApplicationServiceBean,PersonReader,PersonWriter,jobLauncher,jobRepository,transactionManager,minimal]; root of factory hierarchy

      Comment


      • #4
        It looks like the bean binded to JNDI "test/PersonApplicationServiceBean/remote" is EJB3 bean, so try to upgrade to Spring 3.x and try again. I might be wrong, but anyway the problem falls apart from the scope of this forum. Check here or Google.

        Comment


        • #5
          Hi dma_k and thanks a lot for your answer. Your link did help me to find the error.

          I changed the beginning of my XML config file for :

          Code:
          	<bean id="PersonApplicationServiceBean" class="org.springframework.jndi.JndiObjectFactoryBean">
          		<property name="jndiName" value="test/PersonApplicationServiceBean/remote" />
          		<property name="jndiEnvironment">
          			<props>
          				<prop key="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory</prop>
          				<prop key="java.naming.factory.url.pkgs">org.jboss.naming:org.jnp.interfaces</prop>
          				<prop key="java.naming.provider.url">jnp://localhost:1099</prop>
          			</props>
          		</property>
          	</bean>
          It now works with the JndiObjectFactoryBean instead of SimpleRemoteStatelessSessionProxyFactoryBean.

          Comment

          Working...
          X