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.18
List Price:  €95.97
You save:  €28.79
£55.86
List Price:  £79.80
You save:  £23.94
CA$97.87
List Price:  CA$139.82
You save:  CA$41.95
A$107.62
List Price:  A$153.75
You save:  A$46.13
S$94.24
List Price:  S$134.64
You save:  S$40.39
HK$544.83
List Price:  HK$778.36
You save:  HK$233.53
CHF 62.54
List Price:  CHF 89.34
You save:  CHF 26.80
NOK kr774.97
List Price:  NOK kr1,107.14
You save:  NOK kr332.17
DKK kr501
List Price:  DKK kr715.75
You save:  DKK kr214.74
NZ$119.95
List Price:  NZ$171.37
You save:  NZ$51.41
د.إ257.07
List Price:  د.إ367.26
You save:  د.إ110.19
৳8,361.58
List Price:  ৳11,945.63
You save:  ৳3,584.04
₹5,909.84
List Price:  ₹8,442.99
You save:  ₹2,533.15
RM312.71
List Price:  RM446.75
You save:  RM134.04
₦118,484.88
List Price:  ₦169,271.38
You save:  ₦50,786.49
₨19,443.22
List Price:  ₨27,777.22
You save:  ₨8,334
฿2,412.28
List Price:  ฿3,446.26
You save:  ฿1,033.98
₺2,418.32
List Price:  ₺3,454.90
You save:  ₺1,036.57
B$406.01
List Price:  B$580.04
You save:  B$174.03
R1,267.89
List Price:  R1,811.35
You save:  R543.45
Лв131.37
List Price:  Лв187.69
You save:  Лв56.31
₩98,301.65
List Price:  ₩140,436.95
You save:  ₩42,135.30
₪259.10
List Price:  ₪370.16
You save:  ₪111.06
₱4,125.14
List Price:  ₱5,893.31
You save:  ₱1,768.17
¥10,832.35
List Price:  ¥15,475.45
You save:  ¥4,643.10
MX$1,429.79
List Price:  MX$2,042.64
You save:  MX$612.85
QR255.18
List Price:  QR364.56
You save:  QR109.38
P956.90
List Price:  P1,367.06
You save:  P410.16
KSh9,061.51
List Price:  KSh12,945.58
You save:  KSh3,884.06
E£3,475.01
List Price:  E£4,964.52
You save:  E£1,489.50
ብር8,566
List Price:  ብር12,237.67
You save:  ብር3,671.66
Kz63,900.87
List Price:  Kz91,290.87
You save:  Kz27,390
CLP$69,057.73
List Price:  CLP$98,658.13
You save:  CLP$29,600.40
CN¥506.93
List Price:  CN¥724.22
You save:  CN¥217.29
RD$4,217.06
List Price:  RD$6,024.63
You save:  RD$1,807.57
DA9,397.90
List Price:  DA13,426.15
You save:  DA4,028.25
FJ$159.29
List Price:  FJ$227.57
You save:  FJ$68.27
Q540.13
List Price:  Q771.64
You save:  Q231.51
GY$14,638.82
List Price:  GY$20,913.50
You save:  GY$6,274.67
ISK kr9,776.20
List Price:  ISK kr13,966.60
You save:  ISK kr4,190.40
DH703.91
List Price:  DH1,005.63
You save:  DH301.72
L1,275.33
List Price:  L1,821.98
You save:  L546.64
ден4,132.76
List Price:  ден5,904.20
You save:  ден1,771.43
MOP$561.01
List Price:  MOP$801.48
You save:  MOP$240.46
N$1,268.91
List Price:  N$1,812.81
You save:  N$543.90
C$2,574.70
List Price:  C$3,678.31
You save:  C$1,103.60
रु9,449.77
List Price:  रु13,500.25
You save:  रु4,050.48
S/265.32
List Price:  S/379.05
You save:  S/113.72
K281.71
List Price:  K402.47
You save:  K120.75
SAR262.77
List Price:  SAR375.40
You save:  SAR112.63
ZK1,934.92
List Price:  ZK2,764.29
You save:  ZK829.37
L334.42
List Price:  L477.77
You save:  L143.34
Kč1,702.59
List Price:  Kč2,432.37
You save:  Kč729.78
Ft27,646.05
List Price:  Ft39,496.05
You save:  Ft11,850
SEK kr772.42
List Price:  SEK kr1,103.50
You save:  SEK kr331.08
ARS$70,259.44
List Price:  ARS$100,374.93
You save:  ARS$30,115.49
Bs483.50
List Price:  Bs690.75
You save:  Bs207.24
COP$307,238.59
List Price:  COP$438,931.09
You save:  COP$131,692.49
₡35,641.51
List Price:  ₡50,918.63
You save:  ₡15,277.11
L1,768.23
List Price:  L2,526.16
You save:  L757.92
₲546,248.87
List Price:  ₲780,388.98
You save:  ₲234,140.10
$U2,983.14
List Price:  $U4,261.82
You save:  $U1,278.67
zł291.40
List Price:  zł416.31
You save:  zł124.90
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.