Skip to content
Draft
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
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
32 changes: 28 additions & 4 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 @@ -115,13 +115,37 @@
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-jetty-client</artifactId>
<artifactId>jetty-websocket-core-client</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>jetty-websocket-core-server</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>jetty-websocket-jetty-client</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-jetty-server</artifactId>
<artifactId>jetty-websocket-jetty-api</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<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.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 @@ -26,19 +26,16 @@
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.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* STOMP over WS based Connection class
*/
public class StompWSConnection extends WebSocketAdapter implements WebSocketListener {
public class StompWSConnection extends org.eclipse.jetty.websocket.api.Session.Listener.AbstractAutoDemanding implements Session.Listener.AutoDemanding {

private static final Logger LOG = LoggerFactory.getLogger(StompWSConnection.class);

private Session connection;
private final CountDownLatch connectLatch = new CountDownLatch(1);

private final BlockingQueue<String> prefetch = new LinkedBlockingDeque<String>();
Expand All @@ -47,36 +44,37 @@ public class StompWSConnection extends WebSocketAdapter implements WebSocketList
private int closeCode = -1;
private String closeMessage;

@Override
public boolean isConnected() {
return connection != null ? connection.isOpen() : false;
Session session = getSession();
return session != null && session.isOpen();
}

public void close() {
if (connection != null) {
connection.close();
Session session = getSession();
if (session != null) {
session.close();
}
}

protected Session getConnection() {
return connection;
return getSession();
}

//---- Send methods ------------------------------------------------------//

public synchronized void sendRawFrame(String rawFrame) throws Exception {
checkConnected();
connection.getRemote().sendString(rawFrame);
getSession().sendText(rawFrame, null);
}

public synchronized void sendFrame(StompFrame frame) throws Exception {
checkConnected();
connection.getRemote().sendString(wireFormat.marshalToString(frame));
getSession().sendText(wireFormat.marshalToString(frame), null);
}

public synchronized void keepAlive() throws Exception {
checkConnected();
connection.getRemote().sendString("\n");
getSession().sendText("\n", null);
}

//----- Receive methods --------------------------------------------------//
Expand Down Expand Up @@ -136,22 +134,21 @@ public void onWebSocketText(String data) {
public void onWebSocketClose(int statusCode, String reason) {
LOG.trace("STOMP WS Connection closed, code:{} message:{}", statusCode, reason);

this.connection = null;
this.closeCode = statusCode;
this.closeMessage = reason;
}

@Override
public void onWebSocketConnect(org.eclipse.jetty.websocket.api.Session session) {
this.connection = session;
this.connection.setIdleTimeout(Duration.ZERO);
public void onWebSocketOpen(Session session) {
super.onWebSocketOpen(session);
session.setIdleTimeout(Duration.ZERO);
this.connectLatch.countDown();
}

//----- Internal implementation ------------------------------------------//

private void checkConnected() throws IOException {
if (!isConnected()) {
if (!isOpen()) {
throw new IOException("STOMP WS Connection is closed.");
}
}
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 @@ -21,24 +21,22 @@
import java.net.URI;
import java.util.Map;

import jakarta.servlet.Servlet;

import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.BrokerServiceAware;
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 +75,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 +95,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 +117,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
Loading