16

Looking for a dropwizard example I found:

https://github.com/codahale/dropwizard/tree/master/dropwizard-example

But I am interested in a more complete example with at least:

  1. a 1:n relationship like customer - account
  2. a html gui represenation at least with forms
  3. full crud support for xml

2 out of three would be a start and would earn "accepted" by me.

Wolfgang Fahl
  • 12,097
  • 9
  • 75
  • 150

7 Answers7

19

Take a look at some of my Dropwzard projects

In particular the MultiBit Merchant projects (Admin, Store and Platform) will provide you with a wealth of demonstration code that shows how to get stuff done in Dropwizard. There is also an example of OpenID with Dropwizard that should provide a good launch point for a new application.

They are all FOSS under the MIT license.

Gary Rowe
  • 6,934
  • 2
  • 34
  • 56
7

Wolfgang,

here is an example Dropwizard application where Authentication, Configuration and database access using Hibernate are used.

The application is discussed in several tutorials:

And here is another example, where one can store bookmarks for authenticated users and access data via REST API.

Good luck.

javaeeeee
  • 651
  • 8
  • 13
4

That looks like a nice example as well: https://github.com/spinscale/dropwizard-blog-sample

oae
  • 1,022
  • 13
  • 16
2

I wrote an example in my Dropwizard XML Bundle project:

https://github.com/yunspace/dropwizard-xml/tree/master/dropwizard-xml-example

It's probably the closest to what you are looking for. It has:

  • 1:N relationship between Pirates and Ships, stored in a H2 db.
  • Full CRUD support for XML using custom JacksonMessageBodyProvider with validation.

Adding HTML gui via Freemarker or Mustache templates should be pretty trivial and is covered in the standard docs.

yunspace
  • 2,242
  • 17
  • 19
2

A good example who want dropwizard with authentication.

Dropwizard: Authentication, Configuration and HTTPS https://dzone.com/articles/getting-started-dropwizard-0

gonella
  • 186
  • 1
  • 6
0

You can try this project from Github.

Dropwizard: CRUD operation, HTML views, Healthcheck

https://github.com/HoldInArms/dropwizard-mssql-crud-example

Prasad Revanaki
  • 693
  • 4
  • 10
  • 21
  • Good example but the above code seems to use an older version of dropwizard. Same code ported to Mysql with 1.0.5 dropwizard version - https://github.com/rahulsh1/dropwizard-mysql-crud-example – Neo Dec 02 '16 at 05:43
-2

follow below step.

  1. Add dependencies in pom file

    <dependencies>
    <dependency>
        <groupId>com.yammer.dropwizard</groupId>
        <artifactId>dropwizard-core</artifactId>
        <version>0.6.2</version>
    </dependency> 
    

  2. Create configuration class

    import com.yammer.dropwizard.config.Configuration;
    public class BlogConfiguration extends Configuration{
    
     }
    
  3. Create Service class

       import com.yammer.dropwizard.Service;
       import com.yammer.dropwizard.config.Bootstrap;
       import com.yammer.dropwizard.config.Environment;
    
       public class BlogService extends Service<BlogConfiguration> {
    
       public static void main(String[] args) throws Exception {
       new BlogService().run(new String[] { "server",
       "C:\\LocalEnv\\Workspace\\dropwizarddemo\\configuration.yml" });
        }
    
        @Override
       public void initialize(Bootstrap<BlogConfiguration> bootstrap) {
       bootstrap.setName("blog");
       }
    
       @Override
        public void run(BlogConfiguration configuration, 
        Environment    environment) throws Exception {
        environment.addResource(new IndexResource());
        }
    
      }
    

Note: put below configuration.yml file in current directory

       # HTTP-specific options.
       http:

       # The port on which the HTTP server listens for service requests.
       port: 8079

       # The port on which the HTTP server listens for administrative
       # requests.
       adminPort: 8179

      # Maximum number of threads.
      maxThreads: 100

      # Minimum number of thread to keep alive.
      minThreads: 10

4. Write Index resources.

     import java.util.ArrayList;
     import java.util.Arrays;
     import java.util.List;
     import javax.ws.rs.GET;
     import javax.ws.rs.Path;
     import javax.ws.rs.Produces;
     import javax.ws.rs.core.MediaType;


    import com.yammer.metrics.annotation.Timed;

    @Path("/")
    public class IndexResource {

   @GET
   @Produces(value = MediaType.APPLICATION_JSON)
   @Timed
   public List<Blog> index() {
    return Arrays.asList(new Blog("for Java Developers",
   "http://stackoverflow.com/questions/13345693/looking-for-a-dropwizard-
    example”));
   }


   @Path("/service")


   @GET
   @Produces(value = MediaType.APPLICATION_JSON)
   @Timed
   public List<Users> users() {
    List<Users> list = new ArrayList<Users>();
    list.add(new Users(25,"Sambhu","SA"));
    list.add(new Users(35,"Amit","VP"));
    list.add(new Users(45,"Sanket","AVP"));


    return list;
    }


  }
  1. Write POJO for Blog and Users like

     public class Users {
    
    
     Integer id;
     String name;
     String designation;
    
     public Users(Integer id, String name, String desination){
    this.id=id;
    this.name=name;
    this.designation=desination;
    }
    
    public Integer getId() {
    return id;
    }
    public void setId(Integer id) {
    this.id = id;
    }
    public String getName() {
    return name;
    }
    public void setName(String name) {
    this.name = name;
    }
    public String getDesignation() {
    return designation;
    }
    public void setDesignation(String designation) {
    this.designation = designation;
    }
    @Override
    public String toString() {
    return "Users [id=" + id + ", name=" + name + ", designation="
            + designation + "]";
    }
    
  2. Run BlogService which will start the Jetty server and hit the localhost with port such as http://localhost:8079/

sambhu
  • 111
  • 1
  • 5