Announcement Announcement Module
Collapse
No announcement yet.
how to pass outputstream object as paramter to writer class?. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Also, you shouldn't need to check whether logFileList is null since you should always be setting it in the first step...

    Comment


    • #17
      Thanks for the response.
      I this I didn't explain the requirement clearly.
      In fact this ListFieldSetMapper is executed as step1. This is starting place where I want to initialize logfile. later same log file is used at writer of the first step, as well as the tasklet in the second step.
      So, I need to create logfile and put it into executioncontext. As this class repeats for every record, it picks up the logfie from executioncontext for subsequent calls.
      so, what I need is just to initailize execution context. I implemented Itemstream interface with open, update and write methods as follows,similar to the way I was suggested in my previous mail(first mail of this thread) for writer class.
      Code:
      public class ListFieldSetMapper extends StepExecutionListenerSupport  implements FieldSetMapper<ListItem>,ItemStream,InitializingBean {
      public void open(ExecutionContext executionContext)
      	{
      		System.out.println("open method");
      		this.executionContext = executionContext;
      		
      	}
      	
      	public void update(ExecutionContext executionContext) throws ItemStreamException
      	{
      		System.out.println("update method");
      		this.executionContext.put("logFile",  logFileList);
      	}
      	
      	public void close() throws ItemStreamException
      	{
      		
      	}
                   public ListItem  mapFieldSet(FieldSet fs) {
      		itemSubValidation = new ItemSubValidation();
      		jdbcListItemDao = new JdbcListItemDao();
      	validationMessageList = new ArrayList<ValidationMessage>();
      	this.logFileList = (ArrayList<ListItem>)stepExecution.getJobExecution().getExecutionContext().get("logFile");	
      		if(logFileList==null)
      		{
      			logFileList = new ArrayList<ListItem>();
      
      	      	this.executionContext.put("logFile",  logFileList);
      		}	
      		else
      		{
                               ArrayList<ListItem>logFileList = (ArrayList<ListItem>)   
                                this.executionContext.get("logFile");
                                System.out.println("retrieved the existing  stream  
                                 object "+logFileList);
                                }
      }
      The open method is not getting called, and executioncontext is always null .
      I changed before method to as follows just to initialize execution context.
      Code:
      public void beforeStep(StepExecution stepExecution) {
      	logFileList = new ArrayList<ListItem>();
      	this.executionContext = stepExecution.getJobExecution().getExecutionContext();
      System.out.println("Execution Context is"+executionContext);
        // this.executionContext.put("logFile",  logFileList);
      }
      Though it is initializing here, it is again becoming null in the mapfieldset.
      I implemented both stepexecutionlistener and Itemstream.
      please suggest how can I initialize execution context in ListFieldSetMapper.


      Thanks

      Comment


      • #18
        First, if a class implements ItemStream, it needs to be registered as a stream in the configuration using the <streams> element (similar to the <listeners>). Next, you should get rid of the StepExecutionListenerSupport and InitializingBean from your code and just use the ItemStream:

        Code:
        public class ListFieldSetMapper implements FieldSetMapper<ListItem>, ItemStream {
        	private static final String KEY_NAME = "logFile";
        
        	private List<ListItem> listItems;
        
        	public void open(ExecutionContext executionContext) {
        		if (executionContext.containsKey(KEY_NAME)) {
        			this.listItems = (List<ListItem>) executionContext.get(KEY_NAME);
        		}
        		else {
        			this.listItems = new ArrayList<ListItem>();
        		}
        	}
        
        	public void update(ExecutionContext executionContext) throws ItemStreamException {
        		executionContext.put(KEY_NAME, this.listItems);
        	}
        
        	public void close() throws ItemStreamException {}
        Finally, you have the signature of the mapFieldSet() method wrong (the method transforms a FieldSet into something else). This makes me think that you are using the wrong class for what you want to do. So, what are you trying to do with this class?

        Comment


        • #19
          What Iím trying to do here is just catch all possible exceptions, thrown by FlatFileItemReader into mapFiledSet(FieldSet) method of ListFieldSetMapper class,
          while transforming the field set.
          I need to catch these exceptions, log the errors and store the log object in execution context. This is first place, where I use executioncontext for dumping the log object.

          Later same log object is retrieved by writer from execution context, and append other possible exceptions, at writer level, and save it back into execution context. (I donít have any issues here)

          Then step2 of the job, will retrieve the same object, from execution context, construct input stream and dump it into ftp server.
          . (I donít have any issues here too)


          I followed your suggestions, but it didnít resolve my problem helped me to understand the usage of streams.
          I configured the streams as you suggested and now, open and update methods are Getting called and exuectioncontext is initialized. But executioncontext is becoming null soon after entering into mapFieldSet() method. It appers like mapFieldSet() method is not synced with ItemStream methods(open/update).

          If mapFieldSet() is not the right method to log the information, where else I can cath and log these exceptions?

          Please suggest
          Thanks

          Comment


          • #20
            can any one help me on this please?

            Comment

            Working...
            X