activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dej...@apache.org
Subject svn commit: r911492 - in /activemq/trunk/activemq-optional: ./ src/main/java/org/apache/activemq/transport/ws/ src/main/resources/META-INF/services/org/apache/activemq/transport/ src/test/java/org/apache/activemq/transport/ws/
Date Thu, 18 Feb 2010 17:00:47 GMT
Author: dejanb
Date: Thu Feb 18 17:00:46 2010
New Revision: 911492

URL: http://svn.apache.org/viewvc?rev=911492&view=rev
Log:
https://issues.apache.org/activemq/browse/AMQ-2617 - initial ws transport implementation

Added:
    activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/ws/
    activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/ws/StompServlet.java
    activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/ws/StompSocket.java
    activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/ws/WSTransportFactory.java
    activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/ws/WSTransportServer.java
    activemq/trunk/activemq-optional/src/main/resources/META-INF/services/org/apache/activemq/transport/ws
    activemq/trunk/activemq-optional/src/test/java/org/apache/activemq/transport/ws/
    activemq/trunk/activemq-optional/src/test/java/org/apache/activemq/transport/ws/WSTransportTest.java
Modified:
    activemq/trunk/activemq-optional/pom.xml

Modified: activemq/trunk/activemq-optional/pom.xml
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-optional/pom.xml?rev=911492&r1=911491&r2=911492&view=diff
==============================================================================
--- activemq/trunk/activemq-optional/pom.xml (original)
+++ activemq/trunk/activemq-optional/pom.xml Thu Feb 18 17:00:46 2010
@@ -94,6 +94,11 @@
       <artifactId>jetty-webapp</artifactId>
       <version>${jetty-version}</version>
     </dependency>
+    <dependency>
+        <groupId>org.eclipse.jetty</groupId>
+        <artifactId>jetty-websocket</artifactId>
+        <version>${jetty-version}</version>
+    </dependency>
     
     <dependency>
       <groupId>axis</groupId>

Added: activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/ws/StompServlet.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/ws/StompServlet.java?rev=911492&view=auto
==============================================================================
--- activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/ws/StompServlet.java
(added)
+++ activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/ws/StompServlet.java
Thu Feb 18 17:00:46 2010
@@ -0,0 +1,60 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.activemq.transport.ws;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.activemq.transport.TransportAcceptListener;
+import org.eclipse.jetty.websocket.WebSocket;
+import org.eclipse.jetty.websocket.WebSocketServlet;
+
+/**
+ * 
+ * Handle connection upgrade requests and creates web sockets
+ *
+ */
+public class StompServlet extends WebSocketServlet {
+
+    private static final long serialVersionUID = -4716657876092884139L;
+    
+    private TransportAcceptListener listener;
+    
+    public void init() throws ServletException {
+        super.init();
+        listener = (TransportAcceptListener)getServletContext().getAttribute("acceptListener");
+        if (listener == null) {
+            throw new ServletException("No such attribute 'acceptListener' available in the
ServletContext");
+        }
+    }
+
+    protected void doGet(HttpServletRequest request, HttpServletResponse response) 
+        throws ServletException ,IOException  {
+        getServletContext().getNamedDispatcher("default").forward(request,response);
+    }
+    
+    protected WebSocket doWebSocketConnect(HttpServletRequest request, String protocol) {
+        StompSocket socket = new StompSocket();
+        listener.onAccept(socket);
+        return socket;
+    }
+    
+}

Added: activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/ws/StompSocket.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/ws/StompSocket.java?rev=911492&view=auto
==============================================================================
--- activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/ws/StompSocket.java
(added)
+++ activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/ws/StompSocket.java
Thu Feb 18 17:00:46 2010
@@ -0,0 +1,94 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.transport.ws;
+
+import java.io.IOException;
+import java.security.cert.X509Certificate;
+
+import org.apache.activemq.command.Command;
+import org.apache.activemq.transport.TransportSupport;
+import org.apache.activemq.transport.stomp.LegacyFrameTranslator;
+import org.apache.activemq.transport.stomp.ProtocolConverter;
+import org.apache.activemq.transport.stomp.StompFrame;
+import org.apache.activemq.transport.stomp.StompTransport;
+import org.apache.activemq.transport.stomp.StompWireFormat;
+import org.apache.activemq.util.ByteSequence;
+import org.apache.activemq.util.IOExceptionSupport;
+import org.apache.activemq.util.ServiceStopper;
+import org.eclipse.jetty.websocket.WebSocket;
+
+/**
+ * 
+ * Implements web socket and mediates between servlet and the broker
+ *
+ */
+class StompSocket extends TransportSupport implements WebSocket, StompTransport {
+    Outbound outbound;
+    ProtocolConverter protocolConverter = new ProtocolConverter(this, new LegacyFrameTranslator(),
null);
+    StompWireFormat wireFormat = new StompWireFormat();
+
+    public void onConnect(Outbound outbound) {
+        this.outbound=outbound;
+    }
+    
+    public void onMessage(byte frame, byte[] data,int offset, int length) {}
+
+    public void onMessage(byte frame, String data) {
+        try {
+            protocolConverter.onStompCommand((StompFrame)wireFormat.unmarshal(new ByteSequence(data.getBytes())));
+        } catch (Exception e) {
+            onException(IOExceptionSupport.create(e));
+        }
+    }
+
+    public void onDisconnect() {
+    }
+
+    protected void doStart() throws Exception {
+    }
+
+    protected void doStop(ServiceStopper stopper) throws Exception {
+    }
+
+    public int getReceiveCounter() {
+        return 0;
+    }
+
+    public String getRemoteAddress() {
+        return "StompSocket_" + this.hashCode();
+    }
+
+    public void oneway(Object command) throws IOException {
+        try {
+            protocolConverter.onActiveMQCommand((Command)command);
+        } catch (Exception e) {
+            onException(IOExceptionSupport.create(e));
+        }
+    }
+
+    public X509Certificate[] getPeerCertificates() {
+        return null;
+    }
+
+    public void sendToActiveMQ(Command command) {
+        doConsume(command);
+    }
+
+    public void sendToStomp(StompFrame command) throws IOException {
+        outbound.sendMessage(WebSocket.SENTINEL_FRAME, command.toString());
+    }
+}

Added: activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/ws/WSTransportFactory.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/ws/WSTransportFactory.java?rev=911492&view=auto
==============================================================================
--- activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/ws/WSTransportFactory.java
(added)
+++ activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/ws/WSTransportFactory.java
Thu Feb 18 17:00:46 2010
@@ -0,0 +1,37 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.activemq.transport.ws;
+
+import java.io.IOException;
+import java.net.URI;
+
+import org.apache.activemq.transport.TransportFactory;
+import org.apache.activemq.transport.TransportServer;
+
+/**
+ * 
+ * Factory for WebSocket (ws) transport
+ *
+ */
+public class WSTransportFactory extends TransportFactory {
+
+    public TransportServer doBind(URI location) throws IOException {
+        return new WSTransportServer(location);
+    }
+
+}

Added: activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/ws/WSTransportServer.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/ws/WSTransportServer.java?rev=911492&view=auto
==============================================================================
--- activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/ws/WSTransportServer.java
(added)
+++ activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/ws/WSTransportServer.java
Thu Feb 18 17:00:46 2010
@@ -0,0 +1,106 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.activemq.transport.ws;
+
+import java.net.InetSocketAddress;
+import java.net.URI;
+
+import org.apache.activemq.command.BrokerInfo;
+import org.apache.activemq.transport.TransportServerSupport;
+import org.apache.activemq.util.ServiceStopper;
+import org.eclipse.jetty.server.Connector;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.bio.SocketConnector;
+import org.eclipse.jetty.server.handler.ContextHandler;
+import org.eclipse.jetty.server.session.SessionHandler;
+import org.eclipse.jetty.servlet.ServletHandler;
+import org.eclipse.jetty.servlet.ServletHolder;
+import org.eclipse.jetty.servlet.ServletMapping;
+
+/**
+ * Creates a web server and registers web socket server
+ *
+ */
+public class WSTransportServer extends TransportServerSupport {
+    
+    private URI bindAddress;
+    private Server server;
+    private Connector connector;
+    
+    public WSTransportServer(URI location) {
+        super(location);
+        this.bindAddress = location;
+    }
+
+    protected void doStart() throws Exception {
+        server = new Server();
+        if (connector == null) {
+            connector = new SocketConnector();
+        }
+        connector.setHost(bindAddress.getHost());
+        connector.setPort(bindAddress.getPort());
+        server.setConnectors(new Connector[] {
+                connector
+        });
+        
+        ContextHandler contextHandler = new ContextHandler();
+        contextHandler.setContextPath("/");
+        contextHandler.setServer(server);
+        server.setHandler(contextHandler);
+
+        SessionHandler sessionHandler = new SessionHandler();
+        contextHandler.setHandler(sessionHandler);
+
+        ServletHandler servletHandler = new ServletHandler();
+        sessionHandler.setHandler(servletHandler);
+        
+        ServletHolder holder = new ServletHolder();
+        holder.setName("WSStomp");
+        holder.setClassName(StompServlet.class.getName());
+        servletHandler.setServlets(new ServletHolder[] {
+            holder
+        });
+
+        ServletMapping mapping = new ServletMapping();
+        mapping.setServletName("WSStomp");
+        mapping.setPathSpec("/*");
+        servletHandler.setServletMappings(new ServletMapping[] {
+            mapping
+        });
+
+        contextHandler.setAttribute("acceptListener", getAcceptListener());
+        
+        server.start();
+    }
+
+    protected void doStop(ServiceStopper stopper) throws Exception {
+        Server temp = server;
+        server = null;
+        if (temp != null) {
+            temp.stop();
+        }
+    }
+
+    public InetSocketAddress getSocketAddress() {
+        return null;
+    }
+
+    public void setBrokerInfo(BrokerInfo brokerInfo) {
+    }
+
+}

Added: activemq/trunk/activemq-optional/src/main/resources/META-INF/services/org/apache/activemq/transport/ws
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-optional/src/main/resources/META-INF/services/org/apache/activemq/transport/ws?rev=911492&view=auto
==============================================================================
--- activemq/trunk/activemq-optional/src/main/resources/META-INF/services/org/apache/activemq/transport/ws
(added)
+++ activemq/trunk/activemq-optional/src/main/resources/META-INF/services/org/apache/activemq/transport/ws
Thu Feb 18 17:00:46 2010
@@ -0,0 +1,17 @@
+## ---------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements.  See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You under the Apache License, Version 2.0
+## (the "License"); you may not use this file except in compliance with
+## the License.  You may obtain a copy of the License at
+## 
+## http://www.apache.org/licenses/LICENSE-2.0
+## 
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+## ---------------------------------------------------------------------------
+class=org.apache.activemq.transport.ws.WSTransportFactory
\ No newline at end of file

Added: activemq/trunk/activemq-optional/src/test/java/org/apache/activemq/transport/ws/WSTransportTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-optional/src/test/java/org/apache/activemq/transport/ws/WSTransportTest.java?rev=911492&view=auto
==============================================================================
--- activemq/trunk/activemq-optional/src/test/java/org/apache/activemq/transport/ws/WSTransportTest.java
(added)
+++ activemq/trunk/activemq-optional/src/test/java/org/apache/activemq/transport/ws/WSTransportTest.java
Thu Feb 18 17:00:46 2010
@@ -0,0 +1,45 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.activemq.transport.ws;
+
+import java.net.URI;
+
+import org.apache.activemq.broker.BrokerFactory;
+import org.apache.activemq.broker.BrokerService;
+import org.junit.Test;
+
+
+public class WSTransportTest {
+    
+    protected String getBindLocation() {
+        return "ws://localhost:61614";
+    }
+
+    @Test
+    public void testBrokerStart() throws Exception {
+        BrokerService broker = BrokerFactory.createBroker(new URI("broker:()/localhost?persistent=false&useJmx=false"));
+        broker.addConnector(getBindLocation());
+        broker.start();
+        broker.waitUntilStarted();
+        Thread.sleep(2000);
+        //System.in.read();
+        broker.stop();
+        broker.waitUntilStopped();
+    }
+    
+}



Mime
View raw message