Java 类io.dropwizard.jetty.MutableServletContextHandler 实例源码

项目:karamel    文件:KaramelServiceApplication.java   
public int getPort(Environment environment) {
  int defaultPort = 9090;
  MutableServletContextHandler h = environment.getApplicationContext();
  if (h == null) {
    return defaultPort;
  }
  Server s = h.getServer();
  if (s == null) {
    return defaultPort;
  }
  Connector[] c = s.getConnectors();
  if (c != null && c.length > 0) {
    AbstractNetworkConnector anc = (AbstractNetworkConnector) c[0];
    if (anc != null) {
      return anc.getLocalPort();
    }
  }
  return defaultPort;
}
项目:dropwizard-guicey    文件:SessionListenersSupport.java   
@Override
public void start() throws Exception {
    for (MutableServletContextHandler environment : listeners.keySet()) {
        final SessionHandler sessionHandler = environment.getSessionHandler();
        if (sessionHandler == null) {
            final String msg = String.format(
                    "Can't register session listeners for %s because sessions support is not enabled: %s",
                    environment.getDisplayName().toLowerCase(),
                    Joiner.on(',').join(listeners.get(environment).stream()
                            .map(it -> FeatureUtils.getInstanceClass(it).getSimpleName())
                            .collect(Collectors.toList())));
            if (failWithoutSession) {
                throw new IllegalStateException(msg);
            } else {
                logger.warn(msg);
            }
        } else {
            listeners.get(environment).forEach(sessionHandler::addEventListener);
        }
    }
}
项目:openregister-java    文件:CorsBundle.java   
@Override
public void run(Environment environment) {
    MutableServletContextHandler applicationContext = environment.getApplicationContext();
    FilterHolder filterHolder = applicationContext
            .addFilter(CrossOriginFilter.class, "/*", EnumSet.allOf(DispatcherType.class));
    filterHolder.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, "*");
    filterHolder.setInitParameter(CrossOriginFilter.ALLOWED_HEADERS_PARAM, "X-Requested-With,Content-Type,Accept,Origin");
    filterHolder.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, "GET,HEAD");

    filterHolder.setInitParameter(CrossOriginFilter.ALLOW_CREDENTIALS_PARAM, "false");
}
项目:dropwizard-websocket-jee7-bundle    文件:WebsocketContainerInitializer.java   
public WebsocketContainer initialize(WebsocketConfiguration configuration,
                                     MutableServletContextHandler contextHandler) {
    try {
        return new WebsocketContainer(configuration, WebSocketServerContainerInitializer.configureContext(contextHandler));
    } catch (Exception e) {
        throw new IllegalStateException("Could not initialize contexthandler to enable Websockets", e);
    }
}
项目:dropwizard-websockets    文件:InstWebSocketServerContainerInitializer.java   
public static ServerContainer configureContext(final MutableServletContextHandler context, final MetricRegistry metrics) throws ServletException {
    WebSocketUpgradeFilter filter = WebSocketUpgradeFilter.configureContext(context);
    NativeWebSocketConfiguration wsConfig = filter.getConfiguration();

    ServerContainer wsContainer = new ServerContainer(wsConfig, context.getServer().getThreadPool());
    EventDriverFactory edf = wsConfig.getFactory().getEventDriverFactory();
    edf.clearImplementations();

    edf.addImplementation(new InstJsrServerEndpointImpl(metrics));
    edf.addImplementation(new InstJsrServerExtendsEndpointImpl(metrics));
    context.addBean(wsContainer);
    context.setAttribute(javax.websocket.server.ServerContainer.class.getName(), wsContainer);
    context.setAttribute(WebSocketUpgradeFilter.class.getName(), filter);
    return wsContainer;
}
项目:dropwizard-guicey    文件:WebListenerInstaller.java   
private void configure(final MutableServletContextHandler environment, final EventListener listener,
                       final boolean context, final boolean session) {
    if (session) {
        support.add(environment, listener);
    }
    if (context) {
        environment.addEventListener(listener);
    }
}
项目:dropwizard-websocket-jee7-bundle    文件:WebsocketHandlerTest.java   
@Before
public void init() {
    when(containerInitializer.initialize(any(WebsocketConfiguration.class), any(MutableServletContextHandler.class))).thenReturn(container);
    when(endpointRegistration.getRegisteredEndpoints()).thenReturn(endpoints);
}
项目:microservice-bundle    文件:µsEnvironment.java   
public MutableServletContextHandler getApplicationContext() {
  return this.environment.getApplicationContext();
}
项目:microservice-bundle    文件:µsEnvironment.java   
public MutableServletContextHandler getAdminContext() {
  return this.environment.getAdminContext();
}
项目:microservice-bundle    文件:µServiceFactory.java   
@Override
protected Handler createAppServlet(Server server,
                                   JerseyEnvironment jersey,
                                   ObjectMapper objectMapper,
                                   Validator validator,
                                   MutableServletContextHandler handler,
                                   @Nullable Servlet jerseyContainer,
                                   MetricRegistry metricRegistry) {
    if (jerseyContainer != null) {
        jersey.register(new LoggingExceptionMapper<Throwable>() {
            @Override
            public Response toResponse(Throwable exception) {
                final int status;
                final StatusEntity statusEntity;

                if (exception instanceof WebApplicationException) {
                    final Response response = ((WebApplicationException) exception).getResponse();
                    if (response.getStatusInfo().getFamily().equals(Response.Status.Family.SERVER_ERROR)) {
                        logException(exception);
                    }
                    status = response.getStatus();
                    statusEntity = new StatusEntity(status, new StatusMessage(µService.WEB_APPLICATION_ERROR, exception.getLocalizedMessage()));
                } else {
                    final long id = logException(exception);
                    status = Response.Status.INTERNAL_SERVER_ERROR.getStatusCode();
                    StatusMessage message = new StatusMessage(StatusMessage.Type.ERROR, String.format("%016x", id), µService.INTERNAL_SERVER_ERROR, formatErrorMessage(id, exception), null);
                    statusEntity = new StatusEntity(status, message);
                }

                return Response.status(status)
                        .type(MediaType.APPLICATION_JSON_TYPE)
                        .entity(statusEntity)
                        .build();
            }
        });
        jersey.register(new ConstraintViolationExceptionMapper());
        jersey.register(new JsonProcessingExceptionMapper());
        jersey.register(new EarlyEofExceptionMapper());
    }
    Handler appServlet = super.createAppServlet(server, jersey, objectMapper, validator, handler, jerseyContainer, metricRegistry);
    return appServlet;
}
项目:dropwizard-guicey    文件:SessionListenersSupport.java   
public void add(final MutableServletContextHandler environment, final EventListener listener) {
    listeners.put(environment, listener);
}
项目:dropwizard-guicey    文件:WebInstallersBundle.java   
private void nameContext(final MutableServletContextHandler context, final String name) {
    if (context.getDisplayName() == null) {
        context.setDisplayName(name);
    }
}
项目:dropwizard-pac4j    文件:Pac4jBundle.java   
/**
 * Override if needed, but prefer to exploit
 * {@link Pac4jFactory#setSessionEnabled(boolean)} first.
 * 
 * @param environment
 *            the dropwizard {@link Environment}
 * @since 1.1.0
 */
protected void setupJettySession(Environment environment) {
    MutableServletContextHandler contextHandler = environment
            .getApplicationContext();
    if (contextHandler.getSessionHandler() == null) {
        contextHandler.setSessionHandler(new SessionHandler());
    }
}