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.
No comments:
Post a Comment