Multi-web services deployment on a Tomcat server

In this labs, we will create a service converting cm to inch and another service calculating the ideal weight (in kg) based on a height (in cm). These services contain two operations and are deployed on the same server. The response messages of the second service include two parameters: men's and women's weight.

Deploying the Converter WS

The deployment is somehow similar to the previous lab.

  1. File → New → Dynamic Web Project. Name it as MultiWS. Select Web service module version as 2.5 and click on modify in the configuration tab to include Axis2 web services.


  2. Create a Java Package named tps.multi.ws under the Java Resources\src folder.
  3. Create a new Java Class, named ConverterWS inside the tps.multi.ws package.
  4. Copy and paste the following codes to the ConverterWS.java file.
    package tps.multi.ws;
     
    public class ConverterWS {
    	public static double inch_to_cm (double inch){
    		return 2.54*inch;
    	}
     
    	public static double cm_to_inch (double cm){
    		return 0.3937*cm;
    	}
    }
  5. Save and right-click on the ConverterWS, select Web Services → Create Web Service. Select Web service runtime: Apache axis and choose Apache axis2. Click Next→Next.


  6. Start the Tomcat Server and Finish.
  7. Right click on MultiWS project. Select Runs as→Run on server. Select Apache Tomcat v7.0. Click Next.
  8. Make sure that MutliWS is in the Configured list and click Finish.
  9. Select on services in the Welcome page. Select the ConverterWS to access the WSDL file.
  10. To invoke the cm_to_inch operation with the input 163, enter the following url http://localhost:8080/MultiWS/services/ConverterWS/cm_to_inch?cm=163. You will get the following response:


  11. Done.

Deploying the Ideal Weight Calculator WS

  1. By the same way, under the package tps.multi.ws, create a Java class named IdealWeight and copy/paste the following codes into it.

    package tps.multi.ws;
     
    public class IdealWeight {
     
    	public double men_weight_in_kg;
    	public double women_weight_in_kg;
     
            public double getMenWeight(){return men_weight_in_kg;}
    	public double getWomenWeight(){return women_weight_in_kg;}
     
    }
  2. Create another class named IdealWeightWS to compute the ideal weight for men and women based on Devine's Formula and Miller Formula contains the codes (remember that the function names always begin with a small letter):

    package tps.multi.ws;
     
    public class IdealWeightWS {
     
    	public IdealWeight devineFormula(double height_in_cm){
    		IdealWeight iw = new IdealWeight();
    		iw.men_weight_in_kg = 50 + 2.3*(ConverterWS.cm_to_inch(height_in_cm)-60);
    		iw.women_weight_in_kg = 45.5 + 2.3*(ConverterWS.cm_to_inch(height_in_cm)-60);
    		return iw;
    	}
     
    	public IdealWeight millerFormula(double height_in_cm){
    		IdealWeight iw = new IdealWeight();
    		iw.men_weight_in_kg = 56.2 + 1.41*(ConverterWS.cm_to_inch(height_in_cm)-60);
    		iw.women_weight_in_kg = 53.1 + 1.36*(ConverterWS.cm_to_inch(height_in_cm)-60);
    		return iw;
    	}
    }
  3. Save and right click on the IdealWeightWS class, select Web Services → Create Web Service. Selecy Apache axis2 as Web service runtime. Click Finish.
  4. Now, right click on MultiWS. Select Run as→Run on a server. Select services. You will see that there are two services ConverterWS and IdealWeightWS.
  5. Click on IdealWeightWS to access the WSDL file. Then test the devineFormula operation with the input 162 by entering the URL http://localhost:8080/MultiWS/services/IdealWeightWS/devineFormula?height_in_cm=162.


Deploying two created service on a Tomcat server

  1. Export the MultiWS project to a WAR file, suppose MultiWS.war.


  2. Copy this WAR file to [your Tomcat]\webapps folder.
  3. Restart the Tomcat. (if the parameter deployable in your Tomcat is set to “true”, you do need to do this step)
  4. Now two service are running at: http://[Tomcat's address]:[port]/MultiWS/services/ConverterWS?wsdl and http://[Tomcat's address]:[port]/MultiWS/services/IdealWeightWS?wsdl. You can open these addresses by your web browser to verify them or using the Eclipse's Web Service Explorer open the created WSDL files.
  5. Done.
teaching_assistant/web_services/webservice_multiservice_multiparameters_v9.txt · Last modified: 2021/09/21 13:37 by Nour
Back to top
CC Attribution-Share Alike 4.0 International
chimeric.de = chi`s home Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0