This problem is related to the virtual learning environment application discussed in one theory session and a few practicals. In this problem, you are tasked with creating and updating learner profiles, a particular type of user. As well, given a learner profile, we would like to retrieve the learning materials in the form of topics. Note that the learning materials for a given course will differ from one learner profile to another. For example, for a course "Distributed Systems and Applications", the learning materials for a learner with a weak background in "Programming" compared o another learner profile with a stronger background in programming.
Your task is to:
1. Provide a description in OpenAPI of the API that allows for communication between a client and a service for the functionalities discussed above;
2. Implement a corresponding client and a service.
{
"description": "user to add to the system",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/User"
},
"examples": {
"user" : {
"summary": "User Example",
"externalValue": "http://foo.bar/examples/user-example.json"
}
}
},
"application/xml": {
"schema": {
"$ref": "#/components/schemas/User"
},
"examples": {
"user" : {
"summary": "User example in XML",
"externalValue": "http://foo.bar/examples/user-example.xml"
}
}
},
"text/plain": {
"examples": {
"user" : {
"summary": "User example in Plain text",
"externalValue": "http://foo.bar/examples/user-example.txt"
}
}
},
"*/*": {
"examples": {
"user" : {
"summary": "User example in other format",
"externalValue": "http://foo.bar/examples/user-example.whatever"
}
}
}
}
}
{
"description": "user to add to the system",
"content": {
"text/plain": {
"schema": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
}
2.
try {
// create a socket
String serverHost = ... ; // server hostname or IP adress
int serverPort = ... ; // server port number
Socket socket = new Socket(serverHost, serverPort)
// get the streams
OutputStream sockOut = socket.getOutputStream();
InputStream sockIn = socket.getInputStream();
// Communicate:
// send a request to the server
sockOut.write(...);
...
// get the response
sockIn.read(...);
...
// communication completed
// close streams and the socket
sockOut.close();
sockIn.close();
socket.close();
} catch (UnknownHostException exc) {
// unknown host
} catch (SocketException exc) {
// socket-related exceptions
} catch (IOException exc) {
// input-output exceptions
}
Comments
Leave a comment