camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r736980 - in /camel/trunk/components/camel-mina: ./ src/main/java/org/apache/camel/component/mina/ src/test/java/org/apache/camel/component/mina/ src/test/resources/org/ src/test/resources/org/apache/ src/test/resources/org/apache/camel/ sr...
Date Fri, 23 Jan 2009 10:04:37 GMT
Author: davsclaus
Date: Fri Jan 23 02:04:36 2009
New Revision: 736980

URL: http://svn.apache.org/viewvc?rev=736980&view=rev
Log:
CAMEL-505: Mina endpoints can now be configued using spring bean style.

Added:
    camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConfiguration.java
  (with props)
    camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/SpringMinaEndpointTest.java
  (with props)
    camel/trunk/components/camel-mina/src/test/resources/org/
    camel/trunk/components/camel-mina/src/test/resources/org/apache/
    camel/trunk/components/camel-mina/src/test/resources/org/apache/camel/
    camel/trunk/components/camel-mina/src/test/resources/org/apache/camel/component/
    camel/trunk/components/camel-mina/src/test/resources/org/apache/camel/component/mina/
    camel/trunk/components/camel-mina/src/test/resources/org/apache/camel/component/mina/SpringMinaEndpointTest-context.xml
  (with props)
Modified:
    camel/trunk/components/camel-mina/pom.xml
    camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java
    camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConsumer.java
    camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpoint.java
    camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaPayloadHelper.java
    camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaProducer.java
    camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaUdpUsingTemplateTest.java

Modified: camel/trunk/components/camel-mina/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina/pom.xml?rev=736980&r1=736979&r2=736980&view=diff
==============================================================================
--- camel/trunk/components/camel-mina/pom.xml (original)
+++ camel/trunk/components/camel-mina/pom.xml Fri Jan 23 02:04:36 2009
@@ -70,6 +70,17 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-spring</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-spring</artifactId>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <scope>test</scope>

Modified: camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java?rev=736980&r1=736979&r2=736980&view=diff
==============================================================================
--- camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java
(original)
+++ camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java
Fri Jan 23 02:04:36 2009
@@ -29,6 +29,7 @@
 import org.apache.camel.ExchangePattern;
 import org.apache.camel.NoTypeConversionAvailableException;
 import org.apache.camel.impl.DefaultComponent;
+import org.apache.camel.util.ObjectHelper;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.mina.common.ByteBuffer;
@@ -64,19 +65,7 @@
  */
 public class MinaComponent extends DefaultComponent {
     private static final transient Log LOG = LogFactory.getLog(MinaComponent.class);
-
-    private static final long DEFAULT_CONNECT_TIMEOUT = 30000;
-    private boolean sync = true;
-    private boolean textline;
-    private TextLineDelimiter textlineDelimiter;
-    private String codec;
-    private String encoding;
-    private long timeout;
-    private boolean lazySessionCreation;
-    private boolean transferExchange;
-    private boolean minaLogger;
-    // encoder used for datagram
-    private CharsetEncoder encoder;
+    private MinaConfiguration configuration = new MinaConfiguration();
 
     public MinaComponent() {
     }
@@ -87,49 +76,69 @@
 
     @Override
     protected Endpoint createEndpoint(String uri, String remaining, Map parameters) throws
Exception {
-        setProperties(this, parameters);
+        // must use copy as each endpoint can have different options
+        ObjectHelper.notNull(configuration, "configuration");
+        MinaConfiguration config = configuration.copy();
 
         URI u = new URI(remaining);
+        config.setHost(u.getHost());
+        config.setPort(u.getPort());
+        config.setProtocol(u.getScheme());
+        setProperties(config, parameters);
+
+        return createEndpoint(uri, config);
+    }
+
+    public Endpoint createEndpoint(MinaConfiguration config) throws Exception {
+        return createEndpoint(null, config);
+    }
 
-        String protocol = u.getScheme();
+    private Endpoint createEndpoint(String uri, MinaConfiguration config) throws Exception
{
+        String protocol = config.getProtocol();
         // if mistyped uri then protocol can be null
         if (protocol != null) {
             if (protocol.equals("tcp")) {
-                return createSocketEndpoint(uri, u, parameters);
+                return createSocketEndpoint(uri, config);
             } else if (protocol.equals("udp") || protocol.equals("mcast") || protocol.equals("multicast"))
{
-                return createDatagramEndpoint(uri, u, parameters);
+                return createDatagramEndpoint(uri, config);
             } else if (protocol.equals("vm")) {
-                return createVmEndpoint(uri, u);
+                return createVmEndpoint(uri, config);
             }
         }
         // protocol not resolved so error
         throw new IllegalArgumentException("Unrecognised MINA protocol: " + protocol + "
for uri: " + uri);
+
     }
 
     // Implementation methods
     //-------------------------------------------------------------------------
 
-    protected MinaEndpoint createVmEndpoint(String uri, URI connectUri) {
+    protected MinaEndpoint createVmEndpoint(String uri, MinaConfiguration configuration)
{
+        boolean minaLogger = configuration.isMinaLogger();
+        boolean sync = configuration.isSync();
+
         IoAcceptor acceptor = new VmPipeAcceptor();
-        SocketAddress address = new VmPipeAddress(connectUri.getPort());
+        SocketAddress address = new VmPipeAddress(configuration.getPort());
         IoConnector connector = new VmPipeConnector();
 
         // connector config
-        configureCodecFactory("MinaProducer", connector.getDefaultConfig(), textline, encoding,
codec);
+        configureCodecFactory("MinaProducer", connector.getDefaultConfig(), configuration);
         if (minaLogger) {
             connector.getFilterChain().addLast("logger", new LoggingFilter());
         }
 
         // acceptor connectorConfig
-        configureCodecFactory("MinaConsumer", acceptor.getDefaultConfig(), textline, encoding,
codec);
+        configureCodecFactory("MinaConsumer", acceptor.getDefaultConfig(), configuration);
         if (minaLogger) {
             acceptor.getFilterChain().addLast("logger", new LoggingFilter());
         }
 
-        MinaEndpoint endpoint = new MinaEndpoint(uri, this, address, acceptor, null, connector,
null, false, timeout, transferExchange, sync);
-        if (encoding != null) {
-            endpoint.setCharsetName(getEncodingParameter("MinaProducer", encoding).name());
-        }
+        MinaEndpoint endpoint = new MinaEndpoint(uri, this);
+        endpoint.setAddress(address);
+        endpoint.setAcceptor(acceptor);
+        endpoint.setConnector(connector);
+        endpoint.setConfiguration(configuration);
+
         // set sync or async mode after endpoint is created
         if (sync) {
             endpoint.setExchangePattern(ExchangePattern.InOut);
@@ -140,34 +149,41 @@
         return endpoint;
     }
 
-    protected MinaEndpoint createSocketEndpoint(String uri, URI connectUri, Map parameters)
{
+    protected MinaEndpoint createSocketEndpoint(String uri, MinaConfiguration configuration)
{
+        boolean minaLogger = configuration.isMinaLogger();
+        long timeout = configuration.getTimeout();
+        boolean sync = configuration.isSync();
+
         IoAcceptor acceptor = new SocketAcceptor();
-        SocketAddress address = new InetSocketAddress(connectUri.getHost(), connectUri.getPort());
+        SocketAddress address = new InetSocketAddress(configuration.getHost(), configuration.getPort());
         IoConnector connector = new SocketConnector();
 
         // connector config
         SocketConnectorConfig connectorConfig = new SocketConnectorConfig();
-        configureCodecFactory("MinaProducer", connectorConfig, textline, encoding, codec);
+        configureCodecFactory("MinaProducer", connectorConfig, configuration);
         if (minaLogger) {
             connectorConfig.getFilterChain().addLast("logger", new LoggingFilter());
         }
         // set connect timeout to mina in seconds
-        long connectTimeout = timeout > 0 ? timeout : DEFAULT_CONNECT_TIMEOUT;
-        connectorConfig.setConnectTimeout((int)(connectTimeout / 1000));
+        connectorConfig.setConnectTimeout((int) (timeout / 1000));
 
         // acceptor connectorConfig
         SocketAcceptorConfig acceptorConfig = new SocketAcceptorConfig();
-        configureCodecFactory("MinaConsumer", acceptorConfig, textline, encoding, codec);
+        configureCodecFactory("MinaConsumer", acceptorConfig, configuration);
         acceptorConfig.setReuseAddress(true);
         acceptorConfig.setDisconnectOnUnbind(true);
         if (minaLogger) {
             acceptorConfig.getFilterChain().addLast("logger", new LoggingFilter());
         }
 
-        MinaEndpoint endpoint = new MinaEndpoint(uri, this, address, acceptor, acceptorConfig,
connector, connectorConfig, lazySessionCreation, timeout, transferExchange, sync);
-        if (encoding != null) {
-            endpoint.setCharsetName(getEncodingParameter("MinaProducer", encoding).name());
-        }
+        MinaEndpoint endpoint = new MinaEndpoint(uri, this);
+        endpoint.setAddress(address);
+        endpoint.setAcceptor(acceptor);
+        endpoint.setAcceptorConfig(acceptorConfig);
+        endpoint.setConnector(connector);
+        endpoint.setConnectorConfig(connectorConfig);
+        endpoint.setConfiguration(configuration);
+
         // set sync or async mode after endpoint is created
         if (sync) {
             endpoint.setExchangePattern(ExchangePattern.InOut);
@@ -178,17 +194,18 @@
         return endpoint;
     }
 
-    protected void configureCodecFactory(String type, IoServiceConfig config, boolean textline,
String encoding, String codec) {
-        ProtocolCodecFactory codecFactory = getCodecFactory(type, codec);
+    protected void configureCodecFactory(String type, IoServiceConfig config, MinaConfiguration
configuration) {
+        ProtocolCodecFactory codecFactory = getCodecFactory(type, configuration.getCodec());
 
         if (codecFactory == null) {
-            if (textline) {
-                Charset charset = getEncodingParameter(type, encoding);
-                LineDelimiter delimiter = getLineDelimiterParameter();
+            if (configuration.isTextline()) {
+                Charset charset = getEncodingParameter(type, configuration);
+                LineDelimiter delimiter = getLineDelimiterParameter(configuration.getTextlineDelimiter());
                 codecFactory = new TextLineCodecFactory(charset, delimiter);
                 if (LOG.isDebugEnabled()) {
                     LOG.debug(type + ": Using TextLineCodecFactory: " + codecFactory + "
using encoding: "
-                              + charset + " and line delimiter: " + textlineDelimiter + "("
+ delimiter + ")");
+                            + charset + " and line delimiter: " + configuration.getTextlineDelimiter()
+                            + "(" + delimiter + ")");
                 }
             } else {
                 codecFactory = new ObjectSerializationCodecFactory();
@@ -201,9 +218,14 @@
         addCodecFactory(config, codecFactory);
     }
 
-    protected MinaEndpoint createDatagramEndpoint(String uri, URI connectUri, Map parameters)
{
+    protected MinaEndpoint createDatagramEndpoint(String uri, MinaConfiguration configuration)
{
+        boolean minaLogger = configuration.isMinaLogger();
+        long timeout = configuration.getTimeout();
+        boolean transferExchange = configuration.isTransferExchange();
+        boolean sync = configuration.isSync();
+
         IoAcceptor acceptor = new DatagramAcceptor();
-        SocketAddress address = new InetSocketAddress(connectUri.getHost(), connectUri.getPort());
+        SocketAddress address = new InetSocketAddress(configuration.getHost(), configuration.getPort());
         IoConnector connector = new DatagramConnector();
 
         if (transferExchange) {
@@ -211,26 +233,28 @@
         }
 
         DatagramConnectorConfig connectorConfig = new DatagramConnectorConfig();
-        configureDataGramCodecFactory("MinaProducer", connectorConfig, encoding, codec);
+        configureDataGramCodecFactory("MinaProducer", connectorConfig, configuration);
         if (minaLogger) {
             connectorConfig.getFilterChain().addLast("logger", new LoggingFilter());
         }
         // set connect timeout to mina in seconds
-        long connectTimeout = timeout > 0 ? timeout : DEFAULT_CONNECT_TIMEOUT;
-        connectorConfig.setConnectTimeout((int)(connectTimeout / 1000));
+        connectorConfig.setConnectTimeout((int) (timeout / 1000));
 
         DatagramAcceptorConfig acceptorConfig = new DatagramAcceptorConfig();
-        configureDataGramCodecFactory("MinaConsumer", acceptorConfig, encoding, codec);
+        configureDataGramCodecFactory("MinaConsumer", acceptorConfig, configuration);
         acceptorConfig.setDisconnectOnUnbind(true);
         // reuse address is default true for datagram
         if (minaLogger) {
             acceptorConfig.getFilterChain().addLast("logger", new LoggingFilter());
         }
 
-        MinaEndpoint endpoint = new MinaEndpoint(uri, this, address, acceptor, acceptorConfig,
connector, connectorConfig, lazySessionCreation, timeout, transferExchange, sync);
-        if (encoding != null) {
-            endpoint.setCharsetName(getEncodingParameter("MinaProducer", encoding).name());
-        }
+        MinaEndpoint endpoint = new MinaEndpoint(uri, this);
+        endpoint.setAddress(address);
+        endpoint.setAcceptor(acceptor);
+        endpoint.setAcceptorConfig(acceptorConfig);
+        endpoint.setConnector(connector);
+        endpoint.setConnectorConfig(connectorConfig);
+        endpoint.setConfiguration(configuration);
         // set sync or async mode after endpoint is created
         if (sync) {
             endpoint.setExchangePattern(ExchangePattern.InOut);
@@ -241,32 +265,26 @@
         return endpoint;
     }
 
-    private static Charset getEncodingParameter(String type, String encoding) {
-        if (encoding == null) {
-            encoding = Charset.defaultCharset().name();
-            if (LOG.isDebugEnabled()) {
-                LOG.debug(type + ": No encoding parameter using default charset: " + encoding);
-            }
-        }
-        if (!Charset.isSupported(encoding)) {
-            throw new IllegalArgumentException("The encoding: " + encoding + " is not supported");
-        }
-
-        return Charset.forName(encoding);
-    }
-
     /**
      * For datagrams the entire message is available as a single ByteBuffer so lets just
pass those around by default
      * and try converting whatever they payload is into ByteBuffers unless some custom converter
is specified
      */
-    protected void configureDataGramCodecFactory(String type, IoServiceConfig config, String
encoding, String codec) {
-        ProtocolCodecFactory codecFactory = getCodecFactory(type, codec);
+    protected void configureDataGramCodecFactory(final String type, final IoServiceConfig
config, final MinaConfiguration configuration) {
+        ProtocolCodecFactory codecFactory = getCodecFactory(type, configuration.getCodec());
         if (codecFactory == null) {
+            final Charset charset = getEncodingParameter(type, configuration);
+
+            // set the encoder used for this datagram codec factory
             codecFactory = new ProtocolCodecFactory() {
                 public ProtocolEncoder getEncoder() throws Exception {
                     return new ProtocolEncoder() {
+                        private CharsetEncoder encoder;
+
                         public void encode(IoSession session, Object message, ProtocolEncoderOutput
out) throws Exception {
-                            ByteBuffer buf = toByteBuffer(message);
+                            if (encoder == null) {
+                                encoder = charset.newEncoder();
+                            }
+                            ByteBuffer buf = toByteBuffer(message, encoder);
                             buf.flip();
                             out.write(buf);
                         }
@@ -298,10 +316,6 @@
                 }
             };
 
-            // set the encoder used for this datagram codec factory
-            Charset charset = getEncodingParameter(type, encoding);
-            encoder = charset.newEncoder();
-
             if (LOG.isDebugEnabled()) {
                 LOG.debug(type + ": Using CodecFactory: " + codecFactory + " using encoding:
" + charset);
             }
@@ -310,8 +324,8 @@
         addCodecFactory(config, codecFactory);
     }
 
-    protected ByteBuffer toByteBuffer(Object message) throws CharacterCodingException {
-        ByteBuffer answer = null;
+    private ByteBuffer toByteBuffer(Object message, CharsetEncoder encoder) throws CharacterCodingException
{
+        ByteBuffer answer;
         try {
             answer = convertTo(ByteBuffer.class, message);
         } catch (NoTypeConversionAvailableException e) {
@@ -322,7 +336,7 @@
         return answer;
     }
 
-    protected ProtocolCodecFactory getCodecFactory(String type, String codec) {
+    private ProtocolCodecFactory getCodecFactory(String type, String codec) {
         ProtocolCodecFactory codecFactory = null;
         if (codec != null) {
             codecFactory = mandatoryLookup(codec, ProtocolCodecFactory.class);
@@ -333,16 +347,16 @@
         return codecFactory;
     }
 
-    protected void addCodecFactory(IoServiceConfig config, ProtocolCodecFactory codecFactory)
{
+    private void addCodecFactory(IoServiceConfig config, ProtocolCodecFactory codecFactory)
{
         config.getFilterChain().addLast("codec", new ProtocolCodecFilter(codecFactory));
     }
 
-    private LineDelimiter getLineDelimiterParameter() {
-        if (textlineDelimiter == null) {
+    private static LineDelimiter getLineDelimiterParameter(TextLineDelimiter delimiter) {
+        if (delimiter == null) {
             return LineDelimiter.AUTO;
         }
 
-        switch (textlineDelimiter) {
+        switch (delimiter) {
         case AUTO:
             return LineDelimiter.AUTO;
         case UNIX:
@@ -352,83 +366,38 @@
         case MAC:
             return LineDelimiter.MAC;
         default:
-            throw new IllegalArgumentException("Unknown textline delimiter: " + textlineDelimiter);
+            throw new IllegalArgumentException("Unknown textline delimiter: " + delimiter);
         }
     }
 
-    // Properties
-    //-------------------------------------------------------------------------
-
-    public boolean isSync() {
-        return sync;
-    }
-
-    public void setSync(boolean sync) {
-        this.sync = sync;
-    }
-
-    public boolean isTextline() {
-        return textline;
-    }
-
-    public void setTextline(boolean textline) {
-        this.textline = textline;
-    }
-
-    public TextLineDelimiter getTextlineDelimiter() {
-        return textlineDelimiter;
-    }
-
-    public void setTextlineDelimiter(TextLineDelimiter textlineDelimiter) {
-        this.textlineDelimiter = textlineDelimiter;
-    }
-
-    public String getCodec() {
-        return codec;
-    }
-
-    public void setCodec(String codec) {
-        this.codec = codec;
-    }
-
-    public String getEncoding() {
-        return encoding;
-    }
-
-    public void setEncoding(String encoding) {
-        this.encoding = encoding;
-    }
-
-    public long getTimeout() {
-        return timeout;
-    }
-
-    public void setTimeout(long timeout) {
-        this.timeout = timeout;
-    }
-
-    public boolean isLazySessionCreation() {
-        return lazySessionCreation;
-    }
-
-    public void setLazySessionCreation(boolean lazySessionCreation) {
-        this.lazySessionCreation = lazySessionCreation;
-    }
+    private static Charset getEncodingParameter(String type, MinaConfiguration configuration)
{
+        String encoding = configuration.getEncoding();
+        if (encoding == null) {
+            encoding = Charset.defaultCharset().name();
+            // set in on configuration so its updated
+            configuration.setEncoding(encoding);
+            if (LOG.isDebugEnabled()) {
+                LOG.debug(type + ": No encoding parameter using default charset: " + encoding);
+            }
+        }
+        if (!Charset.isSupported(encoding)) {
+            throw new IllegalArgumentException("The encoding: " + encoding + " is not supported");
+        }
 
-    public boolean isTransferExchange() {
-        return transferExchange;
+        return Charset.forName(encoding);
     }
 
-    public void setTransferExchange(boolean transferExchange) {
-        this.transferExchange = transferExchange;
-    }
+    // Properties
+    //-------------------------------------------------------------------------
 
-    public boolean isMinaLogger() {
-        return minaLogger;
+    public synchronized MinaConfiguration getConfiguration() {
+        if (configuration == null) {
+            configuration = new MinaConfiguration();
+        }
+        return configuration;
     }
 
-    public void setMinaLogger(boolean minaLogger) {
-        this.minaLogger = minaLogger;
+    public void setConfiguration(MinaConfiguration configuration) {
+        this.configuration = configuration;
     }
-
 }

Added: camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConfiguration.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConfiguration.java?rev=736980&view=auto
==============================================================================
--- camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConfiguration.java
(added)
+++ camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConfiguration.java
Fri Jan 23 02:04:36 2009
@@ -0,0 +1,158 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.mina;
+
+import java.nio.charset.Charset;
+
+import org.apache.camel.RuntimeCamelException;
+
+/**
+ * Mina configuration
+ */
+public class MinaConfiguration implements Cloneable {
+    private String protocol;
+    private String host;
+    private int port;
+    private boolean sync = true;
+    private boolean textline;
+    private TextLineDelimiter textlineDelimiter;
+    private String codec;
+    private String encoding;
+    private long timeout = 30000;
+    private boolean lazySessionCreation;
+    private boolean transferExchange;
+    private boolean minaLogger;
+
+    /**
+     * Returns a copy of this configuration
+     */
+    public MinaConfiguration copy() {
+        try {
+            return (MinaConfiguration) clone();
+        } catch (CloneNotSupportedException e) {
+            throw new RuntimeCamelException(e);
+        }
+    }
+
+    public String getCharsetName() {
+        if (encoding == null) {
+            return null;
+        }
+        if (!Charset.isSupported(encoding)) {
+            throw new IllegalArgumentException("The encoding: " + encoding + " is not supported");
+        }
+
+        return Charset.forName(encoding).name();
+    }
+
+
+    public String getProtocol() {
+        return protocol;
+    }
+
+    public void setProtocol(String protocol) {
+        this.protocol = protocol;
+    }
+
+    public String getHost() {
+        return host;
+    }
+
+    public void setHost(String host) {
+        this.host = host;
+    }
+
+    public int getPort() {
+        return port;
+    }
+
+    public void setPort(int port) {
+        this.port = port;
+    }
+
+    public boolean isSync() {
+        return sync;
+    }
+
+    public void setSync(boolean sync) {
+        this.sync = sync;
+    }
+
+    public boolean isTextline() {
+        return textline;
+    }
+
+    public void setTextline(boolean textline) {
+        this.textline = textline;
+    }
+
+    public TextLineDelimiter getTextlineDelimiter() {
+        return textlineDelimiter;
+    }
+
+    public void setTextlineDelimiter(TextLineDelimiter textlineDelimiter) {
+        this.textlineDelimiter = textlineDelimiter;
+    }
+
+    public String getCodec() {
+        return codec;
+    }
+
+    public void setCodec(String codec) {
+        this.codec = codec;
+    }
+
+    public String getEncoding() {
+        return encoding;
+    }
+
+    public void setEncoding(String encoding) {
+        this.encoding = encoding;
+    }
+
+    public long getTimeout() {
+        return timeout;
+    }
+
+    public void setTimeout(long timeout) {
+        this.timeout = timeout;
+    }
+
+    public boolean isLazySessionCreation() {
+        return lazySessionCreation;
+    }
+
+    public void setLazySessionCreation(boolean lazySessionCreation) {
+        this.lazySessionCreation = lazySessionCreation;
+    }
+
+    public boolean isTransferExchange() {
+        return transferExchange;
+    }
+
+    public void setTransferExchange(boolean transferExchange) {
+        this.transferExchange = transferExchange;
+    }
+
+    public boolean isMinaLogger() {
+        return minaLogger;
+    }
+
+    public void setMinaLogger(boolean minaLogger) {
+        this.minaLogger = minaLogger;
+    }
+}

Propchange: camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConfiguration.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConfiguration.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConsumer.java?rev=736980&r1=736979&r2=736980&view=diff
==============================================================================
--- camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConsumer.java
(original)
+++ camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConsumer.java
Fri Jan 23 02:04:36 2009
@@ -48,7 +48,7 @@
         this.endpoint = endpoint;
         this.address = endpoint.getAddress();
         this.acceptor = endpoint.getAcceptor();
-        this.sync = endpoint.isSync();
+        this.sync = endpoint.getConfiguration().isSync();
     }
 
     @Override
@@ -96,8 +96,8 @@
 
             Exchange exchange = endpoint.createExchange(session, object);
             //Set the exchange charset property for converting
-            if (endpoint.getCharsetName() != null) {
-                exchange.setProperty(Exchange.CHARSET_NAME, endpoint.getCharsetName());
+            if (endpoint.getConfiguration().getCharsetName() != null) {
+                exchange.setProperty(Exchange.CHARSET_NAME, endpoint.getConfiguration().getCharsetName());
             }
             getProcessor().process(exchange);
 
@@ -110,7 +110,7 @@
                     body = MinaPayloadHelper.getIn(endpoint, exchange);
                 }
                 boolean failed = exchange.isFailed();
-                if (failed && !endpoint.isTransferExchange()) {
+                if (failed && !endpoint.getConfiguration().isTransferExchange())
{
                     if (exchange.getException() != null) {
                         body = exchange.getException();
                     } else {

Modified: camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpoint.java?rev=736980&r1=736979&r2=736980&view=diff
==============================================================================
--- camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpoint.java
(original)
+++ camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpoint.java
Fri Jan 23 02:04:36 2009
@@ -17,15 +17,13 @@
 package org.apache.camel.component.mina;
 
 import java.net.SocketAddress;
-import java.nio.charset.Charset;
 
 import org.apache.camel.Consumer;
 import org.apache.camel.Exchange;
-import org.apache.camel.ExchangePattern;
 import org.apache.camel.Processor;
 import org.apache.camel.Producer;
 import org.apache.camel.impl.DefaultEndpoint;
-import org.apache.camel.impl.DefaultExchange;
+import org.apache.camel.util.ObjectHelper;
 import org.apache.mina.common.IoAcceptor;
 import org.apache.mina.common.IoAcceptorConfig;
 import org.apache.mina.common.IoConnector;
@@ -39,43 +37,39 @@
  */
 public class MinaEndpoint extends DefaultEndpoint {
 
-    private static final long DEFAULT_TIMEOUT = 30000;
-    private long timeout = DEFAULT_TIMEOUT;
+    private SocketAddress address;
+    private IoAcceptor acceptor;
+    private IoConnector connector;
+    private IoAcceptorConfig acceptorConfig;
+    private IoConnectorConfig connectorConfig;
+    private MinaConfiguration configuration;
 
-    private final IoAcceptor acceptor;
-    private final SocketAddress address;
-    private final IoConnector connector;
-    private final IoAcceptorConfig acceptorConfig;
-    private final IoConnectorConfig connectorConfig;
-    private final boolean lazySessionCreation;
-    private final boolean transferExchange;
-    private final boolean sync;
-    private String charsetName;
-
-    public MinaEndpoint(String endpointUri, MinaComponent component, SocketAddress address,
-                        IoAcceptor acceptor, IoAcceptorConfig acceptorConfig, IoConnector
connector,
-                        IoConnectorConfig connectorConfig, boolean lazySessionCreation, long
timeout,
-                        boolean transferExchange, boolean sync) {
+    public MinaEndpoint() {
+    }
+
+    public MinaEndpoint(String endpointUri, MinaComponent component) {
         super(endpointUri, component);
-        this.address = address;
-        this.acceptor = acceptor;
-        this.acceptorConfig = acceptorConfig;
-        this.connectorConfig = connectorConfig;
-        this.connector = connector;
-        this.lazySessionCreation = lazySessionCreation;
-        if (timeout > 0) {
-            // override default timeout if provided
-            this.timeout = timeout;
-        }
-        this.transferExchange = transferExchange;
-        this.sync = sync;
     }
 
     public Producer createProducer() throws Exception {
+        ObjectHelper.notNull(configuration, "configuration"); 
+        ObjectHelper.notNull(address, "address");
+        ObjectHelper.notNull(connector, "connector");
+        // wm protocol does not have config
+        if (!configuration.getProtocol().equalsIgnoreCase("vm")) {
+            ObjectHelper.notNull(connectorConfig, "connectorConfig");
+        }
         return new MinaProducer(this);
     }
 
     public Consumer createConsumer(Processor processor) throws Exception {
+        ObjectHelper.notNull(configuration, "configuration");
+        ObjectHelper.notNull(address, "address");
+        ObjectHelper.notNull(acceptor, "acceptor");
+        // wm protocol does not have config
+        if (!configuration.getProtocol().equalsIgnoreCase("vm")) {
+            ObjectHelper.notNull(acceptorConfig, "acceptorConfig");
+        }
         return new MinaConsumer(this, processor);
     }
 
@@ -85,53 +79,58 @@
         return exchange;
     }
 
+    public boolean isSingleton() {
+        return true;
+    }
+
     // Properties
     // -------------------------------------------------------------------------
-    public IoAcceptor getAcceptor() {
-        return acceptor;
+
+    public MinaConfiguration getConfiguration() {
+        return configuration;
     }
 
-    public SocketAddress getAddress() {
-        return address;
+    public void setConfiguration(MinaConfiguration configuration) {
+        this.configuration = configuration;
     }
 
-    public IoConnector getConnector() {
-        return connector;
+    public SocketAddress getAddress() {
+        return address;
     }
 
-    public boolean isLazySessionCreation() {
-        return lazySessionCreation;
+    public void setAddress(SocketAddress address) {
+        this.address = address;
     }
 
-    public IoAcceptorConfig getAcceptorConfig() {
-        return acceptorConfig;
+    public IoAcceptor getAcceptor() {
+        return acceptor;
     }
 
-    public IoConnectorConfig getConnectorConfig() {
-        return connectorConfig;
+    public void setAcceptor(IoAcceptor acceptor) {
+        this.acceptor = acceptor;
     }
 
-    public boolean isSingleton() {
-        return true;
+    public IoConnector getConnector() {
+        return connector;
     }
 
-    public long getTimeout() {
-        return timeout;
+    public void setConnector(IoConnector connector) {
+        this.connector = connector;
     }
 
-    public boolean isTransferExchange() {
-        return transferExchange;
+    public IoAcceptorConfig getAcceptorConfig() {
+        return acceptorConfig;
     }
 
-    public boolean isSync() {
-        return sync;
+    public void setAcceptorConfig(IoAcceptorConfig acceptorConfig) {
+        this.acceptorConfig = acceptorConfig;
     }
 
-    public void setCharsetName(String charset) {
-        this.charsetName = charset;
+    public IoConnectorConfig getConnectorConfig() {
+        return connectorConfig;
     }
 
-    public String getCharsetName() {
-        return charsetName;
+    public void setConnectorConfig(IoConnectorConfig connectorConfig) {
+        this.connectorConfig = connectorConfig;
     }
 }

Modified: camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaPayloadHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaPayloadHelper.java?rev=736980&r1=736979&r2=736980&view=diff
==============================================================================
--- camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaPayloadHelper.java
(original)
+++ camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaPayloadHelper.java
Fri Jan 23 02:04:36 2009
@@ -34,7 +34,7 @@
     }
 
     public static Object getIn(MinaEndpoint endpoint, Exchange exchange) {
-        if (endpoint.isTransferExchange()) {
+        if (endpoint.getConfiguration().isTransferExchange()) {
             // we should transfer the entire exchange over the wire (includes in/out)
             return MinaPayloadHolder.marshal(exchange);
         } else {
@@ -44,7 +44,7 @@
     }
 
     public static Object getOut(MinaEndpoint endpoint, Exchange exchange) {
-        if (endpoint.isTransferExchange()) {
+        if (endpoint.getConfiguration().isTransferExchange()) {
             // we should transfer the entire exchange over the wire (includes in/out)
             return MinaPayloadHolder.marshal(exchange);
         } else {

Modified: camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaProducer.java?rev=736980&r1=736979&r2=736980&view=diff
==============================================================================
--- camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaProducer.java
(original)
+++ camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaProducer.java
Fri Jan 23 02:04:36 2009
@@ -53,9 +53,9 @@
     public MinaProducer(MinaEndpoint endpoint) {
         super(endpoint);
         this.endpoint = endpoint;
-        this.lazySessionCreation = endpoint.isLazySessionCreation();
-        this.timeout = endpoint.getTimeout();
-        this.sync = endpoint.isSync();
+        this.lazySessionCreation = endpoint.getConfiguration().isLazySessionCreation();
+        this.timeout = endpoint.getConfiguration().getTimeout();
+        this.sync = endpoint.getConfiguration().isSync();
     }
 
     public void process(Exchange exchange) throws Exception {
@@ -67,8 +67,8 @@
         }
 
         // set the exchange encoding property
-        if (endpoint.getCharsetName() != null) {
-            exchange.setProperty(Exchange.CHARSET_NAME, endpoint.getCharsetName());
+        if (endpoint.getConfiguration().getCharsetName() != null) {
+            exchange.setProperty(Exchange.CHARSET_NAME, endpoint.getConfiguration().getCharsetName());
         }
 
         Object body = MinaPayloadHelper.getIn(endpoint, exchange);

Modified: camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaUdpUsingTemplateTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaUdpUsingTemplateTest.java?rev=736980&r1=736979&r2=736980&view=diff
==============================================================================
--- camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaUdpUsingTemplateTest.java
(original)
+++ camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaUdpUsingTemplateTest.java
Fri Jan 23 02:04:36 2009
@@ -44,7 +44,7 @@
 
     protected void sendUdpMessages() throws Exception {
         for (int i = 0; i < messageCount; i++) {
-            template.sendBody("mina:udp://127.0.0.1:4445", "Hello Message: " + i);
+            template.sendBody("mina:udp://127.0.0.1:4445?sync=false", "Hello Message: " +
i);
         }
     }
 

Added: camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/SpringMinaEndpointTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/SpringMinaEndpointTest.java?rev=736980&view=auto
==============================================================================
--- camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/SpringMinaEndpointTest.java
(added)
+++ camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/SpringMinaEndpointTest.java
Fri Jan 23 02:04:36 2009
@@ -0,0 +1,42 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.mina;
+
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.SpringTestSupport;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * Unit test spring based mina endpoint configuraiton.
+ */
+public class SpringMinaEndpointTest extends SpringTestSupport {
+
+    public void testMinaSpringEndpoint() throws Exception {
+        MockEndpoint result = getMockEndpoint("mock:result");
+        result.expectedMessageCount(1);
+
+        template.sendBody("myMinaEndpoint", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected ClassPathXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/component/mina/SpringMinaEndpointTest-context.xml");
+    }
+
+}

Propchange: camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/SpringMinaEndpointTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/SpringMinaEndpointTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-mina/src/test/resources/org/apache/camel/component/mina/SpringMinaEndpointTest-context.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina/src/test/resources/org/apache/camel/component/mina/SpringMinaEndpointTest-context.xml?rev=736980&view=auto
==============================================================================
--- camel/trunk/components/camel-mina/src/test/resources/org/apache/camel/component/mina/SpringMinaEndpointTest-context.xml
(added)
+++ camel/trunk/components/camel-mina/src/test/resources/org/apache/camel/component/mina/SpringMinaEndpointTest-context.xml
Fri Jan 23 02:04:36 2009
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+       http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd">
+
+    <!-- START SNIPPET: e1 -->
+    <!-- Creating mina endpoints is a bit complex so we reuse MinaComponnet
+         as a factory bean to create our endpoint, this is the easiest to do -->
+    <bean id="myMinaFactory" class="org.apache.camel.component.mina.MinaComponent"/>
+
+    <!-- This is our mina endpoint configured with spring, we will use the factory above
+         to create it for us. The goal is to invoke the createEndpoint method with the
+         mina configuration parameter we defined using the constructor-arg option -->
+    <bean id="myMinaEndpoint"
+          factory-bean="myMinaFactory"
+          factory-method="createEndpoint">
+        <constructor-arg index="0" ref="myMinaConfig"/>
+    </bean>
+
+    <!-- this is our mina configuration with plain properties -->
+    <bean id="myMinaConfig" class="org.apache.camel.component.mina.MinaConfiguration">
+        <property name="protocol" value="tcp"/>
+        <property name="host" value="localhost"/>
+        <property name="port" value="1234"/>
+        <property name="sync" value="false"/>
+    </bean>
+    <!-- END SNIPPET: e1 -->
+
+    <camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
+        <!-- START SNIPPET: e2 -->
+        <route>
+            <!-- here we route from or mina endpoint we have defined above -->
+            <from ref="myMinaEndpoint"/>
+            <to uri="mock:result"/>
+        </route>
+        <!-- END SNIPPET: e2 -->
+    </camelContext>
+
+</beans>

Propchange: camel/trunk/components/camel-mina/src/test/resources/org/apache/camel/component/mina/SpringMinaEndpointTest-context.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-mina/src/test/resources/org/apache/camel/component/mina/SpringMinaEndpointTest-context.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: camel/trunk/components/camel-mina/src/test/resources/org/apache/camel/component/mina/SpringMinaEndpointTest-context.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message