Consuming Soap Webservice using Webservice Consumer and using choice router

Mule 4 Indepth Consuming Rest and Soap Webservices
26 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
€65.39
List Price:  €93.41
You save:  €28.02
£55.92
List Price:  £79.90
You save:  £23.97
CA$96.01
List Price:  CA$137.16
You save:  CA$41.15
A$107.15
List Price:  A$153.08
You save:  A$45.93
S$95.13
List Price:  S$135.90
You save:  S$40.77
HK$547.14
List Price:  HK$781.66
You save:  HK$234.52
CHF 63.86
List Price:  CHF 91.23
You save:  CHF 27.37
NOK kr775.40
List Price:  NOK kr1,107.76
You save:  NOK kr332.36
DKK kr487.78
List Price:  DKK kr696.86
You save:  DKK kr209.07
NZ$118.01
List Price:  NZ$168.60
You save:  NZ$50.58
د.إ257.06
List Price:  د.إ367.24
You save:  د.إ110.18
৳7,680.49
List Price:  ৳10,972.60
You save:  ৳3,292.11
₹5,842.03
List Price:  ₹8,346.11
You save:  ₹2,504.08
RM332.86
List Price:  RM475.54
You save:  RM142.67
₦86,437.65
List Price:  ₦123,487.65
You save:  ₦37,050
₨19,491.96
List Price:  ₨27,846.85
You save:  ₨8,354.89
฿2,586.09
List Price:  ฿3,694.58
You save:  ฿1,108.48
₺2,265.39
List Price:  ₺3,236.41
You save:  ₺971.02
B$363.53
List Price:  B$519.35
You save:  B$155.82
R1,302.64
List Price:  R1,861
You save:  R558.35
Лв127.90
List Price:  Лв182.73
You save:  Лв54.82
₩96,270.48
List Price:  ₩137,535.16
You save:  ₩41,264.67
₪262.29
List Price:  ₪374.71
You save:  ₪112.42
₱4,033.94
List Price:  ₱5,763.02
You save:  ₱1,729.07
¥10,867.12
List Price:  ¥15,525.12
You save:  ¥4,658
MX$1,187.12
List Price:  MX$1,695.96
You save:  MX$508.84
QR254.93
List Price:  QR364.20
You save:  QR109.27
P994.08
List Price:  P1,420.18
You save:  P426.09
KSh9,360.69
List Price:  KSh13,372.99
You save:  KSh4,012.30
E£3,358.63
List Price:  E£4,798.26
You save:  E£1,439.62
ብር4,003.77
List Price:  ብር5,719.92
You save:  ብር1,716.15
Kz58,546.63
List Price:  Kz83,641.63
You save:  Kz25,095
CLP$67,216.99
List Price:  CLP$96,028.39
You save:  CLP$28,811.40
CN¥506.70
List Price:  CN¥723.89
You save:  CN¥217.19
RD$4,073.53
List Price:  RD$5,819.58
You save:  RD$1,746.04
DA9,418.34
List Price:  DA13,455.35
You save:  DA4,037.01
FJ$158.31
List Price:  FJ$226.17
You save:  FJ$67.86
Q543.96
List Price:  Q777.12
You save:  Q233.16
GY$14,650.29
List Price:  GY$20,929.88
You save:  GY$6,279.59
ISK kr9,815.39
List Price:  ISK kr14,022.59
You save:  ISK kr4,207.20
DH707.71
List Price:  DH1,011.06
You save:  DH303.35
L1,237.78
List Price:  L1,768.33
You save:  L530.55
ден4,025.24
List Price:  ден5,750.59
You save:  ден1,725.35
MOP$563.96
List Price:  MOP$805.69
You save:  MOP$241.73
N$1,304.33
List Price:  N$1,863.42
You save:  N$559.08
C$2,570.38
List Price:  C$3,672.13
You save:  C$1,101.75
रु9,397.27
List Price:  रु13,425.24
You save:  रु4,027.97
S/263.43
List Price:  S/376.35
You save:  S/112.91
K270.11
List Price:  K385.89
You save:  K115.77
SAR262.49
List Price:  SAR375.01
You save:  SAR112.51
ZK1,873.89
List Price:  ZK2,677.10
You save:  ZK803.21
L325.37
List Price:  L464.84
You save:  L139.46
Kč1,643.47
List Price:  Kč2,347.91
You save:  Kč704.44
Ft25,458.03
List Price:  Ft36,370.18
You save:  Ft10,912.14
SEK kr764.90
List Price:  SEK kr1,092.76
You save:  SEK kr327.86
ARS$61,327.27
List Price:  ARS$87,614.14
You save:  ARS$26,286.87
Bs483.57
List Price:  Bs690.85
You save:  Bs207.27
COP$273,218.78
List Price:  COP$390,329.27
You save:  COP$117,110.49
₡35,710.66
List Price:  ₡51,017.42
You save:  ₡15,306.75
L1,733.65
List Price:  L2,476.75
You save:  L743.09
₲524,442.73
List Price:  ₲749,236.02
You save:  ₲224,793.28
$U2,683.09
List Price:  $U3,833.15
You save:  $U1,150.06
zł283.24
List Price:  zł404.64
You save:  zł121.40
Already have an account? Log In

Transcript

Welcome back. In this video, you will understand about how to consumer soap web service. And also we'll use choice router. Let us see how easy it is to consume a soap web service before I proceed, I have a soap web service I want you to understand what is my soap web service. So in this lab documents given to you, there is a jar file product soap service, this is a jar file, which I created using spring framework. And if I run this jar file, it is exposing a soap web service.

I also have written a soap brought back Let me open this Yep, if you see if I execute this so bad bad. It is executing a jar file. It will start internal Tomcat Port 1234 and the This part will be SOP. Okay, so let me start. It looks good. So good, bad.

Yes. So this should start my soap web service. Yep. So it's almost starting. Yep. You can see that the Tomcat started on port 1234.

I want to see the wisdom right now. Let's see. I open the browser. I'll do a request to localhost 1234. Slash Ws is a base user slash public slash soap. Is slash soap because there's a Basic slash, so slash, Ws slash products dot visit.

If we give a request to this URL, it will show me the wisdom for my soap web service. Yep. This is the register. So according to this wisdom, how many operations are there? Again, see here in this port type, there's only one port type. There's no question call us get all products that you get all the products, add a product, get product by name, these are three operations.

I want to actually consume this. So soap service using soap UI, so just open. So UI installed on this machine Yes. Open so I want to actually create a sub project so I'll click on this icon which will create a new sub project. And here I give the vistal URL. So what is my visitor Well, this is one create Yep, you can see this is showing three operations, add product, get all products, get product by name, file use get all products.

And here if I double click on it, it will show me the sample request. Yes. Actually, if you see there is no data to get all the products the only the route tech get all products request. So every play I got the response the route tag is getting All products response and root under that I have products and it has given me products up to productivity six There are six products. Okay. Now if I want to get products by name, I want to give a request for this operation.

I'll click on sample request. Okay. See the route tag is Get Products by name request. Here I'll pass a name as hp. So it should give me only the HP products. I'll make a request.

Yes, get products by name response. And I have only one product. Number one product by name Mac. I will type your Mac give a request. See I got two apps products. Please don't worry, the font is very, very low here.

So due to resolution of my system, but I hope that you're able to understand the concept. Similarly, I can make a request to add product by passing this big document. Now you understood how to consume a soap service using soap UI. I want to do the same thing using mule. So let's get started. I'll be working on this consuming scope service.

Here in SRC made mule, I'll create a new XML by clicking on new you will configuration file. I will give the file name as soap demo. Okay, now I need a web service consumer module. So actually, this website Consumer module you are seeing on the left side because earlier when I created this project I have added initially it will not be there, I removed it, how to click on Add modules and select web service consumer, drag it to the left side. Now the web service module web service consumer module is added to the project. Now, drag and drop consume a flow should be created with web service consumers consume operation.

Now for this consume to give the corrector configuration for every connector, which we see on the right side, we need to configure the connector configuration. So I'll click on plus. Yep, here it is asking for wisdom location. So I think Get the same vistal URL. Okay, and now the first tab, it should automatically download the physical and other fields should be automatically populated if we check here is populated. Not yet.

It'll take some time. Yep, slowly it got populated. Yep, here also the port got populated. and here also the endpoint URL got populated. So automatically once I gave the wisdom URL, a download the wisdom. And if there are multiple service declarations in one way, still, I can select what service I want to consume through this drop down.

And the same service expose or multiple ports I can select what port and also the endpoint you are. Right now the endpoint URL is 1234 slash soap slash Ws. Okay. Sir. Now, what operation do I want to consume? Again, it is taking some time to fetch metadata it fetched.

If you see here again, it is showing me all the operations. Now I want to consume, get all get all products all selected simple. So now I have configured this consume operation to consume get all products. So, what I'll do is right now I'll double click on the flow and I'll change the flow name to get all products. Okay. So now for testing this, I'll drag and drop one more flow with the HTTP listener.

I want this flow to be named as main flow. All requests will come first here. So we'll configure this listener as usual. To listen on port 18081 and the base path has a slash products. Then how to invoke the second floor from first floor by using flow reference. So go to core or we'll go to favorites and and drag and drop flow reference.

And then I'll configure this flow reference to point to get out products display name also it will be always a good practice to use the display name same name as a floating grid. So now I want to test this so let me run this Okay, so what got deployed Now let me give a request to localhost 8081 slash products I should get the same response from So, so it was a with not back. Oh yeah, I think you can see that the response looks like JSON where body value is an XML. Good if you can see the same thing on postman okay. Request now let's see. Yep, you can see that the response is a Jason received the response headers.

Your content type is Java and it looks like adjacent value body and the value is an XML. So I don't want it to be like this I want to extract all of the XML and see. So basically there are a lot of Transformers which we can use to convert to extract the body. The important Transformers The best transformer is a transformer called as transform methods component. So I've been in my favorites I have or I'll type here. transform method.

Yep, this is the one so I'll drag and drop it here. Over here Excuse me. So here I'll drag and drop this transform message to get our products. Now, this is a component where we write an expression called as data v expression. I didn't introduce you to what is this de Ws till now, you'll understand it slowly. But right now, I will tell you some basics.

If you want to write some transformation logic using dw L, you can use a transformer called as transform message. So, in the transform message, here you have to write the logic. So, the code before dash dash dash will contain some headers. The first line is telling that we're going to use data view version 2.0 and the output MIME type is application slash Java. But I want output now to be XML Don't worry, what is this data we have language. We'll have a deep dive into data view transformation language later.

Right now just understand that for transformations in noon, we'll be using a language called has dw Data View transformation language. And here I'm writing a simple data expression. What R is after dash dash dash is that every expression has type payload, dot body, I want the content of the body because if you can see the response in the payload, the first case body, I want the value of body. So I wrote payload dot body dot. The next tag is get all products response and here it is using some As the zero hash I will delete it. Don't worry, you will understand what is the Xs zero has said I will delete it.

So literally I can say that I want the body of get all correct response. So that's fine. Now I have a transformer and I should see the transform message. I guess since I made some changes, if I save, this should get restarted, the application should get restarted. So I just started. Now if I give a request to same slash products Yep, I see the response is an XML whose root tag is products and I have a list of all the products up to product with ID six normally in a real Application once we get this XML after transformation, we might want to extract some data and we will do some logic.

But right now, I just want display the result XML So, I did like this. Now, I want to write one more flow to consume Get Products by name. So again, what I will do is I just go to web service consumer module and I will drag and drop this consume operation again. I want to rename this flow as Get Products by name. Okay, get products by name. Okay.

Now, for this consumer. See, I don't need to configure the character configuration again. It's a global element which can be reused same thing, but know the operation. I want to select as get product by name. That's fine. But actually from soap UI earlier, we understood that if I want to consume Get Products by name, the body should contain this XML is it so how to prepare this XML before the web service consumer component, I need to somehow make sure that the body of the mule message is this XML.

There are multiple ways on how to create an XML. What I have done is right now I expand this SRC main sources. Here I have it in some template. I have an XML in SRC main resources called us get product by name here, this is how I want the XML in the soul body. I have written an XML For the dynamic part, I have to write an expression which will get the product name from query parameters. So, I will write hash attributes dot query params This is same data expression dot product name.

So, basically this is this file is looking like a template wherever dynamic part is that I want this database expression to be evaluated. Okay. So, I have a template file with some dynamic parts. I want a component dot transformer in mule which can load a template file, evaluate any expressions inside it and the output of revelation Oh Input should be the XML right? So, I need a component what is that component there is a component called as parse template, I will drag and drop here before this consumer now, it is asking me to specify the location since it is in SRC main resources it isn't a class but I can just give it the file name Get Products by name dot XML okay. So, this past template will load this template, but it is expecting a query parameter called us Product Name it will evaluate and then the content of this template file will be the body.

So, that will go as an input to my consume operation. and consume operational we'll make a soap request. So let us check I want to test this. So the flow reference right now I'll make it a point to get products by name. And I'll make sure that the display name also is the same. Okay.

So the main floor is known working Get Products by name. So it should have restarted after I saved. Yes. So I'll make a request. A lot of past question mark. A query parameter right.

Product Name is equals to hp. So again, I got the Jason Jason like a data. So where the key is body and the value is this XML is it So I want to transfer over again. Okay, in this flow, I'll go and I'll drag and drop transform message component again. And here I will write the data wave expression as payload, dot, body dot. Get product by name response here.

As usual like earlier, I'll delete this and a zero hash. Don't worry, I'll understand make you understand about this. Later when I was when I'll be talking about D wl in detail. That's it. Now I have saved it again it is getting redeployed. Now I will give a request to the same URL.

Oh, it is showing as a hash map right because in this transform methods component the output is given as Java Oh no, I want it as an XML so that I can display it properly on the browser XML. Now, I will save this automatically it should get redeployed. Okay, so let me give a request same request. Yep, I got only HP products. If I give a request for slash for Mac I should get the Mac products. Yep, there are two Mac products.

So now you understood how to consume a soap operation which required Some data before the consume operation, you should make sure that the payload of the mule message should be whatever you were expecting to go as part of somebody. So, in this case, I used a template, I wrote a template file and I wrote expression in the dynamic part. So, parse template will load the given template file, evaluate these expressions and then the content of this file will be set as board right. So you understood about how to consume I will leave it as an exercise for you to consume add product operation. Now, I want to modify this application to you As a choice router, so that it can conditional route to either get products by name or get our products. So I will delete this floor reference.

Then I will drag and drop choice, then immediately I will drag and drop for flow reference. One flow reference instead is one, another flow reference outside of it, but after choice and then in default, I'll drag and drop a set payload. Here I'll set the payload as a simple text. I don't want an expression I'll just use in protest invalid input. Okay, so the first floor reference, I'll point to get all products. I'll go the display name also as catalog products.

Then similarly here, I will make the second one to point to get products by name. I'll give the display name and same. Then I had to configure this when, when they should be executed GitHub products. When attributes dot query params dot product name, I'm exploiting query parameter plus product name. If it is equals to null then get out from should be executed. And second one I'll write the opposite condition for the one is not equals to null.

That's how I have configured a choice router to conditionally route the quiz. I hope that you have already started as I saved it. Yes. So I'll go to postman and make a request with product name as query parameter. See I got only the Apple products. Now if I don't go product name, I should get all the products.

Yes, I got all the products from you will Samsung products up to PR credit six So we understood how to actually route conditionally. Also how to consume a soap web service very easily by using web service consumer modules. Consume operation, right. So after this video, there is one exercise to be done. See the lab document, there'll be a document called as consuming soap web service. Follow the step by step instruction and consume all these operations.

See when 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.