### Question:
JettyHTTPServerEngine implements ServerEngine { public synchronized ContextHandler getContextHandler(URL url) { String contextName = HttpUriMapper.getContextName(url.getPath()); ContextHandler ret = null; if (server != null) { for (Handler handler : server.getChildHandlersByClass(ContextHandler.class)) { ContextHandler contextHandler = null; if (handler instanceof ContextHandler) { contextHandler = (ContextHandler) handler; if (contextName.equals(contextHandler.getContextPath())) { ret = contextHandler; break; } } } } return ret; } JettyHTTPServerEngine(
        Container.Listener mBeanContainer,
        String host,
        int port);  JettyHTTPServerEngine(); void setThreadPool(ThreadPool p); void setPort(int p); void setHost(String host); void setContinuationsEnabled(boolean enabled); boolean getContinuationsEnabled(); String getProtocol(); int getPort(); String getHost(); void shutdown(); Server getServer(); void setServer(Server s); void setConnector(Connector c); void setHandlers(List<Handler> h); void setSessionSupport(boolean support); boolean isSessionSupport(); List<Handler> getHandlers(); Connector getConnector(); boolean isReuseAddress(); void setReuseAddress(boolean reuse); int getMaxIdleTime(); void setMaxIdleTime(int maxIdle); synchronized void addServant(URL url, JettyHTTPHandler handler); synchronized void removeServant(URL url); synchronized Handler getServant(URL url); synchronized ContextHandler getContextHandler(URL url); @PostConstruct void finalizeConfig(); void setTlsServerParameters(TLSServerParameters params); TLSServerParameters getTlsServerParameters(); void setThreadingParameters(ThreadingParameters params); boolean isSetThreadingParameters(); ThreadingParameters getThreadingParameters(); void setSendServerVersion(Boolean sendServerVersion); Boolean getSendServerVersion(); int getSessionTimeout(); void setSessionTimeout(int sessionTimeout); static final String DO_NOT_CHECK_URL_PROP; }### Answer:
@Test public void testGetContextHandler() throws Exception { String urlStr = "http: JettyHTTPServerEngine engine = factory.createJettyHTTPServerEngine(PORT1, "http"); ContextHandler contextHandler = engine.getContextHandler(new URL(urlStr)); assertNull(contextHandler); JettyHTTPTestHandler handler1 = new JettyHTTPTestHandler("string1", true); JettyHTTPTestHandler handler2 = new JettyHTTPTestHandler("string2", true); engine.addServant(new URL(urlStr), handler1); contextHandler = engine.getContextHandler(new URL(urlStr)); contextHandler.stop(); contextHandler.setHandler(handler2); contextHandler.start(); String response = null; try { response = getResponse(urlStr); } catch (Exception ex) { fail("Can't get the reponse from the server " + ex); } assertEquals("the jetty http handler did not take effect", response, "string2"); JettyHTTPServerEngineFactory.destroyForPort(PORT1); }