Search in sources :

Example 76 with ContextHandler

use of org.eclipse.jetty.server.handler.ContextHandler in project jetty.project by eclipse.

the class AnnotatedEndpointConfigTest method startEnv.

@BeforeClass
public static void startEnv() throws Exception {
    // Server
    server = new Server();
    ServerConnector connector = new ServerConnector(server);
    server.addConnector(connector);
    handler = new EchoHandler();
    ContextHandler context = new ContextHandler();
    context.setContextPath("/");
    context.setHandler(handler);
    server.setHandler(context);
    // Start Server
    server.start();
    String host = connector.getHost();
    if (host == null) {
        host = "localhost";
    }
    int port = connector.getLocalPort();
    serverUri = new URI(String.format("ws://%s:%d/", host, port));
    // Connect client
    WebSocketContainer container = ContainerProvider.getWebSocketContainer();
    socket = new AnnotatedEndpointClient();
    session = container.connectToServer(socket, serverUri);
    Assert.assertThat("Session", session, notNullValue());
    config = socket.config;
    Assert.assertThat("EndpointConfig", config, notNullValue());
    Assert.assertThat("EndpointConfig", config, instanceOf(ClientEndpointConfig.class));
    ceconfig = (ClientEndpointConfig) config;
    Assert.assertThat("EndpointConfig", ceconfig, notNullValue());
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) Server(org.eclipse.jetty.server.Server) WebSocketContainer(javax.websocket.WebSocketContainer) ClientEndpointConfig(javax.websocket.ClientEndpointConfig) URI(java.net.URI) BeforeClass(org.junit.BeforeClass)

Example 77 with ContextHandler

use of org.eclipse.jetty.server.handler.ContextHandler in project jetty.project by eclipse.

the class AbstractHandlerMBean method getObjectContextBasis.

/* ------------------------------------------------------------ */
@Override
public String getObjectContextBasis() {
    if (_managed != null) {
        String basis = null;
        if (_managed instanceof ContextHandler) {
            ContextHandler handler = (ContextHandler) _managed;
            String context = getContextName(handler);
            if (context == null)
                context = handler.getDisplayName();
            if (context != null)
                return context;
        } else if (_managed instanceof AbstractHandler) {
            AbstractHandler handler = (AbstractHandler) _managed;
            Server server = handler.getServer();
            if (server != null) {
                ContextHandler context = AbstractHandlerContainer.findContainerOf(server, ContextHandler.class, handler);
                if (context != null)
                    basis = getContextName(context);
            }
        }
        if (basis != null)
            return basis;
    }
    return super.getObjectContextBasis();
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) Server(org.eclipse.jetty.server.Server) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler)

Example 78 with ContextHandler

use of org.eclipse.jetty.server.handler.ContextHandler in project jetty.project by eclipse.

the class ContextHandlerMBean method removeContextAttribute.

@ManagedOperation(value = "Remove context attribute", impact = "ACTION")
public void removeContextAttribute(@Name(value = "name", description = "attribute name") String name) {
    Attributes attrs = ((ContextHandler) _managed).getAttributes();
    attrs.removeAttribute(name);
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) Attributes(org.eclipse.jetty.util.Attributes) ManagedOperation(org.eclipse.jetty.util.annotation.ManagedOperation)

Example 79 with ContextHandler

use of org.eclipse.jetty.server.handler.ContextHandler in project jetty.project by eclipse.

the class ContextHandlerMBean method setContextAttribute.

@ManagedOperation(value = "Set context attribute", impact = "ACTION")
public void setContextAttribute(@Name(value = "name", description = "attribute name") String name, @Name(value = "value", description = "attribute value") String value) {
    Attributes attrs = ((ContextHandler) _managed).getAttributes();
    attrs.setAttribute(name, value);
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) Attributes(org.eclipse.jetty.util.Attributes) ManagedOperation(org.eclipse.jetty.util.annotation.ManagedOperation)

Example 80 with ContextHandler

use of org.eclipse.jetty.server.handler.ContextHandler in project jetty.project by eclipse.

the class ContextHandlerMBean method getContextAttributes.

@ManagedAttribute("Map of context attributes")
public Map<String, Object> getContextAttributes() {
    Map<String, Object> map = new HashMap<String, Object>();
    Attributes attrs = ((ContextHandler) _managed).getAttributes();
    Enumeration<String> en = attrs.getAttributeNames();
    while (en.hasMoreElements()) {
        String name = (String) en.nextElement();
        Object value = attrs.getAttribute(name);
        map.put(name, value);
    }
    return map;
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) HashMap(java.util.HashMap) Attributes(org.eclipse.jetty.util.Attributes) ManagedObject(org.eclipse.jetty.util.annotation.ManagedObject) ManagedAttribute(org.eclipse.jetty.util.annotation.ManagedAttribute)

Aggregations

ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)127 Server (org.eclipse.jetty.server.Server)47 ServerConnector (org.eclipse.jetty.server.ServerConnector)27 URI (java.net.URI)21 ResourceHandler (org.eclipse.jetty.server.handler.ResourceHandler)20 Test (org.junit.Test)20 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)19 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)19 IOException (java.io.IOException)18 Handler (org.eclipse.jetty.server.Handler)14 HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)14 SessionHandler (org.eclipse.jetty.server.session.SessionHandler)14 File (java.io.File)13 ServletException (javax.servlet.ServletException)13 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)13 BeforeClass (org.junit.BeforeClass)11 BaseIntegrationTest (com.ctrip.framework.apollo.BaseIntegrationTest)10 Config (com.ctrip.framework.apollo.Config)10 ApolloConfig (com.ctrip.framework.apollo.core.dto.ApolloConfig)10 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)10