Showing posts with label rest. Show all posts
Showing posts with label rest. Show all posts

Saturday, February 2, 2013

Lessons learned Spring 3.0 project

Another quick post with some bullet points of lessons learned during my last Spring 3.0 project.
Tools used were:

  • Spring 3.0 (3.1.2 when moving to Hibernate 4)
  • Spring MVC
  • Spring WebFlow 2
  • Spring Batch
  • Spring Agent Framework
  • Hibernate 3.2.6
  • Apache CXF
  • JBehave (Behavior Driven Development)
  • Tiny bit of GXT, which is a Google Web Toolkit extension based on GWT and ExtJS technology. Formally known as Ext GWT, GXT is a Java library for building rich internet applications with the Google Web Toolkit (GWT)
  • JBoss jBPM 5.2.0
  • JBoss Drools 5.3.1
  • Jenkins for CI
  • Crucible for code reviews
  • Jira for issue tracking en sprint user stories and tasks and progress tracking
  • SpringSource Tool Suite 2.9.1 as Eclipse based IDE
  • JUnit 4.8
  • EasyMock 2.5.2, EasyMockSupport
  • Java 6
  • Cargo-itest (introduction here) for integration testing
  • Tomcat 6
  • Oracle SQL Developer (free version)
Besides learning new tools like JBehave an Cargo-itest, below are some things picked up using above tools.

Spring MVC
Had some issues getting REST-like services available, mainly from inexperience, but good to know what's working and what not:

    @GET
    @Path("some-path/?role={roleId}")
    Response getSomeOtherUrlParams(@PathParam(value = "roleId") final String roleId);
    // Unable to call it, because PathParam is not existing (it's not really part of the path)

    @GET
    @Path("some-path2/role/{roleId}")
    Response getSomeOtherUrlParamsNotAsRequest(@PathParam(value = "roleId") final String roleId);
    // Works

    @GET
    @Path("some-path3/")
    Response getSomeOtherUrlParamsAsQueryParam(@QueryParam("role") final String roleId);
    // Works, will have clients of this service (like SoapUI) already generate a ?role= parameter

    @GET
    @Path("some-path4/")
    Response getSomeOtherUrlParamsAsRequestParam(@RequestParam("role") final String roleId);
    // Won't generate a ?role= parameter for clients, the WADL also looks different for this method/parameter

Don't use @FormParam for submitting XML because if the mediatype is text/xml for example, the mapping on the REST method fails because JAXRS expects HTML (default if not specified at the service definition).
So suppose the service is defined as:

    @POST
    @Path("message/{messageCode}/send")
    Response sendMessage(@PathParam(value = "messageCode") final String messageCode, 
                                         @FormParam("moduleName") String moduleName,
                                         @FormParam("userId") String userId, 
                                         final MessageContentsRequest messageContents);

When invoking the above method by POSTing to 

http://localhost:8080/webservice/v1/message/SECRET_MESSAGE_CODE/send 

with as POST body parameters moduleName and userId + the MessageContentsRequest XML, that gives the following error in the log:

2013-01-05 11:24:38,491 WARN  [http-8890-1] JAXRSUtils#processFormParam - An application/x-www-form-urlencoded form request is expected but the request media type is text/xml;charset=UTF-8. Consider removing @FormParam annotations.
2013-01-05 11:24:38,493 WARN  [http-8890-1] WebApplicationExceptionMapper#toResponse - WebApplicationException has been caught : no cause is available

The same error occurs when invoking: ..../send/?moduleName=abc&userId=ttl  (so adding them as POST URL name/value parameters).

So make sure you use in that case:

    @POST
    @Path("message/{messageCode}/send")
    Response sendMessage(@PathParam(value = "messageCode") final String message ode, 
                                         @QueryParam("moduleName") String moduleName,
                                         @QueryParam("userId") String userId, 
                                         final MessageContentsRequest messageContents);

The moduleName and userId can then be passed in via the POST URL name/value parameters.


EasyMock
Use replayAll() and verifyAll() instead of replay(mock) and verify(mock) for each mock seperately. Requires extending EasyMockSupport.
 


SQL Developer
The free SQL Developer can't export clob column values. Nor can it import clob values larger than 4K.




 

Sunday, August 29, 2010

Best of this Week Summary 23 August - 29 August 2010

Sunday, March 28, 2010

Best of this Week Summary 22 March - 28 March 2010

Sunday, March 14, 2010

Best of this Week Summary 8 March - 14 March 2010

Sunday, February 28, 2010

Best of this Week Summary 22 February - 28 February 2010

Sunday, December 20, 2009

Best of this Week Summary 14 December - 20 December 2009

Sunday, September 20, 2009

Best of this Week Summary 14 September - 20 September 2009

  • Scala is slowly getting some more and more traction lately. Is it a potential long term replacement for Java?
    Interview with Scala creator Martin Odersky where he tells its history, future and why it's so interesting (like combining OO- and functional techniques).

  • Six valid "takeaways on what most REST adopters can and should do to get the most from their use of this increasingly popular architectural style" summarised by Dion Hinchcliffe.

  • Article that describes using Benerator, which is a data generator tool that can be used to feed database with pseudo-random test data.

  • Tip that shows you how to implement composite keys with JPA and Hibernate. Check also the comments here.

Sunday, September 6, 2009

Best of this Week Summary 24 August - 06 September 2009

  • Great introduction to Solr, a search server (and more). The article describes how to get it running, send it some documents to index and how to search those documents in a controlled way.

  • More details on Google Wave: the draft specification for the Google Wave Federation Protocol and the Java source code for the Google Wave Federation Prototype Server

  • An extensive comparison of Spring and Seam. And, recently added chapter 5, comparing them with Wicket 1.3.6. Too long for you to read? Then at least read the conclusion :)
    Talking about Wicket, here are some
    experiences written down on migrating an existing Wicket application to the new 1.4 version.

  • This article provides a short overview on the basics of RESTful HTTP and discusses typical issues that developers face when they design RESTful HTTP applications. It shows how to apply the REST architecture style in practice. It describes commonly used approaches to name URIs, discusses how to interact with resources through the Uniform interface, when to use PUT or POST and how to support non-CRUD operations.
    Related to that, here's 8 great tips/lessons learned for creating an API.

Sunday, June 14, 2009

Best of this Week Summary 8 June - 14 June 2009

Sunday, May 24, 2009

Best of this Week Summary 18 May - 24 May 2009

Sunday, March 8, 2009

Best of this Week Summary 02 March - 08 March 2009

Sunday, February 1, 2009

Best of this Week Summary 26 January - 01 February 2009

Sunday, January 18, 2009

Best of this Week Summary 12 January - 19 January 2009

Sunday, January 11, 2009

Best of this Week Summary 29 December - 11 January 2009

  • Interesting comparison whether and when to use SOAP or REST.

  • OpenSocial now has Java, PHP, Ruby and Python client libraries available.

  • A few weeks ago, PKI which uses MD5 as cryptographic hash function, has now officially been broken at the hackers convention Chaos Communication Congress 2008. Six Certificate Authorities still give out MD5-signed certificates as mentioned in the article. Since 2004 it is already known that MD5-collisions can be created for different data. Therefore, certificates should be issued with at least SHA-1 encryption. Here's a summary of what an MD5 collision is and what Mozilla and Microsoft issued as advisories. Additionally some (other) SSL issues are described.

  • Nice summary of lessons learned during a project using GWT, Axis and JPA. Some more comments here.

  • Paper by Kate McKinley (a researcher at iSec Partners, a San Francisco security firm) on the privacy protection mechanisms of FireFox, Chrome, IE and Safari. Conclusion: "We find current browsers are unable to extend tracking protection to third party plug-ins such as Google Gears and Adobe Flash. Some of these require no user prompting under common configurations and even expose tracking data saved with one browser sites visited by a different browser. [...] Safari on Windows fared the worst of all in these tests with respect to private browsing, and did not clear any data at all, either before entering or after exiting the private mode. On OS X, Safari’s behavior was quirky; in no case was the HTML 5 database storage cleared before or after private browsing.".

Sunday, December 28, 2008

Best of this Week Summary 16 December - 28 December 2008

  • Great insight on Second Life's architecture. For example: "A physical server (1 CPU) is responsible for about 16 acres of land and it is connected to neighboring ones which are each responsible for another 16 acres. The server is responsible for the objects existing in its area, the scripts running, the users logged in and standing in its area". Presentation is one hour in total.

  • There's more to REST than meets the eye. And many REST APIs are not really as REST as Roy Fielding defines it. Media type design is an important item that was not in his original REST dissertation. Some interpretation of what Roy actually means can be found here.

  • JanRain (known for their OpenID libraries) have created a nice widget named RPX that allows you to integrate authentication within your existing site in an easy and user-intuitive way. I really like the clear, easy and non-intrusive way the possibilities are shown. For real novice users the redirecting to and from the authenticating sites might still be a little bit confusing though. Supported protocols are: OpenID 1.x/2.0, Facebook Connect, MySpaceID and Google. Below is a screenshot of what the registration part looks like:

    A couple of example sites where this is already implemented can be found here. And some more on the possibilities here.
    Note that from the technical overview you can see that the RPX server sits in between. That is the only disadvantage of this solution: that you are dependent on an intermediate server.

  • The W3 Consortium has released a webpage mobile-friendliness checker. The tests it performs can be found at the mobileOK Basic Tests 1.0 specification. Other validators you might know from them are the feed validator, XML Schema Validator, CSS validator or Markup validator. Running these very succesful services without any advertising is costing a lot of money. Therefore you can now donate here for support. If you compute how much time those validators have saved you, donating any small percentage of that will already help W3C keep these validators running.

Sunday, November 30, 2008

Best of this Week Summary 17 November - 30 November 2008

  • Interesting recent long discussion (with a bit of framework flame-war in between) and tips on when to pick what web client framework. Tapestry, Wicket, Stripes, GWT, Flex seem to jump out.

  • Interesting Javascript optimizer: Razor Optimizer. It dynamically analyzes the runtime profile information, trying to load each Javascript function only when needed, potentially creating 60-90% savings. It does require a client and server component. The question is: are you prepared to take a (small?) risk that your Javascript is dynamically modified?

  • Good article that explains why Scrum often fails as implementation of Agile. Lots of times Scrum is only seen as fast Sprints and Scrums. But: "Don't leave out the 'regular' agile good engineering practices". Check also the comments for good tips.

  • A good introduction to RESTful webservices.

  • Great, soapUI 2.5 now also suppports testing RESTful webservices. It includes testing JSON output.

Saturday, November 15, 2008

Best of this Week Summary 04 November - 16 November 2008

Saturday, October 25, 2008

Best of this Week Summary 20 October - 26 October 2008

Saturday, July 12, 2008

Best of this Week Summary 7 July - 13 July 2008

Sunday, April 27, 2008

Best of this Week Summary 05 May - 11 May 2008