/** * Creates a Jetty context handler that can be used to expose the cross-domain functionality as implemented by * {@link FlashCrossDomainServlet}. * * Note that an invocation of this method will not register the handler (and thus make the related functionality * available to the end user). Instead, the created handler is returned by this method, and will need to be * registered with the embedded Jetty webserver by the caller. * * @return A Jetty context handler (never null). */ protected Handler createCrossDomainHandler() { final ServletContextHandler context = new ServletContextHandler( null, "/crossdomain.xml", ServletContextHandler.SESSIONS ); // Ensure the JSP engine is initialized correctly (in order to be able to cope with Tomcat/Jasper precompiled JSPs). final List<ContainerInitializer> initializers = new ArrayList<>(); initializers.add( new ContainerInitializer( new JasperInitializer(), null ) ); context.setAttribute( "org.eclipse.jetty.containerInitializers", initializers ); context.setAttribute( InstanceManager.class.getName(), new SimpleInstanceManager() ); // Generic configuration of the context. context.setAllowNullPathInfo( true ); // Add the functionality-providers. context.addServlet( new ServletHolder( new FlashCrossDomainServlet() ), "" ); return context; }
context.setAttribute( "org.eclipse.jetty.containerInitializers", initializers ); context.setAttribute( InstanceManager.class.getName(), new SimpleInstanceManager() );
contextHandler.setAttribute(CONTEXT_ATTRIBUTE_PROCESSOR, this); contextHandler.setAttribute(CONTEXT_ATTRIBUTE_LOGGER, getLogger()); contextHandler.setAttribute(CONTEXT_ATTRIBUTE_SESSION_FACTORY_HOLDER, sessionFactoryReference); contextHandler.setAttribute(CONTEXT_ATTRIBUTE_PROCESS_CONTEXT_HOLDER, context); contextHandler.setAttribute(CONTEXT_ATTRIBUTE_FLOWFILE_MAP, flowFileMap); contextHandler.setAttribute(CONTEXT_ATTRIBUTE_AUTHORITY_PATTERN, Pattern.compile(context.getProperty(AUTHORIZED_DN_PATTERN).getValue())); contextHandler.setAttribute(CONTEXT_ATTRIBUTE_STREAM_THROTTLER, streamThrottler); contextHandler.setAttribute(CONTEXT_ATTRIBUTE_BASE_PATH, basePath); contextHandler.setAttribute(CONTEXT_ATTRIBUTE_RETURN_CODE, returnCode); contextHandler.setAttribute(CONTEXT_ATTRIBUTE_MULTIPART_REQUEST_MAX_SIZE, requestMaxSize); contextHandler.setAttribute(CONTEXT_ATTRIBUTE_MULTIPART_READ_BUFFER_SIZE, readBufferSize); contextHandler.setAttribute(CONTEXT_ATTRIBUTE_HEADER_PATTERN, Pattern.compile(context.getProperty(HEADERS_AS_ATTRIBUTES_REGEX).getValue()));
public static void server(int port, String mapping, String routes, Object api) throws Exception { ServletContextHandler handler = new ServletContextHandler(ServletContextHandler.SESSIONS); handler.setContextPath("/"); handler.setAttribute("api", api); ServletHolder holder = new ServletHolder(new Servlet()); holder.setInitParameter("routes", routes); handler.addServlet(holder, mapping); server(port, handler); }
protected ServletContextHandler createPippoHandler() { MultipartConfigElement multipartConfig = createMultipartConfigElement(); ServletContextHandler handler = new PippoHandler(ServletContextHandler.SESSIONS, multipartConfig); handler.setContextPath(getSettings().getContextPath()); // inject application as context attribute handler.setAttribute(PIPPO_APPLICATION, getApplication()); // add pippo filter addPippoFilter(handler); // add initializers handler.addEventListener(new PippoServletContextListener()); // all listeners listeners.forEach(listener -> { try { handler.addEventListener(listener.newInstance()); } catch (InstantiationException | IllegalAccessException e) { throw new PippoRuntimeException(e); } }); return handler; }
/** * @param name * @param value * @see org.eclipse.jetty.servlet.ServletContextHandler#setAttribute(java.lang.String, java.lang.Object) */ public void setAttribute(String name, Object value) { _context.setAttribute(name,value); }
public void setAttribute(String name, Object value) { _context.setAttribute(name,value); }
/** * @param name * @param value * @see org.eclipse.jetty.handler.ContextHandler#setAttribute(java.lang.String, java.lang.Object) */ public void setAttribute(String name, Object value) { _context.setAttribute(name,value); }
public void setAttribute(String name, Object value) { _context.setAttribute(name,value); }
public void setAttribute(String name, Object value) { _context.setAttribute(name,value); }
private ContextHandler createGatewayHandler() { logger.info("Add Gravitee Gateway Reactor handler..."); ServletContextHandler handler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS); handler.setAttribute(GraviteeDispatcherServlet.GRAVITEE_REACTOR_ATTRIBUTE, reactor); handler.setContextPath("/"); ServletHolder dispatchServletHolder = new ServletHolder(GraviteeDispatcherServlet.class); handler.addServlet(dispatchServletHolder, REGEX_SERVLET_MAPPING_ALL); return handler; }
final ServletContextHandler servletContext = new ServletContextHandler(ServletContextHandler.SESSIONS); servletContext.setContextPath("/"); servletContext.setAttribute("myAttr", new ArrayList<>()); servletContext.addServlet(ServerServlet.class, "/*"); servletContext.addServlet(DefaultServlet.class, "/");
ServletContextHandler servletContextHandler = new ServletContextHandler(server, "/server"); ServletHolder jerseyServletHolder = new ServletHolder(ServletContainer.class); jerseyServletHolder.setInitParameter("com.sun.jersey.config.property.packages", "my.package.to.scan"); servletContextHandler.addServlet(jerseyServletHolder, "/*"); MyRestResource resource = new MyRestResource(param1, param2); // Set resource as a context attribute servletContextHandler.setAttribute("rest-1", resource);
public JspStarter (ServletContextHandler context) { this.sci = new JettyJasperInitializer(); this.context = context; this.context.setAttribute("org.apache.tomcat.JarScanner", new StandardJarScanner()); }
public void addServlet(String basePath, ServletHolder servletHolder, List<Pair<String, Object>> attributes) { ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath(basePath); context.addServlet(servletHolder, "/*"); for (Pair<String, Object> attribute : attributes) { context.setAttribute(attribute.getLeft(), attribute.getRight()); } if (config.isAuthenticationEnabled()) { FilterHolder filter = new FilterHolder(new AuthenticationFilter(authenticationService)); context.addFilter(filter, MATCH_ALL, EnumSet.allOf(DispatcherType.class)); } handlers.add(context); }
private ServletContextHandler createHttpContext(@SuppressWarnings("rawtypes") Dictionary dictionary) { ServletContextHandler httpContext = new ServletContextHandler(); // hack in the mime type for xsd until jetty fixes it (bug 393218) httpContext.getMimeTypes().addMimeMapping("xsd", "application/xml"); //$NON-NLS-1$ //$NON-NLS-2$ httpContext.setAttribute(INTERNAL_CONTEXT_CLASSLOADER, Thread.currentThread().getContextClassLoader()); httpContext.setClassLoader(this.getClass().getClassLoader()); httpContext.setContextPath(Details.getString(dictionary, JettyConstants.CONTEXT_PATH, "/")); //$NON-NLS-1$ File contextWorkDir = new File(workDir, DIR_PREFIX + dictionary.get(Constants.SERVICE_PID).hashCode()); contextWorkDir.mkdir(); httpContext.setAttribute(CONTEXT_TEMPDIR, contextWorkDir); SessionHandler handler = new SessionHandler(); handler.setMaxInactiveInterval(Details.getInt(dictionary, JettyConstants.CONTEXT_SESSIONINACTIVEINTERVAL, -1)); httpContext.setSessionHandler(handler); return httpContext; }
protected void addServlet() { ResourceConfig config = new DefaultResourceConfig(); // load all our REST API modules, JSON, and Swagger for (Object r: NatServiceRestApi.getAllResources()) config.getSingletons().add(r); // Accept gzipped requests and responses config.getProperties().put(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS, GZIPContentEncodingFilter.class.getName()); config.getProperties().put(ResourceConfig.PROPERTY_CONTAINER_RESPONSE_FILTERS, GZIPContentEncodingFilter.class.getName()); // configure to match empty path, or any thing which looks like a file path with /assets/ and extension html, css, js, or png // and treat that as static content config.getProperties().put(ServletContainer.PROPERTY_WEB_PAGE_CONTENT_REGEX, "(/?|[^?]*/assets/[^?]+\\.[A-Za-z0-9_]+)"); // and anything which is not matched as a servlet also falls through (but more expensive than a regex check?) config.getFeatures().put(ServletContainer.FEATURE_FILTER_FORWARD_ON_404, true); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); ServletHolder servletHolder = new ServletHolder(new ServletContainer(config)); servletHolder.setInitParameter(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE.toString()); context.addServlet(servletHolder,"/*"); context.setContextPath("/"); context.setAttribute(AbstractRestResource.NAT_SERVICE_DISPATCHER, dispatcher); server.setHandler(context); }
public void addRestResources(String basePath, String javaPackages, String attribute, Object attributeValue) { JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider(); provider.setMapper(ObjectMapperFactory.create()); ResourceConfig config = new ResourceConfig(); config.packages("jersey.config.server.provider.packages", javaPackages); config.register(provider); ServletHolder servletHolder = new ServletHolder(new ServletContainer(config)); servletHolder.setAsyncSupported(true); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath(basePath); context.addServlet(servletHolder, "/*"); context.setAttribute(attribute, attributeValue); handlers.add(context); }
public void addRestResources(String basePath, String javaPackages, String attribute, Object attributeValue) { JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider(); provider.setMapper(ObjectMapperFactory.create()); ResourceConfig config = new ResourceConfig(); config.packages("jersey.config.server.provider.packages", javaPackages); config.register(provider); ServletHolder servletHolder = new ServletHolder(new ServletContainer(config)); servletHolder.setAsyncSupported(true); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath(basePath); context.addServlet(servletHolder, "/*"); context.setAttribute(attribute, attributeValue); handlers.add(context); }
public void addServlet(String path, ServletHolder servletHolder, boolean requiresAuthentication, Map<String,Object> attributeMap) { ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath(path); context.addServlet(servletHolder, MATCH_ALL); if (attributeMap != null) { attributeMap.forEach((key, value) -> { context.setAttribute(key, value); }); } if (requiresAuthentication && pulsar.getConfiguration().isAuthenticationEnabled()) { FilterHolder filter = new FilterHolder(new AuthenticationFilter( pulsar.getBrokerService().getAuthenticationService())); context.addFilter(filter, MATCH_ALL, EnumSet.allOf(DispatcherType.class)); } FilterHolder responseFilter = new FilterHolder(new ResponseHandlerFilter(pulsar)); context.addFilter(responseFilter, MATCH_ALL, EnumSet.allOf(DispatcherType.class)); handlers.add(context); }