Java Code Examples for org.mortbay.jetty.servlet.Context#SESSIONS
The following examples show how to use
org.mortbay.jetty.servlet.Context#SESSIONS .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CacheReplicationTestCase.java From reladomo with Apache License 2.0 | 6 votes |
protected void setupPspMithraService() { server = new Server(this.getApplicationPort1()); Context context = new Context (server,"/",Context.SESSIONS); ServletHolder holder = context.addServlet(PspServlet.class, "/PspServlet"); holder.setInitParameter("serviceInterface.MasterCacheService", "com.gs.fw.common.mithra.cache.offheap.MasterCacheService"); holder.setInitParameter("serviceClass.MasterCacheService", "com.gs.fw.common.mithra.cache.offheap.MasterCacheServiceImpl"); holder.setInitOrder(10); // System.out.println(holder.getServlet().getClass().getName()); try { server.start(); } catch (Exception e) { throw new RuntimeException("could not start server", e); } finally { } }
Example 2
Source File: PspTestCase.java From reladomo with Apache License 2.0 | 6 votes |
protected void setupServerWithHandler( Handler handler) throws Exception { this.port = (int) (Math.random() * 10000.0 + 10000.0); this.pspUrl = "http://localhost:" + this.port + "/PspServlet"; this.server = new Server(this.port); Context context = new Context(server, "/", Context.SESSIONS); if (handler != null) { context.addHandler(handler); } ServletHolder holder = context.addServlet(PspServlet.class, "/PspServlet"); holder.setInitParameter("serviceInterface.Echo", "com.gs.fw.common.mithra.test.tinyproxy.Echo"); holder.setInitParameter("serviceClass.Echo", "com.gs.fw.common.mithra.test.tinyproxy.EchoImpl"); holder.setInitOrder(10); this.server.start(); this.servlet = (PspServlet) holder.getServlet(); }
Example 3
Source File: TestServer.java From nomulus with Apache License 2.0 | 6 votes |
private Context createHandler( Map<String, Path> runfiles, ImmutableList<Route> routes, ImmutableList<Class<? extends Filter>> filters) { Context context = new Context(server, CONTEXT_PATH, Context.SESSIONS); context.addServlet(new ServletHolder(HealthzServlet.class), "/healthz"); for (Map.Entry<String, Path> runfile : runfiles.entrySet()) { context.addServlet( StaticResourceServlet.create(runfile.getKey(), runfile.getValue()), runfile.getKey()); } for (Route route : routes) { context.addServlet( new ServletHolder(wrapServlet(route.servletClass(), filters)), route.path()); } ServletHolder holder = new ServletHolder(DefaultServlet.class); holder.setInitParameter("aliases", "1"); context.addServlet(holder, "/*"); return context; }
Example 4
Source File: TestStringsWithRestEasy.java From curator with Apache License 2.0 | 6 votes |
@BeforeMethod public void setup() throws Exception { RestEasyApplication.singletonsRef.set(new RestEasySingletons()); ResteasyProviderFactory.setInstance(new ResteasyProviderFactory()); HttpServletDispatcher dispatcher = new HttpServletDispatcher(); port = InstanceSpec.getRandomPort(); server = new Server(port); Context root = new Context(server, "/", Context.SESSIONS); root.getInitParams().put("javax.ws.rs.Application", RestEasyApplication.class.getName()); root.addServlet(new ServletHolder(dispatcher), "/*"); root.addEventListener(new ResteasyBootstrap()); server.start(); }
Example 5
Source File: EmbeddedServer.java From xdocreport.samples with GNU Lesser General Public License v3.0 | 6 votes |
public static void main( String[] args ) throws Exception { Server server = new Server( 8080 ); WebAppContext webappcontext = new WebAppContext( "src/main/webapp", "/xdocreport-webapp" ); ContextHandlerCollection servlet_contexts = new ContextHandlerCollection(); webappcontext.setClassLoader( Thread.currentThread().getContextClassLoader() ); HandlerCollection handlers = new HandlerCollection(); handlers.setHandlers( new Handler[] { servlet_contexts, webappcontext, new DefaultHandler() } ); server.setHandler( handlers ); // JSP Servlet + Context Context jsp_ctx = new Context( servlet_contexts, "/jsp", Context.SESSIONS ); jsp_ctx.addServlet( new ServletHolder( new org.apache.jasper.servlet.JspServlet() ), "*.jsp" ); server.start(); server.join(); }
Example 6
Source File: SlackNotificationTestServer.java From tcSlackBuildNotifier with MIT License | 5 votes |
public SlackNotificationTestServer(String host, Integer port) { server = new Server(port); Context root = new Context(server,"/",Context.SESSIONS); root.addServlet(new ServletHolder(new MyHttpServlet(HttpServletResponse.SC_OK)), "/200"); root.addServlet(new ServletHolder(new MyHttpServlet(HttpServletResponse.SC_MOVED_TEMPORARILY)), "/302"); root.addServlet(new ServletHolder(new MyHttpServlet(HttpServletResponse.SC_INTERNAL_SERVER_ERROR)), "/500"); }
Example 7
Source File: TestStringsWithJersey.java From curator with Apache License 2.0 | 5 votes |
@BeforeMethod public void setup() throws Exception { context = new StringDiscoveryContext(new MockServiceDiscovery<String>(), new RandomStrategy<String>(), 1000); serviceNamesMarshaller = new JsonServiceNamesMarshaller(); serviceInstanceMarshaller = new JsonServiceInstanceMarshaller<String>(context); serviceInstancesMarshaller = new JsonServiceInstancesMarshaller<String>(context); Application application = new DefaultResourceConfig() { @Override public Set<Class<?>> getClasses() { Set<Class<?>> classes = Sets.newHashSet(); classes.add(StringDiscoveryResource.class); return classes; } @Override public Set<Object> getSingletons() { Set<Object> singletons = Sets.newHashSet(); singletons.add(context); singletons.add(serviceNamesMarshaller); singletons.add(serviceInstanceMarshaller); singletons.add(serviceInstancesMarshaller); return singletons; } }; ServletContainer container = new ServletContainer(application); port = InstanceSpec.getRandomPort(); server = new Server(port); Context root = new Context(server, "/", Context.SESSIONS); root.addServlet(new ServletHolder(container), "/*"); server.start(); }
Example 8
Source File: TestObjectPayloadWithJersey.java From curator with Apache License 2.0 | 5 votes |
@BeforeMethod public void setup() throws Exception { context = new ServiceDetailsDiscoveryContext(new MockServiceDiscovery<ServiceDetails>(), new RandomStrategy<ServiceDetails>(), 1000); serviceNamesMarshaller = new JsonServiceNamesMarshaller(); serviceInstanceMarshaller = new JsonServiceInstanceMarshaller<ServiceDetails>(context); serviceInstancesMarshaller = new JsonServiceInstancesMarshaller<ServiceDetails>(context); Application application = new DefaultResourceConfig() { @Override public Set<Class<?>> getClasses() { Set<Class<?>> classes = Sets.newHashSet(); classes.add(ServiceDetailsDiscoveryResource.class); return classes; } @Override public Set<Object> getSingletons() { Set<Object> singletons = Sets.newHashSet(); singletons.add(context); singletons.add(serviceNamesMarshaller); singletons.add(serviceInstanceMarshaller); singletons.add(serviceInstancesMarshaller); return singletons; } }; ServletContainer container = new ServletContainer(application); port = InstanceSpec.getRandomPort(); server = new Server(port); Context root = new Context(server, "/", Context.SESSIONS); root.addServlet(new ServletHolder(container), "/*"); server.start(); }
Example 9
Source File: RestServer.java From hraven with Apache License 2.0 | 5 votes |
@Override protected void startUp() throws Exception { // setup the jetty config ServletHolder sh = new ServletHolder(ServletContainer.class); sh.setInitParameter("com.sun.jersey.config.property.packages", "com.twitter.hraven.rest"); sh.setInitParameter(JSONConfiguration.FEATURE_POJO_MAPPING, "true"); server = new Server(); Connector connector = new SelectChannelConnector(); connector.setPort(this.port); connector.setHost(address); server.addConnector(connector); // TODO: in the future we may want to provide settings for the min and max threads // Jetty sets the default max thread number to 250, if we don't set it. // QueuedThreadPool threadPool = new QueuedThreadPool(); server.setThreadPool(threadPool); server.setSendServerVersion(false); server.setSendDateHeader(false); server.setStopAtShutdown(true); // set up context Context context = new Context(server, "/", Context.SESSIONS); context.addServlet(sh, "/*"); // start server server.start(); }
Example 10
Source File: JettyServer.java From exhibitor with Apache License 2.0 | 5 votes |
public JettyServer(int port, HttpsConfiguration httpsConf) { server = new Server(); SslSelectChannelConnector connector = new SslSelectChannelConnector(); connector.setPort(port); connector.setKeystore(httpsConf.getServerKeystorePath()); connector.setKeyPassword(httpsConf.getServerKeystorePassword()); if ( httpsConf.isVerifyPeerCert() ) { connector.setTruststore(httpsConf.getTruststorePath()); connector.setTrustPassword(httpsConf.getTruststorePassword()); connector.setNeedClientAuth(true); } connector.setWantClientAuth(httpsConf.isRequireClientCert()); connector.setAcceptors(8); connector.setMaxIdleTime(5000); connector.setAcceptQueueSize(32); server.addConnector(connector); server.setStopAtShutdown(true); DefaultResourceConfig config = new DefaultResourceConfig(JettyServer.RestService.class); ServletContainer container = new ServletContainer(config); Context context = new Context(server, "/", Context.SESSIONS); context.addServlet(new ServletHolder(container), "/*"); }
Example 11
Source File: ConsumerAndProviderTest.java From openid4java with Apache License 2.0 | 5 votes |
public ConsumerAndProviderTest(final String testName) throws Exception { super(testName); int servletPort = Integer.parseInt(System.getProperty("SERVLET_PORT", "8989")); _server = new Server(servletPort); Context context = new Context(_server, "/", Context.SESSIONS); _baseUrl = "http://localhost:" + servletPort; // + // context.getContextPath(); SampleConsumer consumer = new SampleConsumer(_baseUrl + "/loginCallback"); context.addServlet(new ServletHolder(new LoginServlet(consumer)), "/login"); context.addServlet(new ServletHolder(new LoginCallbackServlet(consumer)), "/loginCallback"); context.addServlet(new ServletHolder(new UserInfoServlet()), "/user"); SampleServer server = new SampleServer(_baseUrl + "/provider") { protected List userInteraction(ParameterList request) throws ServerException { List back = new ArrayList(); back.add("userSelectedClaimedId"); // userSelectedClaimedId back.add(Boolean.TRUE); // authenticatedAndApproved back.add("[email protected]"); // email return back; } }; context.addServlet(new ServletHolder(new ProviderServlet(server)), "/provider"); }
Example 12
Source File: SlackNotificationTestProxyServer.java From tcSlackBuildNotifier with MIT License | 4 votes |
public SlackNotificationTestProxyServer(String host, Integer port, String proxyUsername, String proxyPassword) { server = new Server(port); Context root = new Context(server,"/",Context.SESSIONS); root.addServlet(new ServletHolder(new ProxyServerServlet(proxyUsername, proxyPassword)), "/*"); }
Example 13
Source File: Main.java From stanbol-freeling with GNU Affero General Public License v3.0 | 4 votes |
/** * @param args * @throws Exception */ public static void main(String[] args) throws Exception { CommandLineParser parser = new PosixParser(); CommandLine line = parser.parse(options, args); args = line.getArgs(); if(line.hasOption('h')){ printHelp(); System.exit(0); } //Parse the Freeling parameter and init the Freeling instance String sharedFolder = System.getenv(ENV_FREELING_SHARED_FOLDER); sharedFolder = System.getProperty(PROPERTY_FREELING_SHARED_FOLDER, sharedFolder); sharedFolder = line.getOptionValue('s', sharedFolder); if(sharedFolder == null){ System.err.println("The Freeling shared Folder MUST BE set! \n"); printHelp(); System.exit(0); } File shared = new File(sharedFolder); if(!shared.isDirectory()){ System.err.println("The configured Freeling shared folder '" + sharedFolder + "' is not a directory!\n"); System.exit(1); } String configFolder = FilenameUtils.concat(sharedFolder, "config"); configFolder = System.getProperty(PROPERTY_FREELING_CONFIG_FOLDER, configFolder); configFolder = line.getOptionValue('c', configFolder); File config = new File(configFolder); if(!config.isDirectory()){ System.err.println("The configured Freeling config folder '" + configFolder + "' is not a directory!\n"); System.exit(1); } String nativeLib = FilenameUtils.concat(sharedFolder, Freeling.DEFAULT_FREELING_LIB_PATH); if(new File(Freeling.DEFAULT_FREELING_LIB_PATH).isFile()){ nativeLib = Freeling.DEFAULT_FREELING_LIB_PATH; } nativeLib = line.getOptionValue('l', nativeLib); if(!new File(nativeLib).isFile()){ System.err.println("The configured Freeling native lib '" + nativeLib + "' is not a file!\n"); System.exit(1); } Freeling freeling = new Freeling( config.getPath(), Freeling.DEFAULT_CONFIGURATION_FILENAME_SUFFIX, shared.getPath(), nativeLib, Freeling.DEFAULT_FREELING_LOCALE, getInt(line, 'i', DEFAULT_INIT_THREADS), getInt(line, 'm', DEFAULT_MAX_POOL_SIZE), getInt(line, 'q', DEFAULT_MIN_QUEUE_SIZE)); //init the Jetty Server Server server = new Server(); Connector con = new SelectChannelConnector(); //we need the port con.setPort(getInt(line,'p',DEFAULT_PORT)); server.addConnector(con); //init the Servlet and the ServletContext Context context = new Context(server, "/", Context.SESSIONS); ServletHolder holder = new ServletHolder(RestServlet.class); holder.setInitParameter("javax.ws.rs.Application", FreelingApplication.class.getName()); context.addServlet(holder, "/*"); //now initialise the servlet context context.setAttribute(Constants.SERVLET_ATTRIBUTE_CONTENT_ITEM_FACTORY, lookupService(ContentItemFactory.class)); context.setAttribute(Constants.SERVLET_ATTRIBUTE_FREELING, freeling); context.setAttribute(Constants.SERVLET_ATTRIBUTE_MAX_RESOURCE_WAIT_TIEM, getLong(line,'w',Constants.DEFAULT_RESOURCE_WAIT_TIME)); //Freeling server.start(); try { server.join(); }catch (InterruptedException e) { } System.err.println("Shutting down Freeling"); freeling.close(); }
Example 14
Source File: JettyHttpServer.java From dubbox with Apache License 2.0 | 4 votes |
public JettyHttpServer(URL url, final HttpHandler handler){ super(url, handler); // modified by lishen this.url = url; // TODO we should leave this setting to slf4j Log.setLog(new StdErrLog()); Log.getLog().setDebugEnabled(false); DispatcherServlet.addHttpHandler(url.getPort(), handler); int threads = url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS); QueuedThreadPool threadPool = new QueuedThreadPool(); threadPool.setDaemon(true); threadPool.setMaxThreads(threads); threadPool.setMinThreads(threads); SelectChannelConnector connector = new SelectChannelConnector(); if (! url.isAnyHost() && NetUtils.isValidLocalHost(url.getHost())) { connector.setHost(url.getHost()); } connector.setPort(url.getPort()); server = new Server(); server.setThreadPool(threadPool); server.addConnector(connector); ServletHandler servletHandler = new ServletHandler(); ServletHolder servletHolder = servletHandler.addServletWithMapping(DispatcherServlet.class, "/*"); servletHolder.setInitOrder(2); // modified by lishen // dubbo's original impl can't support the use of ServletContext // server.addHandler(servletHandler); // TODO Context.SESSIONS is the best option here? Context context = new Context(server, "/", Context.SESSIONS); context.setServletHandler(servletHandler); ServletManager.getInstance().addServletContext(url.getPort(), context.getServletContext()); try { server.start(); } catch (Exception e) { throw new IllegalStateException("Failed to start jetty server on " + url.getAddress() + ", cause: " + e.getMessage(), e); } }
Example 15
Source File: HbaseRestLocalCluster.java From hadoop-mini-clusters with Apache License 2.0 | 4 votes |
@Override public void start() throws Exception { VersionInfo.logVersion(); Configuration conf = builder.getHbaseConfiguration(); conf.set("hbase.rest.port", hbaseRestPort.toString()); conf.set("hbase.rest.readonly", (hbaseRestReadOnly == null) ? "true" : hbaseRestReadOnly.toString()); conf.set("hbase.rest.info.port", (hbaseRestInfoPort == null) ? "8085" : hbaseRestInfoPort.toString()); String hbaseRestHost = (this.hbaseRestHost == null) ? "0.0.0.0" : this.hbaseRestHost; Integer hbaseRestThreadMax = (this.hbaseRestThreadMax == null) ? 100 : this.hbaseRestThreadMax; Integer hbaseRestThreadMin = (this.hbaseRestThreadMin == null) ? 2 : this.hbaseRestThreadMin; UserProvider userProvider = UserProvider.instantiate(conf); Pair<FilterHolder, Class<? extends ServletContainer>> pair = loginServerPrincipal(userProvider, conf); FilterHolder authFilter = pair.getFirst(); Class<? extends ServletContainer> containerClass = pair.getSecond(); RESTServlet.getInstance(conf, userProvider); // set up the Jersey servlet container for Jetty ServletHolder sh = new ServletHolder(containerClass); sh.setInitParameter("com.sun.jersey.config.property.resourceConfigClass", ResourceConfig.class.getCanonicalName()); sh.setInitParameter("com.sun.jersey.config.property.packages", "jetty"); ServletHolder shPojoMap = new ServletHolder(containerClass); Map<String, String> shInitMap = sh.getInitParameters(); for (Map.Entry<String, String> e : shInitMap.entrySet()) { shPojoMap.setInitParameter(e.getKey(), e.getValue()); } shPojoMap.setInitParameter(JSONConfiguration.FEATURE_POJO_MAPPING, "true"); // set up Jetty and run the embedded server server = new Server(); Connector connector = new SelectChannelConnector(); if (conf.getBoolean(RESTServer.REST_SSL_ENABLED, false)) { SslSelectChannelConnector sslConnector = new SslSelectChannelConnector(); String keystore = conf.get(RESTServer.REST_SSL_KEYSTORE_STORE); String password = HBaseConfiguration.getPassword(conf, RESTServer.REST_SSL_KEYSTORE_PASSWORD, null); String keyPassword = HBaseConfiguration.getPassword(conf, RESTServer.REST_SSL_KEYSTORE_KEYPASSWORD, password); sslConnector.setKeystore(keystore); sslConnector.setPassword(password); sslConnector.setKeyPassword(keyPassword); connector = sslConnector; } connector.setPort(hbaseRestPort); connector.setHost(hbaseRestHost); connector.setHeaderBufferSize(8192); server.addConnector(connector); QueuedThreadPool threadPool = new QueuedThreadPool(hbaseRestThreadMax); threadPool.setMinThreads(hbaseRestThreadMin); server.setThreadPool(threadPool); server.setSendServerVersion(false); server.setSendDateHeader(false); server.setStopAtShutdown(true); // set up context Context context = new Context(server, "/", Context.SESSIONS); context.addServlet(shPojoMap, "/status/cluster"); context.addServlet(sh, "/*"); if (authFilter != null) { context.addFilter(authFilter, "/*", 1); } HttpServerUtil.constrainHttpMethods(context); // Put up info server. int port = (hbaseRestInfoPort == null) ? 8085 : hbaseRestInfoPort; if (port >= 0) { conf.setLong("startcode", System.currentTimeMillis()); String a = hbaseRestHost; infoServer = new InfoServer("rest", a, port, false, conf); infoServer.setAttribute("hbase.conf", conf); infoServer.start(); } // start server server.start(); }
Example 16
Source File: JettyHttpServer.java From dubbox with Apache License 2.0 | 4 votes |
public JettyHttpServer(URL url, final HttpHandler handler){ super(url, handler); // modified by lishen this.url = url; // TODO we should leave this setting to slf4j Log.setLog(new StdErrLog()); Log.getLog().setDebugEnabled(false); DispatcherServlet.addHttpHandler(url.getPort(), handler); int threads = url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS); QueuedThreadPool threadPool = new QueuedThreadPool(); threadPool.setDaemon(true); threadPool.setMaxThreads(threads); threadPool.setMinThreads(threads); SelectChannelConnector connector = new SelectChannelConnector(); if (! url.isAnyHost() && NetUtils.isValidLocalHost(url.getHost())) { connector.setHost(url.getHost()); } connector.setPort(url.getPort()); server = new Server(); server.setThreadPool(threadPool); server.addConnector(connector); ServletHandler servletHandler = new ServletHandler(); ServletHolder servletHolder = servletHandler.addServletWithMapping(DispatcherServlet.class, "/*"); servletHolder.setInitOrder(2); // modified by lishen // dubbo's original impl can't support the use of ServletContext // server.addHandler(servletHandler); // TODO Context.SESSIONS is the best option here? Context context = new Context(server, "/", Context.SESSIONS); context.setServletHandler(servletHandler); ServletManager.getInstance().addServletContext(url.getPort(), context.getServletContext()); try { server.start(); } catch (Exception e) { throw new IllegalStateException("Failed to start jetty server on " + url.getAddress() + ", cause: " + e.getMessage(), e); } }
Example 17
Source File: BaseJettyServer.java From recipes-rss with Apache License 2.0 | 4 votes |
public void start() { final int port = ConfigurationManager.getConfigInstance().getInt(RSSConstants.JETTY_HTTP_PORT, Integer.MIN_VALUE); final Context context = new Context(jettyServer, "/", Context.SESSIONS); context.setResourceBase(RSSConstants.WEBAPPS_DIR); context.setClassLoader(Thread.currentThread().getContextClassLoader()); context.addServlet(JspServlet.class, "*.jsp"); // Enable hystrix.stream context.addServlet(HystrixMetricsStreamServlet.class, RSSConstants.HYSTRIX_STREAM_PATH); final Server server = new Server(port); server.setHandler(context); try { karyonServer.start(); server.start(); } catch (Exception exc) { throw new RuntimeException("Cannot start karyon server ...", exc); } }
Example 18
Source File: JettyHttpServer.java From dubbox with Apache License 2.0 | 4 votes |
public JettyHttpServer(URL url, final HttpHandler handler){ super(url, handler); // modified by lishen this.url = url; // TODO we should leave this setting to slf4j Log.setLog(new StdErrLog()); Log.getLog().setDebugEnabled(false); DispatcherServlet.addHttpHandler(url.getPort(), handler); int threads = url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS); QueuedThreadPool threadPool = new QueuedThreadPool(); threadPool.setDaemon(true); threadPool.setMaxThreads(threads); threadPool.setMinThreads(threads); SelectChannelConnector connector = new SelectChannelConnector(); if (! url.isAnyHost() && NetUtils.isValidLocalHost(url.getHost())) { connector.setHost(url.getHost()); } connector.setPort(url.getPort()); server = new Server(); server.setThreadPool(threadPool); server.addConnector(connector); ServletHandler servletHandler = new ServletHandler(); ServletHolder servletHolder = servletHandler.addServletWithMapping(DispatcherServlet.class, "/*"); servletHolder.setInitOrder(2); // modified by lishen // dubbo's original impl can't support the use of ServletContext // server.addHandler(servletHandler); // TODO Context.SESSIONS is the best option here? Context context = new Context(server, "/", Context.SESSIONS); context.setServletHandler(servletHandler); ServletManager.getInstance().addServletContext(url.getPort(), context.getServletContext()); try { server.start(); } catch (Exception e) { throw new IllegalStateException("Failed to start jetty server on " + url.getAddress() + ", cause: " + e.getMessage(), e); } }
Example 19
Source File: JettyHttpServer.java From dubbo-2.6.5 with Apache License 2.0 | 4 votes |
public JettyHttpServer(URL url, final HttpHandler handler) { super(url, handler); this.url = url; // TODO we should leave this setting to slf4j // we must disable the debug logging for production use Log.setLog(new StdErrLog()); Log.getLog().setDebugEnabled(false); DispatcherServlet.addHttpHandler(url.getParameter(Constants.BIND_PORT_KEY, url.getPort()), handler); int threads = url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS); QueuedThreadPool threadPool = new QueuedThreadPool(); threadPool.setDaemon(true); threadPool.setMaxThreads(threads); threadPool.setMinThreads(threads); SelectChannelConnector connector = new SelectChannelConnector(); String bindIp = url.getParameter(Constants.BIND_IP_KEY, url.getHost()); if (!url.isAnyHost() && NetUtils.isValidLocalHost(bindIp)) { connector.setHost(bindIp); } connector.setPort(url.getParameter(Constants.BIND_PORT_KEY, url.getPort())); server = new Server(); server.setThreadPool(threadPool); server.addConnector(connector); ServletHandler servletHandler = new ServletHandler(); ServletHolder servletHolder = servletHandler.addServletWithMapping(DispatcherServlet.class, "/*"); servletHolder.setInitOrder(2); // dubbo's original impl can't support the use of ServletContext // server.addHandler(servletHandler); // TODO Context.SESSIONS is the best option here? Context context = new Context(server, "/", Context.SESSIONS); context.setServletHandler(servletHandler); ServletManager.getInstance().addServletContext(url.getParameter(Constants.BIND_PORT_KEY, url.getPort()), context.getServletContext()); try { server.start(); } catch (Exception e) { throw new IllegalStateException("Failed to start jetty server on " + url.getParameter(Constants.BIND_IP_KEY) + ":" + url.getParameter(Constants.BIND_PORT_KEY) + ", cause: " + e.getMessage(), e); } }
Example 20
Source File: YadisResolverTest.java From openid4java with Apache License 2.0 | 3 votes |
public void setUp() throws Exception { _resolver = new YadisResolver(new HttpFetcherFactory()); _server = new Server(_servletPort); Context context = new Context(_server, "/", Context.SESSIONS); context.addServlet(new ServletHolder(new YadisTestServlet()), "/*"); _server.start(); }