You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by dfgcamel <df...@gmail.com> on 2015/10/02 03:11:11 UTC

Cannot write null body to file - using ftp component

All,

I have the following code snippet and exception:

I have a route that has a jetty enpoint which accessed, starts a process
which builds an excel file and stores in in a 
directory.  The next component, file, should pick the file up and pass it to
the ftp component, transferring it to a remote server.

Everything seems to work up to the ftp component.  The .xls files are being
generated to in the X:\xxx\reports\finished\ directory.

Any assistance would be greatly appreciated!

*public class ReportRouteBuilder extends RouteBuilder {

	public void configure() throws Exception {

		final Endpoint jettyEndPoint = configureSslForJetty();
		
		from(jettyEndPoint)
				.process(new Processor() {

					@Override
					public void process(Exchange exchange) throws Exception {
						/*
						 * code to generate .xls document and store on the local file system
						 */
						.
                        .
                        .
						exchange.getOut().setHeader(Exchange.FILE_NAME, outputFileName);
						exchange.getOut().setHeader("status", table.getStatus());
						exchange.getOut().setHeader("CamelFileName",table.getFileName());
						exchange.getOut().setHeader("CamelFileNameOnly",table.getFileName());
						exchange.getOut().setHeader("CamelFileAbsolute","true");
					
exchange.getOut().setHeader("CamelFileAbsolute","X:\\xxx\\reports\\finished\\");
					
exchange.getOut().setHeader("CamelFilePath","X:\\xxx\\reports\\finished\\"+currentPivotTable.getFileName());
						exchange.getOut().setHeader("CamelFileParent","X:\\xxx\\reports\\");
    .
    .
    .
						}
				}).choice().when(header("status").isEqualTo("success")).
			
from("file:X:\\xxx\\reports\\finished?fileExist=Ignore&doneFileName=${file:name}.
				done&delete=true&maxMessagesPerPoll=1")
				to("ftp://ccc.xxx.1.2:21/?username=userx&password=abcd&binary=true")
				;
	}
	
	
	private Endpoint configureSslForJetty() 
	.
	.
	.
	/*
	 * SSL code
	 */
	return (Endpoint)
jettyComponent.createEndpoint("jetty:https://0.0.0.0:1111/exportXls");
	}
	
}*

	Id                  ID-ABC-LT-54988-1443747180739-0-1
	ExchangePattern     InOut
	Headers             {CamelFileAbsolute=X:\xxx\reports\finished,
CamelFileName=abc.xls, 
                                  CamelFileNameOnly=abc.xls, 
CamelFileNameProduced=
                                    X:\xxx\reports\finished\abc.xls,
CamelFileParent=X:\xxx\reports\, 
				CamelFilePath=X:\xxx\reports\finished\abc.xls, CamelRedelivered=false, 
                               CamelRedeliveryCounter=0, status=success}
	BodyType            null
	Body                [Body is null]

org.apache.camel.component.file.GenericFileOperationFailedException: Cannot
write null body to file: abc.xls
	at
org.apache.camel.component.file.remote.FtpOperations.doStoreFile(FtpOperations.java:560)
	at
org.apache.camel.component.file.remote.FtpOperations.storeFile(FtpOperations.java:522)
	at
org.apache.camel.component.file.GenericFileProducer.writeFile(GenericFileProducer.java:277)
	at
org.apache.camel.component.file.GenericFileProducer.processExchange(GenericFileProducer.java:165)
	at
org.apache.camel.component.file.remote.RemoteFileProducer.process(RemoteFileProducer.java:56)
	at
org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
	at
org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:157)
	at
org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:304)
	at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:152)
	at
org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
	at
org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:448)
	at
org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
	at org.apache.camel.processor.Pipeline.process(Pipeline.java:118)
	at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)
	at
org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
	at
org.apache.camel.component.jetty.CamelContinuationServlet.service(CamelContinuationServlet.java:162)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:684)
	at
org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1496)
	at
org.eclipse.jetty.servlets.MultiPartFilter.doFilter(MultiPartFilter.java:136)
	at
org.apache.camel.component.jetty.CamelFilterWrapper.doFilter(CamelFilterWrapper.java:43)
	at
org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1467)
	at
org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:501)
	at
org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086)
	at
org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:429)
	at
org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020)
	at
org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
	at
org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
	at org.eclipse.jetty.server.Server.handle(Server.java:370)
	at
org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:494)
	at
org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:971)
	at
org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:1033)
	at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:644)
	at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
	at
org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
	at org.eclipse.jetty.io.nio.SslConnection.handle(SslConnection.java:196)
	at
org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:696)
	at
org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:53)
	at
org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
	at
org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
	at java.lang.Thread.run(Thread.java:745)



--
View this message in context: http://camel.465427.n5.nabble.com/Cannot-write-null-body-to-file-using-ftp-component-tp5772164.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Cannot write null body to file - using ftp component

Posted by Claus Ibsen <cl...@gmail.com>.
You cannot have from inside a route, that is only to start a route.

You need to use the content enricher EIP
http://camel.apache.org/content-enricher.html

There is a pollEnrich you can use to poll a file.

On Fri, Oct 2, 2015 at 6:46 PM, dfgcamel <df...@gmail.com> wrote:
> Thanks for the response Claus.
>
> I've tried the allowNullBody option but it still doesn't work.  I'm
> wondering if it could be that in my scenario, I branch and use the
> .to("file.. instead a .from("file...  I say this because  I had this
> partially working before without the branching and I used .from("file..
> directly after the .process( section.  is there a way to achieve a branch
> that still allows me to use the .from("file.. syntax?
>
> Thanks,
>
> Dennis...
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Cannot-write-null-body-to-file-using-ftp-component-tp5772164p5772192.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2nd edition:
https://www.manning.com/books/camel-in-action-second-edition

Re: Cannot write null body to file - using ftp component

Posted by dfgcamel <df...@gmail.com>.
Thanks for the response Claus.

I've tried the allowNullBody option but it still doesn't work.  I'm
wondering if it could be that in my scenario, I branch and use the
.to("file.. instead a .from("file...  I say this because  I had this
partially working before without the branching and I used .from("file..
directly after the .process( section.  is there a way to achieve a branch
that still allows me to use the .from("file.. syntax?

Thanks,

Dennis...



--
View this message in context: http://camel.465427.n5.nabble.com/Cannot-write-null-body-to-file-using-ftp-component-tp5772164p5772192.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Cannot write null body to file - using ftp component

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

See the allowNullBody option
http://camel.apache.org/file2

On Fri, Oct 2, 2015 at 3:11 AM, dfgcamel <df...@gmail.com> wrote:
> All,
>
> I have the following code snippet and exception:
>
> I have a route that has a jetty enpoint which accessed, starts a process
> which builds an excel file and stores in in a
> directory.  The next component, file, should pick the file up and pass it to
> the ftp component, transferring it to a remote server.
>
> Everything seems to work up to the ftp component.  The .xls files are being
> generated to in the X:\xxx\reports\finished\ directory.
>
> Any assistance would be greatly appreciated!
>
> *public class ReportRouteBuilder extends RouteBuilder {
>
>         public void configure() throws Exception {
>
>                 final Endpoint jettyEndPoint = configureSslForJetty();
>
>                 from(jettyEndPoint)
>                                 .process(new Processor() {
>
>                                         @Override
>                                         public void process(Exchange exchange) throws Exception {
>                                                 /*
>                                                  * code to generate .xls document and store on the local file system
>                                                  */
>                                                 .
>                         .
>                         .
>                                                 exchange.getOut().setHeader(Exchange.FILE_NAME, outputFileName);
>                                                 exchange.getOut().setHeader("status", table.getStatus());
>                                                 exchange.getOut().setHeader("CamelFileName",table.getFileName());
>                                                 exchange.getOut().setHeader("CamelFileNameOnly",table.getFileName());
>                                                 exchange.getOut().setHeader("CamelFileAbsolute","true");
>
> exchange.getOut().setHeader("CamelFileAbsolute","X:\\xxx\\reports\\finished\\");
>
> exchange.getOut().setHeader("CamelFilePath","X:\\xxx\\reports\\finished\\"+currentPivotTable.getFileName());
>                                                 exchange.getOut().setHeader("CamelFileParent","X:\\xxx\\reports\\");
>     .
>     .
>     .
>                                                 }
>                                 }).choice().when(header("status").isEqualTo("success")).
>
> from("file:X:\\xxx\\reports\\finished?fileExist=Ignore&doneFileName=${file:name}.
>                                 done&delete=true&maxMessagesPerPoll=1")
>                                 to("ftp://ccc.xxx.1.2:21/?username=userx&password=abcd&binary=true")
>                                 ;
>         }
>
>
>         private Endpoint configureSslForJetty()
>         .
>         .
>         .
>         /*
>          * SSL code
>          */
>         return (Endpoint)
> jettyComponent.createEndpoint("jetty:https://0.0.0.0:1111/exportXls");
>         }
>
> }*
>
>         Id                  ID-ABC-LT-54988-1443747180739-0-1
>         ExchangePattern     InOut
>         Headers             {CamelFileAbsolute=X:\xxx\reports\finished,
> CamelFileName=abc.xls,
>                                   CamelFileNameOnly=abc.xls,
> CamelFileNameProduced=
>                                     X:\xxx\reports\finished\abc.xls,
> CamelFileParent=X:\xxx\reports\,
>                                 CamelFilePath=X:\xxx\reports\finished\abc.xls, CamelRedelivered=false,
>                                CamelRedeliveryCounter=0, status=success}
>         BodyType            null
>         Body                [Body is null]
>
> org.apache.camel.component.file.GenericFileOperationFailedException: Cannot
> write null body to file: abc.xls
>         at
> org.apache.camel.component.file.remote.FtpOperations.doStoreFile(FtpOperations.java:560)
>         at
> org.apache.camel.component.file.remote.FtpOperations.storeFile(FtpOperations.java:522)
>         at
> org.apache.camel.component.file.GenericFileProducer.writeFile(GenericFileProducer.java:277)
>         at
> org.apache.camel.component.file.GenericFileProducer.processExchange(GenericFileProducer.java:165)
>         at
> org.apache.camel.component.file.remote.RemoteFileProducer.process(RemoteFileProducer.java:56)
>         at
> org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
>         at
> org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:157)
>         at
> org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:304)
>         at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:152)
>         at
> org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
>         at
> org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:448)
>         at
> org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
>         at org.apache.camel.processor.Pipeline.process(Pipeline.java:118)
>         at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)
>         at
> org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
>         at
> org.apache.camel.component.jetty.CamelContinuationServlet.service(CamelContinuationServlet.java:162)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
>         at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:684)
>         at
> org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1496)
>         at
> org.eclipse.jetty.servlets.MultiPartFilter.doFilter(MultiPartFilter.java:136)
>         at
> org.apache.camel.component.jetty.CamelFilterWrapper.doFilter(CamelFilterWrapper.java:43)
>         at
> org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1467)
>         at
> org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:501)
>         at
> org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086)
>         at
> org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:429)
>         at
> org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020)
>         at
> org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
>         at
> org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
>         at org.eclipse.jetty.server.Server.handle(Server.java:370)
>         at
> org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:494)
>         at
> org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:971)
>         at
> org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:1033)
>         at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:644)
>         at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
>         at
> org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
>         at org.eclipse.jetty.io.nio.SslConnection.handle(SslConnection.java:196)
>         at
> org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:696)
>         at
> org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:53)
>         at
> org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
>         at
> org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
>         at java.lang.Thread.run(Thread.java:745)
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Cannot-write-null-body-to-file-using-ftp-component-tp5772164.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2nd edition:
https://www.manning.com/books/camel-in-action-second-edition