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
€66.54
List Price:  €95.06
You save:  €28.52
£55.59
List Price:  £79.41
You save:  £23.82
CA$98.62
List Price:  CA$140.89
You save:  CA$42.27
A$107.77
List Price:  A$153.97
You save:  A$46.19
S$94.24
List Price:  S$134.63
You save:  S$40.39
HK$544.69
List Price:  HK$778.17
You save:  HK$233.47
CHF 61.97
List Price:  CHF 88.53
You save:  CHF 26.56
NOK kr777.48
List Price:  NOK kr1,110.74
You save:  NOK kr333.25
DKK kr496.36
List Price:  DKK kr709.11
You save:  DKK kr212.75
NZ$119.56
List Price:  NZ$170.81
You save:  NZ$51.24
د.إ257.07
List Price:  د.إ367.26
You save:  د.إ110.19
৳8,365.27
List Price:  ৳11,950.91
You save:  ৳3,585.63
₹5,900.44
List Price:  ₹8,429.57
You save:  ₹2,529.12
RM312.50
List Price:  RM446.45
You save:  RM133.95
₦117,802.26
List Price:  ₦168,296.16
You save:  ₦50,493.90
₨19,453.72
List Price:  ₨27,792.22
You save:  ₨8,338.50
฿2,424.59
List Price:  ฿3,463.85
You save:  ฿1,039.26
₺2,424.79
List Price:  ₺3,464.14
You save:  ₺1,039.34
B$407.45
List Price:  B$582.09
You save:  B$174.64
R1,266.19
List Price:  R1,808.93
You save:  R542.73
Лв130.55
List Price:  Лв186.51
You save:  Лв55.96
₩97,779.29
List Price:  ₩139,690.68
You save:  ₩41,911.39
₪255.44
List Price:  ₪364.94
You save:  ₪109.49
₱4,127.53
List Price:  ₱5,896.73
You save:  ₱1,769.19
¥10,761.39
List Price:  ¥15,374.07
You save:  ¥4,612.68
MX$1,436.97
List Price:  MX$2,052.90
You save:  MX$615.93
QR254.80
List Price:  QR364.02
You save:  QR109.21
P956.33
List Price:  P1,366.25
You save:  P409.91
KSh9,063.70
List Price:  KSh12,948.70
You save:  KSh3,885
E£3,472.08
List Price:  E£4,960.32
You save:  E£1,488.24
ብር8,640.26
List Price:  ብር12,343.76
You save:  ብር3,703.50
Kz63,900.87
List Price:  Kz91,290.87
You save:  Kz27,390
CLP$68,324.23
List Price:  CLP$97,610.23
You save:  CLP$29,286
CN¥507.13
List Price:  CN¥724.50
You save:  CN¥217.37
RD$4,227.39
List Price:  RD$6,039.39
You save:  RD$1,812
DA9,355.03
List Price:  DA13,364.90
You save:  DA4,009.87
FJ$160.86
List Price:  FJ$229.81
You save:  FJ$68.95
Q540.54
List Price:  Q772.23
You save:  Q231.69
GY$14,646.31
List Price:  GY$20,924.19
You save:  GY$6,277.88
ISK kr9,657.22
List Price:  ISK kr13,796.62
You save:  ISK kr4,139.40
DH702.24
List Price:  DH1,003.24
You save:  DH301
L1,275.33
List Price:  L1,821.98
You save:  L546.64
ден4,122.75
List Price:  ден5,889.90
You save:  ден1,767.14
MOP$561
List Price:  MOP$801.47
You save:  MOP$240.46
N$1,262.61
List Price:  N$1,803.81
You save:  N$541.20
C$2,572.83
List Price:  C$3,675.63
You save:  C$1,102.80
रु9,443
List Price:  रु13,490.57
You save:  रु4,047.57
S/265.82
List Price:  S/379.76
You save:  S/113.94
K281.76
List Price:  K402.53
You save:  K120.77
SAR262.83
List Price:  SAR375.49
You save:  SAR112.66
ZK1,930.37
List Price:  ZK2,757.79
You save:  ZK827.42
L331.18
List Price:  L473.14
You save:  L141.95
Kč1,682.84
List Price:  Kč2,404.16
You save:  Kč721.32
Ft27,375.34
List Price:  Ft39,109.31
You save:  Ft11,733.96
SEK kr767.08
List Price:  SEK kr1,095.88
You save:  SEK kr328.79
ARS$70,438.83
List Price:  ARS$100,631.22
You save:  ARS$30,192.38
Bs485.51
List Price:  Bs693.62
You save:  Bs208.10
COP$307,934.64
List Price:  COP$439,925.49
You save:  COP$131,990.84
₡35,677.50
List Price:  ₡50,970.05
You save:  ₡15,292.54
L1,765.49
List Price:  L2,522.24
You save:  L756.75
₲545,419.77
List Price:  ₲779,204.49
You save:  ₲233,784.72
$U2,983.14
List Price:  $U4,261.82
You save:  $U1,278.67
zł287.23
List Price:  zł410.35
You save:  zł123.11
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.