Professional Documents
Culture Documents
Access to MuleContext
We have removed the methods for accessing the MuleContext or Registry statically. Therefore, MuleServer.getMuleContext() is no longer static, and org.mule.impl.RegistryContext has been removed completely. You can now access the MuleContext in the following ways: From within a component class, implement org.mule.api.MuleContextAware, and Mule will inject the instance for you before the initialize lifecycle phase. From within a transformer, extend AbstractTransformer or AbstractMessageAwareTransformer, and the 'muleContext' variable is available in the base class. From a JSP page or Servlet, the MuleContext is available in the ServletContext using servletContext.getAttribute(MuleProperties.MULE_CONTEXT_PROPERTY). Inbound and outbound routers have the 'muleContext' variable in the base classes. From any other object configured via a configuration builder (such as XML or scripting), implement org.mule.api.MuleContextAware to have the current instance injected.
Deployment Model
The deployment model has changed from Mule 2.2.x to Mule 3.0. You can find more information here.
MuleMessage
If you ever need to create an org.mule.DefaultMuleMessage instance (usually Mule will handle this for you), you must pass in the current MuleContext as described in the previous section.
TransactionManagerFactory
The create() method on org.mule.api.transaction.TransactionManagerFactory now accepts a org.mule.MuleConfiguration parameter, which can be used to set global transaction configuration on the transaction manager. A Spring-based org.mule.config.spring.factories.MuleTransactionManagerFactoryBean object has been added that can be used inject the current TransactionManager into other objects. This is useful when configuring XA data sources that need access to the TransactionManager instance.
<mule xmlns="http://www.mulesource.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:jbossts="http://www.mulesource.org/schema/mule/jbossts" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.mulesource.org/schema/mule/core http://www.mulesource.org/schema/mule/core/3.0/mule.xsd http://www.mulesource.org/schema/mule/jbossts http://www.mulesource.org/schema/mule/jbossts/3.0/mule-jbossts.xsd"> <jbossts:transaction-manager/> <!-- grab the transaction manager that is configured in Mule, in this case Ajruna --> <spring:bean id="muleTM" class= "org.mule.config.spring.factories.MuleTransactionManagerFactoryBean"/> <!-- Data Source --> <spring:bean id="jdbcDataSource" class="org.enhydra.jdbc.standard.StandardXADataSource" destroy-method="shutdown"> <spring:property name="transactionManager" ref="muleTM"/> <spring:property name="driverName" value="org.apache.derby.jdbc.EmbeddedDriver"/> <spring:property name="url" value="#{database.connection}"/> </spring:bean> <mule>
Object Serialization
Serialization of objects such as DefaultMuleMessage, DefaultMuleSession and DefaultMuleEvent need access to the MuleContext once they have been deserialized. The new marker interface org.mule.util.store.DeserializationPostInitialisable provides this access. This interface works in the same way as the Java Cloneable interface. It is a marker that expects a private (or protected) method to be present on the object. Implementers of this interface must add the following method to their class:
This method will get invoked after the object has been deserialized passing in the current {{MuleContext} when using any of the following serialization mechanisms in Mule: org.mule.transformer.wire.SerializationWireFormat org.mule.transformer.wire.SerializedMuleMessageWireFormat org.mule.xml.transformer.wire.XStreamWireFormat org.mule.transformer.simple.ByteArrayToSerializable transformer org.mule.xml.transformer.XmlToObject XStream transformer The reason for doing this rather than a regular interface method was not to clutter object interfaces with public methods that are only required when the object is serialized, especially since these objects are part of the public facing API.
AbstractMuleTestCase
A few new methods have been added to org.mule.tck.AbstractMuleTestCase (and thus the org.mule.tck.functional.FunctionalTestCase) to help wire objects via the Mule Registry. This means that when the objects are created or passed in, they will be added to the registry, and any required objects will be injected and the object lifecycle will be executed.
protected <T extends Object> T createObject(Class<T> clazz, Object... args) throws Exception
Create an object of instance clazz. It will then register the object with the registry so that any dependencies are injected and then the object will be initialized. Note that if the object needs to be configured with additional state that cannot be passed into the constructor, you should create an instance first, set any additional data on the object, and then call initialiseObject(Object). There is also a convenience method createObject(Class) that will pass in empty arguments to the method above.
The initialiseObject is a convenience method that will register an object in the registry using its hashcode as the key. This will cause the object to have any objects injected and lifecycle methods called. Note that the object lifecycle will be called to the same current.
CXF Migration
CXF is no longer a transport inside of Mule. Instead, it is a series of message processors. You'll need to use normal endpoints (non CXF) in your configurations and these message processors in Mule 3. For more information, see upgrading CXF from Mule 2
Inbound Transformers
Inbound transformer are no longer invoked when the component is invoke but rather as part of the inbound message processing pipeline after the security filter. This has a couple of consequences: It is no longer possible to skip transformation by having a custom component that does not call context.transformMessage(). Inbound transformation always happens before any SelectiveConsumer inbound router. This was the default in 2.2 so the only difference is that now it is not possible to do the equivalent of "transformFirst=false" Inbound transformation always happens before any entry point resolvers. This was the default in 2.2 so the only difference is that now it is not possible to do the equivalent of "transformFirst=false" This change does affect the behavior of LegacyEntryPointResolverSet which although still respects the type and order of resolvers used in Mule 1.x, no longer resolves before transformation.
MessageDispatchers
It is no longer the responsibility of the Dispatcher to transform messages. Any call such as: Object data = event.transformMessage(); should be replaced with: Object data = event.getMessage().getPayload(); If a Dispatcher needs special functionality before transformers are applied to the message, it can override the method AbstractMessageDispatcher.applyOutboundTransformers(MuleEvent event)
Model/Service
Direct/Pipeline service implementations have been removed. These were not exposed via configuration and are never really used.
Inbound Routers
Inbound routers are now invoked one after another in a pipeline fashion with the result of a router being used as the input for the next inbound router. Because of this "matchAll" which default to "true" in 2.x no longer makes any sense and has been removed.
Another consequence of this approach is that filtering is easy to achieve by adding a filter where required and so existing inbound routers (apart from selective-consumer which is now simply implemented as a message filter) no longer accept child filter elements. The catchAllStrategy has been conserved but when it is invoked has changed; rather than being invoked when no inbound routers match, it will be invoked if any filters in the pipeline don't match. The ForwardingConsumer and SelectiveConsumer inbound routers are still supported but have been deprecated. You can no longer use the ForwardingConsumer to selectively skip the component, you should do this with a component interceptor instead.
Outbound Routers
TemplateEndpointRouter has been removed. This functionality is available with almost all other routers (that extend FilteringOutboundRouter) by enabling useTemplates. The useTemplates value of FilteringOutboundRouter (and all subclasses) has i) been exposed in configuration ii) has it's default value changed from false to true.
Response Routers
ResponseRouter's no longer exist in code as they are now no different to inbound routers. CollectionAggregator is common to inbound and response SingleResponseAggregator is now redundant and doesn't need to be configured. The xml configuration still supports Mule 2.x response specific elements When implementing your own ResponseAggregators you'll now need to extend org.mule.routing.AbstractCorrelationAggregator rather than org.mule.routing.response.AbstractResponseAggregator
Endpoint configuration
The synchronous attribute on endpoints has been replaced by the exchange-pattern attribute. As a rule of thumb use one-way where synchronous was set to false before use request-response on endpoints that where synchronous before Note that some transports do not allow to configure an exchange-pattern on transport specific endpoints. In this case, the transport supports only a single exchange pattern which is assumed as default for all endpoints.
Exception Strategy
Exception strategies have been revamped for 3.0. See documentation
Expression Evaluators
Expressions including #[headers:], #[headers-list:], #[attachments:] and #[attachments-list:] can retrieve all headers or attachments in a given scope. The notation in Mule 2.2 for doing this was #[headers:all]. IN Mule 3.0 the notation uses a '' instead of 'all' #[headers:] or #[headers:INBOUND:*].
jBPM Transport
The jBPM transport has been overhauled for 3.0, including an upgrade to the latest major version of jBPM (4.3), much simplified configuration, and cleaner integration with Mule from your process definition, including custom process elements.
Mule 2.2 MuleMessage.get/setProperty() MuleMessage.getPropertyNames() MuleMessage.getStringProperty() DefaultMuleMessage(Object) DefaultMuleMessage(Object, MuleMessageAdatper) DefaultMuleMessage(Object message, Map properties) TransactionManagerFactory.create() Transaction() MuleEndpointURI(String) FutureMessageResult(Callable callable) MessagingException(Message message, Object payload) MessagingException(Message message, Object payload, Throwable cause) Added EndpointURIBuilder.build(URI) Added Added RouterResultsHandler.aggregateResults(List <MuleMessage>, MuleMessage) Added
Mule 3.0 Deprecated, replaced with scope-aware methods Deprecated, replaced with scope-aware methods Deprecated, replaced with scope-aware methods DefaultMuleMessage(Object, MuleContext) DefaultMuleMessage(Object, MuleMessageAdapter, MuleContext) DefaultMuleMessage(Object message, Map properties, MuleContext muleContext) TransactionManagerFactory.create(MuleConfiguration) Transaction(MuleContext) MuleEndpointURI(String, MuleContext) FutureMessageResult(Callable callable, MuleContext muleContext) Removed Removed EndpointURI.getMuleContext() EndpointURIBuilder.build(URI, MuleContext) URIBuilder(MuleContext) RetryContext.getMuleContext() RouterResultsHandler.aggregateResults(List<MuleMessage>, MuleMessage, MuleContext) Transformer.transform(Object, String)
Notes
Implements MuleContextAware
ExceptionMessage.getEndpoint() Added
Returns a string representation instead of EndpointURI instance DeserializationPostInitialisable A marker interface for post deserialization initialization Singleton class for accessing the registry No longer a static method No More singleton references to MuleContext, you can now have the MuleContext injected using the MuleContextAware interface or by using the javax.inject.Inject annotation (as of Mule 3.0.0-M3). Transformation now always occurs as part of inbound endpoint
AbstractEntryPointResolver.setTransformFirst()
Removed
AbstractEntryPointResolver.isTransformFirst()
Removed
Transformation now always occurs as part of inbound endpoint Transformation now always occurs as part of inbound endpoint Transformation now always occurs as part of inbound endpoint
SelectiveConsumer.setTransformFirst()
Removed
SelectiveConsumer.isTransformFirst()
Removed
Removed Removed Removed Removed This was deprecated in 2.x and has now been removed. For bridging, simply don't specify a Component on your Service.
AbstractMessageReceiver LifecycleAdapterFactory DefaultComponentLifecycleAdapterFactory DefaultComponentLifecycleAdapter MuleEvent/MuleSession/MuleEventContext org/mule/transport/file/SimpleFilenameParser AbstractMessageDispatcher.returnResponse(MuleEvent event) org.mule.routing.response.AbstractResponseRouter org.mule.routing.response.AbstractResponseAggregator org.mule.routing.response.ResponseCorrelationAggregator
Signatures updated to use FlowConstruct instead of Service Signatures updated to take additional FlowConstruct parameter getService() replacement with getFlowConstruct() use ExpressionFilenameParser deprecated response specific routers no longer exists, inbound routers are not used for async reply no longer exists, logic here is now done as part of async reply response specific routers no longer exist, inbound routers are now used for async reply, extend org.mule.routing.AbstractCorrelationAggregator for implementing custom inbound/response aggregators response router collection no longer exists, an inbound router collection is used for async reply org.mule.routing.SimpleCollectionAggregator Removed. No longer required as async-reply does reply aggregation now. see MULE-4479
<mule xmlns="http://www.mulesource.org/schema/mule/core/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cxf="http://www.mulesource.org/schema/mule/cxf/2.2" xsi:schemaLocation=" http://www.mulesource.org/schema/mule/core/2.2 http://www.mulesource.org/schema/mule/core/2.2/mule.xsd http://www.mulesource.org/schema/mule/cxf/2.2 http://www.mulesource.org/schema/mule/cxf/2.2/mule-cxf.xsd"> </mule>
Below is the equivalent in Mule 3. Notice that the version has been removed from the namespace and now is only present in the actual schema location, this makes moving from one version of Mule to another easier since only the schema location is updated.
<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf" xsi:schemaLocation=" http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.0/mule.xsd http://www.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/3.0/mule-cxf.xsd"> </mule>
Scripting
Affects Scripted transformers and components Change Message properties are no longer bound as global variables of the script. Description Use message.get<Scope>Property() to access the desired property.
Testing
For transformer tests add: transformer.setMuleContext(muleContext); to method getTransformer()