nifi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Payne <marka...@hotmail.com>
Subject Re: transfer relationship not specified (failed to process session due to org.apache.nifi.processor.exception.FlowFileHandlingException: )
Date Tue, 18 Apr 2017 13:04:01 GMT
Rahul,

In your onTrigger, you are transferring the FlowFile that you create but you are not transferring
the original
FlowFile that you received (the one assigned to 'flowFile') to any relationship. You have
to do something with
that FlowFile also.

Additionally, I would point out that the FlowFile that you are creating should be created
as a "child" as the original:

FlowFile listFlowFile = session.create(flowFile);

instead of just session.create() - this will properly setup the lineage so that your data
provenance will show that the
new FlowFile came from the parent and will also transfer all FlowFile attributes from the
parent to the child.

Alternatively, if your intent is to modify the incoming FlowFile, instead of creating a child,
you can do so without using
the session.create() at all and just using:

flowFile = session.write(flowFile, new OuptutStreamCallback() { ... } );


Thanks
-Mark


> On Apr 18, 2017, at 1:03 AM, rahul <rahulsinghrawat7990@gmail.com> wrote:
> 
> Below is my onTrigger method where i am getting transfer relation ship not
> specified, However i have debugged this method and stepped through
> session.transfer() statement but still my custom processor not creating and
> transferring new flow file.
> 
> 
> public void onTrigger(final ProcessContext context, final ProcessSession
> session) throws ProcessException {
> 			final ComponentLog log = this.getLogger();
> 			  final AtomicReference<String> value = new AtomicReference<>();
> 			
> 			FlowFile flowFile = session.get();
> 			Map<String,String> attributes = flowFile.getAttributes();
> 			log.info("*********"+ flowFile.getAttributes());
> 			
> 			for(String attribute : attributes.keySet()){
> 				if(attribute.equals("outputPath")){
> 					inputDirectory = attributes.get("outputPath");
> 				}
> 			}
> 			
> 			// listing files and creating flow files:
> 			File file = new File(inputDirectory);
> 			File [] filePaths = file.listFiles();
> 			
> 			
> 			for(File filePath : filePaths){
> 		
> 				FlowFile listFlowFile = session.create();
> 				
> 				try {
> 					String content = new String(Files.readAllBytes(filePath.toPath()));
> 					value.set(content);
> 				} catch (IOException e) {
> 					e.printStackTrace();
> 				}
> 				
> 				listFlowFile =	session.write(listFlowFile, new OutputStreamCallback() {
> 					@Override
> 					public void process(OutputStream out) throws IOException {
> 						out.write(value.get().getBytes());
> 						
> 					}
> 			    });
> 			
> 				log.info("********* inputDirectory: "+ inputDirectory);
> 				log.info("********* ListFlowFile"+listFlowFile.getAttributes());
> 			//	session.getProvenanceReporter().receive(listFlowFile,
> filePath.toURI().toString());
> 				session.transfer(listFlowFile, SUCCESS);
> 			
> 			}
> 			
> 		}
> 
> 
> 
> 
> --
> View this message in context: http://apache-nifi-developer-list.39713.n7.nabble.com/transfer-relationship-not-specified-failed-to-process-session-due-to-org-apache-nifi-processor-excep-tp15487.html
> Sent from the Apache NiFi Developer List mailing list archive at Nabble.com.


Mime
View raw message