title: Embedded jetty. java.lang.IllegalStateException: !STOPPED
body: <p>I trying to make simple servlet in embedded jetty container.
  This is my jetty configuration:</p>
  
  <pre><code>public class Application {
    public static void main(String[] args) throws Exception {
      //-Dport=8188
      int port = 8188;
      if(System.getProperty("port") != null) {
        port = Integer.valueOf(System.getProperty("port"));
      }
  
      //-Dhost="127.0.0.1"
      String host = System.getProperty("host");
      if(host == null || host.isEmpty()) {
        host = "127.0.0.1";
      }
  
      ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
      context.setContextPath("/");
  
      InetAddress address = InetAddress.getByName(host);
      InetSocketAddress socketAddress = new InetSocketAddress(address, port);
  
      Server jettyServer = new Server(socketAddress);
      jettyServer.setHandler(context);
  
      ServletHolder jerseyServlet = context.addServlet(org.glassfish.jersey.servlet.ServletContainer.class, "/*");
      jerseyServlet.setInitOrder(0);
  
      // Initializing servlet
      jerseyServlet.setInitParameter(
        "jersey.config.server.provider.classnames",
        Proxy.class.getCanonicalName()
      );
  
      try {
        jettyServer.start();
        jettyServer.join();
      } finally {
        jettyServer.destroy();
      }
    }
  }
  </code></pre>
  
  <p>I add a simplest servlet, that does nothing. Just wrote some string to response:</p>
  
  <pre><code>public class Proxy extends HttpServlet {
      protected void doGet(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
          doRequest(request, response);
      }
  
      protected void doPost(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
          doRequest(request, response);
      }
  
      private void doRequest(HttpServletRequest request, HttpServletResponse response) throws IOException {
         PrintWriter writer = response.getWriter();
          writer.println("GOT IT!");
      }
  }
  </code></pre>
  
  <p>When I start it, I get an error:</p>
  
  <pre><code>2016-08-14 10:53:42.338:INFO::main: Logging initialized @110ms
  2016-08-14 10:53:47.404:INFO:oejs.Server:main: jetty-9.3.z-SNAPSHOT
  2016-08-14 10:53:47.923:INFO:oejsh.ContextHandler:main: Started o.e.j.s.ServletContextHandler@8458f04{/,null,AVAILABLE}
  Exception in thread "main" java.lang.IllegalStateException: !STOPPED
      at org.eclipse.jetty.server.handler.HandlerWrapper.destroy(HandlerWrapper.java:135)
      at ru.gridr.Application.main(Application.java:50)
  </code></pre>
  
  <p>Where is the mistake?
  May be someone can show some simple example?</p>