Discussion:
[mule-scm] [mule][24418] branches/mule-3.3.x: MULE-6247: Custom transformers are not registered on mule context
Daniel Feist
2012-05-27 20:44:28 UTC
Permalink
They are already in the registry, just they are put in the spring registry via spring. This will of course mean that any logic in registerTransformer() is never called.

While this fix will fix the problem, doesn't it mean that each of these transformers are now in the registry twice? Wouldn't it be best (maybe not right now), to extract the additional logic needed and then call it from both registerTransformer() and spring?

Dan
Revision
24418
Author
pablo.kraan
Date
2012-05-27 09:27:26 -0500 (Sun, 27 May 2012)
Log Message
MULE-6247: Custom transformers are not registered on mule context
_ Adding TransformerPostProcessor in order to properly register transformers in the mule context
Modified Paths
branches/mule-3.3.x/modules/spring-config/src/main/java/org/mule/config/spring/MuleApplicationContext.java
branches/mule-3.3.x/tests/integration/src/test/java/org/mule/test/transformers/GraphTransformerResolutionTestCase.java
Added Paths
branches/mule-3.3.x/modules/spring-config/src/main/java/org/mule/config/spring/TransformerPostProcessor.java
Diff
Modified: branches/mule-3.3.x/modules/spring-config/src/main/java/org/mule/config/spring/MuleApplicationContext.java (24417 => 24418)
--- branches/mule-3.3.x/modules/spring-config/src/main/java/org/mule/config/spring/MuleApplicationContext.java 2012-05-26 14:10:28 UTC (rev 24417)
+++ branches/mule-3.3.x/modules/spring-config/src/main/java/org/mule/config/spring/MuleApplicationContext.java 2012-05-27 14:27:26 UTC (rev 24418)
@@ -63,6 +63,7 @@
super.prepareBeanFactory(beanFactory);
beanFactory.addBeanPostProcessor(new MuleContextPostProcessor(muleContext));
beanFactory.addBeanPostProcessor(new ExpressionEvaluatorPostProcessor(muleContext));
+ beanFactory.addBeanPostProcessor(new TransformerPostProcessor(muleContext));
beanFactory.registerSingleton(MuleProperties.OBJECT_MULE_CONTEXT, muleContext);
}
Added: branches/mule-3.3.x/modules/spring-config/src/main/java/org/mule/config/spring/TransformerPostProcessor.java (0 => 24418)
--- branches/mule-3.3.x/modules/spring-config/src/main/java/org/mule/config/spring/TransformerPostProcessor.java (rev 0)
+++ branches/mule-3.3.x/modules/spring-config/src/main/java/org/mule/config/spring/TransformerPostProcessor.java 2012-05-27 14:27:26 UTC (rev 24418)
@@ -0,0 +1,56 @@
+/*
+ * $Id$
+ * --------------------------------------------------------------------------------------
+ * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
+ *
+ * The software in this package is published under the terms of the CPAL v1.0
+ * license, a copy of which has been included with this distribution in the
+ * LICENSE.txt file.
+ */
+
+package org.mule.config.spring;
+
+import org.mule.api.MuleContext;
+import org.mule.api.MuleException;
+import org.mule.api.transformer.Transformer;
+
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.BeanInitializationException;
+import org.springframework.beans.factory.config.BeanPostProcessor;
+
+/**
+ */
+public class TransformerPostProcessor implements BeanPostProcessor
+{
+
+ private final MuleContext muleContext;
+
+ public TransformerPostProcessor(MuleContext muleContext)
+ {
+ this.muleContext = muleContext;
+ }
+
+ public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException
+ {
+ return bean;
+ }
+
+ public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException
+ {
+ if (bean instanceof Transformer)
+ {
+ try
+ {
+ muleContext.getRegistry().registerTransformer((Transformer) bean);
+ }
+ catch (MuleException e)
+ {
+ throw new BeanInitializationException("Error registering transformer", e);
+ }
+ }
+ return bean;
+ }
+}
Property changes on: branches/mule-3.3.x/modules/spring-config/src/main/java/org/mule/config/spring/TransformerPostProcessor.java
___________________________________________________________________
Added: svn:keywords
Added: svn:eol-style
Modified: branches/mule-3.3.x/tests/integration/src/test/java/org/mule/test/transformers/GraphTransformerResolutionTestCase.java (24417 => 24418)
--- branches/mule-3.3.x/tests/integration/src/test/java/org/mule/test/transformers/GraphTransformerResolutionTestCase.java 2012-05-26 14:10:28 UTC (rev 24417)
+++ branches/mule-3.3.x/tests/integration/src/test/java/org/mule/test/transformers/GraphTransformerResolutionTestCase.java 2012-05-27 14:27:26 UTC (rev 24418)
@@ -12,11 +12,9 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-
import org.mule.api.MuleMessage;
import org.mule.api.client.LocalMuleClient;
import org.mule.api.transformer.DiscoverableTransformer;
-import org.mule.api.transformer.Transformer;
import org.mule.api.transformer.TransformerException;
import org.mule.tck.junit4.FunctionalTestCase;
import org.mule.transformer.AbstractTransformer;
@@ -68,11 +66,6 @@
@Test
public void resolvesNonDirectTransformation() throws Exception
{
- Transformer aToB = new AtoBConverter();
- Transformer btoC = new BtoCConverter();
- muleContext.getRegistry().registerTransformer(aToB);
- muleContext.getRegistry().registerTransformer(btoC);
-
LocalMuleClient client = muleContext.getClient();
MuleMessage response = client.send("vm://testInput", new A("Hello"), null);
assertTrue(response.getPayload() instanceof C);
http://xircles.codehaus.org/manage_email
Pablo Kraan
2012-05-27 20:56:23 UTC
Permalink
The registry is some sort of map, so no, the transformers won't be
duplicated there.
The fix breaks a couple of tests, I already have another fix, but I'll
spend more time to improve it

Pablo
Post by Daniel Feist
They are already in the registry, just they are put in the spring registry
via spring. This will of course mean that any logic in
registerTransformer() is never called.
While this fix will fix the problem, doesn't it mean that each of these
transformers are now in the registry twice? Wouldn't it be best (maybe not
right now), to extract the additional logic needed and then call it from
both registerTransformer() and spring?
Dan
Revision 24418 <http://fisheye.codehaus.org/changelog/mule/?cs=24418>
Author pablo.kraan Date 2012-05-27 09:27:26 -0500 (Sun, 27 May 2012) Log
Message
MULE-6247: Custom transformers are not registered on mule context
_ Adding TransformerPostProcessor in order to properly register transformers in the mule context
Modified Paths
-
branches/mule-3.3.x/modules/spring-config/src/main/java/org/mule/config/spring/MuleApplicationContext.java
-
branches/mule-3.3.x/tests/integration/src/test/java/org/mule/test/transformers/GraphTransformerResolutionTestCase.java
Added Paths
-
branches/mule-3.3.x/modules/spring-config/src/main/java/org/mule/config/spring/TransformerPostProcessor.java
Diff
branches/mule-3.3.x/modules/spring-config/src/main/java/org/mule/config/spring/MuleApplicationContext.java
(24417 => 24418)
--- branches/mule-3.3.x/modules/spring-config/src/main/java/org/mule/config/spring/MuleApplicationContext.java 2012-05-26 14:10:28 UTC (rev 24417)
branches/mule-3.3.x/modules/spring-config/src/main/java/org/mule/config/spring/TransformerPostProcessor.java
(0 => 24418)
--- branches/mule-3.3.x/modules/spring-config/src/main/java/org/mule/config/spring/TransformerPostProcessor.java (rev 0)
+ * $Id$
+ * --------------------------------------------------------------------------------------
+ * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
+ *
+ * The software in this package is published under the terms of the CPAL v1.0
+ * license, a copy of which has been included with this distribution in the
+ * LICENSE.txt file.
+ */
+
+package org.mule.config.spring;
+
+import org.mule.api.MuleContext;
+import org.mule.api.MuleException;
+import org.mule.api.transformer.Transformer;
+
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.BeanInitializationException;
+import org.springframework.beans.factory.config.BeanPostProcessor;
+
+/**
+ */
+public class TransformerPostProcessor implements BeanPostProcessor
+{
+
+ private final MuleContext muleContext;
+
+ public TransformerPostProcessor(MuleContext muleContext)
+ {
+ this.muleContext = muleContext;
+ }
+
+ public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException
+ {
+ return bean;
+ }
+
+ public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException
+ {
+ if (bean instanceof Transformer)
+ {
+ try
+ {
+ muleContext.getRegistry().registerTransformer((Transformer) bean);
+ }
+ catch (MuleException e)
+ {
+ throw new BeanInitializationException("Error registering transformer", e);
+ }
+ }
+ return bean;
+ }
+}Property changes on: branches/mule-3.3.x/modules/spring-config/src/main/java/org/mule/config/spring/TransformerPostProcessor.java___________________________________________________________________
Added: svn:keywords
Added: svn:eol-style
branches/mule-3.3.x/tests/integration/src/test/java/org/mule/test/transformers/GraphTransformerResolutionTestCase.java
(24417 => 24418)
--- branches/mule-3.3.x/tests/integration/src/test/java/org/mule/test/transformers/GraphTransformerResolutionTestCase.java 2012-05-26 14:10:28 UTC (rev 24417)
- Transformer btoC = new BtoCConverter();
- muleContext.getRegistry().registerTransformer(aToB);
- muleContext.getRegistry().registerTransformer(btoC);
- LocalMuleClient client = muleContext.getClient(); MuleMessage response = client.send("vm://testInput", new A("Hello"), null); assertTrue(response.getPayload() instanceof C);
------------------------------
http://xircles.codehaus.org/manage_email
Loading...