You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by js...@apache.org on 2007/03/21 21:02:42 UTC
svn commit: r520985 - in /activemq/camel/trunk: ./
camel-core/src/main/java/org/apache/camel/
camel-core/src/main/java/org/apache/camel/builder/
camel-core/src/main/java/org/apache/camel/impl/
camel-jms/src/main/java/org/apache/camel/component/jms/ cam...
Author: jstrachan
Date: Wed Mar 21 13:02:40 2007
New Revision: 520985
URL: http://svn.apache.org/viewvc?view=rev&rev=520985
Log:
minor refactorings to make it easy to implement a resolver and avoid wrapping any underlying exceptions; also added a very rough initial spike of a MINA module
Added:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/ResolveEndpointFailedException.java (with props)
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java (with props)
activemq/camel/trunk/camel-mina/
activemq/camel/trunk/camel-mina/pom.xml (with props)
activemq/camel/trunk/camel-mina/src/
activemq/camel/trunk/camel-mina/src/main/
activemq/camel/trunk/camel-mina/src/main/java/
activemq/camel/trunk/camel-mina/src/main/java/org/
activemq/camel/trunk/camel-mina/src/main/java/org/apache/
activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/
activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/
activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/
activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java (with props)
activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpoint.java (with props)
activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpointResolver.java (with props)
activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaExchange.java (with props)
activemq/camel/trunk/camel-mina/src/main/resources/
activemq/camel/trunk/camel-mina/src/main/resources/META-INF/
activemq/camel/trunk/camel-mina/src/main/resources/META-INF/services/
activemq/camel/trunk/camel-mina/src/main/resources/META-INF/services/org/
activemq/camel/trunk/camel-mina/src/main/resources/META-INF/services/org/apache/
activemq/camel/trunk/camel-mina/src/main/resources/META-INF/services/org/apache/camel/
activemq/camel/trunk/camel-mina/src/main/resources/META-INF/services/org/apache/camel/EndpointResolver/
activemq/camel/trunk/camel-mina/src/test/
activemq/camel/trunk/camel-mina/src/test/java/
activemq/camel/trunk/camel-mina/src/test/java/org/
activemq/camel/trunk/camel-mina/src/test/java/org/apache/
activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/
activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/
activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/
activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaTest.java (with props)
Removed:
activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/Builder.java
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/EndpointResolver.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpointResolver.java
activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpointResolver.java
activemq/camel/trunk/pom.xml
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/EndpointResolver.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/EndpointResolver.java?view=diff&rev=520985&r1=520984&r2=520985
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/EndpointResolver.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/EndpointResolver.java Wed Mar 21 13:02:40 2007
@@ -16,6 +16,8 @@
*/
package org.apache.camel;
+import java.io.IOException;
+
/**
* A resolver of endpoints from a String URI
*
@@ -26,12 +28,12 @@
/**
* Resolves the component for a given uri or returns null if now component handles it.
*/
- public Component resolveComponent(CamelContext container, String uri);
+ public Component resolveComponent(CamelContext container, String uri) throws Exception;
/**
* Resolves the endpoint for a given uri or returns null if no endpoint could be found
*/
- public Endpoint<E> resolveEndpoint(CamelContext container, String uri);
+ public Endpoint<E> resolveEndpoint(CamelContext container, String uri) throws Exception;
}
Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/ResolveEndpointFailedException.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/ResolveEndpointFailedException.java?view=auto&rev=520985
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/ResolveEndpointFailedException.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/ResolveEndpointFailedException.java Wed Mar 21 13:02:40 2007
@@ -0,0 +1,36 @@
+/**
+ *
+ * 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;
+
+/**
+ * A runtime exception thrown if an {@link Endpoint} can not be resolved via URI
+ *
+ * @version $Revision$
+ */
+public class ResolveEndpointFailedException extends RuntimeCamelException {
+ private final String uri;
+
+ public ResolveEndpointFailedException(String uri, Throwable cause) {
+ super("Failed to resolve endpoint: " + uri + " due to: " + cause, cause);
+ this.uri = uri;
+ }
+
+ public String getUri() {
+ return uri;
+ }
+}
Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/ResolveEndpointFailedException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/ResolveEndpointFailedException.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/ResolveEndpointFailedException.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java?view=diff&rev=520985&r1=520984&r2=520985
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java Wed Mar 21 13:02:40 2007
@@ -53,15 +53,6 @@
*/
public abstract void configure();
- /**
- * Resolves the given URI to an endpoint
- */
- public Endpoint<E> endpoint(String uri) {
- CamelContext<E> c = getContext();
- EndpointResolver<E> er = c.getEndpointResolver();
- return er.resolveEndpoint(c, uri);
- }
-
public FromBuilder<E> from(String uri) {
return from(endpoint(uri));
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?view=diff&rev=520985&r1=520984&r2=520985
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java Wed Mar 21 13:02:40 2007
@@ -21,15 +21,7 @@
import java.util.Map;
import java.util.concurrent.Callable;
-import org.apache.camel.CamelContext;
-import org.apache.camel.Component;
-import org.apache.camel.Endpoint;
-import org.apache.camel.EndpointResolver;
-import org.apache.camel.Exchange;
-import org.apache.camel.ExchangeConverter;
-import org.apache.camel.Processor;
-import org.apache.camel.RouteFactory;
-import org.apache.camel.TypeConverter;
+import org.apache.camel.*;
import org.apache.camel.builder.RouteBuilder;
/**
@@ -112,7 +104,12 @@
*/
public Endpoint<E> resolveEndpoint(String uri) {
EndpointResolver<E> er = getEndpointResolver();
- return er.resolveEndpoint(this, uri);
+ try {
+ return er.resolveEndpoint(this, uri);
+ }
+ catch (Exception e) {
+ throw new ResolveEndpointFailedException(uri, e);
+ }
}
/**
Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java?view=auto&rev=520985
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java Wed Mar 21 13:02:40 2007
@@ -0,0 +1,44 @@
+/**
+ *
+ * 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.impl;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Component;
+import org.apache.camel.CamelContext;
+
+/**
+ * @version $Revision$
+ */
+public class DefaultComponent<E extends Exchange> implements Component<E> {
+ private CamelContext context;
+
+ public DefaultComponent() {
+ }
+
+ public DefaultComponent(CamelContext context) {
+ this.context = context;
+ }
+
+ public CamelContext getContext() {
+ return context;
+ }
+
+ public void setContext(CamelContext context) {
+ this.context = context;
+ }
+}
Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpointResolver.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpointResolver.java?view=diff&rev=520985&r1=520984&r2=520985
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpointResolver.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpointResolver.java Wed Mar 21 13:02:40 2007
@@ -37,12 +37,12 @@
public class DefaultEndpointResolver<E> implements EndpointResolver<E> {
static final private FactoryFinder endpointResolverFactory = new FactoryFinder("META-INF/services/org/apache/camel/EndpointResolver/");
- public Endpoint<E> resolveEndpoint(CamelContext container, String uri) {
+ public Endpoint<E> resolveEndpoint(CamelContext container, String uri) throws Exception {
EndpointResolver resolver = getDelegate(uri);
return resolver.resolveEndpoint(container, uri);
}
- public Component resolveComponent(CamelContext container, String uri) {
+ public Component resolveComponent(CamelContext container, String uri) throws Exception {
EndpointResolver resolver = getDelegate(uri);
return resolver.resolveComponent(container, uri);
}
Modified: activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java?view=diff&rev=520985&r1=520984&r2=520985
==============================================================================
--- activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java (original)
+++ activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java Wed Mar 21 13:02:40 2007
@@ -21,6 +21,7 @@
import org.apache.camel.CamelContext;
import org.apache.camel.Component;
import org.apache.camel.Processor;
+import org.apache.camel.impl.DefaultComponent;
import org.apache.camel.util.ObjectHelper;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.listener.AbstractMessageListenerContainer;
@@ -30,13 +31,12 @@
import javax.jms.Session;
/**
- * @version $Revision$
+ * @version $Revision:520964 $
*/
-public class JmsComponent implements Component<JmsExchange> {
+public class JmsComponent extends DefaultComponent<JmsExchange> {
public static final String QUEUE_PREFIX = "queue/";
public static final String TOPIC_PREFIX = "topic/";
- private CamelContext container;
private JmsTemplate template;
/**
@@ -79,9 +79,9 @@
this.template = template;
}
- public JmsComponent(CamelContext container) {
- this();
- this.container = container;
+ public JmsComponent(CamelContext context) {
+ super(context);
+ this.template = new JmsTemplate();
}
public JmsEndpoint createEndpoint(Uri uri) {
@@ -92,7 +92,7 @@
}
public JmsEndpoint createEndpoint(String uri, String path) {
- ObjectHelper.notNull(container, "container");
+ ObjectHelper.notNull(getContext(), "container");
if (path.startsWith(QUEUE_PREFIX)) {
template.setPubSubDomain(false);
@@ -124,7 +124,7 @@
// messageConverter
// durableSubscriberName
- return new JmsEndpoint(uri, container, subject, template, listenerContainer);
+ return new JmsEndpoint(uri, getContext(), subject, template, listenerContainer);
}
public JmsTemplate getTemplate() {
@@ -135,14 +135,6 @@
this.template = template;
}
-
- public CamelContext getContainer() {
- return container;
- }
-
- public void setContext(CamelContext container) {
- this.container = container;
- }
protected AbstractMessageListenerContainer createMessageListenerContainer(JmsTemplate template) {
// TODO use an enum to auto-switch container types?
Modified: activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpointResolver.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpointResolver.java?view=diff&rev=520985&r1=520984&r2=520985
==============================================================================
--- activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpointResolver.java (original)
+++ activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpointResolver.java Wed Mar 21 13:02:40 2007
@@ -36,11 +36,11 @@
* the component is optional, and if it is not specified, the default component name
* is assumed.
*
- * @version $Revision$
+ * @version $Revision:520964 $
*/
public class JmsEndpointResolver implements EndpointResolver<JmsExchange> {
- public static final String DEFAULT_COMPONENT_NAME = QueueComponent.class.getName();
+ public static final String DEFAULT_COMPONENT_NAME = JmsEndpointResolver.class.getName();
/**
* Finds the {@see JmsComponent} specified by the uri. If the {@see JmsComponent}
Added: activemq/camel/trunk/camel-mina/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-mina/pom.xml?view=auto&rev=520985
==============================================================================
--- activemq/camel/trunk/camel-mina/pom.xml (added)
+++ activemq/camel/trunk/camel-mina/pom.xml Wed Mar 21 13:02:40 2007
@@ -0,0 +1,55 @@
+<?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.
+-->
+
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-parent</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-mina</artifactId>
+ <name>Camel :: MINA</name>
+ <description>Camel MINA support</description>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.mina</groupId>
+ <artifactId>mina-java5</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
Propchange: activemq/camel/trunk/camel-mina/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/camel/trunk/camel-mina/pom.xml
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: activemq/camel/trunk/camel-mina/pom.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java?view=auto&rev=520985
==============================================================================
--- activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java (added)
+++ activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java Wed Mar 21 13:02:40 2007
@@ -0,0 +1,61 @@
+/**
+ *
+ * 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.CamelContext;
+import org.apache.camel.impl.DefaultComponent;
+import org.apache.mina.common.ConnectFuture;
+import org.apache.mina.common.IoAcceptor;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.transport.vmpipe.VmPipeAcceptor;
+import org.apache.mina.transport.vmpipe.VmPipeAddress;
+import org.apache.mina.transport.vmpipe.VmPipeConnector;
+
+import java.io.IOException;
+
+/**
+ * @version $Revision$
+ */
+public class MinaComponent extends DefaultComponent<MinaExchange> {
+ public MinaComponent() {
+ }
+
+ public MinaComponent(CamelContext context) {
+ super(context);
+ }
+
+ public MinaEndpoint createEndpoint(String uri, String[] urlParts) throws IOException {
+ IoAcceptor acceptor = new VmPipeAcceptor();
+ MinaEndpoint endpoint = new MinaEndpoint(uri, getContext(), acceptor);
+
+ VmPipeAddress address = new VmPipeAddress(8080);
+
+ // Set up server
+ acceptor.bind(address, endpoint.getServerHandler());
+
+ // Connect to the server.
+ VmPipeConnector connector = new VmPipeConnector();
+ ConnectFuture future = connector.connect(address, endpoint.getClientHandler());
+ future.join();
+ IoSession session = future.getSession();
+
+ endpoint.setSession(session);
+
+ return endpoint;
+ }
+}
Propchange: activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpoint.java?view=auto&rev=520985
==============================================================================
--- activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpoint.java (added)
+++ activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpoint.java Wed Mar 21 13:02:40 2007
@@ -0,0 +1,97 @@
+/**
+ *
+ * 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.CamelContext;
+import org.apache.camel.impl.DefaultEndpoint;
+import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.IoHandlerAdapter;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.IoAcceptor;
+
+/**
+ * @version $Revision$
+ */
+public class MinaEndpoint extends DefaultEndpoint<MinaExchange> {
+ private IoSession session;
+ private IoHandler serverHandler;
+ private IoHandler clientHandler;
+ private final IoAcceptor acceptor;
+
+ public MinaEndpoint(String endpointUri, CamelContext container, IoAcceptor acceptor) {
+ super(endpointUri, container);
+ this.acceptor = acceptor;
+ }
+
+ public void onExchange(MinaExchange minaExchange) {
+ session.write(minaExchange.getIn().getBody());
+ }
+
+ public MinaExchange createExchange() {
+ return new MinaExchange(getContext());
+ }
+
+ public IoHandler getServerHandler() {
+ if (serverHandler == null) {
+ serverHandler = createServerHandler();
+ }
+ return serverHandler;
+ }
+
+ public IoHandler getClientHandler() {
+ if (clientHandler == null) {
+ clientHandler = createClientHandler();
+ }
+ return clientHandler;
+ }
+
+ public IoSession getSession() {
+ return session;
+ }
+
+ public void setSession(IoSession session) {
+ this.session = session;
+ }
+
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+
+ @Override
+ protected void doDeactivate() {
+ acceptor.unbindAll();
+ }
+
+ protected IoHandler createClientHandler() {
+ return new IoHandlerAdapter() {
+ @Override
+ public void messageReceived(IoSession ioSession, Object object) throws Exception {
+ super.messageReceived(ioSession, object); /** TODO */
+ }
+ };
+ }
+
+ protected IoHandler createServerHandler() {
+ return new IoHandlerAdapter() {
+ @Override
+ public void messageReceived(IoSession ioSession, Object object) throws Exception {
+ super.messageReceived(ioSession, object); /** TODO */
+ }
+ };
+ }
+}
Propchange: activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpoint.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpoint.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpoint.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpointResolver.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpointResolver.java?view=auto&rev=520985
==============================================================================
--- activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpointResolver.java (added)
+++ activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpointResolver.java Wed Mar 21 13:02:40 2007
@@ -0,0 +1,87 @@
+/**
+ *
+ * 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.EndpointResolver;
+import org.apache.camel.Component;
+import org.apache.camel.CamelContext;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.component.queue.QueueComponent;
+
+import java.util.concurrent.Callable;
+import java.io.IOException;
+
+/**
+ * An implementation of {@link EndpointResolver} that creates
+ * {@link MinaEndpoint} objects.
+ *
+ * The syntax for a MINA URI looks like:
+ *
+ * <pre><code>mina:</code></pre>
+ *
+ * @version $Revision:520964 $
+ */
+public class MinaEndpointResolver implements EndpointResolver<MinaExchange> {
+
+ public static final String DEFAULT_COMPONENT_NAME = MinaEndpointResolver.class.getName();
+
+ /**
+ * Finds the {@link MinaComponent} specified by the uri. If the {@link MinaComponent}
+ * object do not exist, it will be created.
+ */
+ public Component resolveComponent(CamelContext container, String uri) {
+ String[] id = getEndpointId(uri);
+ return resolveMinaComponent(container, id[0]);
+ }
+
+ /**
+ * Finds the {@link MinaEndpoint} specified by the uri. If the {@link MinaEndpoint} or it's associated
+ * {@see QueueComponent} object do not exist, they will be created.
+ */
+ public MinaEndpoint resolveEndpoint(CamelContext container, String uri) throws IOException {
+ String[] urlParts = getEndpointId(uri);
+ MinaComponent component = resolveMinaComponent(container, urlParts[0]);
+ return component.createEndpoint(uri, urlParts);
+ }
+
+ /**
+ * @return an array that looks like: [componentName,endpointName]
+ */
+ private String[] getEndpointId(String uri) {
+ String rc [] = {DEFAULT_COMPONENT_NAME, null};
+ String splitURI[] = ObjectHelper.splitOnCharacter(uri, ":", 3);
+ if( splitURI[2] != null ) {
+ rc[0] = splitURI[1];
+ rc[1] = splitURI[2];
+ } else {
+ rc[1] = splitURI[1];
+ }
+ return rc;
+ }
+
+ @SuppressWarnings("unchecked")
+ private MinaComponent resolveMinaComponent(final CamelContext context, final String componentName) {
+ Component rc = context.getOrCreateComponent(componentName, new Callable<MinaComponent>(){
+ public MinaComponent call() throws Exception {
+ return new MinaComponent(context);
+ }});
+ return (MinaComponent) rc;
+ }
+
+
+}
Propchange: activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpointResolver.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpointResolver.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpointResolver.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaExchange.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaExchange.java?view=auto&rev=520985
==============================================================================
--- activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaExchange.java (added)
+++ activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaExchange.java Wed Mar 21 13:02:40 2007
@@ -0,0 +1,34 @@
+/**
+ *
+ * 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.impl.DefaultExchange;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+
+/**
+ * A {@link Exchange} for MINA
+ *
+ * @version $Revision$
+ */
+public class MinaExchange extends DefaultExchange {
+
+ public MinaExchange(CamelContext camelContext) {
+ super(camelContext);
+ }
+}
Propchange: activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaExchange.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaExchange.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaExchange.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaTest.java?view=auto&rev=520985
==============================================================================
--- activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaTest.java (added)
+++ activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaTest.java Wed Mar 21 13:02:40 2007
@@ -0,0 +1,69 @@
+/**
+ *
+ * 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 junit.framework.TestCase;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.Endpoint;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.DefaultCamelContext;
+
+/**
+ * @version $Revision$
+ */
+public class MinaTest extends TestCase {
+ public void testMinaRoute() throws Exception {
+ final CountDownLatch latch = new CountDownLatch(1);
+
+ CamelContext container = new DefaultCamelContext<Exchange>();
+
+ // lets add some routes
+ container.setRoutes(new RouteBuilder() {
+ public void configure() {
+ from("mina:vm:8080").process(new Processor<MinaExchange>() {
+ public void onExchange(MinaExchange exchange) {
+ System.out.println("Received exchange: " + exchange.getIn());
+ latch.countDown();
+ }
+ });
+ }
+ });
+
+
+ container.activateEndpoints();
+
+ // now lets fire in a message
+ Endpoint<MinaExchange> endpoint = container.resolveEndpoint("mina:vm:8080");
+ MinaExchange exchange2 = endpoint.createExchange();
+ //exchange2.setInBody("Hello there!")
+ exchange2.getIn().getHeaders().setHeader("cheese", 123);
+ endpoint.onExchange(exchange2);
+
+ // now lets sleep for a while
+ boolean received = latch.await(5, TimeUnit.SECONDS);
+ assertTrue("Did not recieve the message!", received);
+
+ container.deactivateEndpoints();
+ }
+}
Propchange: activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: activemq/camel/trunk/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/pom.xml?view=diff&rev=520985&r1=520984&r2=520985
==============================================================================
--- activemq/camel/trunk/pom.xml (original)
+++ activemq/camel/trunk/pom.xml Wed Mar 21 13:02:40 2007
@@ -110,6 +110,7 @@
<module>camel-core</module>
<module>camel-jms</module>
<module>camel-jbi</module>
+ <module>camel-mina</module>
<module>camel-xbean</module>
</modules>
@@ -231,6 +232,12 @@
</dependency>
<dependency>
+ <groupId>org.apache.mina</groupId>
+ <artifactId>mina-java5</artifactId>
+ <version>1.0.2</version>
+ </dependency>
+
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
@@ -303,6 +310,7 @@
<link>http://jakarta.apache.org/commons/pool/apidocs/</link>
<link>http://junit.sourceforge.net/javadoc/</link>
<link>http://logging.apache.org/log4j/docs/api/</link>
+ <link>http://mina.apache.org/report/trunk/apidocs/</link>
</links>
<stylesheetfile>${basedir}/../etc/css/stylesheet.css</stylesheetfile>
<linksource>true</linksource>