Title: [748] trunk/core/src/test/java/org/servicemix/jbi/nmr/flow: Added support for properties on flow name and point clusterFlow to JMSFlow,
- Revision
- 748
- Author
- rajdavies
- Date
- 2005-11-04 07:05:20 -0500 (Fri, 04 Nov 2005)
Log Message
Added support for properties on flow name and point clusterFlow to JMSFlow,
because the JMSFlow provides load balancing and more configuration options
Modified Paths
Added Paths
Diff
Modified: trunk/core/src/main/java/org/servicemix/jbi/nmr/flow/FlowProvider.java (747 => 748)
--- trunk/core/src/main/java/org/servicemix/jbi/nmr/flow/FlowProvider.java 2005-11-04 08:34:57 UTC (rev 747)
+++ trunk/core/src/main/java/org/servicemix/jbi/nmr/flow/FlowProvider.java 2005-11-04 12:05:20 UTC (rev 748)
@@ -18,11 +18,14 @@
**/
package org.servicemix.jbi.nmr.flow;
+import org.activemq.util.BeanUtils;
import org.activemq.util.FactoryFinder;
+import org.activemq.util.URIHelper;
import javax.jbi.JBIException;
import java.io.IOException;
+import java.util.Map;
/**
* Find a Flow by Name
@@ -41,26 +44,48 @@
*/
public static Flow getFlow(String flow) throws JBIException {
Object value;
- try {
- value = finder.newInstance(flow);
- if (value != null && value instanceof Flow) {
+ String flowName = getFlowName(flow);
+
+ try{
+ value=finder.newInstance(flowName);
+ if(value!=null&&value instanceof Flow){
+ String query=getQuery(flow);
+ if(query!=null){
+ Map map=URIHelper.parseQuery(query);
+ if(map!=null&&!map.isEmpty()){
+ BeanUtils.populate(value,map);
+ }
+ }
return (Flow) value;
+ }else{
+ throw new JBIException("No implementation found for: "+flow);
}
- else {
- throw new JBIException("No implementation found for: " + flow);
- }
- }
- catch (IllegalAccessException e) {
+ }catch(IllegalAccessException e){
throw new JBIException(e);
- }
- catch (InstantiationException e) {
+ }catch(InstantiationException e){
throw new JBIException(e);
- }
- catch (IOException e) {
+ }catch(IOException e){
throw new JBIException(e);
- }
- catch (ClassNotFoundException e) {
+ }catch(ClassNotFoundException e){
throw new JBIException(e);
}
}
+
+ protected static String getFlowName(String str){
+ String result = str;
+ int index = str.indexOf('?');
+ if (index >= 0 ){
+ result = str.substring(0,index);
+ }
+ return result;
+ }
+
+ protected static String getQuery(String str){
+ String result = null;
+ int index = str.indexOf('?');
+ if (index >= 0 && (index + 1) < str.length()) {
+ result = str.substring(index + 1);
+ }
+ return result;
+ }
}
\ No newline at end of file
Modified: trunk/core/src/main/resources/META-INF/services/org/servicemix/jbi/nmr/flow/cluster
(Binary files differ)
Added: trunk/core/src/test/java/org/servicemix/jbi/nmr/flow/FlowProviderTest.java (747 => 748)
--- trunk/core/src/test/java/org/servicemix/jbi/nmr/flow/FlowProviderTest.java 2005-11-04 08:34:57 UTC (rev 747)
+++ trunk/core/src/test/java/org/servicemix/jbi/nmr/flow/FlowProviderTest.java 2005-11-04 12:05:20 UTC (rev 748)
@@ -0,0 +1,58 @@
+/**
+ * <a href="" The open source ESB</a>
+ *
+ * Copyright 2005 RAJD Consultancy Ltd
+ *
+ * Licensed 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.servicemix.jbi.nmr.flow;
+
+import javax.jbi.JBIException;
+import org.servicemix.jbi.nmr.flow.jms.JMSFlow;
+import org.servicemix.jbi.nmr.flow.seda.SedaFlow;
+import org.servicemix.jbi.nmr.flow.st.STFlow;
+import junit.framework.TestCase;
+
+public class FlowProviderTest extends TestCase{
+
+ public void testGetFlowName(){
+ String name = "fred";
+ String query ="props=foo";
+ String nameAndQuery = name + "?" + query;
+ assertTrue(FlowProvider.getFlowName(name).equals(name));
+ assertTrue(FlowProvider.getFlowName(nameAndQuery).equals(name));
+ assertTrue(FlowProvider.getQuery(nameAndQuery).equals(query));
+
+ }
+
+ public void testGetFlows() throws Exception{
+ Flow flow = FlowProvider.getFlow("st");
+ assertTrue(flow instanceof STFlow);
+ flow = FlowProvider.getFlow("seda");
+ assertTrue(flow instanceof SedaFlow);
+ flow = FlowProvider.getFlow("jms");
+ assertTrue(flow instanceof JMSFlow);
+ flow = FlowProvider.getFlow("cluster");
+ assertTrue(flow instanceof JMSFlow);
+ }
+
+ public void testSetProperties() throws Exception {
+ String jmsURL = "reliable://tcp://fred:666";
+ Flow flow = FlowProvider.getFlow("jms?jmsURL="+jmsURL);
+ assertTrue(flow instanceof JMSFlow);
+ JMSFlow jmsFlow = (JMSFlow)flow;
+ assertTrue(jmsFlow.getJmsURL().equals(jmsURL));
+ }
+}