This repository will host the monitoring system for BlockData
All you need to know about Java Websockets API, Please study these classes carefully. This is much better than referring other websites. Please understand the objects, their return types and play with the code.
https://docs.oracle.com/javaee/7/api/javax/websocket/package-summary.html
http://www.java2s.com/Code/Jar/j/Downloadjsonjar.htm
OR
http://www.java2s.com/Code/Jar/j/Downloadjsonsimple11jar.htm
Prefix 11
while uploading file to server
Server changes 11
to 00
while distributing file
Use Prefix 01
while broadcasting ledger from server
import javax.servlet.http.HttpSession;
import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig;
import java.io.*;
import java.util.*;
import java.lang.*;
import java.util.logging.Logger;
public class HttpSessionConfigurator extends ServerEndpointConfig.Configurator {
private static Logger LOGGER = Logger.getLogger("HttpSessionConfigurator");
@Override
public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response) {
LOGGER.info("modifyHandshake() Current thread " + Thread.currentThread().getName());
LOGGER.info(request.SEC_WEBSOCKET_KEY);
config.getUserProperties().put("request",request);
LOGGER.info((request.getHeaders()).get("sec-websocket-key").toString());
super.modifyHandshake(config, request, response);
}
}
The following code is to intercept HTTP Request to server before calling @onOpen
method. This is a method of Interface ServerEndpointConfig.Configurator
.
@Override
public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response)
This is overridden here to get HTTP Headers, Request and Session object. The user properties acquired from HandshakeRequest request
are accessible from EndpointConfig
public void onOpen(Session session,EndpointConfig config)
public void onMessage(Session session,EndpointConfig config)
public void onClose(Session session,EndpointConfig config)
Send the JSON data to server in these formats only
//JSON File Upload Structure
{
"messageType":"fileUpload",
"files":[
{
fileName:""
fileSize:"",
fileType:""
}
]
}
//Send and Storage size IP Message
{
"messageType":"metaData"
"ipAddress":"",
"storageSpace":""
"userId":""
}
Server Sends data to destination node for file Upload
//Send IP and file data
{
"messageType":"fileDownload",
"method":"POST",
"file-exchange-key":Base64 key,
"fileId":""
"fileSize":"",
"owner":""
"ownerId":""
}
Send file data to server as per Specification below- Create a service for the app which runs even after app is Closed
Handle nanoHTTP Server errorsAuthentication using key exchange- Server Side Authentication
Create Blockchain and save data on a file/csv/json- Send file permissions
Broadcast ledgers- Check ledgers