use of org.eclipse.jetty.util.DecoratedObjectFactory in project jetty.project by eclipse.
the class ServletContextHandlerTest method testLegacyDecorator.
/**
* Test behavior of legacy ServletContextHandler.Decorator, with
* new DecoratedObjectFactory class
* @throws Exception on test failure
*/
@SuppressWarnings("deprecation")
@Test
public void testLegacyDecorator() throws Exception {
ServletContextHandler context = new ServletContextHandler();
context.addDecorator(new DummyLegacyDecorator());
_server.setHandler(context);
context.addServlet(DecoratedObjectFactoryServlet.class, "/objfactory/*");
_server.start();
String response = _connector.getResponses("GET /objfactory/ HTTP/1.0\r\n\r\n");
assertThat("Response status code", response, containsString("200 OK"));
String expected = String.format("Attribute[%s] = %s", DecoratedObjectFactory.ATTR, DecoratedObjectFactory.class.getName());
assertThat("Has context attribute", response, containsString(expected));
assertThat("Decorators size", response, containsString("Decorators.size = [2]"));
expected = String.format("decorator[] = %s", DummyLegacyDecorator.class.getName());
assertThat("Specific Legacy Decorator", response, containsString(expected));
}
use of org.eclipse.jetty.util.DecoratedObjectFactory in project jetty.project by eclipse.
the class ServletContextHandlerTest method testUtilDecorator.
/**
* Test behavior of new {@link org.eclipse.jetty.util.Decorator}, with
* new DecoratedObjectFactory class
* @throws Exception on test failure
*/
@Test
public void testUtilDecorator() throws Exception {
ServletContextHandler context = new ServletContextHandler();
context.getObjectFactory().addDecorator(new DummyUtilDecorator());
_server.setHandler(context);
context.addServlet(DecoratedObjectFactoryServlet.class, "/objfactory/*");
_server.start();
String response = _connector.getResponses("GET /objfactory/ HTTP/1.0\r\n\r\n");
assertThat("Response status code", response, containsString("200 OK"));
String expected = String.format("Attribute[%s] = %s", DecoratedObjectFactory.ATTR, DecoratedObjectFactory.class.getName());
assertThat("Has context attribute", response, containsString(expected));
assertThat("Decorators size", response, containsString("Decorators.size = [2]"));
expected = String.format("decorator[] = %s", DummyUtilDecorator.class.getName());
assertThat("Specific Legacy Decorator", response, containsString(expected));
}
use of org.eclipse.jetty.util.DecoratedObjectFactory in project jetty.project by eclipse.
the class WebSocketServerFactory method doStart.
@Override
protected void doStart() throws Exception {
if (this.objectFactory == null && context != null) {
this.objectFactory = (DecoratedObjectFactory) context.getAttribute(DecoratedObjectFactory.ATTR);
if (this.objectFactory == null) {
throw new IllegalStateException("Unable to find required ServletContext attribute: " + DecoratedObjectFactory.ATTR);
}
}
if (this.executor == null && context != null) {
ContextHandler contextHandler = ContextHandler.getContextHandler(context);
this.executor = contextHandler.getServer().getThreadPool();
}
Objects.requireNonNull(this.objectFactory, DecoratedObjectFactory.class.getName());
Objects.requireNonNull(this.executor, Executor.class.getName());
super.doStart();
}
use of org.eclipse.jetty.util.DecoratedObjectFactory in project core by weld.
the class WeldDecorator method process.
public static void process(ServletContext context) {
if (context instanceof ContextHandler.Context) {
ContextHandler.Context cc = (ContextHandler.Context) context;
ContextHandler handler = cc.getContextHandler();
if (handler instanceof ServletContextHandler) {
ServletContextHandler sch = (ServletContextHandler) handler;
DecoratedObjectFactory decObjFact = sch.getObjectFactory();
decObjFact.addDecorator(new WeldDecorator(context));
}
}
}
Aggregations