WfsServlet.java

  1. package de.turnertech.ows.servlet;

  2. import java.io.IOException;

  3. import de.turnertech.ows.common.OwsContext;
  4. import de.turnertech.ows.common.OwsContextFactory;
  5. import de.turnertech.ows.common.OwsRequestContext;
  6. import jakarta.servlet.ServletException;
  7. import jakarta.servlet.http.HttpServlet;
  8. import jakarta.servlet.http.HttpServletRequest;
  9. import jakarta.servlet.http.HttpServletResponse;

  10. public class WfsServlet extends HttpServlet {
  11.    
  12.     public static final String OWS_CONTEXT_FACTORY_KEY = "ows.context.factory.class";

  13.     private OwsContext owsContext;

  14.     private OwsServiceDispatcher owsServiceDispatcher;

  15.     @Override
  16.     public void init() throws ServletException {
  17.         String owsContextFactoryClassString = super.getInitParameter(OWS_CONTEXT_FACTORY_KEY);
  18.         if(owsContextFactoryClassString == null || "".equals(owsContextFactoryClassString)) {
  19.             throw new ServletException("ows.context.factory.class init parameter was not set.");
  20.         }

  21.         try {
  22.             Class<?> owsContextFactoryClass = Class.forName(owsContextFactoryClassString);
  23.             OwsContextFactory owsContextFactory = (OwsContextFactory)owsContextFactoryClass.getDeclaredConstructor().newInstance();
  24.             owsContext = owsContextFactory.createOwsContext();
  25.         } catch (ClassNotFoundException e) {
  26.             throw new ServletException("Could not find class: " + owsContextFactoryClassString, e);
  27.         } catch (Exception e) {
  28.             throw new ServletException("Could not intantiat OwsContextFactory", e);
  29.         }

  30.         owsServiceDispatcher = new OwsServiceDispatcher();
  31.     }

  32.     @Override
  33.     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  34.         owsServiceDispatcher.handleRequest(request, response, owsContext, new OwsRequestContext());
  35.     }

  36.     @Override
  37.     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  38.         owsServiceDispatcher.handleRequest(request, response, owsContext, new OwsRequestContext());
  39.     }
  40. }