embedded-jetty

How to embed Jetty into Spring and make it use the same AppContext it was embedded into?

五迷三道 提交于 2019-12-04 09:25:41
问题 I have a Spring ApplicationContext where I declare Jetty server bean and start it. Inside Jetty I have a DispatcherServlet and a couple of controllers. How to make that DispatcherServlet and its controllers use beans from the same ApplicationContext where Jetty is declared? In fact, in that outer context I have a couple of daemon-like beans and their dependencies. Controllers inside Jetty use the same dependencies, so I'd like to avoid duplicating them inside and outside Jetty. 回答1: I did

How do you get embedded Jetty 9 to successfully resolve the JSTL URI?

折月煮酒 提交于 2019-12-04 08:26:29
问题 I'm packaging a Web Application Archive (.war) so that it can be started via java -jar webapp.war in a shell by launching an embedded copy of Jetty 9 using this code in a main class: int port = Integer.parseInt(System.getProperty("port", "80")); // I know this has implications :) String contextPath = System.getProperty("contextPath", ""); Server server = new Server(port); ProtectionDomain domain = Deployer.class.getProtectionDomain(); URL location = domain.getCodeSource().getLocation();

Jersey problems with Maven - Shade Plugin

≯℡__Kan透↙ 提交于 2019-12-04 05:28:50
My problem is very similar to: Jersey exception only thrown when depencencies assembled into a single jar I run my application (jetty embedded + jersey) and everything works. When i try to create a executable JAR i get the error: org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor aroundWriteTo GRAVE: MessageBodyWriter not found for media type=application/json, type=class My POM.XML: <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>2.3</version> <executions> <execution> <phase>package<

How can a native Servlet Filter be used when using Spark web framework?

依然范特西╮ 提交于 2019-12-04 05:22:20
I'm playing around with Spark (the Java web framework, not Apache Spark). I find it really nice and easy to define routes and filters, however I'm looking to apply a native servlet filter to my routes and can't seem to find a way to do that. More specifically, I would like to use Jetty's DoSFilter which is a servlet filter (contrast with the Spark Filter definition). Since Spark is using embedded Jetty, I don't have a web.xml to register the DoSFilter. However, Spark doesn't expose the server instance so I can't find an elegant way of registering the filter programatically either. Is there a

Exclude Gradle classpath runtime when launching JettyRun

99封情书 提交于 2019-12-04 05:06:51
I have your basic run of the mill Gradle web application project and it works ok but I noticed that Gradle's runtime classpath is being included in the jetty one which has the potential to conflict with the web applications. Notice below that gradle is using a slightly older version of logback and that SL4J is warning that it found multiple bindings in the classpath. :jettyRun SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/C:/dev/java/tools/gradle-1.0-milestone-5/lib/logback-classic-0.9.29.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found

JNDI lookup failing with Jetty for JDBC connection pooling with MySQL?

ⅰ亾dé卋堺 提交于 2019-12-04 04:43:22
问题 I'm using Jetty 9.2 (embedded) with the standard MySQL connector API and I'm very confused by how this is supposed to be setup. Currently, I have this in my web.xml file: <webapp ... <resource-ref> <description>JDBC Data Source</description> <res-ref-name>jdbc/DataSource</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref> </webapp> ...and this in my jetty-env.xml: <Configure class="org.eclipse.jetty.webapp.WebAppContext"> <New id=

Map jetty ResourceHandler to a URL

落爺英雄遲暮 提交于 2019-12-04 02:49:24
Is it possible using embedded Jetty to serve static files from directory X but mapped to URL Y? I have static files stored under directory "web", but I want the URL be something like http://host/myapp . I have already successfully ran a server configured with ResourceHandler in the following way: ResourceHandler ctx = new ResourceHandler(); ctx.setResourceBase("path-to-web"); HandlerList list = new HandlerList(); list.addHandler(ctx); ... server.setHandler(list); But the result is serving the files under /web and not under the desired URL mapping. The ResourceHandler has no context

How do you set both port and thread pool using embedded jetty, v 9.1.0

我与影子孤独终老i 提交于 2019-12-04 02:10:29
I'm using jetty 9.1.0, embedded, and would like to set both port and ThreadPool. I see a constructor for each, but don't see how to use one of those, and then any way to set the other. doing this Server server = new Server(9090); or Server server = new Server(new QueuedThreadPool(100, 10)); but there's no setPort or setThreadPool on Server. QueuedThreadPool threadPool = new QueuedThreadPool(); threadPool.setMaxThreads(500); Server server = new Server(threadPool); ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(http_config)); http.setPort(81); server.addConnector

javax.servlet.http.HttpServletResponse.getStatus() not found

早过忘川 提交于 2019-12-04 01:44:22
问题 I am working with an embedded Jetty server, deploying a Jersey REST api, and I am trying to log the errors, with log4J. When an error happens, for instance a URL not found, and the console log shows the following error: java.lang.NoSuchMethodError: javax.servlet.http.HttpServletResponse.getStatus()I at org.eclipse.jetty.server.handler.ErrorHandler.doError(ErrorHandler.java:142) at org.eclipse.jetty.server.handler.ErrorHandler.handle(ErrorHandler.java:78) at org.eclipse.jetty.server.Response

Embedded Jetty - IllegalStateException: No SessionManager

一笑奈何 提交于 2019-12-04 01:29:38
I've found plenty of references to this issue on google but no answers. I'm using the latest version of jetty (8.1.2.v20120308) and I can't seem to get an embedded servlet to be able to use sessions. The example is in scala of course, but it should be readable to any java programmer. val server = new Server(); val connector = new SelectChannelConnector() connector.setPort(Integer.getInteger("jetty.port", 8080).intValue()) server.setConnectors(Array(connector)) val webapp = new ServletContextHandler(ServletContextHandler.SESSIONS) webapp.setContextPath("/") webapp.setResourceBase(webDir) webapp