 to take you, walk you through today's lab work, what we are going to do today is basically create a web service and deploy it and then use that web service, call that web service in a client. So the functionality that the web service will provide is going to be similar to what we did yesterday in our exercise. We will kind of create an operation get secret code which was which was told to you yesterday. It will accept a group ID and it will return the secret code of the particular group. So what we can do is we can create the web service from scratch, write the whole code we wrote yesterday all over again, but instead what we will do is we will use yesterday's code inside our today's web service. That's what we do object oriented programming for. So let's start. As you can see this is our yesterday's lab project. You can use you can use the project you created if it is functional completely. In case it is not you can use the one we distributed yesterday through the pen drive as a zip file. Just make sure that the XML file and the XSD file from the zip are extracted on your local disk and the path of that XML file is edited in each of these parser Java files. Like you can see over here make sure that this path points to the XML you've copied on your local disk. After doing this for each of this my DOM parser, my Jaxby parser and my Sacksparser. You build the project and deploy it again. So now we'll start with our web service. We first have to create a new project. Anywhere you store that XML file has to that path as the specific wherever it is called. There's nothing automatic about anything there. So what happens is that the program itself is expecting that the file will be in a certain path. That's what we just showed you in the code, right? Now if the file is not in that path then there will be an exception thrown at that point in time. So wherever the file you can either create this path and store the file there or you store the file anywhere you want and specify that path here. So I don't know whether it will take the C colon backslash. For this particular application it is not required. So we proceed. We are creating a web application. We'll give some name like secret code web app. So now we actually are aiming to reuse yesterday's code. So we'll copy the package we created yesterday to this project. It's been copied because in my yesterday's project I have specified the path of the XML as SRC slash group details.xml. It's basically a relative path. So I need the XML in the relative path of the new project I've created also. So I'll have to copy the XML file as well in the new project. As sir has explained earlier there are two ways of creating a web service. You can create it from a Vizdel or from a Pojo. We'll follow the Vizdel method. So for the first step we need to do is create a Vizdel which will define the web service and the various operations in it. So we right click on the... Okay the Vizdel is not in this list. So we go to other. Was it there? Okay anyways in this window you can specify a name for a port type. You can specify the... And you can specify operations basically. So we are required to create one operation which will give us the secret code of the particular group ID. So we will give a name to the operation. So remember that in the morning's presentation we went through that the Vizdel would have an abstract part in the concrete form. The abstract part is a port type which is basically consisting of a list of operations. Every operation of a list of messages. That's the first part that we're doing in here. Yeah the input we are providing is basically a parameter. It will be a string which will have the group ID. You just change the name of that. We'll click next. In this window you can specify a name for the... You can specify a binding name. You can specify the different types of binding that are available. You can actually... Yeah you can do it later on. After you create the web service you can add more operations using the NetBeans ID. This wizard provides functionality only for one operation. Later on you can add more operations. I'll show you that. That's all. You are actually creating that operation. You are defining that operation. So you will add that data. You will add the data in the Vizdel as well. So we can specify a binding subtype. Now this web service name can also be provided. We'll keep it as default. So it has created a Vizdel. I'll show you the source of the Vizdel file. This is what it looks like. Now as you are saying if you need an extra operation. You can always... See this is the port type that is defined. Under this port type we have defined an operation get secret code through the wizard. If you want to add an operation right click on this add operation. You can define another operation create. So the other way of doing this you can hand write your Vizdel. Yeah you can hand write the whole source code. It's a good way of understanding how to do this if you hand write once. And ID is make things simpler. But if you could it doesn't have to come. These things give you all these wizards to help you create your Vizdel file. Okay so our Vizdel is ready. Now we'll move on to actually creating the web service using this Vizdel. We'll right click the project. New. And you can see here there's an option web service from Vizdel. You can specify a package. I'll give the package name as web service. And we have to specify the Vizdel we just created. So I'll go to the location of the project folder. The Vizdel we created just now. When the Vizdel is loaded it automatically extracts the port name and the service name. It can be sure. This was automatically extracted from the Vizdel. Look at finish. Yeah so what netmeans did it using the Vizdel it generated a class for the service. And the Vizdel defined one operation. So it has basically generated the code for that operation as well. Now basically the operation over here is just a skeleton. We have to implement some code in it. It will provide you with the skeleton. It will implement any kind of business logic you want to do. In our case our implementation would be returning a secret code. So here's the code that netmeans generated. So we want to reuse yesterday's code right. So we'll import that package into this Java file. Now we'll implement the operation. You can see it has already generated a skeleton for this get secret code. We'll remove this. Before we remove that there was a throw not supported except. You can simply compile this when you hit that particular operation. This exception will be thrown. But the end-to-end message cycle will be client to the web services impact. It's just to the operation that is not being implemented. The default implementation is that this point even without doing anything. You can deploy it versus that part end. So we'll now write our implementation. We cleared a string secret code. I'm going to use yesterday's parser class which is my Jaxby parser. I've created an object of the my Jaxby parser class. Now I can get secret code operation of the parser. The output sign to secret code. So I'll do parser dot get secret code. So all that pop-ups that you're seeing right. Say parser dot. The ID knows that the parser is of type my Jaxby parser. So it goes and looks at the class and it knows that this contains all these methods. So it knows that you're going to call one of those methods. So it will pop that list of. You can just select it instead of typing it. So now secret code will basically get the output of get secret code from the parser class. And we'll say return. Okay. Now the implementation is ready. We'll save this. Now we can see that our web service is complete. So we'll build this application and we need to deploy it on the server. So we'll make sure whether the Glassfish server is up. It's not up. So you need to go to services tab. Open the servers tree. Right click on Glassfish v2 and it start. Let's start it. We'll go and deploy. So our web service is now deployed at the Glassfish server. We now will create a consumer web application which will actually use that web service to display the result. Create a new project. This will again be a web application. We'll give it a name. Now in the consumer web application, we basically are calling the web service. So we need to generate some kind of references to those deployed web services. So for that, we'll have to create something called as a web service client. We right click on the project web service client for the Visdell of the web service. In our case, the Visdell is already there in the project folder. So we'll access it from this option. So as you can see over here, it has created a web service reference for secret code service. Now we'll use a web service client to call the web service. And we'll write that code in a JSP so that the result is displayed in the JSP. This index.JSP was created by default when we created a new web application. As you can see, it was created in the previous application also. We actually don't require index.JSP in secret code web application because the web service as such is not providing a GUI. It provides a machine-to-machine interface. So we actually don't require this index.JSP. You can delete it if you want. Now in the consumer web application, I'll write code in the JSP to display the result of the web service operation. So NetBeans provides us automated calling facility. You right click on the JSP page. There's an option web service client resources called web service operation. And you can actually select, it will give you the list of the operations provided by the web service and select one operation. Hit OK. It will generate code to actually call that operation. As you can see, it has created an object for the service, implemented the port and it has, using the port, it has called the get secret code operation. By default, the default generated code specifies group ID as null. We can provide it, say, I want the secret code for group ID 5. I'll just modify this bit. So the code says that the result is stored in this result variable. We'll just display it in a better way. We'll save this. Now our consumer web application is also ready. So we'll build it and deploy. The page through the NetBeans interface or open up a browser can specify a different port to the two different servers. The Tomcat is not. Yeah. We are using only Glassfish. The JSP hard port is the only JSP. Where? Not from exception. Ready that you're giving. Can you look at the JSP again? There's a group ID. There it is. Go down. Time up. Group details.xml. Group details.xml. Group details.xml. Look what it's searching. Let's see the whole part. Oh, this is not taking from application. Yeah. It's taking slash configs. Yeah. Program point last bit to make. This is not the part relative to where the application has been deployed. Okay. Dot slash. Try dot slash. There's nothing wrong with the code. You can see. This is the config slash. It's printed in our application name. This is our season hour application. Our project folder. This is the project folder. But last bit. It's okay. Let me see whether it gives a better... It won't work. It won't work. It just tells the group details.xml or the whole part details. Copy the file into this part that he's expecting. Relative to where the application has been deployed. Yeah. The root. Point the source. It's all right. It's still going to config slash. It's still going to config slash. It's still config to be the root. It's going to search from there. And it's saying source slash. That's all right. It's still config. Hold under config. One minute at a time. Config. I'm looking for under source. You have to change your file also. So the error which we were getting earlier was because of the fact which I had mentioned at the first step that group details.xml was not in the proper place. So he has a lesson. If you don't put it in a proper place, you might land up like this. So what had happened was in my yesterday's project, I have specified the location of the XML as a relative path. As you can see. Now what what NetBeans was Glassfish does it, if you deploy the if you deploy a web application through the NetBeans ID, it actually does not. It it just actually creates a reference. Reference to the what do you say, the project folder on the local file system in the in the web servers library. So it doesn't actually deploy the whole jar file. Solution. Yeah. You just put that double slash into a single slash. It will work. Double slash when you're searching. You just put a double slash into a single slash. When you're searching. No, it works. In the path you're saying before SRC. SRC same. Give two slash. No, that works for backslash. We are not using backslash. For this only. What is happening is. Over here, what is happening is it is trying to search group details.xml in the Glassfish domain. But the whole project folder is not deployed in the domain because we deployed the project using NetBeans ID. If you deployed the project using a war file, that war file would have been expanded in the Glassfish domain itself. In this case. Because that file object is not created here. The problem is with the argument which you are passing here that is SRC slash. I understand your point. Double slash will work. Yeah, that's what it will create that problem if I had used backslash. Because backslash is an escape character in Java. Suggesting you can try. Yeah, sure. Because I tried it, I was also getting unknown. Is this what you're suggesting? I just made that change, I got the result. Is this what you're suggesting? Yeah, this is what it is. Okay. Now the file is anyway being copied under the Glassfish domain. It's going to work anyway. No, I'll remove that. We can blow it away. Okay, we'll remove that xml file from the location. Just search it and configure it. No way, no way. Let us flesh this. No, but you know that SRC is there. Relative to what is the question? See, even if you give an absolute bar, if you give a single slash, it won't work. It worked the first time, right? No, it did not work. Yeah, it worked the first time. I'll show you. No, just before this. Yeah, just before this. At that time it had SRC slash good details. But if you give only the file name, it will work. I'm not saying that. Group detail dot xml is very good. Now my question is, if you give an absolute path here, something in C... Yeah, it will work perfectly. It will not work perfectly. There you need to give this. Yeah, that's what I said. See, because if you give an absolute path, it won't search for the group details dot xml in the Glassfish domain. Because it is searching for... You've given a complete path. Because I've given a relative path, it was searching it in the domain, which I did not find. So basically, it tried to find out the SRC into the domain only? Yeah, it was trying to do that. Exactly. Exactly. Do you want me to rename the domain? Okay. Shall we do the second method? Yeah, that's all. That's all. You're not supposed to do the other method. That's all. Why not? The argument is incorrect. Pyroplastic is not created. We are getting no point of exception. It's not the point. We can fix it to find the point of exception. The point of the exercise mainly is to learn how to decode a web service. Hopefully we have done that, right? I think that is what's important. Yeah, purpose is so. Yeah, which is what's critical. So the handouts that you've received actually walks you through the steps that you just went through. Okay. So you can actually try this in the lab or on your laptop. It can be done locally without a network connection if your client is going to be local to the relative to the web service. Everything is a local host. You can try it on the laptop. What we actually wanted you to do in your original exercise we had planned was that each group would create a web service and another group would access that web service. Over the hand. Right? That was the notion which you can still do actually. It's not that you can't do it because you deployed and when somebody writes a client they can write a client to go to that particular host and pick it up and come up. Right? As long as you know the IP address of that machine. What we are going to do is we are going to create a recording of the web. So it's just a recording of the tool called V. And the recording is a file that will be recording there with the exception fixing thing. Can we at least show a demo of that? We will show the demo. We will show a demo of that wing file that is still what you wanted to edit. It doesn't matter. I will have to create a live link right away. The wing file that you created that you said needs to be edited. We can show that file. I will have to create a new one right now. There is no wing file at all. It's not on this laptop. Okay. So this is what we wanted to do in today. It happens so often that we don't know how the file is going to work. The file can be created any number of times in the hard time. And you can repeat it at the same time. And hopefully the handout also illustrates which screenshots as to how you are supposed to make sure. I think that's enough. Largely. There are specific questions that we got. Sir, this secret for 9 years, you can do 5 years or 2 files. 5 years later. How much time do you want to give out? It's just a case. You can have a form. Pick it up from the form. We have 10, 2 files. You want to collect first 10 from the X7 file. Then you will select. Okay. Suppose there are 3, 2 files, 1 file and 7. From X7 file, all the 3 will come. And from there you will select. See the function as we have written on the other side. We have X7 file and we will have method that is available for you. The JASP function that we have created. Method available for you to call to run a group file. You get the secret code. Whatever group file you create. How do you get that parameter value? These are things. You can give it on command. Run it on command line. Give it on command line. You can come to JASP. You can take it as a parameter and give it. Right upon JASP. On the last day we will make some soft copy. But yesterday's code. The application for the server for son. It will serve. It will serve as a SOAP server. All the containers it has. Apache access is another server that you can use. Open source free. This is also free by the way. That you can download. Pretty much all the servers which were serving J2E content also serve SOAP today. Right. So WebLogic will serve. WebSphere will serve SOAP. All of them are SOAP 1.2 compliant. Yeah. Can you just explain this? Because this is important for them to understand. So there one thing that I would like you to pay some attention to is remember we said that the true promise of service orientation can be realized with dynamic binding. Right. That you can dynamically discover a wisdom and create a request for operations corresponding to that wisdom and dispatch that. Right. Here we have pre-created the stops in the first example that we saw. Right. So in the IDE we pre-created the stops by creating a web service client and then we built the application of the web service client that we had and then we deployed it. Here is an example of the dynamic invocation. Yeah. In this, in previous cases where we have seen we have created a stub and then we are calling, we are creating new service object and we are calling new service object from the stub which we have created and then we are calling a port, a method in a particular port. But here in this case when you are going to dynamically discover a service what you will do is you will maybe pass a query to a UDDI registry or some standard registry which is there and from that registry you will get service details. Maybe if you use UDDI they have their own data structure in which they store service details. In that case you will get a URL reference to Visdal wherever the Visdal is stored. Now here what we have done is service details dot get Visdal URL. If you look at this line service service equals to service dot create. It takes a Visdal URL and a service fully qualified name of service that is service queue name as a parameter and it will go and fetch that Visdal and in next line if you see string request this is your message which you want to send to the service. This is complete SOAP message. So you need to write SOAP message by your hand so you must know what kind of SOAP message is expected from the service at the other end. Since you don't know the Visdal, I mean program doesn't know the Visdal dynamically when you are writing the code you need to specify complete message whatever is expected by the service at other end and after that you create that message and you dispatch that message to the service endpoint. So dispatch method will automatically dispatch it to the point where service is deployed to the service endpoint. So here you need to only know the location at which your Visdal is by that location and by knowing the SOAP message you can dynamically invoke any service programmatically. The only requirement is you, number one, you should know the Visdal location. Number two, you should know what format or what SOAP message is expected by the service. Those are the only two things you should know. So, I think that explains. Okay, see this create dispatch is creating a dispatcher for service. So it takes a fully qualified port name as an input. Okay, so it will automatically fetch that port, qualified name of that particular port from the details which you will get from a, from querying a URIDI registry. Okay, so you will get all these details programmatically. I mean URIDI has a very well defined data structure in which you can store all these details. So the one who is creating the service will publish all these details for you. As a client, you will go and query URIDI registry. You will retrieve all this information programmatically. So since data structure is well defined, you can actually access all these details very easily programmatically, right? Because the data structure is standardized. So once you have these details, so you have fully qualified name of service, you have visual location and you have fully qualified name of the port. By knowing this, these details, you can create a new dispatcher. You can create a new dispatcher. And for this, you must know the SOAP message which is expected by the service. So in this case, my service was having an operation called register for notification or notification registration operation. Now this contains namespace declaration and then these are the parameters which are required. So condition, condition ID and context type, all these are the parameters which are expected by service which is providing you this method. So this message format must be known ahead of the time. When you are writing the code, you must know what format this message is expected. Exactly. See, current requirement of dynamic invocation. I mean, current state of art technology only provides you this flexibility that you must know the message. So the interface, if there are five travel reservation services, we assume that all of them have same interface or interface is known ahead of time. Let me address that. The ideal scenario is that you don't know the format and they all have different formats. And you can still, by reflection, figure out what the current format that you pick is and then construct that message in which case, here the string has been hard coded, you will construct that message dynamically. With the core bar dynamic invocation interface or DII, you could actually do that. They gave you reflection APIs to figure out what are the types of the parameters that were expected on the server side and the order of these parameters and then you constructed that message. Here it's not yet possible to do that, but we can write additional code to try and accomplish something like that. There is no API available. Well, at least the soap side of it is silent. We had to come up with something. For core bar, the orb had a DII API, as it was called. So what we are going to go, we can head over to the lab now. We can take a break now. I think there is some T that is expected in five minutes or whatever. And then we'll head over to the lab and you can try this out. We'll be there to help you if you need help. I'd love you to just fill in bits and pieces of the class to call all the implementations that you might have. So this is how you would wrap up an existing service. So if you had some service that was written in Java, or DII, something else, to wrap up it, you would fill up this process. That way, it will show. It will come to that. Okay. To create the web service using the second method. Is it on? Yeah. When you write it, there's another option which says create a web service. You can give a web service name. I'll keep it as default. And there are two options over there. Create web service from scratch. And a package name for the same. Just creating web service from session B. Obviously, it's good to take advantage of J2E. So here the session B, you can just point it to the session B and say create a web service. Okay. It's a whole lot of stuff automatically. Yeah. So now even we haven't defined any visual. We are directly creating a web service. So the NetBeans IDE will generate a blank web service class. We'll have to define our own operation in that. We'll write an operation. Let's use the NetBeans UI to generate, create an operation. We have an operation. We have functionality over here to do that. The dialog box asks for a name. We'll write, let us say this operation returns a string. And it accepts something as a parameter. It accepts a name as a parameter. So the IDE has generated a skeleton for the operation. But it's not a visual which has told the IDE to generate this skeleton. You see who specified it right now. We'll implement the operation right here. You just say. You can start writing. Yeah. So notice that one of the things it has done when you generate the class in the first place, how you have an annotation to view web service one class, saying it is a web service class. It's a web method. So in other words, this will be an operation in your web service. It should be exposed up with a simple annotation saying, write the class without using any of these ideas. You just say, if I'm going to text editor, we are in Mac, sit down, write a job class, and then sort the appropriate annotations. That's obvious. How does the appropriate books to read and understanding annotations and then generate a visual for me? This is the other way. You're going the other way. Actually, you can also have a method. It's just a regular class. I've got to expose some of this as a web service. Some of it I want. It's just implementation helpers for me. Whatever. So those non-eposite web services. This will be appropriately generated. Is it possible to have a method, which is a web method, but you are not declaring this class as a web service? No. By default, if there's a web method, then it's a web service. Because this corresponds to an operation. A method corresponds to an operation. Okay. So we have implemented the operation. We build a web service and deploy it again. Now, when you build the web service, the ID itself generates the wisdom for the web service. As you see, the tooltip shows the location of the wisdom that has been deployed on the web server. To type in that location, you will actually see the generated wisdom. This is the generated wisdom. Notice one more thing. Keep turning this on now. So one more thing that you notice is that we picked up this wisdom from the server itself. So this was not a file that we picked up from the local file system. We contacted the server at 48080 and said, give me, this is exactly what should be done in a real situation where you would actually retrieve the wisdom from the server and then you would run your stock compiler, I mean stock generator over that and then it will generate the wisdom. We also created a client for this web service in our original consumer web app itself. I would like to add one thing here. In case you don't have a NetBeans ID and you still want to create stocks, first thing you have to do is you have to go to chatsevillus.dev. It comes with classes for you. It is similar to that for chatsevillus also. Moving on, we have the web service client dialog box over here. Earlier we specified the wisdom using pointing to the wisdom from another project. So now we will try to simulate a real life scenario. We will provide the URL of the wisdom which we have over here. We got this URL from the server itself. We had finished. The ID fetches the wisdom from the specified URL. It creates a web service client. Yeah, it's created. We will call this web service and our JSP to the same way. So we will select the operation and it's okay. By the way, that error was not 11 to our codes of action. We generated the code. Here it is. We provide the operation with some names, say siddharth and we are done. We will build this application and upload. Let's try to access the JSP page. Yeah. So it access the web service. The web service contacted it hello with the name and returned the result.