Skip to content

Commit

Permalink
[AMQ-9359] Jetty-12 conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrpav committed Dec 2, 2024
1 parent bb4c8aa commit 93cd60b
Show file tree
Hide file tree
Showing 20 changed files with 109 additions and 74 deletions.
2 changes: 1 addition & 1 deletion activemq-amqp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-jetty-server</artifactId>
<artifactId>jetty-websocket-jetty-server</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
12 changes: 6 additions & 6 deletions activemq-http/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
<artifactId>jetty-xml</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<groupId>org.eclipse.jetty.ee9</groupId>
<artifactId>jetty-ee9-webapp</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
Expand Down Expand Up @@ -120,14 +120,14 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-jetty-client</artifactId>
<groupId>org.eclipse.jetty.ee9.websocket</groupId>
<artifactId>jetty-ee9-websocket-jakarta-client</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-jetty-server</artifactId>
<groupId>org.eclipse.jetty.ee9.websocket</groupId>
<artifactId>jetty-ee9-websocket-jetty-server</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@
import java.net.URI;
import java.util.Map;

import org.apache.activemq.transport.http.BlockingQueueTransport;
import org.apache.activemq.util.InetAddressUtil;
import org.apache.activemq.util.IntrospectionSupport;
import org.eclipse.jetty.security.ConstraintMapping;
import org.eclipse.jetty.security.ConstraintSecurityHandler;
import org.eclipse.jetty.ee9.nested.ServletConstraint;
import org.eclipse.jetty.ee9.security.ConstraintMapping;
import org.eclipse.jetty.ee9.security.ConstraintSecurityHandler;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.security.Constraint;
import org.eclipse.jetty.util.resource.ResourceFactory;
import org.eclipse.jetty.xml.XmlConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -57,13 +56,13 @@ private <T> void setConnectorProperty(String name, Class<T> type, T value) throw
protected void createServer() {
LOG.info("Starting Jetty server");
if (jettyOptions.getConfig() != null) {
try {
try (ResourceFactory.Closeable resourceFactory = ResourceFactory.closeable()) {
LOG.info("Configuring Jetty server using {}", jettyOptions.getConfig());
File file = new File(jettyOptions.getConfig());
if (!file.exists()) {
throw new IllegalArgumentException("Jetty XML not found: " + file.getAbsolutePath());
}
XmlConfiguration xmlConfiguration = new XmlConfiguration(Resource.newResource(file));
XmlConfiguration xmlConfiguration = new XmlConfiguration(resourceFactory.newResource(file.getPath()));
server = (Server) xmlConfiguration.configure();
} catch (Throwable t) {
throw new IllegalStateException("Jetty configuration can't be loaded", t);
Expand Down Expand Up @@ -111,12 +110,17 @@ public URI bind() throws Exception {

protected void configureTraceMethod(ConstraintSecurityHandler securityHandler,
boolean enableTrace) {
Constraint constraint = new Constraint();
constraint.setName("trace-security");

ServletConstraint servletConstraint;
//If enableTrace is true, then we want to set authenticate to false to allow it
constraint.setAuthenticate(!enableTrace);
if(enableTrace) {
servletConstraint = new ServletConstraint("trace-security", ServletConstraint.ANY_AUTH);
} else {
servletConstraint = new ServletConstraint("trace-security", ServletConstraint.ANY_ROLE);
}

ConstraintMapping mapping = new ConstraintMapping();
mapping.setConstraint(constraint);
mapping.setConstraint(servletConstraint);
mapping.setMethod("TRACE");
mapping.setPathSpec("/");
securityHandler.addConstraintMapping(mapping);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import java.net.URI;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.ee9.servlet.ServletContextHandler;
import org.eclipse.jetty.ee9.servlet.ServletHolder;

public class EmbeddedJettyServer implements org.apache.activemq.Service {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@
import org.apache.activemq.transport.util.TextWireFormat;
import org.apache.activemq.transport.xstream.XStreamWireFormat;
import org.apache.activemq.util.ServiceStopper;
import org.eclipse.jetty.security.ConstraintSecurityHandler;
import org.eclipse.jetty.ee9.security.ConstraintSecurityHandler;
import org.eclipse.jetty.server.ConnectionFactory;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.HandlerWrapper;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.server.Handler.Wrapper;
import org.eclipse.jetty.ee9.servlet.ServletContextHandler;
import org.eclipse.jetty.ee9.servlet.ServletHolder;

public class HttpTransportServer extends WebTransportServerSupport {

Expand Down Expand Up @@ -135,11 +136,11 @@ private int getConnectorLocalPort() throws Exception {
}

private void addGzipHandler(ServletContextHandler contextHandler) throws Exception {
HandlerWrapper handler = null;
Handler.Wrapper handler = null;
try {
handler = (HandlerWrapper) forName("org.eclipse.jetty.servlets.gzip.GzipHandler").getConstructor().newInstance();
handler = (Handler.Wrapper) forName("org.eclipse.jetty.servlets.gzip.GzipHandler").getConstructor().newInstance();
} catch (Throwable t) {
handler = (HandlerWrapper) forName("org.eclipse.jetty.server.handler.gzip.GzipHandler").getConstructor().newInstance();
handler = (Handler.Wrapper) forName("org.eclipse.jetty.server.handler.gzip.GzipHandler").getConstructor().newInstance();
}
contextHandler.insertHandler(handler);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

import org.apache.activemq.transport.stomp.StompFrame;
import org.apache.activemq.transport.stomp.StompWireFormat;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.WebSocketAdapter;
import org.eclipse.jetty.websocket.api.WebSocketListener;
import org.eclipse.jetty.ee9.websocket.api.Session;
import org.eclipse.jetty.ee9.websocket.api.WebSocketAdapter;
import org.eclipse.jetty.ee9.websocket.api.WebSocketListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -142,7 +142,7 @@ public void onWebSocketClose(int statusCode, String reason) {
}

@Override
public void onWebSocketConnect(org.eclipse.jetty.websocket.api.Session session) {
public void onWebSocketConnect(org.eclipse.jetty.ee9.websocket.api.Session session) {
this.connection = session;
this.connection.setIdleTimeout(Duration.ZERO);
this.connectLatch.countDown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
import org.apache.activemq.util.IntrospectionSupport;
import org.apache.activemq.util.ServiceStopper;
import org.apache.activemq.wireformat.WireFormat;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.WebSocketListener;
import org.eclipse.jetty.ee9.websocket.api.Session;
import org.eclipse.jetty.ee9.websocket.api.WebSocketListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -222,8 +222,8 @@ public void onWebSocketConnect(Session session) {
this.session.setIdleTimeout(Duration.ZERO);

if (wsTransport.getMaxFrameSize() > 0) {
this.session.getPolicy().setMaxBinaryMessageSize(wsTransport.getMaxFrameSize());
this.session.getPolicy().setMaxTextMessageSize(wsTransport.getMaxFrameSize());
this.session.setMaxBinaryMessageSize(wsTransport.getMaxFrameSize());
this.session.setMaxTextMessageSize(wsTransport.getMaxFrameSize());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@
import org.apache.activemq.command.BrokerInfo;
import org.apache.activemq.transport.SocketConnectorFactory;
import org.apache.activemq.transport.WebTransportServerSupport;
import org.apache.activemq.transport.ws.jetty11.WSServlet;
import org.apache.activemq.transport.ws.jetty12.WSServlet;
import org.apache.activemq.util.IntrospectionSupport;
import org.apache.activemq.util.ServiceStopper;
import org.eclipse.jetty.security.ConstraintSecurityHandler;
import org.eclipse.jetty.server.ConnectionFactory;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.websocket.server.config.JettyWebSocketServletContainerInitializer;
import org.eclipse.jetty.ee9.security.ConstraintSecurityHandler;
import org.eclipse.jetty.ee9.servlet.ServletContextHandler;
import org.eclipse.jetty.ee9.servlet.ServletHolder;
import org.eclipse.jetty.ee9.websocket.server.config.JettyWebSocketServletContainerInitializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -77,6 +77,7 @@ protected void doStart() throws Exception {

ServletContextHandler contextHandler =
new ServletContextHandler(server, "/", ServletContextHandler.SECURITY);
// server.setHandler(contextHandler); Future: Jetty 12 EE10 API change

ServletHolder holder = new ServletHolder();
JettyWebSocketServletContainerInitializer.configure(contextHandler, null);
Expand All @@ -96,7 +97,7 @@ protected void doStart() throws Exception {
contextHandler.addServlet(holder, "/");

contextHandler.setAttribute("acceptListener", getAcceptListener());

server.start();

// Update the Connect To URI with our actual location in case the configured port
Expand All @@ -118,7 +119,7 @@ protected void doStart() throws Exception {
LOG.info("Listening for connections at {}", getConnectURI());
}

private Servlet createWSServlet() throws Exception {
private WSServlet createWSServlet() throws Exception {
servlet = new WSServlet();
servlet.setTransportOptions(transportOptions);
servlet.setBrokerService(brokerService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.activemq.transport.ws.jetty11;
package org.apache.activemq.transport.ws.jetty12;

import java.io.IOException;
import java.nio.ByteBuffer;
Expand All @@ -26,8 +26,8 @@
import org.apache.activemq.transport.ws.AbstractMQTTSocket;
import org.apache.activemq.util.ByteSequence;
import org.apache.activemq.util.IOExceptionSupport;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.WebSocketListener;
import org.eclipse.jetty.ee9.websocket.api.WebSocketListener;
import org.eclipse.jetty.ee9.websocket.api.Session;
import org.fusesource.hawtbuf.Buffer;
import org.fusesource.hawtbuf.DataByteArrayInputStream;
import org.fusesource.mqtt.codec.DISCONNECT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.activemq.transport.ws.jetty11;
package org.apache.activemq.transport.ws.jetty12;

import java.io.IOException;
import java.time.Duration;
Expand All @@ -24,8 +24,8 @@
import org.apache.activemq.transport.stomp.StompFrame;
import org.apache.activemq.transport.ws.AbstractStompSocket;
import org.apache.activemq.util.IOExceptionSupport;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.WebSocketListener;
import org.eclipse.jetty.ee9.websocket.api.Session;
import org.eclipse.jetty.ee9.websocket.api.WebSocketListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.activemq.transport.ws.jetty11;
package org.apache.activemq.transport.ws.jetty12;

import java.io.IOException;
import java.net.URI;
Expand All @@ -38,12 +38,12 @@
import org.apache.activemq.transport.TransportFactory;
import org.apache.activemq.transport.util.HttpTransportUtils;
import org.apache.activemq.transport.ws.WSTransportProxy;
import org.eclipse.jetty.websocket.api.WebSocketListener;
import org.eclipse.jetty.websocket.server.JettyServerUpgradeRequest;
import org.eclipse.jetty.websocket.server.JettyServerUpgradeResponse;
import org.eclipse.jetty.websocket.server.JettyWebSocketCreator;
import org.eclipse.jetty.websocket.server.JettyWebSocketServlet;
import org.eclipse.jetty.websocket.server.JettyWebSocketServletFactory;
import org.eclipse.jetty.ee9.websocket.api.WebSocketListener;
import org.eclipse.jetty.ee9.websocket.server.JettyServerUpgradeRequest;
import org.eclipse.jetty.ee9.websocket.server.JettyServerUpgradeResponse;
import org.eclipse.jetty.ee9.websocket.server.JettyWebSocketCreator;
import org.eclipse.jetty.ee9.websocket.server.JettyWebSocketServlet;
import org.eclipse.jetty.ee9.websocket.server.JettyWebSocketServletFactory;

/**
* Handle connection upgrade requests and creates web sockets
Expand Down
9 changes: 7 additions & 2 deletions activemq-web-console/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@
</dependency>

<!-- web container -->
<dependency>
<groupId>org.eclipse.jetty.ee9</groupId>
<artifactId>jetty-ee9-webapp</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
Expand Down Expand Up @@ -330,8 +335,8 @@
</dependency>

<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>apache-jsp</artifactId>
<groupId>org.eclipse.jetty.ee9</groupId>
<artifactId>jetty-ee9-apache-jsp</artifactId>
<scope>provided</scope>
<exclusions>
<exclusion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.apache.activemq.web.config.JspConfigurer;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.ee9.webapp.WebAppContext;

/**
* A simple bootstrap class for starting Jetty in your IDE using the local web
Expand Down
5 changes: 5 additions & 0 deletions activemq-web-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@
<artifactId>jetty-server</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee9</groupId>
<artifactId>jetty-ee9-webapp</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-client</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.ee9.webapp.WebAppContext;

/**
* A simple bootstrap class for starting Jetty in your IDE using the local web
Expand Down
Loading

0 comments on commit 93cd60b

Please sign in to comment.