Search in sources :

Example 1 with DecoratedObjectFactory

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));
}
Also used : DecoratedObjectFactory(org.eclipse.jetty.util.DecoratedObjectFactory) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 2 with DecoratedObjectFactory

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));
}
Also used : DecoratedObjectFactory(org.eclipse.jetty.util.DecoratedObjectFactory) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 3 with DecoratedObjectFactory

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();
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) Executor(java.util.concurrent.Executor) DecoratedObjectFactory(org.eclipse.jetty.util.DecoratedObjectFactory)

Example 4 with DecoratedObjectFactory

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));
        }
    }
}
Also used : ServletContext(javax.servlet.ServletContext) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) DecoratedObjectFactory(org.eclipse.jetty.util.DecoratedObjectFactory) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Aggregations

DecoratedObjectFactory (org.eclipse.jetty.util.DecoratedObjectFactory)4 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Test (org.junit.Test)2 Executor (java.util.concurrent.Executor)1 ServletContext (javax.servlet.ServletContext)1 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)1