Class Communicator
java.lang.Object
ch.autumo.beetroot.server.communication.Communicator
- Direct Known Subclasses:
ClientCommunicator
Client/Server communication.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringFile deletestatic final StringFile receive request for uploadstatic final StringFile request for downloadstatic final StringHealth commandstatic final StringStop commandstatic final String[]HTTP Header accept with 'application/json'.static final String[]HTTP Header accept with 'application/json; charset=utf-8'.protected static final org.slf4j.Loggerstatic final intMax. message size: 512 kBytesstatic final intConnection timeout in secondsstatic final StringUser agents used for tunneled server commands. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckHttpResponse(org.apache.http.client.methods.CloseableHttpResponse resp) Check closeable HTTP response with HttpResponse.protected static booleanisInternalCommand(ServerCommand command) Is it an internal command?protected static Stringread(DataInputStream in) Server- or client-side read.static ServerCommandRead a server command server side.static ServerCommandreadJsonCommand(InputStream in, int length) Read a JSON server command server side.static final voidSafe close for closeable object (e.g. stream, socket).static voidwriteAnswer(ClientAnswer answer, DataOutputStream out) Write/send client answer from server to client.
-
Field Details
-
LOG
protected static final org.slf4j.Logger LOG -
MAX_MSG_SIZE
public static final int MAX_MSG_SIZEMax. message size: 512 kBytes- See Also:
-
TIMEOUT
public static final int TIMEOUTConnection timeout in seconds- See Also:
-
CMD_STOP
Stop command- See Also:
-
CMD_HEALTH
Health command- See Also:
-
CMD_FILE_DELETE
File delete- See Also:
-
CMD_FILE_REQUEST
File request for download- See Also:
-
CMD_FILE_RECEIVE_REQUEST
File receive request for upload- See Also:
-
USER_AGENT
User agents used for tunneled server commands.- See Also:
-
HTTP_HEADER_ACCEPT_JSON
HTTP Header accept with 'application/json'. -
HTTP_HEADER_CONTENTTYPE_JSON_UTF8
HTTP Header accept with 'application/json; charset=utf-8'.
-
-
Constructor Details
-
Communicator
public Communicator()
-
-
Method Details
-
writeAnswer
Write/send client answer from server to client.- Parameters:
answer- client answerout- output stream- Throws:
IOException- IO exception
-
readCommand
Read a server command server side.- Parameters:
in- input stream- Returns:
- server command or null, if command received was invalid
- Throws:
IOException- IO exception
-
readJsonCommand
Read a JSON server command server side.- Parameters:
in- (body) input stream from HTTP/HTTPS requestlength- length of content- Returns:
- server command or null, if command received was invalid
- Throws:
IOException- IO exception
-
read
Server- or client-side read.- Parameters:
in- input stream- Returns:
- unparsed data
- Throws:
IOException- IO exception
-
safeClose
Safe close for closeable object (e.g. stream, socket).- Parameters:
closeable- closeable object
-
checkHttpResponse
public static void checkHttpResponse(org.apache.http.client.methods.CloseableHttpResponse resp) throws Exception Check closeable HTTP response with HttpResponse.- Parameters:
resp- HTTP response- Throws:
Exception- exception
-
isInternalCommand
Is it an internal command?- Parameters:
command- server command- Returns:
- true if so
-