Category Archives: Java

FAQ: RESTful web service with Jersey&Jackson

  • How to do output in JSON format

    public JSONObject sayPlainTextHello(@PathParam("id")JSONObject inputJsonObj) {  
    String input = (String) inputJsonObj.get("input");  
    String output="The input you sent is :"+input;  
    JSONObject outputJsonObj = new JSONObject();  
    outputJsonObj.put("output", output);  
    return outputJsonObj;  


    ClientConfig config = new DefaultClientConfig();  
    Client client = Client.create(config);  
    WebResource service = client.resource(getBaseURI());  
    JSONObject inputJsonObj = new JSONObject();  
    inputJsonObj.put("input", "Value"); System.out.println(service.path("rest").path("hello").accept(MediaType.APPLICATION_JSON).entity(inputJsonObj).post(JSONObject.class,JSONObject.class));

FAQ: Spring Roo 1.2

  1. Spring Roo Pluging/Addons

    WEB Report – jasperoo

    There is an introduction on blog at:…-jasperoo.html
    The project is hosted on Google Code at:

    roo> osgi start --url
    roo> jasperoo setup
    roo> jasperoo add --type ~.domain
    roo> jasperoo all


  2. Your Own Web App in Under 10 Minutes

    mkdir hello
    cd hello
    roo> hint
    roo> project --topLevelPackage
    roo> jpa setup --provider HIBERNATE --database HYPERSONIC_IN_MEMORY
    roo> entity jpa --class ~.Timer --testAutomatically
    roo> field string --fieldName message --notNull
    roo> jpa setup --provider HIBERNATE --database MYSQL --databaseName commission_app --userName root
    roo> database reverse engineer --package ~.domain --schema commission_app
    roo> hint web mvc
    roo> web mvc setup
    roo> web mvc all --package ~.web
    roo> web mvc finder all
    roo> selenium test --controller ~.web.TimerController
    roo> web gwt setup
    roo> web gwt all --proxyPackage --requestPackage
    roo> perform tests
    roo> quit

    “roo> jpa setup –provider HIBERNATE –database MYSQL –databaseName spring_roo –userName root –password psw“.

    “roo> database reverse engineer –schema –package –testAutomatically –enableViews –includeTables –excludeTables –includeNonPortableAttributes” This command creates JPA entities in your project representing the tables and columns in your database. roo> database reverse engineer –schema order –package ~.domain

    “roo> perform eclipse” create IDE-specific workspace configuration artifacts if you not using STS or m2eclipse. Once this command has completed you are ready to import your project into STS by clicking ‘File > Import > General > Existing Projects into Workspace’. If you’re using STS or have installed m2eclipse into an Eclipse-based IDE can skip the perform eclipse command entirely. In this case you simply need to select in STS/Eclipse the ‘File > Import > General > Maven Projects’ menu option.

    “roo> backup” Issuing this command will create you a
    backup of the current workspace with all sources, log files and the script log file (excluding the target

    “roo> addon search” lists all add-ons

    “roo> script bikeshop.roo” Import roo script

    “roo> perform package” This command produces your war file which can then be easily copied into your production Web container.

    "mvn gwt:run" to play with the GWT client
    "mvn tomcat:run" to start the Tomcat MVC front-end
    "mvn jetty:run-exploded"
    "mvn eclipse:eclipse" and then use Eclipse's "General > Import Existing Project into Workspace" feature. Leave the Roo shell running and feel free to edit in Eclipse
    "mvn install:install-file -DartifactId=ojdbc14 -Dversion= -Dpackaging=jar -Dfile=/path/to/file" maven command to install your driver into your local maven repository
  3. Useful links


    Developing a Spring Framework MVC application step-by-step
    JSR-000303 Bean Validation
    iReport & JasperReport
    Community Forums
    Java community site
    Spring Data

    Source code

  4. org.hibernate.HibernateException: The database returned no natively generated identity value

    It should be an auto_increment column for the IDENTITY generator to work. Else, the database doesn’t return any generated ID.

  5. Themes

    To achieve a higher level of customization you can change the default Tiles template (WEB-INF/layouts/default.jspx) and adjust the JSP pages (WEB-INF/views/*.jspx).
    theming support offered by Spring framework