use of org.eclipse.jetty.server.Handler in project cxf by apache.
the class JettyHTTPServerEngine method removeServant.
/**
* Remove a previously registered servant.
*
* @param url the URL the servant was registered against.
*/
public synchronized void removeServant(URL url) {
final String contextName = HttpUriMapper.getContextName(url.getPath());
final String smap = HttpUriMapper.getResourceBase(url.getPath());
boolean found = false;
if (server != null && server.isRunning()) {
for (Handler handler : contexts.getChildHandlersByClass(ContextHandler.class)) {
if (handler instanceof ContextHandler) {
ContextHandler contextHandler = (ContextHandler) handler;
Handler jh = contextHandler.getHandler();
if (jh instanceof JettyHTTPHandler && (contextName.equals(contextHandler.getContextPath()) || (StringUtils.isEmpty(contextName) && "/".equals(contextHandler.getContextPath()))) && ((JettyHTTPHandler) jh).getName().equals(smap)) {
try {
contexts.removeHandler(handler);
handler.stop();
handler.destroy();
} catch (Exception ex) {
LOG.log(Level.WARNING, "REMOVE_HANDLER_FAILED_MSG", new Object[] { ex.getMessage() });
}
found = true;
break;
}
}
}
}
if (!found) {
LOG.log(Level.WARNING, "CAN_NOT_FIND_HANDLER_MSG", new Object[] { url });
}
registedPaths.remove(url.getPath());
--servantCount;
}
use of org.eclipse.jetty.server.Handler in project cxf by apache.
the class JettyHTTPServerEngine method getContextHandler.
/**
* Get a registered context handler.
*
* @param url the associated URL
* @return the HttpHandler if registered
*/
public synchronized ContextHandler getContextHandler(URL url) {
String contextName = HttpUriMapper.getContextName(url.getPath());
ContextHandler ret = null;
// operation should return null.
if (server != null) {
for (Handler handler : server.getChildHandlersByClass(ContextHandler.class)) {
if (handler instanceof ContextHandler) {
ContextHandler contextHandler = (ContextHandler) handler;
if (contextName.equals(contextHandler.getContextPath())) {
ret = contextHandler;
break;
}
}
}
}
return ret;
}
use of org.eclipse.jetty.server.Handler in project cxf by apache.
the class JettyHTTPServerEngine method getServant.
/**
* Get a registered servant.
*
* @param url the associated URL
* @return the HttpHandler if registered
*/
public synchronized Handler getServant(URL url) {
String contextName = HttpUriMapper.getContextName(url.getPath());
// final String smap = HttpUriMapper.getResourceBase(url.getPath());
Handler ret = null;
// operation should return null.
if (server != null) {
for (Handler handler : server.getChildHandlersByClass(ContextHandler.class)) {
if (handler instanceof ContextHandler) {
ContextHandler contextHandler = (ContextHandler) handler;
if (contextName.equals(contextHandler.getContextPath())) {
ret = contextHandler.getHandler();
break;
}
}
}
}
return ret;
}
use of org.eclipse.jetty.server.Handler in project cxf by apache.
the class JettyHTTPServerEngineTest method testSetHandlers.
@Test
public void testSetHandlers() throws Exception {
URL url = new URL("http://localhost:" + PORT2 + "/hello/test");
JettyHTTPTestHandler handler1 = new JettyHTTPTestHandler("string1", true);
JettyHTTPTestHandler handler2 = new JettyHTTPTestHandler("string2", true);
JettyHTTPServerEngine engine = new JettyHTTPServerEngine();
engine.setPort(PORT2);
List<Handler> handlers = new ArrayList<>();
handlers.add(handler1);
engine.setHandlers(handlers);
engine.finalizeConfig();
engine.addServant(url, handler2);
String response = getResponse(url.toString());
assertEquals("the jetty http handler1 did not take effect", response, "string1string2");
engine.stop();
JettyHTTPServerEngineFactory.destroyForPort(PORT2);
}
use of org.eclipse.jetty.server.Handler in project cxf by apache.
the class EngineLifecycleTest method testUpDownWithServlets.
@Test
public void testUpDownWithServlets() throws Exception {
setUpBus();
Bus bus = (Bus) applicationContext.getBean("cxf");
ServerRegistry sr = bus.getExtension(ServerRegistry.class);
ServerImpl si = (ServerImpl) sr.getServers().get(0);
JettyHTTPDestination jhd = (JettyHTTPDestination) si.getDestination();
JettyHTTPServerEngine e = (JettyHTTPServerEngine) jhd.getEngine();
org.eclipse.jetty.server.Server jettyServer = e.getServer();
for (Handler h : jettyServer.getChildHandlersByClass(WebAppContext.class)) {
WebAppContext wac = (WebAppContext) h;
if ("/jsunit".equals(wac.getContextPath())) {
wac.addServlet("org.eclipse.jetty.servlet.DefaultServlet", "/bloop");
break;
}
}
try {
verifyStaticHtml();
invokeService();
} finally {
shutdownService();
}
}
Aggregations