You are on page 1of 113

TY BSc CS SEM VI ROLL NO.

754

Practical No: 01

Aim:Create a soap web service to convert Celsius temperature to Fahrenheit and vice
versa with Java client.

Practical:
 Make sure that you have Netbeans version 8.2 and selected “Glassfish Server 4.1” as
a server:

Step1: Open netbeans → Create a new project file → Java Web → Web Application.

Step 2: Create the project name-Prac3 → Click on next → Finish.

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 3: Now the project is Created.

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 4: Right click on Project → New → Web Service.

Step 5: Name the Web Service → Give Package name → Finish.

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 6: Web Service is created in ty package.

Tempwebservice code:
Step 7: Right click on the screen → Insert Code → Add Web Service
Operation

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 8: Create the parameter for FtoC i.e a Create the parameter for CtoF i.e b

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 9: Right click on Project → Deploy

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 10: Right Click on your Web service File → Test Web Web Service

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 11: Right Click on Project → New → Other

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 12: In the 'Categories' section → Web Services → WebService Client → Next

Step 13: Browse Project → Web service file → Ok → Finish

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 14: Right Click on your project → select new → jsp → Name it as index → Finish.

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 15: Right Click on your project → select new → jsp → Name it as indexaction →
Finish

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 16: Write a Code in index.jsp and indexaction.jsp

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 17: Deploy the project

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 18: Right Click on project → New →Other → Web Services → Web Service Client

Step 19: Browse the tempwebservice in Project and in Package write tycs1

Step 20: Now on running the index.jsp file → you should be greeted with this browser
popup:

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Practical No: 02

Aim: Create a soap web service to convert celsius temperature to fahrenheit and vice
versa using python client.
Input:

Output:

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Practical No: 03

Aim: Create a soap service to convert Dollar to INR and vice versa using java client

Practical:

Step 1: Open netbeans → Create a new project file → Java Web → Web Application.
Step 2: Right on the project i.e P3 → New → Web Service and name it → Finish

Step 3: Right click on the Project → New → JSP

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 4: Click on Project → New → Other.

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 5: Select Web Services → Web Service Client → Next.

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 6: Browse Web Services and give package name also → Finish.

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

INRtoDOLL code
Step 7: Right click on the screen → Insert Code → Add Web Service Operation
Step 8: Create the parameter for INRtodoll i.e INR → Ok

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 9: input code

Step 10: output code

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 11: Now on running the input.jsp file → you should be greeted with this browser popup

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Practical No: 04

Aim: Create a soap service to convert Dollar to INR and vice versa using python client

Input:

Output:

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Practical No: 05
Aim: Create a web service to perform a CRUD operation (Player database)
Practical:
(REFERENCE: Creating RESTful Web Services in NetBeans 7 : Part 1 (oracle.com) and
Creating RESTful Web Services in NetBeans 7: Part 2 (oracle.com))

On NetBeans v8, go to the services tab, expand Databases and right-click Java DB
and Start Server:

To create playerDB database, right-click on Java DB and select Create Database

Enter the following information:

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

To connect to the newly created database playerDB, Right click on the


jdbc://localhost:1527/playerDB connection and select connect:

Create a table and add a few columns with 1 primary column in playerDB

Created table:

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Now to add the data, right click on a table and click view data:

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Now create Server project, by New project > other > Java web > web application:

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Now connect the new web application to the RESTful database:

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Select New Data Source > select your jdlc database and name it whatever you want:

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Now your tables should appear on the left side, to add them to your web application,
click on “Add all”:

Make sure to add a package:

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

You can verify your RESTful databases are added by checking your newly created
package:

You can now test your RESTful service:

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Select GET(application/xml) to print your table details:

After testing, you can deploy your package to glassfish: right click on project🡪deploy

Now create a new Java application and make sure to uncheck “Create Main Class”:

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Now generate Entity classes from database by right-clicking the new java application
and selecting new > entities classes from database:

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Select your jdbc and add all your tables:

Enter the package name:

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Now we can begin executing CRUD operations, from New > Other > Web Service >
New RESTful Java Client:
For Create:

Code:
public static void main(String args[]) throws IOException

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

{
CreatePlayerJerseyClient client1=new CreatePlayerJerseyClient();
Response response=client1.findAll_XML(Response.class);

GenericType<List<Player>> genericType = new GenericType<List<Player>>() {};


// Returns an ArrayList of Players from the web service
if(response.getStatus() == Response.Status.OK.getStatusCode()){
List<Player> data= response.readEntity(genericType);

Player p=new Player();


p.setFirstname("Sidisha");
p.setId(6);
p.setLastname("Sidisha");
p.setLastspokenwords("Thak gaya hu Vro");
client1.create_XML(p);
}
else{
System.err.println("Error found, Status: "+ response.getStatus());
}
}
}

Output:

For Read:

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Code:
public static void main(String args[]) {
GetPlayerJerseyClient client1 = new GetPlayerJerseyClient();

// Use the correct class for Response, and make sure to handle the response properly
Response response = client1.findAll_XML(Response.class);
// Use the correct GenericType
GenericType<List<Player>> genericType = new GenericType<List<Player>>() {};
// Check if the response is successful before extracting the data
if (response.getStatus() == Response.Status.OK.getStatusCode());
if (response.getStatus() == Response.Status.OK.getStatusCode()) {
List<Player> data = response.readEntity(genericType);
System.out.println("Retrieving and Displaying Players Details");
for (Player player : data) {
System.out.println("FirstName: " + player.getFirstname());
System.out.println("PlayerID: " + player.getId());
System.out.println("Jerseyno: " + player.getJerseynumber());
System.out.println("LastName: " + player.getLastname());
System.out.println("Last Spoken Words: " + player.getLastspokenwords());
System.out.println();
}
} else {
// Handle the case where the response is not successful
System.err.println("Error fetching data from the server. Status: " + response.getStatus());
}
}
}

Output:

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

For Update:

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Original Entry:

Code for Update:


public static void main(String args[])throws IOException {
CreatePlayerJerseyClient client1=new CreatePlayerJerseyClient();

Response response=client1.find_XML(Response.class, "6");


GenericType<Player> genericType = new GenericType<Player>() {};
// Returns an ArrayList of Players from the web service
if(response.getStatus() == Response.Status.OK.getStatusCode()){
Player player= response.readEntity(genericType);
player.setJerseynumber(100);
player.setLastspokenwords(" Yohohohoho");
client1.edit_XML(player, "6");

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

System.out.println("FirstName: "+player.getFirstname());
System.out.println("PlayerID: "+player.getId());
System.out.println(" Jerseyno: "+player.getJerseynumber());
System.out.println("LastName: "+player.getLastname());
System.out.println("Last Spoken Words: "+player.getLastspokenwords());
}
else{
System.err.println("Error found, Status: "+ response.getStatus());
}}

Output:

For Delete:
Code for Delete:
public static void main(String args[])throws IOException {
DeletePlayerJerseyClient client1=new DeletePlayerJerseyClient();
client1.remove("6"); //ID
}
Output:

Practical No: 06

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Aim: Develop Micro-blogger application (like Twitter) using RESTful Web services.

Step 1: Go to services → JavaDB → Start Server :

Step 2: Right click on Java DB → Create Database →Enter Name & Password

Step 3: After above steps database is created → Right Click on Created Database →
Connect

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 4: Right click → Create Table

Step 5: Name the Table → Add column.

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 6: Add Column and name as Message_ID Step 7: Add Column Username
and check the Primary key and Unique → OK

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 8: Add Column Content Step 9: Add Column Password

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 10: Table name →blogbata →Added four columns → Click on OK

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 11: To insert Records Click on the leftmost icon .

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 12: Add content to the database → Click Ok

Step 13: File → New Project → Java Web → Web Application → Next → Project Name →
Next → Finish

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 14: Right Click on Project → New → Other

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 15: Right Click on Project → Web Services → RESTful Web Services from Database

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 16: Select New data Source → Give JNDI Name → Select the database connection →
Ok

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 17: Add Database → Next

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 18: Add a package name as com.blogger → Next → Click on Finish

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 19: Right click on project→Test Restful Web Services

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 20: Select Web Test Client in Project → Browse and Select the Project → Ok → Ok

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Create a Java App:

Step 1: File→ New Project→ JAVA→ Java Application → Next.

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 2: Project Name → Uncheck Create Main Class → Finish

Step 3: Right Click on bloggerClient → New → Entity Classes from Database

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 4: Select database Connection → Add all→ Next

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 5: Add package name (don't include .com) → Next→ Finish

Step 6: Create New RESTful Java Client

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

CreateMessage

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Browse and select BlogbataFacadeREST[com.blogger.blogbata]

CreateMessage Code

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Output:

GetMessage

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

GetMessage Code:

Output:

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

UpdateMessage

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

UpdateMessage Code:

Output:

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

DeleteMessage

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

DeleteMessage Code:

Output:

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Practical No: 07

Aim: A. Create a web service to consume Google Map API


B. Write a program to consume a google search restful API.

Step 1: Go to Google Cloud

Step 2: After clicking on get started for free write → Create New Project
https://console.cloud.google.com/welcome/new

Step 3: Go to API & Services → Enable APls And Services → Enable it .

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 4: Go to Credentials → Create Credentials

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 5: Strat the Spring Tool

Step 6: Interface of Spring Tool

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 7: File → New → Spring Starter Project → Name it → Finish

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 8: Select the following dependencies → Finish

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 9: Click on Package → New → Class → Name it → Finish

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

MapController Code:

package com.example.demo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class MapController {
@GetMapping("/showMap")
public String index() {
return "index";
}
}

Step 10: Click on Project → New → File → Name the File → Finish

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

index.html

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load("current", {
"packages":["map"],
// Note: you will need to get a mapsApiKey for your project.
// See: https://developers.google.com/chart/interactive/docs/basic_load_libs#load-settings
"mapsApiKey": "AIzaSyAtmIGVfCB_Uk-t6dHIDBDBoDtf7T4wdqw"
});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Lat', 'Long', 'Name'],
[19.0760, 72.8777, 'Mumbai'],
[18.5204, 73.8567, 'Pune'],
[19.1176, 72.9060, 'Powai'],
]);

var map = new google.visualization.Map(document.getElementById('map_div'));


map.draw(data, {
showTooltip: true,
showInfoWindow: true
});
}
</script>
</head>
<body>
<div id="map_div" style="width: 800px; height: 700px"></div>
</body>
</html>

Step 11: Click on Project → Run As → 5 Spring Boot App

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Output:

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

(B) Create a web service to consume a Google Search RestFul API.


Step 1: Go to google console website.
Step 2: Create a New Project.
Step 3: Go to APIs and services => Enabled APIs and Services

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 4: Search Custom Search API


Step 5: Go to Custom Search API and click on enable.

Step 6: Now go to Credentials.


Step 7: Click on Create Credentials → API Key

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 8: Key will be generated and the restrict the key.

Step 9: Now we will go to the Programmable Search Engine Website.

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 10: Click on Get Started button → Create a search Engine

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 11: Go Back to all engines, then go to your created engine.

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 12: Copy Search Engine ID

Step 13: Write a code

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Output:

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Output For Image:

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Practical No: 08

Aim: Write a program to consume weather API.

Step 1: Go to the OpenWeather website.

Step 2: Create Account.

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 3: Go to API Keys section and Generate key.

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 4: Copy key and Write Code


Input:

Output:

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Practical No: 09

Aim: Installation and configuration of virtualization using KVM (Kernel Virtual


Machine)

Practical:

Step 1: run uname -m command


The uname -m command is used to display the machine hardware name

Step 2: Add new user


sudo add user username

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 3: Install Library


sudo apt-get install qemu-kvm libvirt-clients bridge-utils virt-manager

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 4: run
sudo add user username libvirt

Step 5: switch from root user to new user

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 6: Select New username

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 7: Type to open virtual machine manager


virsh -c qemu:///system list
virt-manager

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 8: Click on the top left icon to create a New Virtual Machine

Step 9: Select Local Install and go forward

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 10: Set the path to the ISO file installed into Ubuntu

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 11: To add iso file copy the file from windows to ubuntu system , drag and drop from
windows files explorer to ubuntu file explorer
If it does not work then power off the ubuntu and go to view /Customise/:Library

Step 12: Library opens:

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 13: Select the system you created and go to edit virtual machine settings and go to
options and Guest Isolation check the Drag and Drop checkbox and now try to drag and drop
the iso file

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 14: Select the amount of RAM and CPU cores to allocate to the new VM

Step 15: Select the amount of space to allocate

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Step 16: Lastly set the name you want your VM to be known by

Step 17: After setting up, it will open after initial installation

Cloud Computing
TY BSc CS SEM VI ROLL NO. 754

Cloud Computing

You might also like