You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Joe San <co...@gmail.com> on 2013/02/11 11:30:48 UTC
Camel Scala DSL and IntelliJ
Guys,
I'm just trying a simple Scala DSL using intelli. I have a project created
and tried configuring a simple route as below:
class SimpleRouter extends App {
def main(args : Array[String]) {
val camelContext = new DefaultCamelContext()
camelContext.addRoutes(new RouteBuilder() {
def configure() {
"file://Users/joe/Desktop/test.xml".to("file://Users/joe/Desktop/test1.xml")
}
})
camelContext.start()
Thread.sleep(1000)
camelContext.stop()
}
}
But I get to see the following error when I tried to run the above route:
scala: value to is not a member of java.lang.String
"file://Users/joe/Desktop/test.xml".to("file://Users/joe/Desktop/test1.xml")
Any idea as to why the intellij would not recognize the dsl? Is there
anything that I have to do additionally?
Regards,
Joe
^
Re: Camel Scala DSL and IntelliJ
Posted by Henryk Konsek <he...@gmail.com>.
> If you your endpoint is like "from("file:test.xml")" camel searches in the root of your project for "test.xml".
Yes, using relative paths while testing might be confusing. It is
safer to use absolute paths while working with file component.
--
Henryk Konsek
http://henryk-konsek.blogspot.com
Re: Camel Scala DSL and IntelliJ
Posted by Matthias Lüneberg <ma...@googlemail.com>.
Hi,
thanks for the help Henryk. I use sbt for my scala development.
Joe, last time I just checked if the Route compiles and starts properly. For me it did.
Now I did a small simple project on my own using camel 2.10.1, scala 2.9.2 and sbt.
The following code worked for me:
package it.lueneberg
import org.apache.camel.impl.DefaultCamelContext
import org.apache.camel.scala.dsl.builder.RouteBuilder
import org.apache.camel.LoggingLevel
object ExampleTest extends App {
override def main(args: Array[String]) {
val camelContext = new DefaultCamelContext()
camelContext.addRoutes(new RouteBuilder() {
"file://in/".id("fileRoute").log(LoggingLevel.DEBUG,"Moved '${file:name}' to output dir!").to("file://out_camel/")
})
camelContext.start()
Thread.sleep(10000)
camelContext.stop()
}
}
Here is the log output:
info] Running it.lueneberg.ExampleTest
[ run-main] DefaultCamelContext INFO Apache Camel 2.10.1 (CamelContext: camel-1) is starting
[ run-main] ManagementStrategyFactory INFO JMX enabled.
[ run-main] DefaultTypeConverter INFO Loaded 176 type converters
[ run-main] DefaultCamelContext INFO Route: fileRoute started and consuming from: Endpoint[file://in/]
[ run-main] ultManagementLifecycleStrategy INFO StatisticsLevel at All so enabling load performance statistics
[ run-main] DefaultCamelContext INFO Total 1 routes, of which 1 is started.
[ run-main] DefaultCamelContext INFO Apache Camel 2.10.1 (CamelContext: camel-1) started in 0.250 seconds
[amel-1) thread #0 - file://in/] fileRoute DEBUG Moved 'somefile.txt' to output dir!
[ run-main] DefaultCamelContext INFO Apache Camel 2.10.1 (CamelContext: camel-1) is shutting down
[ run-main] DefaultShutdownStrategy INFO Starting to graceful shutdown 1 routes (timeout 300 seconds)
[el-1) thread #2 - ShutdownTask] DefaultShutdownStrategy INFO Route: fileRoute shutdown complete, was consuming from: Endpoint[file://in/]
[ run-main] DefaultShutdownStrategy INFO Graceful shutdown of 1 routes completed in 0 seconds
[ run-main] DefaultTypeConverter INFO TypeConverterRegistry utilization[attempts=8, hits=8, misses=0, failures=0] mappings[total=176, misses=0]
[ run-main] DefaultCamelContext INFO Apache Camel 2.10.1 (CamelContext: camel-1) is shutdown in 0.007 seconds. Uptime 10.259 seconds.
Another guess from me is to check the import section of your Route to really import the scala dsl stuff.
If you your endpoint is like "from("file:test.xml")" camel searches in the root of your project for "test.xml". If it finds nothing than it creates a dir with the given name (testet on Mac osx). I usually work with folders (see "in" / "out_camel").
I hope this will help you. If you have any question don't hesitate to ask.
Matthias
Am 12.02.2013 um 11:12 schrieb Henryk Konsek <he...@gmail.com>:
>> I'm just trying a simple Scala DSL using intelli.
>
> Just a little suggestion from me. If you plan to play around with
> Scala DSL, create small Maven project and always verify Scala errors
> generated by IntelliJ by executing 'mvn clean compile'. IntelliJ Scala
> plugin sometimes gets confused for some reason and produces false
> compilation errors. Maven always tells you the compilation truth :) .
>
> --
> Henryk Konsek
> http://henryk-konsek.blogspot.com
Re: Camel Scala DSL and IntelliJ
Posted by Henryk Konsek <he...@gmail.com>.
> I'm just trying a simple Scala DSL using intelli.
Just a little suggestion from me. If you plan to play around with
Scala DSL, create small Maven project and always verify Scala errors
generated by IntelliJ by executing 'mvn clean compile'. IntelliJ Scala
plugin sometimes gets confused for some reason and produces false
compilation errors. Maven always tells you the compilation truth :) .
--
Henryk Konsek
http://henryk-konsek.blogspot.com
Re: Camel Scala DSL and IntelliJ
Posted by Joe San <co...@gmail.com>.
I doubt how the double quotes for the file path worked for you. I had to
remove the double quotes after file:// and make it just file:/ such that it
worked.
Regards,
Jothi
On Mon, Feb 11, 2013 at 5:05 PM, Matthias Lüneberg <
matthias.lueneberg@googlemail.com> wrote:
> Hi,
>
> I think you don't need the "configure()" function/method.
>
> I think its okay to call "to" on the String, there is some implicit magic
> in between I think.
>
> Look at here: http://camel.apache.org/scala-dsl-getting-started.html
>
> The following worked for me in IntelliJ 12:
>
> class SimpleRouter extends App {
>
> def main(args : Array[String]) {
>
> val camelContext = new DefaultCamelContext()
>
> camelContext.addRoutes(new RouteBuilder() {
>
>
> "file://Users/joe/Desktop/test.xml".to("file://Users/joe/Desktop/test1.xml")
>
> })
>
> camelContext.start()
>
> Thread.sleep(1000)
>
> camelContext.stop()
> }
> }
>
> HTH,
> Matthias
>
> Am 11.02.2013 um 13:36 schrieb James Carman <jcarman@carmanconsulting.com
> >:
>
> > How about from("file://...").to("file:///")
> >
> > You're trying to call "to" on a java.lang.String literal object.
> >
> > On Feb 11, 2013, at 5:30 AM, Joe San <co...@gmail.com> wrote:
> >
> >> Guys,
> >>
> >> I'm just trying a simple Scala DSL using intelli. I have a project
> created
> >> and tried configuring a simple route as below:
> >>
> >> class SimpleRouter extends App {
> >>
> >> def main(args : Array[String]) {
> >>
> >> val camelContext = new DefaultCamelContext()
> >>
> >> camelContext.addRoutes(new RouteBuilder() {
> >> def configure() {
> >>
> >>
> "file://Users/joe/Desktop/test.xml".to("file://Users/joe/Desktop/test1.xml")
> >> }
> >> })
> >>
> >> camelContext.start()
> >>
> >> Thread.sleep(1000)
> >>
> >> camelContext.stop()
> >>
> >> }
> >>
> >> }
> >>
> >> But I get to see the following error when I tried to run the above
> route:
> >>
> >> scala: value to is not a member of java.lang.String
> >>
> >>
> "file://Users/joe/Desktop/test.xml".to("file://Users/joe/Desktop/test1.xml")
> >>
> >> Any idea as to why the intellij would not recognize the dsl? Is there
> >> anything that I have to do additionally?
> >>
> >> Regards,
> >> Joe
> >> ^
> >
>
>
Re: Camel Scala DSL and IntelliJ
Posted by Joe San <co...@gmail.com>.
I managed to get it running. But now got hit with the usual beginners
problem. Following is what I see in my console when I run my program:
[ main] DefaultCamelContext INFO
Apache Camel 2.9.0.fuse-70-097 (CamelContext: camel-1) is starting
[ main] ManagementStrategyFactory INFO JMX
enabled.
[ main] ultManagementLifecycleStrategy INFO
StatisticsLevel at All so enabling load performance statistics
[ main] DefaultTypeConverter INFO
Loaded 169 type converters
[ main] DefaultCamelContext INFO
Route: route1 started and consuming from: Endpoint[file://test.xml]
[ main] DefaultCamelContext INFO Total
1 routes, of which 1 is started.
[ main] DefaultCamelContext INFO
Apache Camel 2.9.0.fuse-70-097 (CamelContext: camel-1) started in 0.509
seconds
[ main] DefaultCamelContext INFO
Apache Camel 2.9.0.fuse-70-097 (CamelContext: camel-1) is shutting down
[ main] DefaultShutdownStrategy INFO
Starting to graceful shutdown 1 routes (timeout 300 seconds)
[el-1) thread #2 - ShutdownTask] DefaultShutdownStrategy INFO
Route: route1 shutdown complete, was consuming from:
Endpoint[file://test.xml]
[ main] DefaultShutdownStrategy INFO
Graceful shutdown of 1 routes completed in 0 seconds
[ main] DefaultTypeConverter INFO
TypeConverterRegistry utilization[attempts=0, hits=0, misses=0, failures=0]
mappings[total=169, misses=0]
[ main] DefaultCamelContext INFO
Apache Camel 2.9.0.fuse-70-097 (CamelContext: camel-1) is shutdown in 0.008
seconds. Uptime 10.523 seconds.
Process finished with exit code 0
Following is how I have managed to made my program work:
object TradeRouter extends App {
override def main(args : Array[String]) {
val camelContext = new DefaultCamelContext()
camelContext.addRoutes(new RouteBuilder() {
def configure() {
from("file:test.xml").to("file:test1.xml")
}
})
camelContext.start()
Thread.sleep(10000)
camelContext.stop()
}
}
Any reasons as to why I cannot see the test1.xml?
Regards,
Joe
On Mon, Feb 11, 2013 at 5:05 PM, Matthias Lüneberg <
matthias.lueneberg@googlemail.com> wrote:
> Hi,
>
> I think you don't need the "configure()" function/method.
>
> I think its okay to call "to" on the String, there is some implicit magic
> in between I think.
>
> Look at here: http://camel.apache.org/scala-dsl-getting-started.html
>
> The following worked for me in IntelliJ 12:
>
> class SimpleRouter extends App {
>
> def main(args : Array[String]) {
>
> val camelContext = new DefaultCamelContext()
>
> camelContext.addRoutes(new RouteBuilder() {
>
>
> "file://Users/joe/Desktop/test.xml".to("file://Users/joe/Desktop/test1.xml")
>
> })
>
> camelContext.start()
>
> Thread.sleep(1000)
>
> camelContext.stop()
> }
> }
>
> HTH,
> Matthias
>
> Am 11.02.2013 um 13:36 schrieb James Carman <jcarman@carmanconsulting.com
> >:
>
> > How about from("file://...").to("file:///")
> >
> > You're trying to call "to" on a java.lang.String literal object.
> >
> > On Feb 11, 2013, at 5:30 AM, Joe San <co...@gmail.com> wrote:
> >
> >> Guys,
> >>
> >> I'm just trying a simple Scala DSL using intelli. I have a project
> created
> >> and tried configuring a simple route as below:
> >>
> >> class SimpleRouter extends App {
> >>
> >> def main(args : Array[String]) {
> >>
> >> val camelContext = new DefaultCamelContext()
> >>
> >> camelContext.addRoutes(new RouteBuilder() {
> >> def configure() {
> >>
> >>
> "file://Users/joe/Desktop/test.xml".to("file://Users/joe/Desktop/test1.xml")
> >> }
> >> })
> >>
> >> camelContext.start()
> >>
> >> Thread.sleep(1000)
> >>
> >> camelContext.stop()
> >>
> >> }
> >>
> >> }
> >>
> >> But I get to see the following error when I tried to run the above
> route:
> >>
> >> scala: value to is not a member of java.lang.String
> >>
> >>
> "file://Users/joe/Desktop/test.xml".to("file://Users/joe/Desktop/test1.xml")
> >>
> >> Any idea as to why the intellij would not recognize the dsl? Is there
> >> anything that I have to do additionally?
> >>
> >> Regards,
> >> Joe
> >> ^
> >
>
>
Re: Camel Scala DSL and IntelliJ
Posted by Matthias Lüneberg <ma...@googlemail.com>.
Hi,
I think you don't need the "configure()" function/method.
I think its okay to call "to" on the String, there is some implicit magic in between I think.
Look at here: http://camel.apache.org/scala-dsl-getting-started.html
The following worked for me in IntelliJ 12:
class SimpleRouter extends App {
def main(args : Array[String]) {
val camelContext = new DefaultCamelContext()
camelContext.addRoutes(new RouteBuilder() {
"file://Users/joe/Desktop/test.xml".to("file://Users/joe/Desktop/test1.xml")
})
camelContext.start()
Thread.sleep(1000)
camelContext.stop()
}
}
HTH,
Matthias
Am 11.02.2013 um 13:36 schrieb James Carman <jc...@carmanconsulting.com>:
> How about from("file://...").to("file:///")
>
> You're trying to call "to" on a java.lang.String literal object.
>
> On Feb 11, 2013, at 5:30 AM, Joe San <co...@gmail.com> wrote:
>
>> Guys,
>>
>> I'm just trying a simple Scala DSL using intelli. I have a project created
>> and tried configuring a simple route as below:
>>
>> class SimpleRouter extends App {
>>
>> def main(args : Array[String]) {
>>
>> val camelContext = new DefaultCamelContext()
>>
>> camelContext.addRoutes(new RouteBuilder() {
>> def configure() {
>>
>> "file://Users/joe/Desktop/test.xml".to("file://Users/joe/Desktop/test1.xml")
>> }
>> })
>>
>> camelContext.start()
>>
>> Thread.sleep(1000)
>>
>> camelContext.stop()
>>
>> }
>>
>> }
>>
>> But I get to see the following error when I tried to run the above route:
>>
>> scala: value to is not a member of java.lang.String
>>
>> "file://Users/joe/Desktop/test.xml".to("file://Users/joe/Desktop/test1.xml")
>>
>> Any idea as to why the intellij would not recognize the dsl? Is there
>> anything that I have to do additionally?
>>
>> Regards,
>> Joe
>> ^
>
Re: Camel Scala DSL and IntelliJ
Posted by James Carman <jc...@carmanconsulting.com>.
How about from("file://...").to("file:///")
You're trying to call "to" on a java.lang.String literal object.
On Feb 11, 2013, at 5:30 AM, Joe San <co...@gmail.com> wrote:
> Guys,
>
> I'm just trying a simple Scala DSL using intelli. I have a project created
> and tried configuring a simple route as below:
>
> class SimpleRouter extends App {
>
> def main(args : Array[String]) {
>
> val camelContext = new DefaultCamelContext()
>
> camelContext.addRoutes(new RouteBuilder() {
> def configure() {
>
> "file://Users/joe/Desktop/test.xml".to("file://Users/joe/Desktop/test1.xml")
> }
> })
>
> camelContext.start()
>
> Thread.sleep(1000)
>
> camelContext.stop()
>
> }
>
> }
>
> But I get to see the following error when I tried to run the above route:
>
> scala: value to is not a member of java.lang.String
>
> "file://Users/joe/Desktop/test.xml".to("file://Users/joe/Desktop/test1.xml")
>
> Any idea as to why the intellij would not recognize the dsl? Is there
> anything that I have to do additionally?
>
> Regards,
> Joe
> ^