Category Archives: Play Framework

Developing Reactive Microservices


reactive_microservices_thumbnail

Advertisements

Playing MultipartFormData: A basic example to handle and test MultipartFormData request in Play Framework 2.3.8


Knoldus

Playing MultipartFormData

The following blog and attached code represent an example to upload file using MultipartFormData request and Testing it into Play Application.

A basic example to handle and test MultipartFormData request in Play Framework 2.3.8

The standard way to upload files in a web application is to use a form with a special multipart/form-data encoding, which lets you mix standard form data with file attachment data. Please note: the HTTP method used to submit the form must be POST (not GET).


Code in action for Controller and Service


  val uploadService: UploadService

  def upload = Action(parse.multipartFormData) { implicit request =>
    val result = uploadService.uploadFile(request)
    Redirect(routes.Application.index).flashing("message" -> result)
  }
 /** * Get file from the request and move it in your location * * @param request * @return */ def uploadFile(request: Request[MultipartFormData[TemporaryFile]]): String = { log.error("Called…

View original post 245 more words

How to use Cookies in Play framework


Browser Cookies in Play framework

Knoldus

Play framework is being used by every Scala developer now a days. In this post we’ll learn about using Cookies in Play framework.

Play has a stateless architecture so in order to keep the data across multiple HTTP request we can use Session & Flash. But both Session & Flash loose data as soon as browser is closed. So, to retain data even after closing the browser, we can use Cookies in Play framework. Cookies are not stored by the server, instead they are stored at the client side.

  • Data stored in cookies are available till they expire or they are cleaned by user.
  • We can set the expiration time of cookies.
  • They can be made secure, but only for sites working on HTTPS.
  • They can be used like a Scala collection.

Before start using Cookies in Play framework these two libraries have to imported.

Storing the data in Cookie :

For the…

View original post 134 more words

Tutorial: AJAX calling in Play Framework 2.3.4


Cool AJAX integration with Play 2.3.4

Knoldus

In this tutorial we will discuss about the following topics of AJAX calling in Play Framework 2.3.4:

  1. Generating a Javascript router
    1. Embedded router
    2. Router resource
  2. Use of Javascript router
    1. jQuery Ajax
    2. Success/Error handler for each router
    3. Single Success/Error handler for all routers

View original post 478 more words

Tutorial: Post Update on LinkedIn via Scribe using Scala


LinkedIn via Scribe using Scala & Play.

Knoldus

To post an Update on LinkedIn via your application, that is being built with Play 2.3.x, follow these steps ( this post summarizes the work done step by step).

1) Create a LinkedIn app (if you do not have one already)

Click here – LinkedIn’s Developer Quick Start Guide and create an app. Enter all the details including Site URL. The Site URL could be something like http://www.example.com (but it should be a valid site URL). Also, select the rw_nus setting under the OAuth User Agreement section (otherwise you wont be able to post updates on LinkedIn).

Once you have saved this app, you will get API Key & Secret Key. Take a note of this API Key & Secret Key. We would use them in our code.

2) If you are using Play, then add the API Key, Secret Key & Context URL(Callback URL) in application.conf file.

3) Download a LinkedIn login image from linkedin.png &…

View original post 98 more words

Map reduce with Akka and Scala: The famous word count


Knoldus

After working for around a decade with Java and family, recently i tried my hands with Scala and Akka. Yes! changing taste buds is not at all easy. But working with Scala is fun!  Prior to this, every time when i start on building some APIs, First thing which comes in my mind is

Number of java classes or beans. Honestly a POJO is never more than having getters and setters. (Do i need them?)

Scala just made it easy. Let’s see how!

Java

Honestly in previous java blogs i used to skip these setters and getters by simply mentioning as

// getters and setters!

With Scala it’s really easy.

By the way, you can also define a property class for this and access it as property.
There are number of things which makes Scala having an added advantage over Java(e.g. immutability, utility functions etc.) but i will skip these…

View original post 323 more words

filter.js – Client side search filtering using JSON and jQuery


I am planning to integrate it with Play framework.

Josh Software - Where Programming is an Art!

Speed for search result filtering is critical. Its fine for site users to wait for some time (maybe a few seconds) to load the search results but after that filtering better be fast otherwise people lose interest.

To give a simple example of how things are not user friendly is if you go to ebay.com or ebay.in. Its frankly appalling! For every click and every selection, the entire page refreshes. Though its good for showing Ad impressions (which I hate) when browsing an e-commerce site, the usability is lost.

On the other hand, have a look at snapdeal.com or groupon.com and it tells a different story. They fire Apis to their server to get json data and render that via Javascript. Usability is excellent. (no wonder they are doing so well!)

We did client-side search filtering in a couple of portals we built and realized that we should generalize this. That…

View original post 439 more words

A simple CRUD application in Play! Framework using Kundera and Cassandra as a Database.


playing-kundera-cassandra: Play 2.3.0, Kundera & Cassandra

Knoldus

playing-kundera-cassandra: Play 2.3.0, Kundera & Cassandra

A simple CRUD application in Play! Framework using Kundera and Cassandra as a Database.

  • Accessing a Cassandra database, using Kundera.
  • Achieving, Futures to use more idiomatic error handling.
  • Accessing JS & CSS libraries by WebJars.
  • Bootswatch-United with Twitter Bootstrap 3.1.1 to improve the look and feel of the application

Instructions :-


  • The Github code for the project is at : playing-kundera-cassandra
  • Clone the project into local system
  • To run the Play framework 2.3.0, you need JDK 6 or later
  • Install Typesafe Activator if you do not have it already. You can get it from here: download
  • Install Cassandra if you do not have it already. Instructions
  • Start Cassandra Server and create schema/tables
[default@unknown] create keyspace EmployeeExample;
395c9500-bf8d-3985-95a2-ddc055090131
[default@unknown] use EmployeeExample;
Authenticated to keyspace: EmployeeExample
[default@EmployeeExample] create column family employees with comparator=UTF8Type and default_validation_class=UTF8Type and key_validation_class=UTF8Type;
840d66b1-a54a-329e-9a43-dc9f373e9386
  • Execute activator clean compile to…

View original post 90 more words

playing-reactive-mongo: Classic CRUD application in Play Framework 2.3.0 with ReactiveMongo, WebJars and Bootswatch-United


Knoldus

Play 2.3.0 application with ReactiveMongo – reactive, asynchronous and non-blocking Scala driver for MongoDB.

This is a classic CRUD application, backed by a MongoDB database. It demonstrates:

  • Achieving, Futures to use more idiomatic error handling.
  • Accessing a MongoDB database, using ReactiveMongo.
  • Achieving, table pagination and sorting functionality.
  • Replaced the embedded JS & CSS libraries with WebJars.
  • Play and Scala-based template engine implementation
  • Bootswatch-United with Twitter Bootstrap 3.1.1 to improve the look and feel of the application

Instructions :-


  • The Github code for the project is at : playing-reactive-mongo
  • Clone the project into local system
  • To run the Play framework 2.3.0, you need JDK 6 or later
  • Install Typesafe Activator if you do not have it already. You can get it from here: download
  • Execute activator clean compile to build the product
  • Execute activator run to execute the product
  • playing-reactive-mongo should now be accessible at localhost:9000

References :-


View original post 68 more words