camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clarkcb <clar...@gmail.com>
Subject Trying to use splitter to process list of URIs
Date Tue, 04 Sep 2012 19:29:38 GMT
Hello,

I'm trying to create a route that reads an HTML directory index page,
process it to get the list of zip files that are listed in the index, and
split the list to grab each zip file separately. It's what to do after split
that has me stumped. Here's what I have so far (it's Scala but using the
Java RouteBuilder syntax):


import org.apache.camel.builder.{RouteBuilder => JRouteBuilder}
. . .
class HtmlToZipFileListProcessor(url: String) extends Processor {
  val FileLineRegex = """<li><a\shref=&quot;(.+?\.zip)&quot;>.+?\.zip
</li>""".r

  def fileNamesFromLines(lines: List[String]): List[String] = {
    lines match {
      case head :: tail =>
        head match {
          case FileLineRegex(filename) =>
            (url + "/" + filename) :: fileNamesFromLines(tail)
          case _ => fileNamesFromLines(tail)
        }
        case Nil => List[String]()
    }
  }

  def process(exchange: Exchange): Unit = {
    val lines =
exchange.getIn.getBody(classOf[String]).split("""\n+""").toList
    val filenames = fileNamesFromLines(lines)
    exchange.getIn.setBody(filenames.mkString(",")) // set body.in to
comma,separated list of URIs
  }
}

class HttpZipCopyBuilder(timerString:String, indexUrl:String,
targetDir:String) extends JRouteBuilder {
  @Override
  def configure() {
    from(timerString).
      to(indexUrl).
      process(new HtmlToZipFileListProcessor(indexUrl)).
      split(body().tokenize(",")).
        to(body(classOf[String])). // trying to use the body as the URI
        to("file://" + targetDir) // copy the file to targetDir
  }
}

The thing that I can't figure out is how to get the step after split to
treat the body as a URI.

Thanks in advance for any guidance.

Cary



--
View this message in context: http://camel.465427.n5.nabble.com/Trying-to-use-splitter-to-process-list-of-URIs-tp5718622.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Mime
View raw message