[jboss-svn-commits] JBL Code SVN: r7739 - labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Nov 21 11:07:07 EST 2006
Author: estebanschifman
Date: 2006-11-21 11:07:03 -0500 (Tue, 21 Nov 2006)
New Revision: 7739
Added:
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/FileCourier.java
Modified:
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/TwoWayCourierImpl.java
Log:
New FileCourier class
Added: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/FileCourier.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/FileCourier.java 2006-11-21 14:03:42 UTC (rev 7738)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/FileCourier.java 2006-11-21 16:07:03 UTC (rev 7739)
@@ -0,0 +1,133 @@
+/*
+ * 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;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.addressing.eprs.FileEpr;
+import org.jboss.soa.esb.couriers.CourierException;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.util.Util;
+
+public class FileCourier implements PickUpOnlyCourier, DeliverOnlyCourier
+{
+ /**
+ * disable default constructor
+ */
+ private FileCourier() { }
+
+ /**
+ * package protected constructor - Objects of Courier should only be instantiated by the Factory
+ * @param epr
+ */
+ FileCourier(FileEpr epr) throws CourierException { this(epr,false); }
+
+ /**
+ * package protected constructor - Objects of Courier should only be instantiated by the Factory
+ * @param epr
+ */
+ FileCourier(FileEpr epr, boolean isReceiver) throws CourierException
+ {
+ _isReceiver = isReceiver;
+ _epr = epr;
+ try
+ {
+ _directory = new File(epr.getURL().getFile());
+ if (! _directory.isDirectory())
+ throw new CourierException("URL for a File EPR must be a directory");
+
+ if (_isReceiver)
+ checkRead();
+ else
+ checkWrite();
+
+ }
+ catch(MalformedURLException e) { throw new CourierException(e); }
+ catch(URISyntaxException e) { throw new CourierException(e); }
+ } //________________________________
+
+
+ private void checkRead () throws CourierException
+ {
+ if (! _directory.canRead())
+ throw new CourierException("Can't read directory "+_directory.toString());
+ }
+
+ private void checkWrite () throws CourierException
+ {
+ if (! _directory.canWrite())
+ throw new CourierException("Can't write in directory "+_directory.toString());
+ }
+
+ /**
+ * package the ESB message in a File
+ * @param message Message - the message to deliver
+ * @return boolean - the result of the delivery
+ * @throws CourierException - if problems were encountered
+ */
+ public boolean deliver(Message message) throws CourierException
+ {
+ if (_isReceiver)
+ throw new CourierException("This is a read-only Courier");
+
+ if (null==message)
+ return false;
+
+ try
+ {
+
+ String messageId = message.getHeader().getCall().getMessageID().toString();
+ File outFile = new File(_directory,messageId);
+ ObjectOutputStream stream = new ObjectOutputStream(new FileOutputStream(outFile));
+ stream.writeObject(Util.serialize(message));
+ stream.close();
+ return true;
+ }
+ catch (MalformedURLException e) { throw new CourierException(e); }
+ catch (URISyntaxException e) { throw new CourierException(e); }
+ catch (IOException e) { throw new CourierException(e); }
+ catch (ParserConfigurationException e) { throw new CourierException(e); }
+ } //________________________________
+
+ public Message pickup(long millis) throws CourierException
+ {
+ if (! _isReceiver)
+ throw new CourierException("This is an outgoing-only Courier");
+
+ return null;
+ } //________________________________
+
+ protected boolean _isReceiver;
+ protected FileEpr _epr;
+ protected File _directory;
+ protected Logger _logger = Logger.getLogger(FileCourier.class);
+
+} //____________________________________________________________________________
Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/TwoWayCourierImpl.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/TwoWayCourierImpl.java 2006-11-21 14:03:42 UTC (rev 7738)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/TwoWayCourierImpl.java 2006-11-21 16:07:03 UTC (rev 7739)
@@ -26,6 +26,7 @@
import java.lang.reflect.Method;
import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.eprs.FileEpr;
import org.jboss.soa.esb.addressing.eprs.JMSEpr;
import org.jboss.soa.esb.couriers.CourierException;
import org.jboss.soa.esb.couriers.CourierTimeoutException;
@@ -78,6 +79,9 @@
return null;
if (toEPR instanceof JMSEpr)
return new JmsCourier((JMSEpr)toEPR);
+ if (toEPR instanceof FileEpr)
+ return new FileCourier((FileEpr)toEPR);
+
throw new CourierException ("Deliver courier for "+toEPR.getClass().getSimpleName()+" not supported yet");
}
@@ -87,8 +91,11 @@
return null;
if (replyToEPR instanceof JMSEpr)
return new JmsCourier((JMSEpr)replyToEPR,true);
+ if (replyToEPR instanceof FileEpr)
+ return new FileCourier((FileEpr)replyToEPR,true);
throw new CourierException ("Couriers for "+replyToEPR.getClass().getSimpleName()+" not supported yet");
}
+
/**
* @see org.jboss.soa.esb.couriers.Courier#deliver(Message message).
*/
More information about the jboss-svn-commits
mailing list