Professional Documents
Culture Documents
Servie Oriented Architecture
Servie Oriented Architecture
Servie Oriented Architecture
Aim : Design SOA for the E-Commerce using the following features:
i) Service granularity
ii) Service versioning and evolution
CODE:-
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
return 0;
}
OUTPUT:-
Practical 2
Aim: Write a program to illustrate any five services for components such as Order Processing,
Payment Processing and stock list using SOA characteristics
CODE:-
#include <iostream>
#include <unordered_map>
#include <vector>
#include <string>
class Service {
public:
virtual ~Service() {}
};
private:
public:
ProductService() {
products = {
{1, "T-Shirt"},
{2, "Mug"},
};}
auto it = products.find(id);
if (it != products.end()) {
return it->second;
return "";
}};
private:
public:
InventoryService() {
stock = {
{1, 10},
{2, 5},
};}
auto it = stock.find(id);
if (it != stock.end()) {
return it->second;
return 0;
}};
private:
public:
productService(productService), inventoryService(inventoryService) {}
if (product_name.empty()) {
}
int available_stock = inventoryService.getStock(product_id);
return "Order placed successfully for " + product_name + " (x" + std::to_string(quantity) + ")";
}};
public:
bool processPayment() {
return true;
}};
class ServiceLocator {
private:
public:
services[name] = service;
auto it = services.find(name);
if (it != services.end()) {
return it->second; }
return nullptr;
};
int main() {
ProductService productService;
InventoryService inventoryService;
PaymentService paymentService;
if (paymentService.processPayment()) {
} else {
return 0;
OUTPUT:-
CODE:-
let products = [
"id": 1,
"price": 109.95,
"descrip on": "Your perfect pack for everyday use and walks in the forest. Stash your laptop (up to 15 inches) in
the padded sleeve, your everyday",
"ra ng": {
"rate": 3.9,
"count": 120
} },
"id": 2,
"price": 22.3,
"descrip on": "Slim- ng style, contrast raglan long sleeve, three-bu on henley placket, light weight & so fabric
for breathable and comfortable wearing. And Solid s tched shirts with round neck made for durability and a great t
for casual fashion wear and diehard baseball fans. The Henley style round neckline includes a three-bu on placket.",
ti
ti
ti
ti
ti
tt
fi
tti
ti
tt
tt
ft
fi
"category": "men's clothing",
"ra ng": {
"rate": 4.1,
"count": 259
} },
"id": 3,
"price": 55.99,
"descrip on": "great outerwear jackets for Spring/Autumn/Winter, suitable for many occasions, such as working,
hiking, camping, mountain/rock climbing, cycling, traveling or other outdoors. Good gi choice for you or your family
member. A warm hearted love to Father, husband or son in this thanksgiving or Christmas Day.",
"ra ng": {
"rate": 4.7,
"count": 500
},
];
app.use(bodyParser.json());
res.json(products);
});
if (!product) {
ti
ti
ti
ti
tt
tt
tt
fi
ft
return res.status(404).json({ message: 'Product not found' });
res.json(product);
});
products.push(newProduct);
res.status(201).json(newProduct);
});
res.json(products[productIndex]);
});
products.splice(productIndex, 1);
res.status(204).end();
});
app.listen(PORT, () => {
});
Principles of stateless, resource based and cacheable are implemented in the following manner:
Stateless:
The statelessness principle is depicted by the fact that the server does not maintain any client state between
requests. This is evident in how each route handler func on (e.g., GET /products, POST /products, etc.) only relies on
the informa on provided in the request itself (e.g., request body, URL parameters) to perform its opera on.
Resource-Based:
The resource-based principle is depicted by the fact that products are represented as resources, each iden ed by a
unique ID.
The routes follow a resource-oriented URI pa ern, where /products represents the collec on of products and /
products/:id represents an individual product by its ID.
Cacheable:
By se ng appropriate caching headers (e.g., Cache-Control, Expires, ETag) in the response, clients and intermediary
caches can cache the responses from these APIs.
Cacheability improves the e ciency of the API by allowing clients to reuse previously fetched responses, reducing
the need for repeated requests to the server.
tti
ti
ffi
tt
tt
ti
ti
ti
ti
fi
OUTPUT:-
#include <iostream>
#include <unordered_map>
#include <string>
class AuthenticationService {
public:
bool authenticateUser(const string& username, const string& password) {
if (userDatabase.find(username) != userDatabase.end()) {
if (userDatabase[username].getPassword() == password) {
cout << "User '" << username << "' authenticated successfully." << endl;
return true;
}
}
cout << "Authentication failed. Invalid username or password." << endl;
return false;
}
};
class TestService {
public:
void takeTest(const string& username, const string& testName) {
cout << "User '" << username << "' is taking the test '" << testName << "'." << endl;
}
};
int main() {
userDatabase["yukti"] = User("yukti", "Yukti@0212");
userDatabase["user2"] = User("user2", "password2");
AuthenticationService authService;
TestService testService;
string username, password;
cout << "Enter username: ";
cin >> username;
cout << "Enter password: ";
cin >> password;
if (authService.authenticateUser(username, password)) {
// If authentication succeeds, allow the user to take a test
string testName;
cout << "Authentication successful. Enter test name: ";
cin >> testName;
testService.takeTest(username, testName);
}
return 0;
}
OUTPUT:-
Practical 5
#include "AccountServiceImpl.h"
#include "TransactionServiceImpl.h"
#include "CustomerServiceImpl.h"
#include <iostream>
#include "AccountService.h"
#include <unordered_map>
#include <vector>
#include <utility>
public:
bool createAccount(const string& accountId, double initialBalance) override {
if (accounts.find(accountId) != accounts.end()) {
return false; // Account already exists
}
accounts[accountId] = initialBalance;
transactionHistory[accountId]; // Initialize transaction history
return true;
}
//TransactionServiceImpl
#pragma once
#include "TransactionService.h"
#include "AccountService.h"
public:
TransactionServiceImpl(AccountService& accountService) : accountService(accountService) {}
bool deposit(const string& accountId, double amount) override {
return accountService.updateAccountBalance(accountId, amount);
}
bool transfer(const string& fromAccount, const string& toAccount, double amount) override {
if (!accountService.updateAccountBalance(fromAccount, -amount)) {
return false; // Insufficient balance
}
return accountService.updateAccountBalance(toAccount, amount);
}
};
//TransactionService
#pragma once
#include <string>
class TransactionService {
public:
virtual bool deposit(const string& accountId, double amount) = 0;
virtual bool withdraw(const string& accountId, double amount) = 0;
virtual bool transfer(const string& fromAccount, const string& toAccount, double amount) = 0;
virtual ~TransactionService() {}
};
//CustumerServiceIMPL
#pragma once
#include "CustomerService.h"
#include <unordered_map>
public:
CustomerServiceImpl() {
// Initialize with some dummy data
customers["user1"] = "password1";
customers["user2"] = "password2";
}
#pragma once
#include "CustomerService.h"
#include <unordered_map>
public:
CustomerServiceImpl() {
// Initialize with some dummy data
customers["user1"] = "password1";
customers["user2"] = "password2";
}
#pragma once
#include <string>
return 0;
}
OUTPUT:-
Practical 6
#include <iostream>
#include <string>
using namespace std;
class ServiceContract {
private:
string clientName;
string developerName;
string fee;
string paymentSchedule;
string penaltyPercentage;
string jurisdiction;
public:
ServiceContract(string clientName, string developerName, string fee, string paymentSchedule, string
penaltyPercentage, string jurisdiction) {
this->clientName = clientName;
this->developerName = developerName;
this->fee = fee;
this->paymentSchedule = paymentSchedule;
this->penaltyPercentage = penaltyPercentage;
this->jurisdiction = jurisdiction;
}
void generateContract() {
cout << "*Service Contract for E-Marketing*\n\n";
cout << "*Parties:*\n\n";
cout << "Client: " << clientName << endl;
cout << "Developers: " << developerName << endl << endl;
cout << "*Payment Terms:*\n\n";
cout << "1. The Client agrees to pay the Developers the agreed-upon fee of " << fee << " for the e-
marketing services provided.\n\n";
cout << "2. Payment will be made in installments as follows:\n - " << paymentSchedule << endl <<
endl;
cout << "3. Late payments will incur a penalty of " << penaltyPercentage << "% per week.\n\n";
cout << "*Governing Law:*\n\n";
cout << "This contract shall be governed by and construed in accordance with the laws of " <<
jurisdiction << ".\n\n";
}};
int main() {
string clientName = "XYZ Company";
string developerName = "ABC Marketing Agency";
string fee = "$5000";
string paymentSchedule = "50% upfront, 25% upon reaching milestones, and 25% upon completion";
string penaltyPercentage = "5";
string jurisdiction = "New York";
ServiceContract contract(clientName, developerName, fee, paymentSchedule, penaltyPercentage,
jurisdiction);
contract.generateContract();
return 0;
}
OUTPUT:-
Practical 7
Aim : Implement SOAP based web service to create to-do list application in XML language.
OUTPUT:-