View Javadoc
1   package au.gov.amsa.craft.analyzer.wms;
2   
3   import java.io.IOException;
4   
5   import javax.servlet.ServletException;
6   import javax.servlet.http.HttpServlet;
7   import javax.servlet.http.HttpServletRequest;
8   import javax.servlet.http.HttpServletResponse;
9   
10  import com.github.davidmoten.grumpy.wms.Capabilities;
11  import com.github.davidmoten.grumpy.wms.Layer;
12  import com.github.davidmoten.grumpy.wms.WmsServletRequestProcessor;
13  
14  public class WmsServlet extends HttpServlet {
15      private static final long serialVersionUID = 1518113833457077766L;
16  
17      private static final String SERVICE_TITLE = "Custom OGC Services";
18      private static final String SERVICE_NAME = "CustomOGC";
19      private static final String SERVICE_ABSTRACT = "Custom OGC WMS services including Custom, Fiddle and Darkness layers";
20  
21      private final WmsServletRequestProcessor processor;
22  
23      public WmsServlet() {
24  
25          // instantiate the layers
26          Layer layer = new DriftingLayer();
27  
28          // setup the capabilities of the service which will extract features
29          // from the layers to fill in defaults for the layer fields in generated
30          // capabilities.xml
31          Capabilities cap = Capabilities.builder()
32          // set service name
33                  .serviceName(SERVICE_NAME)
34                  // set service title
35                  .serviceTitle(SERVICE_TITLE)
36                  // set service abstract
37                  .serviceAbstract(SERVICE_ABSTRACT)
38                  // add image format
39                  .imageFormat("image/png")
40                  // add info format
41                  .infoFormat("text/html")
42                  // add custom layer
43                  .layer(layer)
44                  // build caps
45                  .build();
46  
47          // initialize the request processor
48          processor = WmsServletRequestProcessor.builder()
49          // capabilities
50                  .capabilities(cap)
51                  // or use
52                  // .capabilitiesFromClasspath("/wms-capabilities.xml")
53                  // set image cache size
54                  .imageCache(200)
55                  // add custom layer non-cached
56                  .addLayer("Drifting", layer)
57                  // build it up
58                  .build();
59      }
60  
61      @Override
62      protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException,
63              IOException {
64  
65          // use the processor to handle requests
66          processor.doGet(req, resp);
67      }
68  
69  }