org.eclipse.jetty.servlet.ServletHolder Scala Examples
The following examples show how to use org.eclipse.jetty.servlet.ServletHolder.
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.
Example 1
Source File: Iot_managerSpec.scala From daf with BSD 3-Clause "New" or "Revised" License | 5 votes |
import java.io.{IOException, File => JFile} import java.net.ServerSocket import java.util.Base64 import better.files._ import it.gov.daf.iotmanager.client.Iot_managerClient import org.specs2.mutable.Specification import org.specs2.specification.BeforeAfterAll import play.api.Application import play.api.inject.guice.GuiceApplicationBuilder import play.api.libs.ws.ahc.AhcWSClient import play.api.libs.ws.{WSAuthScheme, WSResponse} import play.api.test.{WithServer, WsTestClient} import scala.concurrent.Await import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.duration.Duration import scala.util.{Failure, Try} import org.apache.solr.client.solrj.embedded.JettyConfig import org.apache.solr.client.solrj.embedded.JettySolrRunner import org.eclipse.jetty.servlet.ServletHolder @SuppressWarnings(Array("org.wartremover.warts.NonUnitStatements", "org.wartremover.warts.Throw")) class Iot_managerSpec extends Specification with BeforeAfterAll { import Iot_managerSpec._ def getAvailablePort: Int = { try { val socket = new ServerSocket(0) try { socket.getLocalPort } finally { socket.close() } } catch { case e: IOException => throw new IllegalStateException(s"Cannot find available port: ${e.getMessage}", e) } } def application: Application = GuiceApplicationBuilder(). configure("hadoop_conf_dir" -> s"${ServiceSpec.confPath.pathAsString}"). configure("pac4j.authenticator" -> "test"). build() "The security_manager" should { "manage user tokens correctly" in new WithServer(app = application, port = getAvailablePort) { print("ciao ciao") } } override def beforeAll(): Unit = { val solrXml = new Nothing("/solr/home/solr.xml") val solrHomeDir = solrXml.getParentFile val port = 8080 val context = "/solr" // use org.apache.solr.client.solrj.embedded.JettySolrRunner val jettySolr = new Nothing(solrHomeDir.getAbsolutePath, context, port) val waitUntilTheSolrWebAppHasStarted = true jettySolr.start(waitUntilTheSolrWebAppHasStarted) } override def afterAll(): Unit = { jettySolr.stop() } } @SuppressWarnings(Array("org.wartremover.warts.Var", "org.wartremover.warts.Null")) object Iot_managerSpec { }
Example 2
Source File: ApplicationServer.scala From udash-core with Apache License 2.0 | 5 votes |
package io.udash.web.server import io.udash.rest._ import io.udash.rpc._ import io.udash.rpc.utils.{CallLogging, DefaultAtmosphereFramework} import io.udash.web.guide.demos.activity.{Call, CallLogger} import io.udash.web.guide.demos.rest.MainServerREST import io.udash.web.guide.rest.ExposedRestInterfaces import io.udash.web.guide.rpc.ExposedRpcInterfaces import io.udash.web.guide.{GuideExceptions, MainServerRPC} import org.eclipse.jetty.server.Server import org.eclipse.jetty.server.handler.ContextHandlerCollection import org.eclipse.jetty.server.handler.gzip.GzipHandler import org.eclipse.jetty.server.session.SessionHandler import org.eclipse.jetty.servlet.{DefaultServlet, ServletContextHandler, ServletHolder} class ApplicationServer(val port: Int, homepageResourceBase: String, guideResourceBase: String) { private val server = new Server(port) def start(): Unit = { server.start() } def stop(): Unit = { server.stop() } private val homepage = { val ctx = createContextHandler(Array("udash.io", "www.udash.io", "127.0.0.1")) ctx.addServlet(createStaticHandler(homepageResourceBase), "?)*$") spaRewrite.setReplacement("/") rewrite.addRule(spaRewrite) rewrite.setHandler(contexts) rewrite } server.setHandler(rewriteHandler) private def createContextHandler(hosts: Array[String]): ServletContextHandler = { val context = new ServletContextHandler context.setSessionHandler(new SessionHandler) context.setGzipHandler(new GzipHandler) context.setVirtualHosts(hosts) context } private def createStaticHandler(resourceBase: String): ServletHolder = { val appHolder = new ServletHolder(new DefaultServlet) appHolder.setAsyncSupported(true) appHolder.setInitParameter("resourceBase", resourceBase) appHolder } }
Example 3
Source File: ServerMain.scala From udash-core with Apache License 2.0 | 5 votes |
package io.udash package rest.examples import io.udash.rest.RestServlet import org.eclipse.jetty.server.Server import org.eclipse.jetty.servlet.{ServletContextHandler, ServletHolder} import scala.concurrent.Future class UserApiImpl extends UserApi { def createUser(name: String): Future[User] = Future.successful(User(UserId(0), name)) def getUser(id: UserId): Future[User] = Future.successful(User(id, s"$id-name")) } object ServerMain { def main(args: Array[String]): Unit = { val server = new Server(9090) val handler = new ServletContextHandler handler.addServlet(new ServletHolder(RestServlet[UserApi](new UserApiImpl)), "/*") server.setHandler(handler) server.start() server.join() } }
Example 4
Source File: ServletBasedRestApiTest.scala From udash-core with Apache License 2.0 | 5 votes |
package io.udash package rest import org.eclipse.jetty.server.Server import org.eclipse.jetty.servlet.{ServletHandler, ServletHolder} import scala.concurrent.duration._ abstract class ServletBasedRestApiTest extends RestApiTest with UsesHttpServer { override implicit def patienceConfig: PatienceConfig = PatienceConfig(10.seconds) def maxPayloadSize: Int = 1024 * 1024 def serverTimeout: FiniteDuration = 10.seconds protected def setupServer(server: Server): Unit = { val servlet = new RestServlet(serverHandle, serverTimeout, maxPayloadSize) val holder = new ServletHolder(servlet) val handler = new ServletHandler handler.addServletWithMapping(holder, "/api/*") server.setHandler(handler) } }
Example 5
Source File: HttpStreamServer.scala From spark-http-stream with BSD 2-Clause "Simplified" License | 5 votes |
package org.apache.spark.sql.execution.streaming.http import org.apache.spark.internal.Logging import org.eclipse.jetty.server.Server import org.eclipse.jetty.servlet.ServletContextHandler import javax.servlet.ServletConfig import javax.servlet.http.HttpServlet import javax.servlet.http.HttpServletRequest import javax.servlet.http.HttpServletResponse import org.eclipse.jetty.servlet.ServletHolder import scala.collection.JavaConversions class MissingRequiredRequestParameterException(paramName: String) extends RuntimeException(s"missing required request parameter: $paramName") { } class UnsupportedActionException(action: String) extends RuntimeException(s"unsupported action in HTTP request header: $action") { } object HttpStreamServer { def start(httpServletPath: String, httpPort: Int) = { val server = new HttpStreamServer(httpServletPath, httpPort); server.start; server; } } def withActionsHandler[T <: ActionsHandler](actionsHandler: T): T = { this.actionsHandler = actionsHandler; actionsHandler; } def withBuffer(): MemoryBufferAsReceiver = { withActionsHandler(new MemoryBufferAsReceiver()); } def withKafka(bootstrapServers: String): KafkaAsReceiver = { withActionsHandler(new KafkaAsReceiver(bootstrapServers)); } def stop() = { httpStreamServlet.destroy(); if (server != null) server.stop(); } }
Example 6
Source File: ApplicationServer.scala From udash-demos with GNU General Public License v3.0 | 5 votes |
package io.udash.todo.jetty import io.udash.todo.services.InMemoryTodoStorage import org.eclipse.jetty.server.Server import org.eclipse.jetty.server.handler.gzip.GzipHandler import org.eclipse.jetty.server.session.SessionHandler import org.eclipse.jetty.servlet.{DefaultServlet, ServletContextHandler, ServletHolder} class ApplicationServer(val port: Int, resourceBase: String) { private val server = new Server(port) private val contextHandler = new ServletContextHandler private val appHolder = createAppHolder() private val atmosphereHolder = createAtmosphereHolder() contextHandler.setSessionHandler(new SessionHandler) contextHandler.setGzipHandler(new GzipHandler) contextHandler.getSessionHandler.addEventListener(new org.atmosphere.cpr.SessionSupport()) contextHandler.addServlet(atmosphereHolder, "/atm/*") contextHandler.addServlet(appHolder, "/*") server.setHandler(contextHandler) def start(): Unit = server.start() def stop(): Unit = server.stop() private def createAppHolder() = { val appHolder = new ServletHolder(new DefaultServlet) appHolder.setAsyncSupported(true) appHolder.setInitParameter("resourceBase", resourceBase) appHolder } private def createAtmosphereHolder() = { import io.udash.rpc._ import io.udash.todo.rpc._ val config = new DefaultAtmosphereServiceConfig(_ => new DefaultExposesServerRPC[MainServerRPC](new ExposedRpcInterfaces(InMemoryTodoStorage)) ) val framework = new DefaultAtmosphereFramework(config) val atmosphereHolder = new ServletHolder(new RpcServlet(framework)) atmosphereHolder.setAsyncSupported(true) atmosphereHolder } }
Example 7
Source File: ApplicationServer.scala From udash-demos with GNU General Public License v3.0 | 5 votes |
package io.udash.demos.files.jetty import javax.servlet.MultipartConfigElement import io.udash.demos.files.ApplicationServerContexts import io.udash.demos.files.rpc.{MainRpcEndpoint, MainServerRPC} import org.eclipse.jetty.server.Server import org.eclipse.jetty.server.handler.gzip.GzipHandler import org.eclipse.jetty.server.session.SessionHandler import org.eclipse.jetty.servlet.{DefaultServlet, ServletContextHandler, ServletHolder} class ApplicationServer(val port: Int, resourceBase: String) { private val server = new Server(port) private val contextHandler = new ServletContextHandler contextHandler.setSessionHandler(new SessionHandler) contextHandler.setGzipHandler(new GzipHandler) server.setHandler(contextHandler) def start(): Unit = server.start() def stop(): Unit = server.stop() private val appHolder = { val appHolder = new ServletHolder(new DefaultServlet) appHolder.setAsyncSupported(true) appHolder.setInitParameter("resourceBase", resourceBase) appHolder } contextHandler.addServlet(appHolder, "/*") private val uploadsHolder = { val holder = new ServletHolder(new DemoFileUploadServlet(resourceBase + "/uploads")) holder.getRegistration.setMultipartConfig(new MultipartConfigElement("")) holder } contextHandler.addServlet(uploadsHolder, ApplicationServerContexts.uploadContextPrefix + "/*") private val downloadsHolder = { val holder = new ServletHolder(new DemoFileDownloadServlet(resourceBase + "/uploads", ApplicationServerContexts.downloadContextPrefix)) holder.getRegistration.setMultipartConfig(new MultipartConfigElement("")) holder } contextHandler.addServlet(downloadsHolder, ApplicationServerContexts.downloadContextPrefix + "/*") private val atmosphereHolder = { import io.udash.rpc._ val config = new DefaultAtmosphereServiceConfig[MainServerRPC]((_) => new DefaultExposesServerRPC[MainServerRPC](new MainRpcEndpoint) ) val framework = new DefaultAtmosphereFramework(config) val atmosphereHolder = new ServletHolder(new RpcServlet(framework)) atmosphereHolder.setAsyncSupported(true) atmosphereHolder } contextHandler.addServlet(atmosphereHolder, ApplicationServerContexts.atmosphereContextPrefix + "/*") }
Example 8
Source File: Server.scala From orders-aws with Apache License 2.0 | 5 votes |
package works.weave.socks.aws.orders.main import org.eclipse.jetty import org.eclipse.jetty.servlet.ServletContextHandler import org.eclipse.jetty.servlet.ServletHolder import org.glassfish.jersey.servlet.ServletContainer import org.slf4j.LoggerFactory import org.springframework.stereotype.Component import scala.collection.JavaConverters._ import scala.util.control.NonFatal import Server._ @Component class Server(val jerseyApp : JerseyApp) { def run() : Unit = { val port = System.getenv().asScala.getOrElse("PORT", "80").toInt val context = new ServletContextHandler(ServletContextHandler.SESSIONS) context.setContextPath("/") val jettyServer = new jetty.server.Server(port) jettyServer.setHandler(context) val servletContainer = new ServletContainer(jerseyApp) val servletHolder = new ServletHolder(servletContainer) context.addServlet(servletHolder, "/*") val jerseyServlet = servletHolder jerseyServlet.setInitOrder(0) try { Log.info("Starting jetty") jettyServer.start() Log.info("Jetty started") jettyServer.join() Log.info("Jetty exited") } finally { Log.info("Destroying jetty") try { jettyServer.destroy() } catch { case NonFatal(e) => Log.error("Error during Jetty shutdown", e) } } } } object Server { val Log = LoggerFactory.getLogger(classOf[Server]) }
Example 9
Source File: HttpServer.scala From amaterasu with Apache License 2.0 | 5 votes |
package org.apache.amaterasu.leader.utilities import org.apache.amaterasu.common.logging.Logging import org.apache.log4j.{BasicConfigurator, Level, Logger} import org.eclipse.jetty.server.handler.ErrorHandler import org.eclipse.jetty.server.{Server, ServerConnector} import org.eclipse.jetty.servlet.{DefaultServlet, ServletContextHandler, ServletHolder} import org.eclipse.jetty.util.log.StdErrLog BasicConfigurator.configure() initLogging() server = new Server() val connector = new ServerConnector(server) connector.setPort(port.toInt) server.addConnector(connector) val context = new ServletContextHandler(ServletContextHandler.SESSIONS) context.setResourceBase(serverRoot) context.setContextPath("/") server.setHandler(context) context.setErrorHandler(new ErrorHandler()) context.setInitParameter("dirAllowed", "true") context.setInitParameter("pathInfoOnly", "true") context.addServlet(new ServletHolder(new DefaultServlet()), "/") server.start() } def stop() { if (server == null) throw new IllegalStateException("Server not started") server.stop() server = null } def initLogging(): Unit = { System.setProperty("org.eclipse.jetty.util.log.class", classOf[StdErrLog].getName) Logger.getLogger("org.eclipse.jetty").setLevel(Level.OFF) Logger.getLogger("org.eclipse.jetty.websocket").setLevel(Level.OFF) } }