done task 5
This commit is contained in:
40
week5_TinsaeGhilay/ReadME.md
Normal file
40
week5_TinsaeGhilay/ReadME.md
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
## Start Glass fish
|
||||||
|
```bash
|
||||||
|
# start glassfish server
|
||||||
|
glassfish7/bin/asadmin start-domain
|
||||||
|
|
||||||
|
# deploy app on it
|
||||||
|
glassfish7/bin/asadmin deploy target/shop-1.0-SNAPSHOT.war
|
||||||
|
```
|
||||||
|
|
||||||
|
we can browse server at [http://localhost:8080/shop-1.0-SNAPSHOT/api/items](http://localhost:8080/shop-1.0-SNAPSHOT/api/items)
|
||||||
|
|
||||||
|
## Start client
|
||||||
|
```bash
|
||||||
|
# cd to clients project directory
|
||||||
|
cd client
|
||||||
|
|
||||||
|
# compile and run project
|
||||||
|
mvn clean compile exec:java
|
||||||
|
```
|
||||||
|
|
||||||
|
The client class handles HTTP operations, while the Delegator class handles user interaction, input validation, and adapts the input into the correct format. Delegator then calls the appropriate Client methods, acting as a proxy in a liberal sense.
|
||||||
|
|
||||||
|
## Ending the program
|
||||||
|
|
||||||
|
Clent program can be ended by typing `done` or `exit` in the interactive terminal
|
||||||
|
|
||||||
|
Glassfish can be stoped using the following command in terminal
|
||||||
|
```bash
|
||||||
|
# first check which domains are running
|
||||||
|
glassfish7/bin/asadmin list-domains
|
||||||
|
# you will get somehing like the below lines
|
||||||
|
# domain1 running
|
||||||
|
# Command list-domains executed successfully.
|
||||||
|
# we have domain1 running. so we stop it with
|
||||||
|
glassfish7/bin/asadmin stop-domain domain1
|
||||||
|
```
|
||||||
|
|
||||||
|
## DONE
|
||||||
|
|
||||||
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,3 +0,0 @@
|
|||||||
artifactId=shop
|
|
||||||
groupId=net.tinsae.rest
|
|
||||||
version=1.0-SNAPSHOT
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
net/tinsae/shop/App.class
|
|
||||||
net/tinsae/shop/Item.class
|
|
||||||
net/tinsae/shop/Util.class
|
|
||||||
net/tinsae/shop/Factory.class
|
|
||||||
net/tinsae/shop/InvalidItemException.class
|
|
||||||
net/tinsae/shop/ItemDao.class
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
/home/tgk/Repos/Trusted/DistributedSystems/week5_TinsaeGhilay/shop/src/main/java/net/tinsae/shop/App.java
|
|
||||||
/home/tgk/Repos/Trusted/DistributedSystems/week5_TinsaeGhilay/shop/src/main/java/net/tinsae/shop/Factory.java
|
|
||||||
/home/tgk/Repos/Trusted/DistributedSystems/week5_TinsaeGhilay/shop/src/main/java/net/tinsae/shop/InvalidItemException.java
|
|
||||||
/home/tgk/Repos/Trusted/DistributedSystems/week5_TinsaeGhilay/shop/src/main/java/net/tinsae/shop/Item.java
|
|
||||||
/home/tgk/Repos/Trusted/DistributedSystems/week5_TinsaeGhilay/shop/src/main/java/net/tinsae/shop/ItemDao.java
|
|
||||||
/home/tgk/Repos/Trusted/DistributedSystems/week5_TinsaeGhilay/shop/src/main/java/net/tinsae/shop/Util.java
|
|
||||||
BIN
week5_TinsaeGhilay/Task 3/Table.pdf
Normal file
BIN
week5_TinsaeGhilay/Task 3/Table.pdf
Normal file
Binary file not shown.
52
week5_TinsaeGhilay/Task 4/Client.cpp
Normal file
52
week5_TinsaeGhilay/Task 4/Client.cpp
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <curl/curl.h>
|
||||||
|
|
||||||
|
size_t WriteCallback(void* contents, size_t size, size_t nmemb, void* userp) {
|
||||||
|
((std::string*)userp)->append((char*)contents, size * nmemb);
|
||||||
|
return size * nmemb;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string httpRequest(const std::string& url,
|
||||||
|
const std::string& method,
|
||||||
|
const std::string& body = "") {
|
||||||
|
CURL* curl;
|
||||||
|
CURLcode res;
|
||||||
|
std::string readBuffer;
|
||||||
|
|
||||||
|
curl = curl_easy_init();
|
||||||
|
if (curl) {
|
||||||
|
struct curl_slist* headers = NULL;
|
||||||
|
headers = curl_slist_append(headers, "Content-Type: application/json");
|
||||||
|
|
||||||
|
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
||||||
|
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, method.c_str());
|
||||||
|
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
|
||||||
|
|
||||||
|
if (!body.empty()) {
|
||||||
|
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
|
||||||
|
|
||||||
|
res = curl_easy_perform(curl);
|
||||||
|
curl_easy_cleanup(curl);
|
||||||
|
}
|
||||||
|
return readBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::string base = "http://localhost:8080/shop-1.0-SNAPSHOT/api/items";
|
||||||
|
|
||||||
|
// GET all items
|
||||||
|
std::cout << "GET all items:\n" << httpRequest(base, "GET") << "\n\n";
|
||||||
|
|
||||||
|
// GET item by ID
|
||||||
|
std::cout << "GET item 1:\n" << httpRequest(base + "/1", "GET") << "\n\n";
|
||||||
|
|
||||||
|
// POST new item
|
||||||
|
std::string newItem = R"({"name":"Mouse","price":1.25, "description":"Logitek gaming mouse"})";
|
||||||
|
std::cout << "POST new item:\n" << httpRequest(base, "POST", newItem) << "\n\n";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
BIN
week5_TinsaeGhilay/Task 4/client
Executable file
BIN
week5_TinsaeGhilay/Task 4/client
Executable file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,3 +0,0 @@
|
|||||||
net/tinsae/Client.class
|
|
||||||
net/tinsae/Main.class
|
|
||||||
net/tinsae/Delegator.class
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
/home/tgk/Repos/Trusted/DistributedSystems/week5_TinsaeGhilay/client/src/main/java/net/tinsae/Client.java
|
|
||||||
/home/tgk/Repos/Trusted/DistributedSystems/week5_TinsaeGhilay/client/src/main/java/net/tinsae/Delegator.java
|
|
||||||
/home/tgk/Repos/Trusted/DistributedSystems/week5_TinsaeGhilay/client/src/main/java/net/tinsae/Main.java
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<beans xmlns="https://jakarta.ee/xml/ns/jakartaee"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/beans_4_1.xsd">
|
|
||||||
|
|
||||||
</beans>
|
|
||||||
5
week5_TinsaeGhilay/solutions.txt
Normal file
5
week5_TinsaeGhilay/solutions.txt
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
Exercise 1: not mandatory
|
||||||
|
Exercise 2: done 100%
|
||||||
|
Exercise 3: done 100%
|
||||||
|
Exercise 4: done 100%
|
||||||
|
Exercise 5: not mandatory
|
||||||
Reference in New Issue
Block a user