Skip to content
This repository has been archived by the owner on Jun 2, 2021. It is now read-only.

Commit

Permalink
Extend from AbstractHandlerContainer instead of AbstractHandler (drop…
Browse files Browse the repository at this point in the history
…wizard#2460)

(cherry picked from commit 5a78323)
  • Loading branch information
jplock authored and joschi committed Aug 16, 2020
1 parent bfbbaef commit 65a5f83
Showing 1 changed file with 24 additions and 4 deletions.
Expand Up @@ -2,9 +2,8 @@

import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.server.handler.AbstractHandlerContainer;
import org.eclipse.jetty.util.ArrayTernaryTrie;
import org.eclipse.jetty.util.Trie;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
Expand All @@ -15,8 +14,8 @@
/**
* A Jetty router which routes requests based on context path.
*/
public class ContextRoutingHandler extends AbstractHandler {
private final Trie<Handler> handlers;
public class ContextRoutingHandler extends AbstractHandlerContainer {
private final ArrayTernaryTrie<Handler> handlers;

public ContextRoutingHandler(Map<String, ? extends Handler> handlers) {
this.handlers = new ArrayTernaryTrie<>(false);
Expand All @@ -38,4 +37,25 @@ public void handle(String target,
handler.handle(target, baseRequest, request, response);
}
}

@Override
protected void doStart() throws Exception {
super.doStart();
for (String key : handlers.keySet()) {
handlers.get(key).start();
}
}

@Override
protected void doStop() throws Exception {
super.doStop();
for (String key : handlers.keySet()) {
handlers.get(key).stop();
}
}

@Override
public Handler[] getHandlers() {
return handlers.entrySet().stream().map(Map.Entry::getValue).toArray(Handler[]::new);
}
}

0 comments on commit 65a5f83

Please sign in to comment.