embedded-jetty

How to add servlet Filter with embedded jetty

我是研究僧i 提交于 2019-11-28 21:14:23
I am embedding jetty into my app, and trying to work out how to add servlet filters (for cookie handling). The wiki and the javadoc's dont make it very clear, what am I missing: Server server = new Server(port); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); FilterHolder f = new FilterHolder(new AuthorisationFilter()); context.addFilter(... f ...); // ????? context.addServlet(new ServletHolder(new TestServlet()), "/"); The only info I have found on this is a forum post suggesting the documentation on this needs to be

How to embed Jetty and Jersey into my Java application

℡╲_俬逩灬. 提交于 2019-11-28 20:40:21
So I'm trying to embed jetty into my web application so that if I package it as a jar someone can just run the jar file without having to worry about configuring a server. However, I'm having some problems setting up my main class so that jetty can access my resource classes. I've looked at tutorials but they haven't given me exactly what I'm looking for. This is what I have so far. package pojo; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.DefaultServlet; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; public

Spring 3.1 WebApplicationInitializer & Embedded Jetty 8 AnnotationConfiguration

回眸只為那壹抹淺笑 提交于 2019-11-28 18:13:26
I'm trying to create a simple webapp without any XML configuration using Spring 3.1 and an embedded Jetty 8 server. However, I'm struggling to get Jetty to recognise my implementaton of the Spring WebApplicationInitializer interface. Project structure: src +- main +- java | +- JettyServer.java | +- Initializer.java | +- webapp +- web.xml (objective is to remove this - see below). The Initializer class above is a simple implementation of WebApplicationInitializer : import javax.servlet.ServletContext; import javax.servlet.ServletException; import org.springframework.web

Configure embedded jetty with web.xml?

孤者浪人 提交于 2019-11-28 17:15:15
I am trying to generate both a war with my web application as well as a self contained jar file with embedded jetty. For the embedded jetty (the jar file distribution) I add a servlet as follows: public static void main(String[] args) throws Exception { Server server = new Server(8080); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); server.setHandler(context); context.addServlet(new ServletHolder(new HelloServlet()),"/*"); server.start(); server.join(); } The war file distribution uses a web.xml file that contains the

How do I create an embedded WebSocket server Jetty 9?

不羁的心 提交于 2019-11-28 16:42:41
I hate asking such a vague question, but I'm having a hard time finding a simple example. Here's what I have so far: public class JettyWebSocketServlet extends WebSocketServlet{ @Override public void configure(WebSocketServletFactory factory) { factory.register(MyEchoSocket.class); } } @WebSocket public class MyEchoSocket { @OnWebSocketMessage public void onText(WebSocketConnection conn, String message) { System.out.println("text: " + message); try { conn.write(null, new FutureCallback(), "got: " + message); } catch (Exception e) { e.printStackTrace(); } } } The embedded Jetty examples I can

Websocket JSR-356 fail with Jetty 9.4.1

[亡魂溺海] 提交于 2019-11-28 13:10:38
My current web server is embedded Jetty 9.1.5. It works well with JSR-356 to create websocket. These days, I am trying to upgrade to Jetty 9.4.1. Everything works nicely except websocket. My code like below: Embedded Jetty and Websocket libs: <dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-server</artifactId> <version>9.4.1.v20170120</version> </dependency> <dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-webapp</artifactId> <version>9.4.1.v20170120</version> </dependency> <dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-annotations<

Embedded Jetty with exploded war, using annotated config

泪湿孤枕 提交于 2019-11-28 12:36:44
问题 I am learning Java EE 7 Servlets and tried to deploy hello2 example from Java EE 7 tutorial using embedded Jetty (v 9.3.7) with little success. hello2 consists of two servlets and an image file. The configuration is annotated and the project does not have any web.xml. Following the WebAppContext part from embedded Jetty examples I created this main class to initiate my embedded server: public class MyServer { public static void main(String[] args) throws Exception { Server server = new Server

create a executable jar using maven and jetty

眉间皱痕 提交于 2019-11-28 07:52:37
I want to start my application using jetty, so I have added the dependency mentioned below. and when I run the main method Jetty starts successfully.(I am working on a struts2+spring3+ hibernate maven project, i am able to deploy it in tomcat too) Now I want to create a executable jar from a war packaging pom. So i added maven-assembly-plugin to my pom. (I tried with maven jar plug-in but it was not adding the dependencies) Sources plugins <build> <plugins> <plugin> <artifactId>maven-war-plugin</artifactId> <version>2.3</version> <configuration> <archive> <manifest> <mainClass>com.dca.engine

Embedding Jetty as a Servlet Container

白昼怎懂夜的黑 提交于 2019-11-28 06:59:47
I'm using Tomcat to serve my Java Servlets and it's kinda more for me. I just need to serve, Servlet Requests alone, no static content, neither JSP, etc. So I was looking for a Servlet container that can be embedded in my Application. I felt it if stripped Jetty and use it as a Servlet Container alone, it can be more scalable and occupying small memory footprint, [I don't need Jetty's 'Web Server' and other Parts]. So I've a few questions though, How do I embed Jetty in my Application Code to serve Servlet Requests alone? If I embed Jetty code in my Application Code, will I be able to easily

How to disable directory listing for Jetty's WebAppContext?

╄→гoц情女王★ 提交于 2019-11-28 05:53:48
I'm embedding Jetty (version 7.4.5.v20110725) into a java application. I'm serving JSP pages in ./webapps/jsp/ using Jetty's WebAppContext, but if I visit localhost:8080/jsp/ I get Jetty's directory listing for the entire contents of ./webapps/jsp/. I've tried setting the dirAllowed parameter to false on the WebAppContext and it does not change the directory listing behavior. Disabling the directory listing on a ResourceHandler is simply done be passing false to setDirectoriesListed, works as expected. Can someone tell me how to do this for the WebAppContext? import org.eclipse.jetty.server