Announcement Announcement Module
Collapse
No announcement yet.
StepExecutionListener Failing! Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • StepExecutionListener Failing!

    Hiyas,

    I am having a problem with code that used to work on the RC1 version of Spring batch...

    I have a StepExecutionListener that determines whether a step should be run based on whether or not an input file was specified. The problem is that while the listener works, the step still appears to be trying to bind to the input.

    Here is the @BeforeStep sequence:

    Code:
    @Override
    	public void beforeStep(StepExecution stepExecution) {
    		JobParameters jobParameters = stepExecution.getJobParameters();
    		Map<String, JobParameter> params = jobParameters.getParameters();
    		
    		Steps step = Enum.valueOf(Steps.class, stepExecution.getStepName());
    		
    		switch (step) {
    			case provisionAccounts:
    				if (!params.containsKey("accounts")) {
    					stepExecution.setStatus(BatchStatus.ABANDONED);
    					log.info("[Step: provisionAccounts] Input not provided... step not required.");
    				}
    				break;
    				
    			case provisionDevices:
    				if (!params.containsKey("devices")) {
    					stepExecution.setStatus(BatchStatus.ABANDONED);
    					log.info("[Step: provisionDevices] Input not provided... step not required.");
    				}
    				break;
    				
    			case provisionServices:
    				if (!params.containsKey("services")) {
    					stepExecution.setStatus(BatchStatus.ABANDONED);
    					log.info("[Step: provisionServices] Input not provided... step not required.");
    				}
    				break;
    				
    			case provisionEmails:
    				if (!params.containsKey("emails")) {
    					stepExecution.setStatus(BatchStatus.ABANDONED);
    					log.info("[Step: provisionEmails] Input not provided... step not required.");
    				}
    				break;
    		}
    		
    	}
    The Step configuration:

    Code:
    <bean id="accountReader" class="org.springframework.batch.item.file.FlatFileItemReader" scope="step">
    		<property name="resource" value="file:#{jobParameters[accounts]}" />
    		<property name="lineMapper">		
    			<bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
    				<property name="lineTokenizer">
    					<bean class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
    						<property name="delimiter" value="|" />
    						<property name="names" value="billingSystem, accountNumber, vip, title, surname, givenName, postalAddress, city, state, postalCode, telephoneNumber, dstBillingTag, csgHouseKey, brdgrNode, headEnd" />
    					</bean>
    				</property>
    				<property name="fieldSetMapper">
    					<bean class="com.comcast.batch.domain.account.AccountMapper" />
    				</property>
    			</bean>
    		</property>
    	</bean>
    And the resulting output (log):

    Code:
    2009-06-02 11:25:38,995 [main] INFO - Job: [FlowJob: [name=BatchAccounts]] launched with the following parameters: [{emails=emails.txt}]
    2009-06-02 11:25:39,057 [main] INFO - Executing step: [TaskletStep: [name=provisionAccounts]]
    2009-06-02 11:25:39,070 [main] INFO - [Step: provisionAccounts] Input not provided... step not required.
    2009-06-02 11:25:39,095 [main] ERROR - Encountered an error executing the step: class org.springframework.batch.item.ItemStreamException: Failed to initialize the reader
    org.springframework.batch.item.ItemStreamException: Failed to initialize the reader
            at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:111)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:616)
            at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
            at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
            at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
            at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
            at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
            at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
            at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
            at $Proxy7.open(Unknown Source)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:616)
            at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
            at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
            at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
            at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
            at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
            at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
            at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
            at $Proxy8.open(Unknown Source)
            at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:98)
            at org.springframework.batch.core.step.tasklet.TaskletStep.open(TaskletStep.java:364)
            at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:195)
            at org.springframework.batch.core.job.AbstractJob.handleStep(AbstractJob.java:348)
            at org.springframework.batch.core.job.flow.FlowJob.access$0(FlowJob.java:1)
            at org.springframework.batch.core.job.flow.FlowJob$JobFlowExecutor.executeStep(FlowJob.java:137)
            at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:60)
            at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:144)
            at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:124)
            at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:105)
            at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:250)
            at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:110)
            at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:49)
            at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:105)
            at com.comcast.batch.BatchAccountJobRunner.start(BatchAccountJobRunner.java:124)
            at com.comcast.batch.BatchAccountJobRunner.main(BatchAccountJobRunner.java:171)
    Caused by: java.lang.IllegalStateException: Input resource must exist (reader is in 'strict' mode): URL [file:#{jobParameters[accounts]}]
            at org.springframework.batch.item.file.FlatFileItemReader.doOpen(FlatFileItemReader.java:245)
            at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:108)
            ... 40 more
    I did upgrade to the batch 2.0.1 Release version thinking fix [BATCH-1203] might have played a factor but to no avail. Can anyone suggest what the problem might be?

    I should probably state that the accounts parameter is in fact not provided and the step should be skipped. Also, removing the "file:" leader from the resource declaration still leads to:

    Code:
    Caused by: java.lang.IllegalStateException: Cannot bind to placeholder: jobParameters[accounts]
    Thanks in advance.

    Keith

  • #2
    Hello

    I dont know if too late, but I had the same problem when I copy a project from windows to Linux (about path problem)

    but according to your error

    Caused by: java.lang.IllegalStateException: Input resource must exist (reader is in 'strict' mode): URL [file:#{jobParameters[accounts]}]
    you must give the value for "accounts" before execute the job

    something like this(assuming that "accounts" is type String )

    Code:
    JobParametersBuilder builder = new JobParametersBuilder();
    builder.addString("accounts","filename.extension");
    
    JobParameters jobParameters = builder.toJobParameters();
    
    jobLauncher.run(job, jobParameters );
    how you have this code "[file:#{jobParameters[accounts]}]",
    you must include the extension (like csv)

    HTH

    regards

    Comment


    • #3
      Ok... but this is not what I am trying to acheive...

      My program accepts 4 possible input parameters: accounts, devices, services, emails.

      Each parameter accepts the file name of the file containing the inputs for that step. The StepExecutionListener above was supposed to be invoked to determine if the input for the step had been provided and, if it had not, set the step to abandoned so that it would not run.

      Prior to release 2.0 of the batch framework, this methodology had worked. When I upgraded to 2.0, however; I started getting the error above which seem to be requiring that I specify all inputs with empty files or use the methodology you suggested.

      How can I achieve the results I originally had with the new changes to the framework - i.e. skip a step when the input for the step is not provided?

      Thanks.

      Keith

      Comment


      • #4
        You could use a <decision/> element before each step. The decision would direct flow either to the step itself or skip it by pointing to the decision of the next step.

        Comment

        Working...
        X