You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by sriramch <sr...@consortemedia.com> on 2009/06/24 02:27:25 UTC

File endpoint and GzipDataFormat question

I am using the latest camel 2.0-m2 release. I have a list of gzipped file in
a step within a route. I need to extract the contents from the gzipped
location and then based on 1 of 3 types of tokens in the filename, I need to
pass the extracted filename to 3 different beans. My route looks like the
following:

<camel:route>
 	<camel:from uri="direct:getGippedFiles" />
	<camel:bean ref="gzipDownloader" method="doDownload"/>
	<!-- This produces an ArrayList<String> for the filePaths -->
	<camel:split>
		<camel:simple>body</camel:simple>
		<camel:choice>
					<camel:when >
						<camel:simple>body contains 'Token1'</camel:simple>
						<camel:to uri="file://filename=${body}" />
						<camel:unmarshal ref="gunzip"/>
						<camel:bean ref="bean1" method="myMethod"/>
					</camel:when>
					<camel:when >
						<camel:simple>body contains 'Token2'</camel:simple>
						<camel:to uri="file://filename=${body}" />
						<camel:unmarshal ref="gunzip"/>
						<camel:bean ref="bean2" method="myMethod"/>
					</camel:when>
		</camel:choice>
	</camel:split>
</camel:route>

I have defined the bean gunzip as 
<bean id="gunzip" class="org.apache.camel.model.dataformat.GzipDataFormat"/>

However I get the following exception. 
ERROR [17:24:20,432] - org.apache.camel.processor.Logger.log(207) | Failed
delivery for exchangeId: ID-CM-Latitude-E55-50750-1245802622632-0-1. On
delivery attempt: 0 caught: java.io.IOException: Not in GZIP format
java.io.IOException: Not in GZIP format
	at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:137)
	at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:58)
	at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:68)
	at org.apache.camel.impl.GzipDataFormat.unmarshal(GzipDataFormat.java:46)
	at
org.apache.camel.processor.UnmarshalProcessor.process(UnmarshalProcessor.java:51)

The problem seems to be that the GzipDataFormat:unmarshal method expects an
inputstream and not a string filename. What do I need to change in my route
to have the file opened as a stream for the GzipDataForm:unmarshal method.
Is what I am trying to do a good usecase for the file endpoint and gzip?
This is simple enough to do with java code, but I am trying to avoid writing
any code if I can help.

Thanks
Sriram
-- 
View this message in context: http://www.nabble.com/File-endpoint-and-GzipDataFormat-question-tp24176769p24176769.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: File endpoint and GzipDataFormat question

Posted by Claus Ibsen <cl...@gmail.com>.
Hi
The body is just a string and thus the gunzip do not know that its a file
name and that it should read the file content.

You can construct the file body yourself in a eg bean, processor or the
likes. Lets use a bean

public File convertToFile(String name) {
  return new File(name);
}

And then use the bean in a route step before the unmarshall

<...>
<beanRef ref="myBean"/>
<unmarshal .../>

But I do believe there is also a type converter already for this so you can
do it like this

<...>
<convertBodyTo type="java.io.File"/>
<unmarshal .../>





On Wed, Jun 24, 2009 at 3:45 AM, Willem Jiang <wi...@gmail.com>wrote:

> Hi,
>
> <camel:to uri="file://filename=${body}" />
> just store the message body with the filename that your body has.
>
> It will not read the file that you want.
> Maybe you need write a bean or processor to do that kind of job for you.
>
> Willem
>
> sriramch wrote:
> > I am using the latest camel 2.0-m2 release. I have a list of gzipped file
> in
> > a step within a route. I need to extract the contents from the gzipped
> > location and then based on 1 of 3 types of tokens in the filename, I need
> to
> > pass the extracted filename to 3 different beans. My route looks like the
> > following:
> >
> > <camel:route>
> >       <camel:from uri="direct:getGippedFiles" />
> >       <camel:bean ref="gzipDownloader" method="doDownload"/>
> >       <!-- This produces an ArrayList<String> for the filePaths -->
> >       <camel:split>
> >               <camel:simple>body</camel:simple>
> >               <camel:choice>
> >                                       <camel:when >
> >                                               <camel:simple>body contains
> 'Token1'</camel:simple>
> >                                               <camel:to
> uri="file://filename=${body}" />
> >                                               <camel:unmarshal
> ref="gunzip"/>
> >                                               <camel:bean ref="bean1"
> method="myMethod"/>
> >                                       </camel:when>
> >                                       <camel:when >
> >                                               <camel:simple>body contains
> 'Token2'</camel:simple>
> >                                               <camel:to
> uri="file://filename=${body}" />
> >                                               <camel:unmarshal
> ref="gunzip"/>
> >                                               <camel:bean ref="bean2"
> method="myMethod"/>
> >                                       </camel:when>
> >               </camel:choice>
> >       </camel:split>
> > </camel:route>
> >
> > I have defined the bean gunzip as
> > <bean id="gunzip"
> class="org.apache.camel.model.dataformat.GzipDataFormat"/>
> >
> > However I get the following exception.
> > ERROR [17:24:20,432] - org.apache.camel.processor.Logger.log(207) |
> Failed
> > delivery for exchangeId: ID-CM-Latitude-E55-50750-1245802622632-0-1. On
> > delivery attempt: 0 caught: java.io.IOException: Not in GZIP format
> > java.io.IOException: Not in GZIP format
> >       at
> java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:137)
> >       at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:58)
> >       at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:68)
> >       at
> org.apache.camel.impl.GzipDataFormat.unmarshal(GzipDataFormat.java:46)
> >       at
> >
> org.apache.camel.processor.UnmarshalProcessor.process(UnmarshalProcessor.java:51)
> >
> > The problem seems to be that the GzipDataFormat:unmarshal method expects
> an
> > inputstream and not a string filename. What do I need to change in my
> route
> > to have the file opened as a stream for the GzipDataForm:unmarshal
> method.
> > Is what I am trying to do a good usecase for the file endpoint and gzip?
> > This is simple enough to do with java code, but I am trying to avoid
> writing
> > any code if I can help.
> >
> > Thanks
> > Sriram
>
>


-- 
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: File endpoint and GzipDataFormat question

Posted by Willem Jiang <wi...@gmail.com>.
Hi,

<camel:to uri="file://filename=${body}" />
just store the message body with the filename that your body has.

It will not read the file that you want.
Maybe you need write a bean or processor to do that kind of job for you.

Willem

sriramch wrote:
> I am using the latest camel 2.0-m2 release. I have a list of gzipped file in
> a step within a route. I need to extract the contents from the gzipped
> location and then based on 1 of 3 types of tokens in the filename, I need to
> pass the extracted filename to 3 different beans. My route looks like the
> following:
> 
> <camel:route>
>  	<camel:from uri="direct:getGippedFiles" />
> 	<camel:bean ref="gzipDownloader" method="doDownload"/>
> 	<!-- This produces an ArrayList<String> for the filePaths -->
> 	<camel:split>
> 		<camel:simple>body</camel:simple>
> 		<camel:choice>
> 					<camel:when >
> 						<camel:simple>body contains 'Token1'</camel:simple>
> 						<camel:to uri="file://filename=${body}" />
> 						<camel:unmarshal ref="gunzip"/>
> 						<camel:bean ref="bean1" method="myMethod"/>
> 					</camel:when>
> 					<camel:when >
> 						<camel:simple>body contains 'Token2'</camel:simple>
> 						<camel:to uri="file://filename=${body}" />
> 						<camel:unmarshal ref="gunzip"/>
> 						<camel:bean ref="bean2" method="myMethod"/>
> 					</camel:when>
> 		</camel:choice>
> 	</camel:split>
> </camel:route>
> 
> I have defined the bean gunzip as 
> <bean id="gunzip" class="org.apache.camel.model.dataformat.GzipDataFormat"/>
> 
> However I get the following exception. 
> ERROR [17:24:20,432] - org.apache.camel.processor.Logger.log(207) | Failed
> delivery for exchangeId: ID-CM-Latitude-E55-50750-1245802622632-0-1. On
> delivery attempt: 0 caught: java.io.IOException: Not in GZIP format
> java.io.IOException: Not in GZIP format
> 	at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:137)
> 	at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:58)
> 	at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:68)
> 	at org.apache.camel.impl.GzipDataFormat.unmarshal(GzipDataFormat.java:46)
> 	at
> org.apache.camel.processor.UnmarshalProcessor.process(UnmarshalProcessor.java:51)
> 
> The problem seems to be that the GzipDataFormat:unmarshal method expects an
> inputstream and not a string filename. What do I need to change in my route
> to have the file opened as a stream for the GzipDataForm:unmarshal method.
> Is what I am trying to do a good usecase for the file endpoint and gzip?
> This is simple enough to do with java code, but I am trying to avoid writing
> any code if I can help.
> 
> Thanks
> Sriram