camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r747697 - in /camel/branches/camel-1.x: ./ camel-core/src/main/java/org/apache/camel/impl/ components/camel-mina/ components/camel-mina/src/main/java/org/apache/camel/component/mina/ components/camel-mina/src/test/java/org/apache/camel/comp...
Date Wed, 25 Feb 2009 07:50:45 GMT
Author: ningjiang
Date: Wed Feb 25 07:50:44 2009
New Revision: 747697

URL: http://svn.apache.org/viewvc?rev=747697&view=rev
Log:
Merged revisions 736980 via svnmerge from 
https://svn.apache.org/repos/asf/camel/trunk

........
  r736980 | davsclaus | 2009-01-23 18:04:36 +0800 (Fri, 23 Jan 2009) | 1 line
  
  CAMEL-505: Mina endpoints can now be configued using spring bean style.
........

Added:
    camel/branches/camel-1.x/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConfiguration.java
      - copied unchanged from r736980, camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConfiguration.java
    camel/branches/camel-1.x/components/camel-mina/src/test/java/org/apache/camel/component/mina/SpringMinaEndpointTest.java
      - copied unchanged from r736980, camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/SpringMinaEndpointTest.java
    camel/branches/camel-1.x/components/camel-mina/src/test/resources/org/
      - copied from r736980, camel/trunk/components/camel-mina/src/test/resources/org/
    camel/branches/camel-1.x/components/camel-mina/src/test/resources/org/apache/
      - copied from r736980, camel/trunk/components/camel-mina/src/test/resources/org/apache/
    camel/branches/camel-1.x/components/camel-mina/src/test/resources/org/apache/camel/
      - copied from r736980, camel/trunk/components/camel-mina/src/test/resources/org/apache/camel/
    camel/branches/camel-1.x/components/camel-mina/src/test/resources/org/apache/camel/component/
      - copied from r736980, camel/trunk/components/camel-mina/src/test/resources/org/apache/camel/component/
    camel/branches/camel-1.x/components/camel-mina/src/test/resources/org/apache/camel/component/mina/
      - copied from r736980, camel/trunk/components/camel-mina/src/test/resources/org/apache/camel/component/mina/
    camel/branches/camel-1.x/components/camel-mina/src/test/resources/org/apache/camel/component/mina/SpringMinaEndpointTest-context.xml
      - copied unchanged from r736980, camel/trunk/components/camel-mina/src/test/resources/org/apache/camel/component/mina/SpringMinaEndpointTest-context.xml
Modified:
    camel/branches/camel-1.x/   (props changed)
    camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java
    camel/branches/camel-1.x/components/camel-mina/pom.xml
    camel/branches/camel-1.x/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java
    camel/branches/camel-1.x/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConsumer.java
    camel/branches/camel-1.x/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpoint.java
    camel/branches/camel-1.x/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaPayloadHelper.java
    camel/branches/camel-1.x/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaProducer.java
    camel/branches/camel-1.x/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaUdpUsingTemplateTest.java
    camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/spring/CamelBeanPostProcessor.java

Propchange: camel/branches/camel-1.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Feb 25 07:50:44 2009
@@ -1 +1 @@
-/camel/trunk:739733,739904,740251,740295,740306,740596,740663,741848,742231,742705,742739,742854,742856,742898,742906,743613,743762,743773,743920,743959-743960,744123,745105,745367,745541,745751,745826,745978,746269,746872,746895,746962,747258
+/camel/trunk:736980,739733,739904,740251,740295,740306,740596,740663,741848,742231,742705,742739,742854,742856,742898,742906,743613,743762,743773,743920,743959-743960,744123,745105,745367,745541,745751,745826,745978,746269,746872,746895,746962,747258

Propchange: camel/branches/camel-1.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java?rev=747697&r1=747696&r2=747697&view=diff
==============================================================================
--- camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java
(original)
+++ camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java
Wed Feb 25 07:50:44 2009
@@ -78,7 +78,7 @@
         return "Endpoint[" + getEndpointUri() + "]";
     }
 
-    public String getEndpointUri() {
+    public String getEndpointUri() {        
         if (endpointUri == null) {
             endpointUri = createEndpointUri();
             if (endpointUri == null) {
@@ -198,6 +198,17 @@
         this.endpointUri = endpointUri;
     }
     
+    /**
+     * Sets the endpointUri if it has not been specified yet via some kind of dependency
injection mechanism.
+     * This allows dependency injection frameworks such as Spring or Guice to set the default
endpoint URI in cases
+     * where it has not been explicitly configured using the name/context in which an Endpoint
is created.
+     */
+    public void setEndpointUriIfNotSpecified(String value) {
+        if (endpointUri == null) {
+            setEndpointUri(value);
+        }
+    }
+    
     @Deprecated
     public CamelContext getContext() {
         return getCamelContext();

Modified: camel/branches/camel-1.x/components/camel-mina/pom.xml
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-mina/pom.xml?rev=747697&r1=747696&r2=747697&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-mina/pom.xml (original)
+++ camel/branches/camel-1.x/components/camel-mina/pom.xml Wed Feb 25 07:50:44 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/branches/camel-1.x/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java?rev=747697&r1=747696&r2=747697&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java
(original)
+++ camel/branches/camel-1.x/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java
Wed Feb 25 07:50:44 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<MinaExchange> {
     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() {
     }
@@ -91,49 +80,69 @@
             LOG.debug("Creating MinaEndpoint from uri: " + uri);
         }
 
-        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);
@@ -144,34 +153,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);
@@ -182,17 +198,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();
@@ -205,9 +222,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) {
@@ -215,26 +237,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);
@@ -245,32 +269,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);
                         }
@@ -302,10 +320,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);
             }
@@ -314,8 +328,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) {
@@ -326,7 +340,7 @@
         return answer;
     }
 
-    protected ProtocolCodecFactory getCodecFactory(String type, String codec) {
+    private ProtocolCodecFactory getCodecFactory(String type, String codec) {
         ProtocolCodecFactory codecFactory = null;
         if (codec != null) {
             codecFactory = getCamelContext().getRegistry().lookup(codec, ProtocolCodecFactory.class);
@@ -340,16 +354,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.DEFAULT;
         }
 
-        switch (textlineDelimiter) {
+        switch (delimiter) {
         case DEFAULT:
             return LineDelimiter.DEFAULT;
         case AUTO:
@@ -361,83 +375,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;
     }
-
 }

Modified: camel/branches/camel-1.x/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConsumer.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConsumer.java?rev=747697&r1=747696&r2=747697&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConsumer.java
(original)
+++ camel/branches/camel-1.x/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConsumer.java
Wed Feb 25 07:50:44 2009
@@ -50,7 +50,7 @@
         this.endpoint = endpoint;
         this.address = endpoint.getAddress();
         this.acceptor = endpoint.getAcceptor();
-        this.sync = endpoint.isSync();
+        this.sync = endpoint.getConfiguration().isSync();
     }
 
     @Override
@@ -98,8 +98,8 @@
 
             MinaExchange 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);
 
@@ -113,7 +113,7 @@
                 }
 
                 boolean failed = exchange.isFailed();
-                if (failed && !endpoint.isTransferExchange()) {
+                if (failed && !endpoint.getConfiguration().isTransferExchange())
{
                     if (exchange.getException() != null) {
                         body = exchange.getException();
                     } else {

Modified: camel/branches/camel-1.x/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpoint.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpoint.java?rev=747697&r1=747696&r2=747697&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpoint.java
(original)
+++ camel/branches/camel-1.x/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpoint.java
Wed Feb 25 07:50:44 2009
@@ -17,13 +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.ExchangePattern;
 import org.apache.camel.Processor;
 import org.apache.camel.Producer;
 import org.apache.camel.impl.DefaultEndpoint;
+import org.apache.camel.util.ObjectHelper;
 import org.apache.mina.common.IoAcceptor;
 import org.apache.mina.common.IoAcceptorConfig;
 import org.apache.mina.common.IoConnector;
@@ -37,49 +37,45 @@
  */
 public class MinaEndpoint extends DefaultEndpoint<MinaExchange> {
 
-    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;
     }
 
 
     @SuppressWarnings({"unchecked"})
     public Producer<MinaExchange> 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<MinaExchange> 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);
     }
 
-    @Override
+    
     public MinaExchange createExchange(ExchangePattern pattern) {
         return new MinaExchange(getCamelContext(), pattern, null);
     }
@@ -90,53 +86,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/branches/camel-1.x/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaPayloadHelper.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaPayloadHelper.java?rev=747697&r1=747696&r2=747697&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaPayloadHelper.java
(original)
+++ camel/branches/camel-1.x/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaPayloadHelper.java
Wed Feb 25 07:50:44 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/branches/camel-1.x/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaProducer.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaProducer.java?rev=747697&r1=747696&r2=747697&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaProducer.java
(original)
+++ camel/branches/camel-1.x/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaProducer.java
Wed Feb 25 07:50:44 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/branches/camel-1.x/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaUdpUsingTemplateTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaUdpUsingTemplateTest.java?rev=747697&r1=747696&r2=747697&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaUdpUsingTemplateTest.java
(original)
+++ camel/branches/camel-1.x/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaUdpUsingTemplateTest.java
Wed Feb 25 07:50:44 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);
         }
     }
 

Modified: camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/spring/CamelBeanPostProcessor.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/spring/CamelBeanPostProcessor.java?rev=747697&r1=747696&r2=747697&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/spring/CamelBeanPostProcessor.java
(original)
+++ camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/spring/CamelBeanPostProcessor.java
Wed Feb 25 07:50:44 2009
@@ -29,6 +29,7 @@
 import org.apache.camel.EndpointInject;
 import org.apache.camel.Produce;
 import org.apache.camel.impl.CamelPostProcessorHelper;
+import org.apache.camel.impl.DefaultEndpoint;
 import org.apache.camel.spring.util.ReflectionUtils;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.commons.logging.Log;
@@ -85,6 +86,10 @@
     }
 
     public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException
{
+        if (bean instanceof DefaultEndpoint) {
+            DefaultEndpoint defaultEndpoint = (DefaultEndpoint) bean;
+            defaultEndpoint.setEndpointUriIfNotSpecified(beanName);
+        }
         return bean;
     }
 



Mime
View raw message