camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r772605 - in /camel/trunk/components/camel-quickfix: ./ src/main/java/org/apache/camel/component/quickfix/ src/main/java/org/apache/camel/component/quickfix/converter/ src/main/java/org/apache/camel/component/quickfix/example/ src/main/reso...
Date Thu, 07 May 2009 10:47:40 GMT
Author: ningjiang
Date: Thu May  7 10:47:39 2009
New Revision: 772605

URL: http://svn.apache.org/viewvc?rev=772605&view=rev
Log:
CAMEL-1350 refactoring camel-quickfix component

Added:
    camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/converter/QuickFixConverter.java
  (contents, props changed)
      - copied, changed from r772503, camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/converter/Exchange2Message.java
    camel/trunk/components/camel-quickfix/src/test/java/org/apache/camel/component/quickfix/example/
  (props changed)
      - copied from r772503, camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/example/
Removed:
    camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/converter/Exchange2Message.java
    camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/example/
    camel/trunk/components/camel-quickfix/src/main/resources/examples/
    camel/trunk/components/camel-quickfix/src/main/resources/log4j.properties
Modified:
    camel/trunk/components/camel-quickfix/pom.xml
    camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/QuickfixAcceptor.java
    camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/QuickfixApplication.java
    camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/QuickfixConsumer.java
    camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/QuickfixEndpoint.java
    camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/QuickfixInitiator.java
    camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/QuickfixProcessor.java
    camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/QuickfixProducer.java
    camel/trunk/components/camel-quickfix/src/test/java/org/apache/camel/component/quickfix/example/PassiveFixGateway.java

Modified: camel/trunk/components/camel-quickfix/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-quickfix/pom.xml?rev=772605&r1=772604&r2=772605&view=diff
==============================================================================
--- camel/trunk/components/camel-quickfix/pom.xml (original)
+++ camel/trunk/components/camel-quickfix/pom.xml Thu May  7 10:47:39 2009
@@ -51,11 +51,7 @@
 			<groupId>commons-logging</groupId>
 			<artifactId>commons-logging</artifactId>
 		</dependency>
-		<dependency>
-			<groupId>log4j</groupId>
-			<artifactId>log4j</artifactId>
-		</dependency>
-
+		
 		<dependency>
 			<groupId>org.quickfixj</groupId>
 			<artifactId>quickfixj-all</artifactId>
@@ -75,12 +71,7 @@
 			<groupId>org.springframework</groupId>
 			<artifactId>spring-test</artifactId>
 			<scope>test</scope>
-		</dependency>
-		<dependency>
-			<groupId>org.apache.camel</groupId>
-			<artifactId>camel-spring-javaconfig</artifactId>
-			<scope>test</scope>
-		</dependency>
+		</dependency>		
 
 		<dependency>
 			<groupId>junit</groupId>

Modified: camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/QuickfixAcceptor.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/QuickfixAcceptor.java?rev=772605&r1=772604&r2=772605&view=diff
==============================================================================
--- camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/QuickfixAcceptor.java
(original)
+++ camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/QuickfixAcceptor.java
Thu May  7 10:47:39 2009
@@ -20,6 +20,7 @@
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.impl.DefaultComponent;
+import org.apache.commons.logging.Log;
 import quickfix.Application;
 import quickfix.ConfigError;
 import quickfix.DefaultMessageFactory;
@@ -36,12 +37,13 @@
  * @author Anton Arhipov
  */
 public class QuickfixAcceptor extends DefaultComponent {
-
+    private static final Log LOG = org.apache.commons.logging.LogFactory.getLog(QuickfixAcceptorEndpoint.class);
+    
     protected QuickfixEndpoint createEndpoint(String uri, String remaining, Map parameters)
throws Exception {
         return new QuickfixAcceptorEndpoint(uri, getCamelContext(), remaining);
     }
 
-    class QuickfixAcceptorEndpoint extends QuickfixEndpoint {
+    class QuickfixAcceptorEndpoint extends QuickfixEndpoint {        
 
         private/* Threaded */SocketAcceptor acceptor;
 
@@ -51,7 +53,8 @@
 
         protected void start(Application application, MessageStoreFactory storeFactory,
                              SessionSettings settings, LogFactory logFactory) throws ConfigError
{
-
+                        // To avoid this exception in OSGi platform
+            // java.lang.NoClassDefFoundError: quickfix/fix41/MessageFactory
             ClassLoader ccl = Thread.currentThread().getContextClassLoader();
             try {
                 Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
@@ -60,6 +63,9 @@
                                               new DefaultMessageFactory());
 
                 acceptor.start();
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Start the accetpor endpoint");
+                }
             } finally {
                 Thread.currentThread().setContextClassLoader(ccl);
             }
@@ -70,6 +76,9 @@
             super.stop();
             if (acceptor != null) {
                 acceptor.stop();
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Stop the accetpor endpoint");
+                }
                 acceptor = null;
             }
         }

Modified: camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/QuickfixApplication.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/QuickfixApplication.java?rev=772605&r1=772604&r2=772605&view=diff
==============================================================================
--- camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/QuickfixApplication.java
(original)
+++ camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/QuickfixApplication.java
Thu May  7 10:47:39 2009
@@ -16,7 +16,9 @@
  */
 package org.apache.camel.component.quickfix;
 
-import org.apache.log4j.Logger;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 import quickfix.Application;
 import quickfix.DoNotSend;
 import quickfix.FieldNotFound;
@@ -35,7 +37,7 @@
  */
 public class QuickfixApplication implements Application {
 
-    private static final Logger LOG = Logger.getLogger(QuickfixApplication.class);
+    private static final Log LOG = LogFactory.getLog(QuickfixApplication.class);
 
     private QuickfixEndpoint endpoint;
 

Modified: camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/QuickfixConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/QuickfixConsumer.java?rev=772605&r1=772604&r2=772605&view=diff
==============================================================================
--- camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/QuickfixConsumer.java
(original)
+++ camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/QuickfixConsumer.java
Thu May  7 10:47:39 2009
@@ -19,7 +19,8 @@
 import org.apache.camel.Endpoint;
 import org.apache.camel.Processor;
 import org.apache.camel.impl.DefaultConsumer;
-import org.apache.log4j.Logger;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 
 /**
@@ -28,7 +29,7 @@
  * @author Anton Arhipov
  */
 public class QuickfixConsumer extends DefaultConsumer {
-    private static final Logger LOG = Logger.getLogger(QuickfixConsumer.class);
+    private static final Log LOG = LogFactory.getLog(QuickfixConsumer.class);
 
     public QuickfixConsumer(Endpoint endpoint, Processor processor) {
         super(endpoint, processor);

Modified: camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/QuickfixEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/QuickfixEndpoint.java?rev=772605&r1=772604&r2=772605&view=diff
==============================================================================
--- camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/QuickfixEndpoint.java
(original)
+++ camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/QuickfixEndpoint.java
Thu May  7 10:47:39 2009
@@ -27,16 +27,12 @@
 import org.apache.camel.Service;
 import org.apache.camel.impl.DefaultEndpoint;
 import org.apache.camel.util.ObjectHelper;
-import org.apache.log4j.Logger;
 import org.springframework.core.io.DefaultResourceLoader;
 import org.springframework.core.io.Resource;
 import org.springframework.core.io.ResourceLoader;
 import quickfix.Application;
 import quickfix.ConfigError;
-import quickfix.FieldNotFound;
 import quickfix.FileStoreFactory;
-import quickfix.IncorrectDataFormat;
-import quickfix.IncorrectTagValue;
 import quickfix.LogFactory;
 import quickfix.Message;
 import quickfix.MessageStoreFactory;
@@ -44,7 +40,6 @@
 import quickfix.Session;
 import quickfix.SessionID;
 import quickfix.SessionSettings;
-import quickfix.UnsupportedMessageType;
 
 /**
  * QuickfixEndpoint is the common class for quickfix endpoints
@@ -60,20 +55,6 @@
  */
 public abstract class QuickfixEndpoint extends DefaultEndpoint implements Service {
 
-    private static final Logger LOG = Logger.getLogger(QuickfixEndpoint.class);
-
-    {
-        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
-            public void run() {
-                try {
-                    stop();
-                } catch (Exception e) {
-                    e.printStackTrace();
-                }
-            }
-        }));
-    }
-
     private boolean strict;
 
     private SessionID sessionID;
@@ -94,25 +75,12 @@
         return true;
     }
 
-    public void onMessage(Message message) throws FieldNotFound, IncorrectDataFormat, IncorrectTagValue,
-        UnsupportedMessageType {
+    public void onMessage(Message message) {
         Exchange exchange = createExchange(message);
         try {
             processor.process(exchange);
-        } catch (FieldNotFound e) {
-            throw e;
-        } catch (IncorrectDataFormat e) {
-            throw e;
-        } catch (IncorrectTagValue e) {
-            throw e;
-        } catch (UnsupportedMessageType e) {
-            throw e;
-        } catch (RuntimeException e) {
-            LOG.error("Unexpected exception encountered in onMessage()", e);
-            throw e;
-        } catch (Throwable e) {
-            LOG.error("Unexpected exception encountered in onMessage()", e);
-            throw new RuntimeException("Unexpected exception encountered in onMessage()",
e);
+        } catch (Exception e) {
+            exchange.setException(e);
         }
 
     }
@@ -152,7 +120,7 @@
         return Session.lookupSession(sessionID);
     }
 
-    public void stop() throws Exception {
+    public void stop() throws Exception {        
         Session session = Session.lookupSession(sessionID);
         if (session != null) {
             session.disconnect();
@@ -201,7 +169,7 @@
                 // then the screen logging factory will be used by default
                 logFactory = new ScreenLogFactory(settings);
             } else {
-                throw new RuntimeException(
+                throw new IllegalArgumentException(
                                            "The strict option is switched on. "
                                                + "You should either inject the required logging
factory via spring context, "
                                                + "or specify the logging factory parameters
via endpoint URI");
@@ -216,7 +184,7 @@
             if (!strict) {
                 messageStoreFactory = new FileStoreFactory(settings);
             } else {
-                throw new RuntimeException(
+                throw new IllegalArgumentException(
                                            "The strict option is switched on. "
                                                + "You should either inject the required logging
factory via spring context, "
                                                + "or specify the logging factory parameters
via endpoint URI");

Modified: camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/QuickfixInitiator.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/QuickfixInitiator.java?rev=772605&r1=772604&r2=772605&view=diff
==============================================================================
--- camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/QuickfixInitiator.java
(original)
+++ camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/QuickfixInitiator.java
Thu May  7 10:47:39 2009
@@ -20,6 +20,7 @@
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.impl.DefaultComponent;
+import org.apache.commons.logging.Log;
 import quickfix.Application;
 import quickfix.ConfigError;
 import quickfix.DefaultMessageFactory;
@@ -36,6 +37,8 @@
  * @author Anton Arhipov
  */
 public class QuickfixInitiator extends DefaultComponent {
+    private static final Log LOG = org.apache.commons.logging.LogFactory.getLog(QuickfixInitiatorEndpoint.class);
+    
     protected QuickfixEndpoint createEndpoint(String uri, String remaining, Map parameters)
throws Exception {
         return new QuickfixInitiatorEndpoint(uri, getCamelContext(), remaining);
     }
@@ -51,6 +54,8 @@
         protected void start(Application application, MessageStoreFactory storeFactory,
                              SessionSettings settings, LogFactory logFactory) throws ConfigError
{
 
+            // To avoid this exception in OSGi platform
+            // java.lang.NoClassDefFoundError: quickfix/fix41/MessageFactory
             ClassLoader ccl = Thread.currentThread().getContextClassLoader();
             try {
                 Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
@@ -59,6 +64,10 @@
                                                 new DefaultMessageFactory());
 
                 initiator.start();
+                
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Start the initiator endpoint");
+                }
             } finally {
                 Thread.currentThread().setContextClassLoader(ccl);
             }
@@ -68,6 +77,9 @@
             super.stop();
             if (initiator != null) {
                 initiator.stop();
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Stop the accetpor endpoint");
+                }
                 initiator = null;
             }
         }

Modified: camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/QuickfixProcessor.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/QuickfixProcessor.java?rev=772605&r1=772604&r2=772605&view=diff
==============================================================================
--- camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/QuickfixProcessor.java
(original)
+++ camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/QuickfixProcessor.java
Thu May  7 10:47:39 2009
@@ -18,6 +18,8 @@
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.log4j.Logger;
 
 /**
@@ -25,9 +27,9 @@
  */
 public class QuickfixProcessor implements Processor {
 
-    private static final Logger LOG = Logger.getLogger(QuickfixProcessor.class);
+    private static final Log LOG = LogFactory.getLog(QuickfixProcessor.class);
 
-    // TODO:
+    // The default processor for the consumer
     public void process(Exchange exchange) throws Exception {
         LOG.debug("Processing exchange " + exchange);
     }

Modified: camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/QuickfixProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/QuickfixProducer.java?rev=772605&r1=772604&r2=772605&view=diff
==============================================================================
--- camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/QuickfixProducer.java
(original)
+++ camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/QuickfixProducer.java
Thu May  7 10:47:39 2009
@@ -22,7 +22,8 @@
 import org.apache.camel.InvalidPayloadException;
 import org.apache.camel.impl.DefaultProducer;
 import org.apache.camel.util.ExchangeHelper;
-import org.apache.log4j.Logger;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import quickfix.Message;
 
 /**
@@ -34,7 +35,7 @@
  */
 public class QuickfixProducer extends DefaultProducer {
 
-    private static final Logger LOG = Logger.getLogger(QuickfixProducer.class);
+    private static final Log LOG = LogFactory.getLog(QuickfixProducer.class);
 
     private QuickfixEndpoint endpoint;
 

Copied: camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/converter/QuickFixConverter.java
(from r772503, camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/converter/Exchange2Message.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/converter/QuickFixConverter.java?p2=camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/converter/QuickFixConverter.java&p1=camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/converter/Exchange2Message.java&r1=772503&r2=772605&rev=772605&view=diff
==============================================================================
--- camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/converter/Exchange2Message.java
(original)
+++ camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/converter/QuickFixConverter.java
Thu May  7 10:47:39 2009
@@ -19,21 +19,32 @@
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
 
 import org.apache.camel.Converter;
+import org.apache.camel.Exchange;
+import org.apache.camel.component.quickfix.QuickfixApplication;
 import org.apache.camel.converter.IOConverter;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import quickfix.InvalidMessage;
 import quickfix.Message;
-import quickfix.MessageCracker;
 
 /**
  * @author Anton Arhipov
  */
 @Converter
-public class Exchange2Message extends MessageCracker {
+public final class QuickFixConverter {
+        
     public static final int BUFFER_SIZE = 8192; 
+    private static final Log LOG = LogFactory.getLog(QuickFixConverter.class);
+    
+    private QuickFixConverter() {
+        // helper class
+    }
+    
     @Converter
-    public static Message convert(InputStream in) throws IOException, InvalidMessage {  
     
+    public static Message convert(InputStream in, Exchange exchange) throws IOException,
InvalidMessage {        
         byte buffer[] = new byte[BUFFER_SIZE];
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         int count;
@@ -42,8 +53,19 @@
             baos.write(buffer, 0, count);
             count = in.read(buffer);
         }
-
-        String str = baos.toString("ISO-8859-1");
+        String str = null;
+        String charsetName = exchange.getProperty(Exchange.CHARSET_NAME, String.class);
+        if (charsetName != null) {
+            try {
+                str = baos.toString(charsetName);
+            } catch (UnsupportedEncodingException e) {
+                LOG.warn("Cannot convert the byte[] into String with the charset: " + charsetName,
e);
+                str = baos.toString();
+            }
+        } else {
+            // using the default encoding 
+            str = baos.toString();
+        }
         in.close();
         return new Message(str);
     }

Propchange: camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/converter/QuickFixConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/converter/QuickFixConverter.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: camel/trunk/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfix/converter/QuickFixConverter.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Propchange: camel/trunk/components/camel-quickfix/src/test/java/org/apache/camel/component/quickfix/example/
------------------------------------------------------------------------------
    svn:mergeinfo = 

Modified: camel/trunk/components/camel-quickfix/src/test/java/org/apache/camel/component/quickfix/example/PassiveFixGateway.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-quickfix/src/test/java/org/apache/camel/component/quickfix/example/PassiveFixGateway.java?rev=772605&r1=772503&r2=772605&view=diff
==============================================================================
--- camel/trunk/components/camel-quickfix/src/test/java/org/apache/camel/component/quickfix/example/PassiveFixGateway.java
(original)
+++ camel/trunk/components/camel-quickfix/src/test/java/org/apache/camel/component/quickfix/example/PassiveFixGateway.java
Thu May  7 10:47:39 2009
@@ -24,7 +24,7 @@
  *         <p/>
  *         To use this example, start Banzai and Executor applications from
  *         Quickfix distribution. The PassiveFixGateway example is intended to
- *         receive the messages from Banzai, forward 'em to Executor, and
+ *         receive the messages from Banzai, forward them to Executor, and
  *         respond back to the Banzai with the execution report.
  */
 public class PassiveFixGateway extends SpringRouteBuilder {



Mime
View raw message