[jboss-svn-commits] JBL Code SVN: r33147 - in labs/jbossesb/trunk/product/rosetta: tests/src/org/jboss/soa/esb/notification and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri May 28 12:26:22 EDT 2010
Author: dward
Date: 2010-05-28 12:26:21 -0400 (Fri, 28 May 2010)
New Revision: 33147
Modified:
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/notification/NotifyTcp.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyTcpUnitTest.java
Log:
Fix for JBESB-3234 ( https://jira.jboss.org/browse/JBESB-3234 ).
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/notification/NotifyTcp.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/notification/NotifyTcp.java 2010-05-28 15:57:46 UTC (rev 33146)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/notification/NotifyTcp.java 2010-05-28 16:26:21 UTC (rev 33147)
@@ -19,9 +19,15 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
-
package org.jboss.soa.esb.notification;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.net.Socket;
+import java.net.URI;
+import java.net.URISyntaxException;
+
import org.apache.log4j.Logger;
import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.listeners.message.MessageDeliverException;
@@ -30,13 +36,6 @@
import org.jboss.soa.esb.message.body.content.BytesBody;
import org.jboss.soa.esb.message.format.MessageType;
-import java.io.IOException;
-import java.io.ObjectOutputStream;
-import java.io.OutputStream;
-import java.net.Socket;
-import java.net.URI;
-import java.net.URISyntaxException;
-
/**
* Send message via TCP. Each connection is maintained only for the duration of
* the notification.
@@ -56,11 +55,10 @@
public static final String PROTOCOL_TAG = "tcp";
- public static final int DEFAULT_PORT = 9090; // default port if none is
- // specified.
+ public static final int DEFAULT_PORT = 9090; // default port if none is specified.
/**
- * Instantiate a NotifyFiles object according to contents of <arg 1>
+ * Instantiate a NotifyTcp object according to contents of <arg 1>
*
* @param configTree
* ConfigTree - Should contain a nonempty set of child elements
@@ -103,29 +101,29 @@
}
sender = new Socket(destination.getHost(), port);
-
- if (MessageType.JAVA_SERIALIZED.equals(message.getType()))
+
+ Object obj = payloadProxy.getPayload(message);
+ if (obj != null)
{
- objectNotification(new ObjectOutputStream(sender
- .getOutputStream()), payloadProxy
- .getPayload(message));
+ if (MessageType.JAVA_SERIALIZED.equals(message.getType()))
+ {
+ // handle objects
+ objectNotification(new ObjectOutputStream(sender.getOutputStream()), obj);
+ }
+ else
+ {
+ if (obj instanceof byte[])
+ {
+ // handle raw bytes (JBESB-3234)
+ bytesNotification(sender.getOutputStream(), (byte[])obj);
+ }
+ else
+ {
+ // handle Strings and everything else
+ stringNotification(sender.getOutputStream(), obj.toString());
+ }
+ }
}
- else
- {
- Object obj = payloadProxy.getPayload(message);
- String content = null;
-
- if (obj instanceof byte[])
- {
- content = new String((byte[]) obj);
- }
- else
- {
- content = obj.toString();
- }
-
- stringNotification(sender.getOutputStream(), content);
- }
}
catch (IOException e)
{
@@ -151,7 +149,7 @@
if (exceptions.length() > 0)
throw new NotificationException(exceptions.toString());
- } // __________________________________
+ }
private void handleException (URI destination, Exception e,
StringBuilder exceptions)
@@ -163,23 +161,27 @@
exceptions.append(NotifyUtil.createExceptionErrorString(msg, e));
}
+
+ protected void objectNotification (ObjectOutputStream sender, Object p_o)
+ throws IOException
+ {
+ sender.writeObject(p_o);
+ sender.flush();
+ sender.close();
+ }
+
+ protected void bytesNotification (OutputStream sender, byte[] p_b)
+ throws IOException
+ {
+ sender.write(p_b);
+ sender.flush();
+ sender.close();
+ }
protected void stringNotification (OutputStream sender, String p_s)
throws IOException
{
- sender.write(p_s.getBytes());
- if (!p_s.endsWith("\n"))
- sender.write("\n".getBytes());
- sender.flush();
- sender.close();
- } // __________________________________
-
- protected void objectNotification (ObjectOutputStream sender, Object p_o)
- throws IOException
- {
- sender.writeObject(p_o);
- sender.flush();
- sender.close();
+ bytesNotification(sender, p_s.getBytes());
}
private void setDestinations (ConfigTree[] dests)
Modified: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyTcpUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyTcpUnitTest.java 2010-05-28 15:57:46 UTC (rev 33146)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyTcpUnitTest.java 2010-05-28 16:26:21 UTC (rev 33147)
@@ -34,7 +34,6 @@
/**
* NotifyTcp unit tests.
*/
-
public class NotifyTcpUnitTest extends TestCase
{
public static final String DATA = "Hello World";
@@ -80,17 +79,29 @@
}
catch (IllegalArgumentException e)
{
- fail();
+ fail(e.getMessage());
}
}
+
+ public void testSendString() throws Exception
+ {
+ // test with a String
+ send(DATA);
+ }
+
+ public void testSendBytes() throws Exception
+ {
+ // test with raw bytes (JBESB-3234)
+ send(DATA.getBytes());
+ }
- public void testSend () throws Exception
+ private void send(Object payload) throws Exception
{
try
{
ServerSocket sock = new ServerSocket(0);
int port = sock.getLocalPort();
- Sender sender = new Sender(port);
+ Sender sender = new Sender(port, payload);
sender.start();
@@ -109,25 +120,25 @@
String receivedString = new String(data);
- if (!receivedString.startsWith(DATA))
+ if (!receivedString.equals(DATA))
{
- System.err.println("Did not receive correct data: "
- + receivedString);
-
- fail();
+ String e = "Did not receive correct data: " + receivedString;
+ System.err.println(e);
+ fail(e);
}
}
catch (IllegalArgumentException e)
{
- fail();
+ fail(e.getMessage());
}
}
- class Sender extends Thread
+ private static class Sender extends Thread
{
- public Sender(int s)
+ private Sender(int s, Object payload)
{
_port = s;
+ _payload = payload;
}
public void run ()
@@ -141,7 +152,7 @@
Message msg = MessageFactory.getInstance().getMessage();
- msg.getBody().add(DATA);
+ msg.getBody().add(_payload);
NotifyTcp test = new NotifyTcp(rootEl);
@@ -154,5 +165,6 @@
}
private int _port;
+ private Object _payload;
}
}
\ No newline at end of file
More information about the jboss-svn-commits
mailing list