9.16.2 Add a Web Service Reference to Our Web-Based Project and Change the Ports
In order to call an operation in our Web service application project, WebAppCourse, we need to add the Web reference in our Web-based client project, WebClientCourse _ Select, to direct all calls to our Web service project. Perform the following operations to add the Web service reference:
1) Build and deploy our Web Service project, WebAppCourse, to make it ready.
2) Right-click on our Web-based client project, WebClientCourse _ Select, and select the New > Web Service Client item to open the New Web Service Client wizard.
3) In the opened wizard, click on the Browse button that is next to the Project field and expand our Web application, WebAppCourse. Then choose our Web service class file, WebServiceCourse, by clicking on it, and click on the OK button.
4) Click on the Finish button to complete the Web service reference addition process.
Prior to building the code for our pages and Java Bean class file, we need first to modify the related Web server HTTP port numbers since currently two Web Servers are utilized for our client projects: GlassFish and Tomcat, and both of them may use the same port to start the service. To avoid any con-flict from a duplicated port number, we need to change some of them to avoid this duplication error. We prefer to keep the HTTP port for the GlassFish server, so we can modify the Tomcat server’s starting HTTP port number. We need to access the default server configuration file of the Tomcat server, server.xml, to do any modifications for those ports. Perform the following operations to enable us to access that configuration file:
1) Open the Windows Explorer and browse to the default location for that configuration file, which is C:\Program Files\Apache Software Foundation\Apache Tomcat 8.0.27\conf. Then right-click on the configuration file server.xml, and select the Properties item to open its Properties wizard.
2) Click on the Security tab on the top and the Edit button to open the Permissions wizard. Then click on the Add button to try to add us as Authenticated Users to access that file.
3) In the opened Select Users wizard, click on the Advanced button on the lower-left corner, and click on the Find Now button.
4) Then select Authenticated Users from the list at the bottom and click on the OK button in two times to add it into the Group or user names list.
5) Click Authenticated Users from the list to select it, and check all checkboxes under the Allow column in the Permissions for Authenticated Users at the bottom.
6) Click on the Apply and OK button (in two times) to complete the authentication process.
Now perform the following operations to modify this configuration file:
1) Right-click on the server.xml file and select the Open with Notepad item to open it.
2) Browse to code line 69 on that file, and change the port number from 8080 to 8082 by changing the code: port = “8082” in that line.
3) Go to File and select the Save item to save these changes. Then you can close this file.
One point to be noted is that you must stop and exit the NetBeans IDE 12.0 prior to doing those modifications to the configuration file to make it effective. Those modifications may not be effective or available if the NetBeans IDE is open.
Now that we have added a Web service reference to our Web-based client project, WebClientCourse _ Select, next let’s develop the code in our client project to call Web service operations to perform related course data query actions. The main code concentrates on building the transaction JSP file, CourseProcess.jsp, and Java Managed Bean class file, CourseQuery.java.
We can still use the original code on the course query part in the CourseProcess.jsp page and add code to the Insert, Update and Delete course parts on that page later, solet’s start from our Java Bean class file, CourseQuery.java.