Using Java Module

Mule 4 Indepth Mule Basics
20 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€67.35
List Price:  €96.21
You save:  €28.86
£55.83
List Price:  £79.77
You save:  £23.93
CA$100.76
List Price:  CA$143.95
You save:  CA$43.19
A$112.23
List Price:  A$160.33
You save:  A$48.10
S$95.14
List Price:  S$135.93
You save:  S$40.78
HK$543.62
List Price:  HK$776.63
You save:  HK$233.01
CHF 63.04
List Price:  CHF 90.06
You save:  CHF 27.02
NOK kr797.48
List Price:  NOK kr1,139.30
You save:  NOK kr341.82
DKK kr502.49
List Price:  DKK kr717.87
You save:  DKK kr215.38
NZ$124.10
List Price:  NZ$177.29
You save:  NZ$53.19
د.إ257.07
List Price:  د.إ367.26
You save:  د.إ110.18
৳8,361.55
List Price:  ৳11,945.58
You save:  ৳3,584.03
₹5,962.79
List Price:  ₹8,518.63
You save:  ₹2,555.84
RM314.04
List Price:  RM448.65
You save:  RM134.61
₦108,335.42
List Price:  ₦154,771.52
You save:  ₦46,436.10
₨19,495.71
List Price:  ₨27,852.21
You save:  ₨8,356.49
฿2,390.81
List Price:  ฿3,415.60
You save:  ฿1,024.78
₺2,467.44
List Price:  ₺3,525.07
You save:  ₺1,057.62
B$434.14
List Price:  B$620.23
You save:  B$186.09
R1,296.68
List Price:  R1,852.48
You save:  R555.80
Лв131.68
List Price:  Лв188.12
You save:  Лв56.44
₩102,198.93
List Price:  ₩146,004.73
You save:  ₩43,805.79
₪256.56
List Price:  ₪366.53
You save:  ₪109.97
₱4,090.81
List Price:  ₱5,844.26
You save:  ₱1,753.45
¥10,994.99
List Price:  ¥15,707.80
You save:  ¥4,712.81
MX$1,408.98
List Price:  MX$2,012.91
You save:  MX$603.93
QR255.09
List Price:  QR364.43
You save:  QR109.34
P967.82
List Price:  P1,382.66
You save:  P414.84
KSh9,046.20
List Price:  KSh12,923.70
You save:  KSh3,877.50
E£3,562.49
List Price:  E£5,089.49
You save:  E£1,527
ብር8,907.19
List Price:  ብር12,725.10
You save:  ብር3,817.91
Kz63,830.88
List Price:  Kz91,190.88
You save:  Kz27,360
CLP$69,323.69
List Price:  CLP$99,038.09
You save:  CLP$29,714.40
CN¥510.80
List Price:  CN¥729.75
You save:  CN¥218.94
RD$4,245.36
List Price:  RD$6,065.06
You save:  RD$1,819.70
DA9,465.07
List Price:  DA13,522.10
You save:  DA4,057.03
FJ$162.39
List Price:  FJ$232
You save:  FJ$69.60
Q539.11
List Price:  Q770.19
You save:  Q231.08
GY$14,638.77
List Price:  GY$20,913.42
You save:  GY$6,274.65
ISK kr9,772.70
List Price:  ISK kr13,961.60
You save:  ISK kr4,188.90
DH703.98
List Price:  DH1,005.73
You save:  DH301.75
L1,291.33
List Price:  L1,844.84
You save:  L553.50
ден4,143.97
List Price:  ден5,920.21
You save:  ден1,776.24
MOP$559.97
List Price:  MOP$800
You save:  MOP$240.02
N$1,289.45
List Price:  N$1,842.15
You save:  N$552.70
C$2,574.80
List Price:  C$3,678.44
You save:  C$1,103.64
रु9,534.71
List Price:  रु13,621.60
You save:  रु4,086.89
S/260.99
List Price:  S/372.86
You save:  S/111.86
K283.85
List Price:  K405.52
You save:  K121.66
SAR262.91
List Price:  SAR375.60
You save:  SAR112.69
ZK1,936.45
List Price:  ZK2,766.47
You save:  ZK830.02
L335.12
List Price:  L478.77
You save:  L143.64
Kč1,694.03
List Price:  Kč2,420.15
You save:  Kč726.12
Ft27,771.44
List Price:  Ft39,675.18
You save:  Ft11,903.74
SEK kr774.38
List Price:  SEK kr1,106.30
You save:  SEK kr331.92
ARS$71,792.58
List Price:  ARS$102,565.23
You save:  ARS$30,772.64
Bs484.55
List Price:  Bs692.24
You save:  Bs207.69
COP$307,165.41
List Price:  COP$438,826.54
You save:  COP$131,661.12
₡35,530.54
List Price:  ₡50,760.09
You save:  ₡15,229.55
L1,777.33
List Price:  L2,539.15
You save:  L761.82
₲546,250
List Price:  ₲780,390.60
You save:  ₲234,140.59
$U3,115.91
List Price:  $U4,451.49
You save:  $U1,335.58
zł287.82
List Price:  zł411.19
You save:  zł123.37
Already have an account? Log In

Transcript

Welcome back. In this video, we are going to understand the modules in mule four. This is a big change from New three to node four. We'll understand about what are modules in mule four. And we'll start using one module colors Java module. Okay, before I start working on this and describing this what I want is I hope you have seen my earlier section on lab documentation.

And you have downloaded the lab documents. zip file in the downloaded zip file. If you see there is one other zip file called us, mule, four Ws. Maybe were time you see this video. Maybe I might have changed this name. Let's assume that it is we will for Ws So I've extracted this workspace this workspace, which I have created already and I have extracted this here.

This contains a lot of projects which are pre built. I want to use this as my workspace in my any points to do. I'll copy this path. Then I'll go to File, switch workspace. Other and paste this launch. The studio will restart with a new workspace.

It is fate. Yes, it's truly opened with the new workspace that we show you Okay. So here we can see there are a lot of products which I have created for you. Actually for each and every topic, there will be one solution project. And one start project you can see here it is a pattern which I followed solution start solutions that solution will contain the whole solution and start project will contain some of the files, which are required for you to get started working on. So, right now, I'll be working on a basic start project.

I'll double click on it, it was if I double click I, okay. So it got open. And when I'm working on any of the project, I want all the other projects to be closed. So right. And I'll say close, unrelated projects. Are you sure?

Yes. Okay. So all the other projects could have been closed. I'll minimize this. I don't want this outline all okay. Now here I have already created a file colors using Java module XML and work on it.

Of course, this is an empty XML. But in this project, I have some Java code. There's a class called us talk code service. Let us see how many methods are there. There are two methods. One method is a static method say hello, which is taking two arguments and another is non static method.

So now in this project, I want to use a Java module and invoke this static method non static method. So, let's go actually If you see in my POM dot XML initially just open my POM dot XML. In this pomerode XML, I will go to the dependencies section. If you see there are two dependencies only HTTP connector dependency and socket. Actually these are the modules by default. If I go back to my XML again, in graphical mode, you can see that in the mule palette on the left side you can see HTTP and sockets are added.

There are no other modules. If I want to use Java module add, click on Add modules and select the module Java and drag and drop it to the left side. So now the Java module is added. Let me open this formula XML again. Yep, see, has been updated. I'll see yes.

So if I go to dependencies section right now, you can see that in the dependencies, there is one more dependency added right now new Java module. That means in mule for whatever modules I'm using, I can just configure them as dependencies in my POM and what our dependencies are added in the palm, they will be automatically added the build path you can see Java here and that module is available. And once I select this module, whatever components that are part of module will be available on the right side. Okay, now you understood how the module system works. Now, I want to drag and drop one HTTP flow, and drag and drop HTTP listener. And as usual, I'll configure one connector configuration One ad and I take default aids right one and base path I will not do, okay.

I'll do here path as slash Hello, simply. Now what I want is whenever a request comes, I want to invoke this static method. Say hello, which is taking two arguments. So I'm expecting name and city to come with query parameters. So when somebody is giving a request to slash Hallo, I'll expect them to send slash Hello question mark. Name is equals to say Siva and CT is equals to save bandwidth.

So I'm expecting a request to come in the request data Name and city using this name and city. I want the static method Say hello to be invoked. Right. So what to do? What I can do is simply I'll go to our module drag and drop invoke static so I'll maximize this as of now which class already there is a Java class if there is no Java class and if you want to create a Java class I can click on Add button I will click on such What is the name of that? stock caught service stock cut service okay.

And which method that method name is say Hello Is it just copy paste say hello which is taking string comma string so, what go here and configure say hello, which is taking string, comma string, that's fine. But I told him what static method to call, how to pass the value of arguments. Here you can see arcs as it. Now, here there is an icon show graphical view of the arcs. I can select this. Once I select, here we can write an expression to set the arcs.

Right. But actually, the methods take two arguments I expect on the right side to contain two argument which is not as expected. Sometimes studio will be here like this. I just click on Close I'll go back to one more file and come back. Okay, now let me click on this. See now, on the right side you can see say hello, which is converting RS zero and r one, right?

I'm expecting this og zero or one as part of query parameters. On the left side you can see attributes and in the attributes is a query params. Yes. So I want to map this query params to Rs zero and r1. What all I have to do is I just have to drag and drop. Okay, so drag and drop, again, drag and drop.

So basically, you are generating data, the expression, the Data View version is two dot zero. Right? Don't worry about what is this data wave as of now we'll have a detailed list section of data Data View, where we'll write starting from basic data expression to complex data expressions. But as of now, for now, what I want you to understand is, in Data View, curly braces, if you write something in curly braces, that means it is a map. So basically in JSON also, you might be knowing if you're working with Jason. in JSON, JavaScript Object Notation, whatever you write inside curly braces is a map or an object.

And whatever we write inside square bracket is an array or a list is it. This data also follows JSON like syntax. So here is a map configured, keys are zero, not one. Whatever I give as a value for zero will go as first argument. I'm expecting query parameter columns. So read dotnet.

And here I'll expect a query parameter called us city. So here I'll say dot city. So what I'm doing I'm mapping query parameters name and city to zero and one. Okay? That's all I told what are the arguments? Right?

So if I maximize, hear arguments Don't worry this is not shown properly. You can see this inside the XML configuration. In the XML configuration, you can see that the tag name is invoke static where the arcs actual the value of arcs is a data v expression, which is a map is it. So that's it. Now, let me run and check. If I run what I should get.

I should get Hello plus name plus from city plus it from city Okay, so now let me deep run it okay deployed. So how do we request right now? What is Melissa configured with slash Hello sir to give a request to slash Hello name and city okay let me do a request procedure console is the exception no Yep, I got Hello the name concatenated with from Bangor right? Yeah. So static method was invoked very nice. So now you understood how to invoke a static method.

Now, let me show you the next one how to invoke a non static method. This is a little bit tricky. So what I will do is again, I will drag and drop one more flow. We teach it is not a good spot as slash code. So, actually this method if you see the non static method, it is taking a stock symbol and returning the price just a hardcoded in the stock symbol is military 100 IBM it is returning 200 l stock doesn't traitor. So, I want to invoke this non static method passing is proxy symbol and I'll be getting a stock price.

So, I wrote class coats. Now, if I go to Java module, there is an operation called as new. I will drag and drop this one. These actually create an object This operation is used to create an object and store it in a variable Which class is that? The class has stock code. And what is the constructor?

Right now I want to invoke default constructor. So what I'll do is I'll give the class name without any arguments. Suppose if I have a constructor with arguments, argue, let's say I have an R, I have a constructor to take string comma string as argument. How to give it like is another pass arguments here, as I should have shown you earlier. But right now, I don't want to pass any arguments. I want to invoke a default constructor.

That's fine. Now, this new operator of Java module will create an object of this class using in using this constructor specified But I want it stored in a variable how to store it in a variable. I'll click on Advanced tab. And here I'll give a variable name. Stock code services q s, these are variable name I want to create and work with attributes value, the payload, the output of this component is what? The new object which is created using this constructor.

That's now the next top next thing is here, I'll drag and drop invoke. After new I will drag and drop invoke here and which instance I will write an expression. I'll rate as well as dot. Yeah, there's a variable called Sq s. So on this object, this is an instance where as our disk is pointing to an object on this What is a method to be invoked? The method name is get stock price it is taking string. So here I'll select z invoke component.

Class I'll give the class name as again the stock code surveys. And the method name is this one which is taking string. Okay, there's only one argument out of pass a valid argument if I click on this it is not showing the method name and argument on the right same as the content. So you know what to do. Just have to go to the another file and come back to reinitialize. Then if I maximize this invoke, and if we click on this graphical view Yep, now you can see get stock price argument.

I'm expecting the argument from let's say query parameter. I'll drag and drop it. So query parameter name. I'm expecting as dot stock. Done. So I configured to invoke this method on which instance vas.sq s. That's it.

The return value of the method will be the payload. I will drag and drop a logger and just log your cash payload. Okay. Now, let me debug. I want to debug and keep a breakpoint. I will kill the existing product.

Which is running application and then I will debug Okay, it's asking me to switch to debug perspective. Yes. No let me do a request to localhost 8081 slash caught. Question mark stock is it goes to IBM, I gave a request. Now it is here. When it is at this point.

Still the new is not executed. If you see in the vast the map size zero, I will press f6 it came it will come to the next component. You can see in the verse, there is SQL it is an object of Stop car service. Now if I say if I say f6 it will invoke the method. And now if you see the payload or the payload 200 because it paused IBM the method is returning 200 The 200 will be the mule message payload which command responsible press f8 now, I should see that 200 response by 200 because I pass the stock value of stock symbol as IBM and in this method if the value was this IBM it is running 200 So, now you understood how to invoke a non static Java method. Great.

What you can do is after this video, you have to follow a documentation in the lab documentation which you have downloaded from section two can just open this using Java module. Here are detailed instructions on what you have to do. Follow this document and complete the exercise. See you next video.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.