How to create and package a custom component for Mule Studio? - mule

I am new to Mule and hoping to avoid going in the completely wrong direction. I would like to create a component, which other devs can add to their Components lists in Mule Studio (to be dropped into their flows).
I see that I can create a Java class that implements callable, which can be added to a Flow by using a Java component and setting its "Class Name" to the one I created. Is there a good way that I can use this to package as a component that can be plugged in to Mule Studio? Or is Mule Devkit the best option for this?

Mule DevKit is the very best option for this. Other alternatives imply messing with Eclipse-related code. You don't want that, go DevKit: http://www.mulesoft.org/documentation/display/current/Mule+DevKit

Related

Facing problem while migrating API from mule 3 to mule 4

In my case, I'm doing a migration from Mule 3 to Mule 4.
I have some questions regarding the manual migration from Mule 3 to Mule 4.
How to use the expression component in Mule 4?
Are there any other ways to use session variables?
In Mule 3, I used an expression component to return Java code to my logic. I'd like to reuse that Java code in Mule 4.
The message enricher component is not supported in Mule 4.
Mule 4 does not support transformers such as DOM to XML, XML to String, and so on.
Please assist me.
Several of the questions asked are already explained in the Migration Guide.
How to use the expression component in Mule 4?
In Mule 4 the expression language is DataWeave 2. You should learn about DataWeave and read the migration guide from MEL to DataWeave.
Are there any other ways to use session variables?
No. This is mentioned in the migration guide Migrating Core Components: "Session variables have been removed. Users must explicitly pass headers across transport boundaries."
In Mule 3, I used an expression component to return Java code to my logic. I'd like to reuse that Java code in Mule 4.
You can call Java static methods directly from DataWeave. Also you can execute any Java method with the Java Module and store the output in a variable to be used in a DataWeave script.
Additionally you can create custom functions to add to DataWeave using the Mule SDK.
Note that in Mule 4 you should not use any Mule APIs in your Java code.
Generally speaking try to see if you can use pure DataWeave features before trying to call Java code.
The message enricher component is not supported in Mule 4.
There is no need for the enricher. Mule 4 can use target variables in any operation. This is mentioned in the migration guide.
Mule 4 does not support transformers such as DOM to XML, XML to String, and so on.
That's right. You should use DataWeave Transformations instead of transformers. Yet another topic mentioned in the migration guide.

Intellij: Go to autowired bean definition

I looking for quick way to find bean definition by their #Autowired dependency in java code. Suppose I have:
#Autowired
private JdbcTemplate template;
I want IDEA tell me in which xml file is the definition of template bean. How to do that?
If you have the spring plugin installed and active you should see some icons on the left gutter which help you to identify the place where the bean has been defined, either xml or annotation. If you have multiple spring profiles you may have to chose the active one.
First install spring plugin by Ctrl+Alt+S
under IDE Settings, select Plugins.
In the right-hand part of the dialog, on the Plugins page, type spring in the search box.
If the check box to the left of Spring Support is not selected, select it. If you are going to use particular Spring frameworks (Spring Security, Spring Integration, etc.), make sure that the check boxes next to their names are also selected.
Then the icons on the left(near the code line-number) helps to identify the bean definition
I am using CDI and not Spring but using Go to Implementation keyboard shortcut achieves that as long as you have only one implementation of your interface in your classpath, otherwise it would pop a small dropdown menu.

Mule spring bean schedule run

We have defined spring beans in Mule-config.xml. Certain public methods in this bean class needs to be periodically executed. We attempted to used spring quartz and spring task scheduler (adding beans in mule-config.xml)- but method is not executing in a schedule way - it is not triggered. Even using annotation (scheduled) does not work. Any work around for this? Any issue with spring scheduler with mule? Kindly help.
Thanks
If you want to use the Schedule annotation, take a look at this recent answer on the subject for a workaround.
Otherwise, Spring Quartz should work fine too. What have you tried? Share your config and specify the Mule version you're using. I'll review my answer accordingly.

Automatic serialization

I want to download xsd specifications from a web service and automatic converting (serialize) these schemas to classes (visual studio - vb.net). If the organization that is responsible for the xsd schemas alter them in a way that only my class corresponding to the xsd have to be altered (not the rest of my code) I would like to automatic update my xsd corresponding class. Is this possible? If so, can somebody tell me how to do it?
Thanks!
I use vs2010. What I want to do is: call a web service where I can send in an input parameter to the service which specifies the xsd I want to retrieve (the service is GetShemaDefenition and returns an object with the schema specification in a string property of the object). I den have to read the xsd string from the string property and convert this to a class representation of this xsd specification. Is it possible to do this automatically? I have done this manually by using xsd.exe. If the owner organization of the xsd has altered the xsd specification, I have to test if there is a new specification, and if there is I have to build a new class representation of this xsd? Is it possible to do what I want? And how would I know if it has been a big change in the xsd which also affect other parts of my code, not just the class representation of the xsd?
Tanks a lot for your reply! So what you are saying, if I understand you correct, is that there is not a good solution for automating this functionality because if the xsd change I most likely (in some occasions’) have to change my code manually? So I have to choose, either in my application or in my intermediate service? But what is the purpose for providing the xsd in a web service? What can I use the web service for? I just wondering, maybe it is clear but I am new to web services and is eager to learn more.
Update:
Thanks! But can you explain a little bit more. What I have to do is: I use one web service where one of the properties is a string. The string is an XML inside a CDATA block. The organization which provides the web service will not pares the xml inside the CDATA block but instead forward this to another organization that will use the xml data. The organization which uses the xml data specifies the xsd schem that I have to follow to generate my xml correct. This is the xsd schema I can get from another web service. I don’t really understand what I can do with this xsd file from the web service. What can I do with it and why do I want to download it from the web service, when I can’t use it automatically? Because I have to manually do the changes when the xsd changes I can easily download the xsd schema from the organization’s home page and make the new class with xsd.exe. I understand there is something I don’t understand :o), can you pleas clarify?
What visual studio version you are using?, Normally you can click on the project's references and Add Web service. In this case Visual studio creates automatically the objects required to consume the service. you can update it any time by a right click on the reference.
However if it is very likely to change often, One solution is to implement an adapter class. use create an interface that provides the same functionality and call the actual web service. In your application you use only the proxy class and not the Web Service. Later when the web service interface changes all you have to do is to change the internals of this intermediate class.
Update:
you can use this tool to create you object model in code. Then you can compile your new object model and use it in you application. There are many complications in what you want to do and the bottom line is; when the object model changes, your code will fail. There is absolutely no way to imagine how the interface will change so while you can do all that automatically there is nothing to do if the name of a function changes.
However the answer to your situation is indirection. If you can't guaranty the stability of a external service. Why not create a stable intermediate service that calls the actual one? this way in future you don't need to touch you application. All you have to do is to modify the intermediate service while keeping it's interface compatible.

MULE lifecycle - how to hook into startup process

I would like to be able to create some directories after Mule has started, but before it starts any other services.
I started looking into notifications but I'm not sure if that is the right place to do it. I will need access to the spring beans so it would have to be after spring init, but before any of the connectors and other processes kick off.
http://www.mulesource.org/display/MULE2USER/Mule+Server+Notifications
Thanks.
The mule lifecycle has several interfaces available that you could use to accomplish this.
http://www.mulesource.org/docs/site/2.2.1/apidocs/org/mule/api/lifecycle/Startable.html
.../Initialisable.html
Essentially, from what I understand, if you want something to happen when your mule instance starts you would implement startable. If you want something to happen when a specific mule component is initialized, then you would implement initialisable.
Also see http://blogs.mulesoft.org/start-me-oh-so-gently/
A really neat way of doing this is to create your own Custom Agent by implementing UMOAgent.
<!-- Enable Agents for Mule -->
<agents>
<!-- The MyAgent provides a convenient place to perform one off actions at startup/shutdown -->
<agent name="MyAgent" className="com.xxx.base.util.MyAgent" />
...
Agents have a start and Stop method which gets called by Mule, your implementing class can then add in any code you want.
See link for more info
http://www.mulesoft.org/documentation/display/MULE2USER/Mule+Agents