Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions features/com.gwtplugins.eclipse.suite.v3.feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,11 @@
version="4.2.0.qualifier"
unpack="false"/>

<plugin
id="com.gwtplugins.eclipse.jettylauncher"
download-size="0"
install-size="0"
version="4.2.0.qualifier"
unpack="false"/>

</feature>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Jettylauncher
Bundle-SymbolicName: com.gwtplugins.eclipse.jettylauncher
Bundle-Version: 4.2.0.qualifier
Automatic-Module-Name: org.gwtproject.jettylauncher
Bundle-RequiredExecutionEnvironment: JavaSE-17
4 changes: 4 additions & 0 deletions plugins/com.gwtplugins.eclipse.jettylauncher/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source.. = src/java/
output.. = target/classes
bin.includes = META-INF/,\
.
134 changes: 134 additions & 0 deletions plugins/com.gwtplugins.eclipse.jettylauncher/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.gwtplugins.eclipse</groupId>
<artifactId>trunk</artifactId>
<version>4.2.0-SNAPSHOT</version>
<relativePath>../../</relativePath>
</parent>

<artifactId>com.gwtplugins.eclipse.jettylauncher</artifactId>
<version>4.2.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>11</java.version>
<maven.test.skip>true</maven.test.skip>
</properties>

<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>12.0.31</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee10</groupId>
<artifactId>jetty-ee10-servlet</artifactId>
<version>12.0.31</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee10</groupId>
<artifactId>jetty-ee10-webapp</artifactId>
<version>12.0.31</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee8</groupId>
<artifactId>jetty-ee8-servlet</artifactId>
<version>12.0.31</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee8</groupId>
<artifactId>jetty-ee8-webapp</artifactId>
<version>12.0.31</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gwtproject</groupId>
<artifactId>gwt-dev</artifactId>
<version>2.12.2</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
<executions>
<execution>
<id>default-testCompile</id>
<phase>none</phase> <!-- Deaktiviert das
Test-Kompilieren -->
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-compiler-plugin</artifactId>
<version>${tycho.version}</version>
<configuration>
<extraClasspathElements>
<extraClasspathElement>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>12.0.36</version> <!-- Version anpassen -->
</extraClasspathElement>
<extraClasspathElement>
<groupId>org.eclipse.jetty.ee8</groupId>
<artifactId>jetty-ee8-servlet</artifactId>
<version>12.0.36</version> <!-- Version anpassen -->
</extraClasspathElement>
<extraClasspathElement>
<groupId>org.eclipse.jetty.ee8</groupId>
<artifactId>jetty-ee8-webapp</artifactId>
<version>12.0.36</version>
</extraClasspathElement>
<extraClasspathElement>
<groupId>org.eclipse.jetty.ee10</groupId>
<artifactId>jetty-ee10-servlet</artifactId>
<version>12.0.36</version> <!-- Version anpassen -->
</extraClasspathElement>
<extraClasspathElement>
<groupId>org.eclipse.jetty.ee10</groupId>
<artifactId>jetty-ee10-webapp</artifactId>
<version>12.0.36</version>
</extraClasspathElement>
<extraClasspathElement>
<groupId>org.gwtproject</groupId>
<artifactId>gwt-dev</artifactId>
<version>2.12.2</version>
<exclusions>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
<exclusion>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
</exclusion>
</exclusions>
</extraClasspathElement>
</extraClasspathElements>
<useProjectDependencies>true</useProjectDependencies>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.gwtplugins.jettylauncher;

import java.io.File;
import java.lang.reflect.Method;
import java.net.BindException;

import com.google.gwt.core.ext.ServletContainer;
import com.google.gwt.core.ext.ServletContainerLauncher;
import com.google.gwt.core.ext.TreeLogger;

/**
* Base class for the Jetty12Launchers.
*/
public abstract class AbstractJetty12Launcher extends ServletContainerLauncher {

@Override
public ServletContainer start(TreeLogger logger, int port, File appRootDir) throws BindException, Exception {
// A custom Classloader to separate the classes of the webapp and app server from the rest of the system.
Jetty12ClassLoader cl = new Jetty12ClassLoader(getJEEVersion());
Thread.currentThread().setContextClassLoader(cl);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restore the calling thread's context classloader. This changes the context classloader for the caller and leaves it changed on both success and failure. Subsequent work on that thread can then use the Jetty-specific loader unexpectedly. Please save the previous value and restore it in a finally block around bootstrap loading and invocation.

//Load and run the Bootstrap in the context of the custom ClassLoader.
Class<?> bsClass = cl.loadClass(getBootstrapClassname());
Class<?>[] types = new Class[2];
types[0] = int.class;
types[1] = File.class;
Method method = bsClass.getDeclaredMethod("start", types);
Object[] params = new Object[2];
params[0] = port;
params[1] = appRootDir;
ServletContainer cont = (ServletContainer) method.invoke(null, params);
return cont;
}

/**
* The jee Version to load. If jee10 ist activated, the jee8 libraries will not be loaded.
* @return
*/
protected abstract JEEVersion getJEEVersion();

/**
* The name of the class that is used to separate the classloader from other eclipse classes.
* @return
*/
abstract protected String getBootstrapClassname();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package com.gwtplugins.jettylauncher;

import java.io.File;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.InetAccessHandler;
import org.eclipse.jetty.util.thread.QueuedThreadPool;

import com.google.gwt.core.ext.ServletContainer;
import com.google.gwt.core.ext.UnableToCompleteException;

public abstract class AbstractJetty12ServletContainer extends ServletContainer {

protected int port;
protected File appRootDir;

public AbstractJetty12ServletContainer(int port, File appRootDir)
{
super();
this.port = port;
this.appRootDir = appRootDir;
try
{
startServer(port);
}
catch (Exception e)
{
e.printStackTrace();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Propagate startup failures. If startup fails, for example because the port is occupied, this catch block prints the exception and still allows the launcher to return a container. Please propagate startup errors through ServletContainerLauncher.start(), preserving BindException where applicable, and clean up partially started resources. Since bootstrap is invoked reflectively, please also unwrap InvocationTargetException in the launcher so callers receive the original exception type.

}
}

/**
* Create a Thread Pool for the Jetty Server
* @return
*/
protected QueuedThreadPool createThreadPool()
{
// Eigenen ThreadPool um Anzahl der Threads kontrollieren zu können
QueuedThreadPool pool = new QueuedThreadPool(50, 20)
{
@Override
public Thread newThread(Runnable runnable) {
// Threads markieren
Thread t = super.newThread(runnable);
t.setName("Jetty - " + t.getName());
return t;
}
};
return pool;
}

/**
* Starts the Jetty Server on the given Port.
* @param port
* @throws Exception
*/
public void startServer(int port) throws Exception
{
QueuedThreadPool pool = createThreadPool();
Server server = new Server(pool);
ServerConnector connector = new ServerConnector(server);
connector.setPort(port);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honor the configured bind address. The launcher does not override setBindAddress(), and this connector only receives a port. An explicit loopback address supplied by GWT is therefore ignored. Please retain the configured address in the launcher, pass it through to the container, and apply it with ServerConnector.setHost() before startup so developers can restrict the server to localhost.

connector.setIdleTimeout(30000);
server.addConnector(connector);
InetAccessHandler ihandler = new InetAccessHandler();

Handler.Sequence shandler = createHandler();

ihandler.setHandler(shandler);
server.setHandler(ihandler);
server.start();
}

/**
* Create a WebAppContext
* @return
*/
abstract protected Handler.Sequence createHandler();

@Override
public int getPort()
{
return port;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return the actual bound port. With automatic port selection (port == 0), Jetty chooses a free port, but getPort() still returns 0. This gives GWT the wrong server address. Please capture connector.getLocalPort() after startup and return that value.

}

@Override
public void refresh() throws UnableToCompleteException
{
}

@Override
public void stop() throws UnableToCompleteException

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implement the container lifecycle. stop() and refresh() are both empty, and startServer() only keeps the Server in a local variable. GWT therefore cannot stop Jetty through the container API or reload the web application after server-side changes. Please retain the server and web application context, implement shutdown, and make refresh reload the application and updated classes. Terminating the whole JVM from Eclipse can hide the shutdown issue, but does not cover these lifecycle operations.

{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.gwtplugins.jettylauncher;

/**
* JEE Versions. JEE8 for javax.servlet and JEE10 for jakarta.servlet
*/
public enum JEEVersion
{
JEE8
, JEE10
}
Loading
Loading