Simple HTTP Client for Scala

I'm writing a Simple HTTP Client for Scala. This is a simple example of GET request:

using (new SimpleHttpClient()){ client =>
  val content: Option[String] = client.get(
    url = "http://localhost:8080/"
  content match {
    case Some(s) => println(s)
    case None => println("Request Failed.")

You can give request parameters to get() method. And it's possible to send POST request to use post() method instead of get() method. The second example shows how to give request parameters with the POST request:

using (new SimpleHttpClient()){ client =>
  val content: Option[String] = client.post(
    url = "http://localhost:8080/",
    params = Map("q" -> "Scala"),
    encode = "UTF-8"

In default SimpleHttpClient returns the response body as Option[String]. You can handle the response to give the your own response handler. The response handler has to be a function has a signature (HttpResponse => T).

using (new SimpleHttpClient()){ client =>
  val content: Array[Byte] = client.post(
    url = "http://localhost:8080/",
    handler = { r: HttpResponse =>
      r.getStatusLine.getStatusCode match {
        case HttpStatus.SC_OK => 
        case _ => 
          throw new RuntimeException("Request Failed.")

SimpleHttpClient also supports http proxy. You can give proxy settings to the constructor.

using(new SimpleHttpClient(
    "proxy.example.com:8080")){ client =>

I'm making useful utilities like this HTTP Client for development of general Scala based applications at scala-utils.


xsbt-scalate-precompile-plugin 1.6

xsbt-scalate-precompile-plugin is a sbt plug-in which makes precompilation Scalate templates in the sbt build process (Scalate is a template engine for Scala).

However xsbt-scalate-precompile-plugin 1.5 had one serious problem which does not process templates in the nested directory. For example, it could't handle the layout template (which have to be placed into WEB-INF/scalate/layouts) correctly.

I made a patch to fix this problem and send it. It's taken in xsbt-scalate-precompile-plugin 1.6.

The fixed version of xsbt-scalate-precompile-plugin 1.6 is already available! Now it can process templates in the nested directory correctly.


Introduction of CookieSessionFilter

CookieSessionFilter is a servlet filter which stores session data into the client cookie for Java based web applications.

In using CookieSessionFilter, session replication becomes unnecessary for multiplexing of application servers. You'll be able to make and manage multiplexing environment more easily.

It provides HttpSession interface. So any modification in your application is not necessary. Probably, you'll be able to use it with not so large cost.

See details about CookieSessionFilter at:


eclipse-scala-tools 0.0.2 is now available!

eclipse-scala-tools provides some small Eclipse plug-ins for Scala. It supplements ScalaIDE for Eclipse. The current version of eclipse-scala-tools provides features that support SBT.

See details about eclipse-scala-tools at the following URL:

New features in eclipse-scala-tools 0.0.2:

  • SBT 0.10 Support
  • Proxy Settings
  • SBT Console (SBT > Open SBT Shell)
  • Built-In SBT Runtime
Context menu of the SBT project Project property page of the SBT project

I hope it helps your Scala development!


AmaterasUML 1.3.3 is now available!

Project Amateras released AmaterasERD 1.3.3 at 13 August 2011.

New features in this release:

  • Improvement of constructor in the class diagram
  • Improvement of Java generics support
  • Quick Filter ("Show only Public" and "Show All")
  • Refresh the class diagram from Java source
  • Copy the diagram as image

See details about AmaterasUML at:

See details about new features in AmaterasUML 1.3.3 at:

Download AmaterasUML 1.3.3 from:

Enjoy your development!


Eclipse Plug-in for SBT

Today, I released eclipse-scala-tools 0.0.1.

eclipse-scala-tools is some small Eclipse plug-ins for Scala. It supplements ScalaIDE for Eclipse.

In the initial release of eclipse-scala-tools provides SBT 0.7.x support on Eclipse.

You can create a SBT project using wizard.

Run SBT command from the context menu of the project. You can also migrate existing SBT projects by 'Migrate SBT Project to Eclipse'.

By this plug-in, we would be able to use SBT with Eclipse without special method such as Eclipsify.

I'm planning to add some more features to eclipse-scala-tools such as unit testing support.


Mirage 1.1.3 is now available!

Mirage is a simple SQL centric database access library. See the following URL to know about Mirage:

New features in Mirage 1.1.3:

This release contains the first release of mirage-scala. This is a wrapper of Mirage for Scala.

I have tested so many features and patterns in mirage-scala. However I couldn't believe how interface is best for mirage-scala. So I decided to release with minimum features in the first release. mirage-scala has not enough features now, however it will be expanded in the future.

I hope Mirage helps your development. Enjoy!


mirage-scala: Scala binding of Mirage

I started working for mirage-scala that is Scala binding of Mirage. mirage-scala works as wrapper of Mirage and provides the best interface to access to the database using Mirage for Scala.

This is a simple example to query using mirage-scala:

// A class that mapped to ResultList
class Book (
  val bookId: Int,
  val bookName: String,
  val author: String,
  val price: Int

// get Session and SqlManager
val session: Session = SessionFactory.getSession()
val sqlManager: SqlManager = session.getSqlManager()

// begin transaction

try {
  val books: List[Book] = sqlManager.getResultList(
    classOf[Book], Sql("""
      /*IF author!=null*/
        WHERE AUTHOR = /*author*/
    """), Map("author"->"Naoki Takezoe"))
  books.foreach { book =>
    println("bookId: " + book.bookId)
    println("bookName: " + book.bookName)
    println("author: " + book.author)
    println("price: " + book.price)
  // commit transaction
} catch {
  // rollback transaction
  ex: Exception => session.rollback()

A most important feature of Mirage is dynamic SQL template named 2waySQL. In Mirage, you have to create it as an external file on the classpath. However in mirage-scala, you can write it inline using multi-line string literal. Of course, you can also use an external file as following:

val result: List[Book] = sqlManager.getResultList(
  Map("author"->"Naoki Takezoe"))

mirage-scala is still under development. I'm evaluating APIs feaibility. So APIs might be changed considerably in the release version.


Mirage 1.1.2 is now available!

Mirage is a simple SQL centric database access library. See the following URL to know about Mirage:

New features in Mirage 1.1.2:

This release does not contain so big new features. However it can be used in more large fields such as small web applications by connection-pooling in standalone usage.

I wish that Mirage helps your development. Enjoy!


AmaterasERD 1.0.8 is now available!

Project Amateras released AmaterasERD 1.0.8 at 12 February 2011.

New features in this release:

  • Sybase support
  • In importing and exporting, table and column comments are mapped to logical name (Oracle and Sybase only)
  • Copy As Image from the context menu
  • Quick Outline ([CTRL]+[O])
  • Diagram font configuration
  • HTML generation tool from *.erd file which could be used in command-line

See details about AmaterasERD at:

See details about new features in AmaterasERD 1.0.8 at:

You can download AmaterasERD 1.0.8 from:

Enjoy your development!


Unit Testting in Mirage

In the unit-testing for database access code, some testing frameworks such as DbUnit are available. However, as you know, to maintain test data is very painful.

Mirage proposes lightweight unit-testing without database for database access code. It's based on string matching of executed SQL and expected SQL. Executed SQLs don't reach to the database actually, they are intercepted and recorded to MirageTestContext by using MockSqlManager.

You can verify executed SQLs and these parameters through MirageTestContext as below:

public void testGetBookById(){
  // set MockSqlManager to the test target
  BookService bookService = new BookService();
  bookService.setSqlManager(new MockSqlManager());

  // configure results which would be 
  // returned by MockSqlManager.
  Book book = new Book();
  book.setBookName("Mirage in Action");


  // execute
  Book result = bookService.getBookById(new Long(100));

  // assert returned object
  assertEquals("Mirage in Action", book.getName);

  // verify the number of executed SQL

  // verify the executed SQL
    "SELECT .* FROM BOOK " + 
    "WHERE ID = ? ORDER BY ID ASC", // verify SQL
    new Long(100)); // verify Parameters

As you see, you can also configure return values of MockSqlManager using MirageTestContext if it's necessary. You can write your test case more simple by static importing of MirageTestContext members.

Please note, the purpose of this way is not to verify whether executed SQLs are correct. It helps to find influence which is not anticipated by modification of database access code. So it requires to current database access code and SQLs are correct.

If your purpose of unit-testing for database access code is matches this concept, Mirage will decrease a cost of unit-testing and maintaining them very much.

Mirage 1.1.0 is now available!

Mirage is a simple SQL centric database access library. See the following URL to know about Mirage:

New features in Mirage 1.1.0:

Primary key generation support

  • @PrimaryKey annotation has new attributes generationType and generator. The generationType attribute supports GenerationType.APPLICATION, GenerationType.IDENTIY and GenerationType.SEQAUENCE.
  • The persistent attribute of @PrimaryKey annotation has been removed.

Improvement of unit testing support

New ConnectionProvider and Dialect

I wish that Mirage helps your development. Enjoy!


Mirage 1.0.6 is now available!

Mirage is a simple SQL centric database access library. See the following URL to know about Mirage:

Here is the list of changes in Mirage 1.0.6:

  • Unit Testing support
    • Added MockSqlManager which is used in unit testing instead of SqlManager. See details about Unit Testing support at the UnitTest section.
  • Ant Task

In addition, Apache Click example is updated which contains examples of TestCase using MockSqlManager. You can get it from the download page.

I wish that Mirage helps your development. Enjoy!