[jboss-svn-commits] JBL Code SVN: r8310 - in labs/jbossesb/trunk/product/core: listeners/src/org/jboss/soa/esb/listeners/config rosetta/src/org/jboss/internal/soa/esb/addressing/helpers rosetta/src/org/jboss/internal/soa/esb/message/format/serialized rosetta/src/org/jboss/internal/soa/esb/message/format/xml rosetta/src/org/jboss/soa/esb/addressing rosetta/src/org/jboss/soa/esb/couriers rosetta/tests/src/org/jboss/internal/soa/esb/couriers/tests
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Dec 14 05:18:40 EST 2006
Author: mark.little at jboss.com
Date: 2006-12-14 05:18:29 -0500 (Thu, 14 Dec 2006)
New Revision: 8310
Added:
labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/internal/soa/esb/couriers/tests/CourierUtilUnitTest.java
Modified:
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/YADOMUtil.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/helpers/CallHelper.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/HeaderImpl.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/HeaderImpl.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/Call.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierUtil.java
Log:
Added CourierUtil test and fixed bug in serialization of Call.
Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/YADOMUtil.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/YADOMUtil.java 2006-12-14 03:22:44 UTC (rev 8309)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/YADOMUtil.java 2006-12-14 10:18:29 UTC (rev 8310)
@@ -35,67 +35,96 @@
import org.w3c.dom.Node;
/**
- * Yet another set of DOM utility methods.
+ * Yet another set of DOM utility methods.
+ *
* @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
*/
-class YADOMUtil {
+class YADOMUtil
+{
- // If there are another set of the same utilities somewhere, or another DOMUtil type class
+ // If there are another set of the same utilities somewhere, or another
+ // DOMUtil type class
// that we can add them too, we should do that :-)
-
+
/**
- * Create a new W3C Document.
- * <p/>
- * Handles exceptions etc.
+ * Create a new W3C Document. <p/> Handles exceptions etc.
+ *
* @return The new Document instance.
- * @throws ConfigurationException
+ * @throws ConfigurationException
*/
- protected static Document createDocument() throws ConfigurationException {
+ protected static Document createDocument() throws ConfigurationException
+ {
Document doc = null;
-
- try {
- doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
- } catch (ParserConfigurationException e) {
- throw new ConfigurationException("Failed to create ESB Configuration Document instance.", e);
+
+ try
+ {
+ doc = DocumentBuilderFactory.newInstance().newDocumentBuilder()
+ .newDocument();
}
-
+ catch (ParserConfigurationException e)
+ {
+ throw new ConfigurationException(
+ "Failed to create ESB Configuration Document instance.", e);
+ }
+
return doc;
}
/**
* Add an Element node to the supplied parent name.
- * @param parent The parent to to which the new Element node is to be added.
- * @param elementName The name of the Element to be added.
+ *
+ * @param parent
+ * The parent to to which the new Element node is to be added.
+ * @param elementName
+ * The name of the Element to be added.
* @return The new Element.
*/
- protected static Element addElement(Node parent, String elementName) {
+ protected static Element addElement(Node parent, String elementName)
+ {
Element element = null;
-
- if(parent instanceof Document) {
- element = ((Document)parent).createElement(elementName);
- } else {
+
+ if (parent instanceof Document)
+ {
+ element = ((Document) parent).createElement(elementName);
+ }
+ else
+ {
element = parent.getOwnerDocument().createElement(elementName);
}
parent.appendChild(element);
-
+
return element;
}
/**
- * Serialize the supplied Document to the specified file in the specified output directory.
- * @param doc The document to be serialised.
- * @param outdir The directory into which the file is to be serialised.
- * @param fileName The name of the file.
- * @throws ConfigurationException Unable to serialise the document.
+ * Serialize the supplied Document to the specified file in the specified
+ * output directory.
+ *
+ * @param doc
+ * The document to be serialised.
+ * @param outdir
+ * The directory into which the file is to be serialised.
+ * @param fileName
+ * The name of the file.
+ * @throws ConfigurationException
+ * Unable to serialise the document.
*/
- protected static void serialize(Document doc, File outdir, String fileName) throws ConfigurationException {
+ protected static void serialize(Document doc, File outdir, String fileName)
+ throws ConfigurationException
+ {
DOMSource domSource = new DOMSource(doc);
StreamResult streamRes = new StreamResult(new File(outdir, fileName));
-
- try {
- TransformerFactory.newInstance().newTransformer().transform(domSource, streamRes);
- } catch (Exception e) {
- throw new ConfigurationException("Failed to serialize ESB Configuration Document instance.", e);
+
+ try
+ {
+ TransformerFactory.newInstance().newTransformer().transform(
+ domSource, streamRes);
}
+ catch (Exception e)
+ {
+ throw new ConfigurationException(
+ "Failed to serialize ESB Configuration Document instance.",
+ e);
+ }
}
}
Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/helpers/CallHelper.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/helpers/CallHelper.java 2006-12-14 03:22:44 UTC (rev 8309)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/helpers/CallHelper.java 2006-12-14 10:18:29 UTC (rev 8310)
@@ -80,14 +80,14 @@
if (call.getAction() != null)
{
Element actionElement = doc.createElementNS(XMLUtil.WSA_NAMESPACE_URI, XMLUtil.WSA_PREFIX+":"+XMLUtil.ACTION_TAG);
- actionElement.setNodeValue(call.getAction().toString());
+ actionElement.setTextContent(call.getAction().toString());
header.appendChild(actionElement);
}
if (call.getMessageID() != null)
{
Element messageIDElement = doc.createElementNS(XMLUtil.WSA_NAMESPACE_URI, XMLUtil.WSA_PREFIX+":"+XMLUtil.MESSAGE_IDENTIFIER_TAG);
- messageIDElement.setNodeValue(call.getMessageID().toString());
+ messageIDElement.setTextContent(call.getMessageID().toString());
header.appendChild(messageIDElement);
}
@@ -107,6 +107,9 @@
{
Call call = null;
+ if (header == null)
+ throw new IllegalArgumentException();
+
try
{
call = new Call();
@@ -181,7 +184,7 @@
{
try
{
- call.setAction(new URI(n.getNodeValue()));
+ call.setAction(new URI(n.getTextContent()));
}
catch (Exception ex)
{
@@ -193,7 +196,7 @@
{
try
{
- call.setMessageID(new URI(n.getNodeValue()));
+ call.setMessageID(new URI(n.getTextContent()));
}
catch (Exception ex)
{
Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/HeaderImpl.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/HeaderImpl.java 2006-12-14 03:22:44 UTC (rev 8309)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/HeaderImpl.java 2006-12-14 10:18:29 UTC (rev 8310)
@@ -21,11 +21,27 @@
* @author mark.little at jboss.com
*/
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
import java.io.Serializable;
+import java.io.StringWriter;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.jboss.internal.soa.esb.addressing.helpers.CallHelper;
import org.jboss.soa.esb.addressing.Call;
+import org.jboss.soa.esb.addressing.XMLUtil;
import org.jboss.soa.esb.message.Header;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.xml.sax.SAXException;
+import com.sun.org.apache.xml.internal.serialize.OutputFormat;
+import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
+
/**
* The message header. Contains such things as routing information.
*/
@@ -34,9 +50,11 @@
{
private static final long serialVersionUID = 0x0;
+ public static final String HEADER_TAG = "Header";
+
public HeaderImpl ()
{
- _call = null;
+ _call = new Call();
}
// TODO add other setters/getters for artibitrary attributes
@@ -54,5 +72,69 @@
_call = call;
}
+ /*
+ * Call and PortReference aren't Serializable so we have to do some
+ * magic.
+ */
+
+ private void writeObject(java.io.ObjectOutputStream out) throws IOException
+ {
+ if (_call != null)
+ {
+ try
+ {
+ Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
+ Element header = doc.createElement(HEADER_TAG);
+
+ doc.appendChild(header);
+
+ header = CallHelper.toXML(_call, doc, header);
+
+ StringWriter sWriter = new StringWriter();
+ OutputFormat format = new OutputFormat();
+ format.setIndenting(true);
+ XMLSerializer xmlS = new XMLSerializer(sWriter, format);
+ xmlS.asDOMSerializer();
+ xmlS.serialize(doc);
+
+ out.writeObject(sWriter.toString());
+ }
+ catch (ParserConfigurationException ex)
+ {
+ ex.printStackTrace();
+
+ throw new IOException(ex.toString());
+ }
+ }
+ }
+
+ private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException
+ {
+ try
+ {
+ String header = (String) in.readObject();
+ InputStream inStream = new ByteArrayInputStream(header.getBytes());
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document doc = builder.parse(inStream);
+
+ Element headerElement = doc.getDocumentElement();
+
+ _call = CallHelper.fromXML(headerElement);
+ }
+ catch (ParserConfigurationException ex)
+ {
+ ex.printStackTrace();
+
+ throw new IOException(ex.toString());
+ }
+ catch (SAXException ex)
+ {
+ ex.printStackTrace();
+
+ throw new IOException(ex.toString());
+ }
+ }
+
private Call _call;
}
\ No newline at end of file
Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/HeaderImpl.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/HeaderImpl.java 2006-12-14 03:22:44 UTC (rev 8309)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/HeaderImpl.java 2006-12-14 10:18:29 UTC (rev 8310)
@@ -39,7 +39,7 @@
public HeaderImpl ()
{
- _call = null;
+ _call = new Call();
}
// TODO add other setters/getters for artibitrary attributes
Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/Call.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/Call.java 2006-12-14 03:22:44 UTC (rev 8309)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/Call.java 2006-12-14 10:18:29 UTC (rev 8310)
@@ -218,6 +218,17 @@
return _messageID;
}
+ public final boolean empty ()
+ {
+ if ((_to == null) && (_from == null) && (_replyTo == null))
+ {
+ if ((_relatesTo == null) && (_faultTo == null) && (_action == null) && (_messageID == null))
+ return true;
+ }
+
+ return false;
+ }
+
/**
* Copy the instance specified.
*
@@ -243,7 +254,7 @@
public String toString ()
{
- return "To: "+_to+" From: "+_from+" ReplyTo: "+_replyTo+" FaultTo: "+_faultTo+" Action: "+_action;
+ return "To: "+_to+" From: "+_from+" ReplyTo: "+_replyTo+" FaultTo: "+_faultTo+" Action: "+_action+" MessagdID: "+_messageID;
}
/**
Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierUtil.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierUtil.java 2006-12-14 03:22:44 UTC (rev 8309)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierUtil.java 2006-12-14 10:18:29 UTC (rev 8310)
@@ -50,74 +50,92 @@
public class CourierUtil
{
public static final String CORRELATION_ID_TAG = "messageCorrelationId";
-
- private CourierUtil() {}
-
- public static List<KeyValuePair> propertiesFromSelector(String selector) throws Exception
- {
+
+ private CourierUtil()
+ {
+ }
+
+ public static List<KeyValuePair> propertiesFromSelector(String selector)
+ throws Exception
+ {
// No problem if selector is null - everything in queue will be returned
List<KeyValuePair> oRet = new ArrayList<KeyValuePair>();
- if (! Util.isNullString(selector))
+ if (!Util.isNullString(selector))
{
- for (String sCurr : selector.split(",")) {
+ for (String sCurr : selector.split(","))
+ {
String[] sa = sCurr.split("=");
- if (sa.length!=2
- || sa[1].charAt(0)!='\''
- || sa[1].charAt(-1+sa[1].length())!='\'')
- throw new Exception("Illegal message selector syntax <"+selector+">");
- KeyValuePair oNew = new KeyValuePair
- (sa[0],sa[1].substring(0,-1+sa[1].length()).substring(1));
+ if (sa.length != 2 || sa[1].charAt(0) != '\''
+ || sa[1].charAt(-1 + sa[1].length()) != '\'')
+ throw new Exception("Illegal message selector syntax <"
+ + selector + ">");
+ KeyValuePair oNew = new KeyValuePair(sa[0], sa[1].substring(0,
+ -1 + sa[1].length()).substring(1));
oRet.add(oNew);
}
- }
+ }
return oRet;
- }
- /**
- * We will be listening the same queue, but with a 'temporary' message selector
- * based of a UUID.
- *
- * @param message to which we ill add the CORRELATION_ID_TAG.
- * @return the generated unique reply selector.
- */
+ }
+
+ /**
+ * We will be listening the same queue, but with a 'temporary' message
+ * selector based of a UUID.
+ *
+ * @param message
+ * to which we ill add the CORRELATION_ID_TAG.
+ * @return the generated unique reply selector.
+ */
public static String getReplySelector()
{
- String uuId = UUID.randomUUID().toString();
- String uniqueReplySelector = new StringBuilder()
- .append(CORRELATION_ID_TAG).append("='")
- .append(uuId).append("'").toString();
- return uniqueReplySelector;
+ String uuId = UUID.randomUUID().toString();
+ String uniqueReplySelector = new StringBuilder().append(
+ CORRELATION_ID_TAG).append("='").append(uuId).append("'")
+ .toString();
+ return uniqueReplySelector;
}
-
- /**
- * Build a temporary replyToEPR, based on the toEpr, to which we can reply to.
- * <ul>
- * <li> for JMS we will use the toEpr, but change the message selector.
- * </ul>
- *
- * @param toEpr - the toEPR which will be used a basis to generate the replyToEPR.
- * @return replyToEPR - the EPR to which the pickup will be delivered.
- * @throws URISyntaxException, CourierException
- */
- public static EPR getTemporaryReplyToEpr(EPR toEpr) throws URISyntaxException, CourierException
- {
- EPR replyToEpr = null;
- if (toEpr instanceof JMSEpr) {
- JMSEpr jpr = (JMSEpr) toEpr;
- //Setting the replyTo to the queue we specific in the epr we are going to call
- //The selectors will do the job.
- replyToEpr = new JMSEpr(jpr.getDestinationType(), jpr.getDestinationName()
- ,jpr.getConnectionFactory() ,jpr.getJndiURL(), jpr.getJndiContextFactory()
- ,jpr.getJndiPkgPrefix(), getReplySelector());
- } else {
- throw new CourierException("Found a non-JMS based EPR, JMS-EPRs is all we support right now");
- }
- return replyToEpr;
- }
-
+
+ /**
+ * Build a temporary replyToEPR, based on the toEpr, to which we can reply
+ * to.
+ * <ul>
+ * <li> for JMS we will use the toEpr, but change the message selector.
+ * </ul>
+ *
+ * @param toEpr -
+ * the toEPR which will be used a basis to generate the
+ * replyToEPR.
+ * @return replyToEPR - the EPR to which the pickup will be delivered.
+ * @throws URISyntaxException,
+ * CourierException
+ */
+ public static EPR getTemporaryReplyToEpr(EPR toEpr)
+ throws URISyntaxException, CourierException
+ {
+ EPR replyToEpr = null;
+ if (toEpr instanceof JMSEpr)
+ {
+ JMSEpr jpr = (JMSEpr) toEpr;
+ // Setting the replyTo to the queue we specific in the epr we are
+ // going to call
+ // The selectors will do the job.
+ replyToEpr = new JMSEpr(jpr.getDestinationType(), jpr
+ .getDestinationName(), jpr.getConnectionFactory(), jpr
+ .getJndiURL(), jpr.getJndiContextFactory(), jpr
+ .getJndiPkgPrefix(), getReplySelector());
+ }
+ else
+ {
+ throw new CourierException(
+ "Found a non-JMS based EPR, JMS-EPRs is all we support right now");
+ }
+ return replyToEpr;
+ }
+
public static File messageToLocalFile(File directory, Message message)
- throws IOException, ParserConfigurationException
+ throws IOException, ParserConfigurationException
{
- File tmpFile = File.createTempFile("EsbFileCourier_", ".__esbPart",directory);
+ File tmpFile = File.createTempFile("EsbFileCourier_", ".__esbPart",
+ directory);
Serializable serial = Util.serialize(message);
FileOutputStream writer = null;
try
@@ -125,46 +143,52 @@
writer = new FileOutputStream(tmpFile);
new ObjectOutputStream(writer).writeObject(serial);
}
- finally
+ finally
{
- if (null!=writer)
- writer.close();
+ if (null != writer)
+ writer.close();
}
return tmpFile;
}
public static Message messageFromLocalFile(File from)
- throws FileNotFoundException,IOException,ClassNotFoundException, ClassCastException
- ,ParserConfigurationException, SAXException , CourierException
+ throws FileNotFoundException, IOException, ClassNotFoundException,
+ ClassCastException, ParserConfigurationException, SAXException,
+ CourierException
{
FileInputStream reader = null;
Serializable serial = null;
try
- {
+ {
reader = new FileInputStream(from);
- serial = (Serializable)new ObjectInputStream(reader).readObject();
+ serial = (Serializable) new ObjectInputStream(reader).readObject();
Message msg = Util.deserialize(serial);
URI msgId = msg.getHeader().getCall().getMessageID();
- if (null==msgId || Util.isNullString(msgId.toString()))
+ if (null == msgId || Util.isNullString(msgId.toString()))
{
- // TODO this should not happen - Serialization/Deserialization perhaps ??
+ // TODO this should not happen - Serialization/Deserialization
+ // perhaps ??
String sId = from.getName();
int iDot = sId.indexOf(".");
- URI fileUri = new URI((iDot<0)?sId:sId.substring(0,iDot));
+ URI fileUri = new URI((iDot < 0) ? sId : sId.substring(0, iDot));
msg.getHeader().getCall().setMessageID(fileUri);
}
return msg;
}
- catch (Exception e) { throw new CourierException(e); }
- finally
+ catch (Exception e)
{
- if (null!=reader)
- reader.close();
+ e.printStackTrace();
+
+ throw new CourierException(e);
}
+ finally
+ {
+ if (null != reader)
+ reader.close();
+ }
}
-
- public static byte[] bytesFromLocalFile(File from)
- throws IOException
+
+ public static byte[] bytesFromLocalFile(File from) throws IOException
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
FileInputStream in = new FileInputStream(from);
@@ -172,41 +196,43 @@
int iQ = 0;
try
{
- while ((iQ=in.read(buff))>=0)
- if (iQ>0)
- out.write(buff,0,iQ);
+ while ((iQ = in.read(buff)) >= 0)
+ if (iQ > 0)
+ out.write(buff, 0, iQ);
}
finally
{
- if (null!=in) in.close();
- if (null!=out) out.close();
+ if (null != in)
+ in.close();
+ if (null != out)
+ out.close();
}
return out.toByteArray();
}
-
+
public static void bytesToLocalFile(byte[] bytes, File to)
- throws IOException
+ throws IOException
{
FileOutputStream out = null;
try
{
- out =new FileOutputStream(to);
+ out = new FileOutputStream(to);
out.write(bytes);
}
- finally
+ finally
{
- if (null!=out)
- out.close();
+ if (null != out)
+ out.close();
}
}
-
+
public static void deliverMessage(Message message)
- throws URISyntaxException, CourierException
+ throws URISyntaxException, CourierException
{
EPR toEpr = message.getHeader().getCall().getTo();
Courier courier = CourierFactory.getCourier(toEpr);
courier.deliver(message);
}
-
+
protected static Logger _logger = Logger.getLogger(CourierUtil.class);
}
Added: labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/internal/soa/esb/couriers/tests/CourierUtilUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/internal/soa/esb/couriers/tests/CourierUtilUnitTest.java 2006-12-14 03:22:44 UTC (rev 8309)
+++ labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/internal/soa/esb/couriers/tests/CourierUtilUnitTest.java 2006-12-14 10:18:29 UTC (rev 8310)
@@ -0,0 +1,96 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * 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.internal.soa.esb.couriers.tests;
+
+import java.io.File;
+import java.net.URI;
+
+import junit.framework.Assert;
+import junit.framework.JUnit4TestAdapter;
+
+import org.jboss.internal.soa.esb.couriers.helpers.FileHandlerFactory;
+import org.jboss.internal.soa.esb.couriers.helpers.FtpFileHandler;
+import org.jboss.soa.esb.addressing.eprs.FTPEpr;
+import org.jboss.soa.esb.addressing.eprs.HTTPEpr;
+import org.jboss.soa.esb.common.tests.BaseTest;
+import org.jboss.soa.esb.couriers.CourierException;
+import org.jboss.soa.esb.couriers.CourierUtil;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.message.format.MessageType;
+import org.junit.Test;
+
+/**
+ * Tests for internal FtpFileHandler class
+ *
+ * @since Version 4.0
+ *
+ */
+public class CourierUtilUnitTest extends BaseTest
+{
+ public static junit.framework.Test suite()
+ {
+ return new JUnit4TestAdapter(CourierUtilUnitTest.class);
+ }
+
+ @Test
+ public void testMessageToFile () throws Exception
+ {
+ Message msg1 = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+
+ msg1.getBody().add("foo", "bar");
+ msg1.getHeader().getCall().setTo(new HTTPEpr("http://foo.bar"));
+ msg1.getHeader().getCall().setMessageID(new URI("urn:1234"));
+
+ System.err.println("Saving: "+msg1.getHeader().getCall());
+
+ File f = CourierUtil.messageToLocalFile(new File("."), msg1);
+
+ f.delete();
+ }
+
+ @Test
+ public void testMessageFromFile () throws Exception
+ {
+ Message msg1 = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+
+ msg1.getBody().add("foo", "bar");
+ msg1.getHeader().getCall().setTo(new HTTPEpr("http://foo.bar"));
+ msg1.getHeader().getCall().setMessageID(new URI("urn:1234"));
+
+ File theFile = new File(".");
+ File tmpFile = CourierUtil.messageToLocalFile(theFile, msg1);
+
+ Message msg2 = CourierUtil.messageFromLocalFile(tmpFile);
+
+ System.err.println("Restored: "+msg2.getHeader().getCall());
+
+ tmpFile.delete();
+
+ Assert.assertNotNull(msg2);
+ Assert.assertEquals(msg2.getBody().get("foo"), "bar");
+ Assert.assertEquals(msg2.getHeader().getCall().getTo().toString(), "EPR: PortReference < http://foo.bar >");
+ Assert.assertEquals(msg2.getHeader().getCall().getMessageID().toString(), "urn:1234");
+ }
+
+}
More information about the jboss-svn-commits
mailing list