mirror of https://github.com/apache/activemq.git
Apply patch from Lukas Treyer to address MQTT over WS in Jetty 9
This commit is contained in:
parent
df8dcb5040
commit
8ca6341d40
|
@ -14,10 +14,10 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.apache.activemq.transport.ws.jetty8;
|
package org.apache.activemq.transport.ws.jetty8;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
@ -31,10 +31,12 @@ import org.eclipse.jetty.websocket.WebSocketServlet;
|
||||||
* Handle connection upgrade requests and creates web sockets
|
* Handle connection upgrade requests and creates web sockets
|
||||||
*/
|
*/
|
||||||
public class WSServlet extends WebSocketServlet {
|
public class WSServlet extends WebSocketServlet {
|
||||||
|
|
||||||
private static final long serialVersionUID = -4716657876092884139L;
|
private static final long serialVersionUID = -4716657876092884139L;
|
||||||
|
|
||||||
private TransportAcceptListener listener;
|
private TransportAcceptListener listener;
|
||||||
|
|
||||||
|
@Override
|
||||||
public void init() throws ServletException {
|
public void init() throws ServletException {
|
||||||
super.init();
|
super.init();
|
||||||
listener = (TransportAcceptListener) getServletContext().getAttribute("acceptListener");
|
listener = (TransportAcceptListener) getServletContext().getAttribute("acceptListener");
|
||||||
|
@ -43,8 +45,8 @@ public class WSServlet extends WebSocketServlet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
@Override
|
||||||
throws ServletException ,IOException {
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
getServletContext().getNamedDispatcher("default").forward(request, response);
|
getServletContext().getNamedDispatcher("default").forward(request, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,22 +23,25 @@ import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.apache.activemq.transport.Transport;
|
||||||
import org.apache.activemq.transport.TransportAcceptListener;
|
import org.apache.activemq.transport.TransportAcceptListener;
|
||||||
import org.eclipse.jetty.websocket.api.WebSocketListener;
|
import org.eclipse.jetty.websocket.api.WebSocketListener;
|
||||||
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
|
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
|
||||||
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
|
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
|
||||||
import org.eclipse.jetty.websocket.servlet.WebSocketServlet;
|
|
||||||
import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
|
import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
|
||||||
|
import org.eclipse.jetty.websocket.servlet.WebSocketServlet;
|
||||||
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
|
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle connection upgrade requests and creates web sockets
|
* Handle connection upgrade requests and creates web sockets
|
||||||
*/
|
*/
|
||||||
public class WSServlet extends WebSocketServlet {
|
public class WSServlet extends WebSocketServlet {
|
||||||
|
|
||||||
private static final long serialVersionUID = -4716657876092884139L;
|
private static final long serialVersionUID = -4716657876092884139L;
|
||||||
|
|
||||||
private TransportAcceptListener listener;
|
private TransportAcceptListener listener;
|
||||||
|
|
||||||
|
@Override
|
||||||
public void init() throws ServletException {
|
public void init() throws ServletException {
|
||||||
super.init();
|
super.init();
|
||||||
listener = (TransportAcceptListener) getServletContext().getAttribute("acceptListener");
|
listener = (TransportAcceptListener) getServletContext().getAttribute("acceptListener");
|
||||||
|
@ -47,12 +50,12 @@ public class WSServlet extends WebSocketServlet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
@Override
|
||||||
throws ServletException ,IOException {
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
getServletContext().getNamedDispatcher("default").forward(request, response);
|
getServletContext().getNamedDispatcher("default").forward(request, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void configure(WebSocketServletFactory factory) {
|
public void configure(WebSocketServletFactory factory) {
|
||||||
factory.setCreator(new WebSocketCreator() {
|
factory.setCreator(new WebSocketCreator() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -60,13 +63,14 @@ public class WSServlet extends WebSocketServlet {
|
||||||
WebSocketListener socket;
|
WebSocketListener socket;
|
||||||
if (req.getSubProtocols().contains("mqtt")) {
|
if (req.getSubProtocols().contains("mqtt")) {
|
||||||
socket = new MQTTSocket();
|
socket = new MQTTSocket();
|
||||||
|
resp.setAcceptedSubProtocol("mqtt");
|
||||||
} else {
|
} else {
|
||||||
socket = new StompSocket();
|
socket = new StompSocket();
|
||||||
|
resp.setAcceptedSubProtocol("stomp");
|
||||||
}
|
}
|
||||||
|
listener.onAccept((Transport) socket);
|
||||||
return socket;
|
return socket;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue