Recently, I have found a little down time and thought I would investigate some other frameworks. I have been working mostly with Spring MVC this last year. I stumbled upon
Play Framework recently. It reminded me of a promotion of Ruby on Rails a few years ago comparing a several feet high stack of books on J2EE with the one simple single Rails book. Play framework is taking the same approach. Simplicity and immediacy.
It uses a command line similar to Rails (and Spring Roo by the way) to create initial constructs based on archetypes/patterns. It incorporates the web server so every change is instantly view-able on the web page and it will immediately display errors right in the web being developed. Further, it includes a simple template engine integrating the framework for creating pages to deliver to the client.
Watch a a nice tutorial posted on YouTube.
One premise play is based on is of more interest than its Rails like simplicity, that is its assumption of a stateless "share nothing'' REST first approach. Keeping state synchronized on the client, in the session and on persistent store can be annoying and difficult. It makes clustering more difficult and tends to produce complexity and as a result bug potential.
Discussions of building enterprise applications leveraging Web 2.0+ concepts with technologies related to Java including: HTML5, Ajax, Spring Roo, GWT and other JavaScript and rich client libraries, while leveraging SOA, REST, ORM Persistence and the Semantic Net.
Showing posts with label REST. Show all posts
Showing posts with label REST. Show all posts
Saturday, March 10, 2012
Friday, March 9, 2012
Looking at Google Plus API
I'm jumping around technologies right now but I am playing around with the new google plus restful APIs.
After watching an interesting youtube video of the API by jenny murphy, I explored the API interactively using the google plus api developers site.
Clicking on REST API, you can go to each api resource (people, activities, comments, oauth) and explore the API including running an example request and seeing the results. I have a google plus identity (+Ed) so I posted a couple of public messages to play with.
I was able to download the google plus java client api and google plus java starter project.
I followed these steps to get started
Copy the google java starter project web app example (./google-plus-java-starter/web-app) to a new directory to begin playing. The instructions are in the readme.txt to get started.
In order to access the API, you first have to register your application using the google api console and get a token for oauth and access to the specific api. The steps
After watching an interesting youtube video of the API by jenny murphy, I explored the API interactively using the google plus api developers site.
Clicking on REST API, you can go to each api resource (people, activities, comments, oauth) and explore the API including running an example request and seeing the results. I have a google plus identity (+Ed) so I posted a couple of public messages to play with.
I was able to download the google plus java client api and google plus java starter project.
I followed these steps to get started
Copy the google java starter project web app example (./google-plus-java-starter/web-app) to a new directory to begin playing. The instructions are in the readme.txt to get started.
In order to access the API, you first have to register your application using the google api console and get a token for oauth and access to the specific api. The steps
- go to https://code.google.com/apis/console/b/0/?api=plus
- click on 'create project'
- agree to the terms of service (and read :)) (two of them)
- Select the google+API (if not already selected (note the url I supplied should select this)
- CLick on API access (left side menu)
- Click on Create an OAuth 2.0 client ID
- describe your project (and upload logo if you have it) and press next
- select application type=web app, and site host name to run locally, select http: and enter localhost
- click 'create client ID'
- there are 4 pieces of info that you'll need to copy to your project: client id, client secret, redirect URI and API key (from the Simple API access)
in your new project (copied from starter) open src/main/resources/config.properties
paste in the 4 bits of information from the registration process (the redirect URI may already be correct)
now from the project root, use maven to launch the project using the built in jetty:
mvn compile jetty:run
go to your browser (chrome naturally) to check out
http://localhost:8080/
This may fail (the version I had downloaded _v5 did fail)
If you get an exception thrown when first accessing with error:
Exception initializing page context java.lang.VerifyError: (class: org/apache/jasper/runtime/PageContextImpl, method: getELResolver signature: ()Ljavax/el/ELResolver;) Incompatible argument to function
Then you may need to fix the pom.xml. Open pom.xml and add scope provided element for the jsp 2.1 dependency:
<dependency> <groupid>org.mortbay.jetty</groupid> <artifactid>jsp-2.1</artifactid> <version>6.1.14</version> <scope>provided</scope> </dependency>
Then restart and access again. Then it works!
You should see 'connect me' button.
This will require you to authorize access to your account from this program. Once authorized, it presents your profile information and a list of public activities.
Now you can play with the API
Friday, July 8, 2011
Testing my RESTful controllers with Spring RESTtemplate
I have been playing with Spring's RESTtemplate as an approach to integration testing on my project.
I feel I should create a set of blog posts related to how I am doing testing with this technology stack. Sometimes this aggregation is helpful. In my team, we are testing at the following levels:
This blog will focus on integration testing.
Integration testing, different from unit testing, tests the code as it is wired up to other components, the server and the data base as well.
To set the stage, I am using spring 3 with Spring MVC for my application. In particular, I am leveraging a lot of Ajax, accessing the controller from the browser and transporting JSON. I am using the Jackson JSON mapping implementation to marshal to from beans to JSON.
I need to create good integration tests of my controller classes so I can run JUnit tests that connect with the deployed web app and interact RESTfully like the client UI, passing JSON objects back and forth.
A helpful blog post I have used for guidance: is ralf.schaeftlein s blog detailing an approach to integration testing of restful MVC controllers with JSON. Exactly what I was interested in.
The basic steps seem to be:
In this case, I am testing my Data Repository, which is essentially my Data Access Object (DAO) for you old schoolers. I will post why Repositories and not DAO in a future blog.
My application context file configures spring with the required setup for my application to run this test. First, the usual name spaces:
Then, we use automatic annotation discovery of out project
Here is wshere we configure the restTemplate to be used for this integration test of our controller
Finally the required configuration for our persistence. Notice we are using JPA configuration here
Finnaly the test code.
We write an integration test for our controller that connects remotely to the deployed application, sends beans mapped from Pojo to json for the call, and then maps back json to Pojo to assert results.
Overview of Testing a RIA with Spring and Spring MVC
I feel I should create a set of blog posts related to how I am doing testing with this technology stack. Sometimes this aggregation is helpful. In my team, we are testing at the following levels:
- unit testing of everyting - pure tests, typically single class only, with mock (using Mockito)
- integration testing of our services - out of container (web server) testing, but with db
- integration testing of our controllers - in container testing, with db
- functional testing of our ui (TBD) - full in container testing
This blog will focus on integration testing.
Integration testing, different from unit testing, tests the code as it is wired up to other components, the server and the data base as well.
Testing the controller layer in Spring MVC
To set the stage, I am using spring 3 with Spring MVC for my application. In particular, I am leveraging a lot of Ajax, accessing the controller from the browser and transporting JSON. I am using the Jackson JSON mapping implementation to marshal to from beans to JSON.
I need to create good integration tests of my controller classes so I can run JUnit tests that connect with the deployed web app and interact RESTfully like the client UI, passing JSON objects back and forth.
A helpful blog post I have used for guidance: is ralf.schaeftlein s blog detailing an approach to integration testing of restful MVC controllers with JSON. Exactly what I was interested in.
The basic steps seem to be:
- create a unit test with java4 leveraging Spring 3 Integration Test Annotations
- configure your application context XML to define your mappers that will convert between JSON and beans
- write your tests pojo style
In this case, I am testing my Data Repository, which is essentially my Data Access Object (DAO) for you old schoolers. I will post why Repositories and not DAO in a future blog.
My application context file configures spring with the required setup for my application to run this test. First, the usual name spaces:
Then, we use automatic annotation discovery of out project
Here is wshere we configure the restTemplate to be used for this integration test of our controller
Finally the required configuration for our persistence. Notice we are using JPA configuration here
Finnaly the test code.
We write an integration test for our controller that connects remotely to the deployed application, sends beans mapped from Pojo to json for the call, and then maps back json to Pojo to assert results.
Subscribe to:
Posts (Atom)