From fdff838d78702be9cd00ac67b93b2812d717be7c Mon Sep 17 00:00:00 2001 From: Howard Gao Date: Mon, 9 Mar 2015 10:48:26 +0800 Subject: [PATCH] Improve jms/Stomp example - add receiving stomp response from server. --- .../activemq/jms/example/StompExample.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/examples/jms/stomp/src/main/java/org/apache/activemq/jms/example/StompExample.java b/examples/jms/stomp/src/main/java/org/apache/activemq/jms/example/StompExample.java index bd3f84a3d2..048be827f7 100644 --- a/examples/jms/stomp/src/main/java/org/apache/activemq/jms/example/StompExample.java +++ b/examples/jms/stomp/src/main/java/org/apache/activemq/jms/example/StompExample.java @@ -16,6 +16,7 @@ */ package org.apache.activemq.jms.example; +import java.io.InputStream; import java.io.OutputStream; import java.net.Socket; import java.nio.charset.StandardCharsets; @@ -28,6 +29,7 @@ import javax.jms.Session; import javax.jms.TextMessage; import javax.naming.InitialContext; + import org.apache.activemq.common.example.ActiveMQExample; /** @@ -65,6 +67,8 @@ public class StompExample extends ActiveMQExample END_OF_FRAME; sendFrame(socket, connectFrame); + readFrame(socket); + // Step 3. Send a SEND frame (a Stomp message) to the // jms.queue.exampleQueue address with a text body String text = "Hello, world from Stomp!"; @@ -133,4 +137,16 @@ public class StompExample extends ActiveMQExample outputStream.flush(); } + private static String readFrame(Socket socket) throws Exception + { + byte[] bytes = new byte[2048]; + InputStream inputStream = socket.getInputStream(); + int nbytes = inputStream.read(bytes); + byte[] data = new byte[nbytes]; + System.arraycopy(bytes, 0, data, 0, data.length); + String resp = new String(data, "UTF-8"); + System.out.println("Got response from server: " + resp); + return resp; + } + }