use of com.tvd12.ezyfoxserver.socket.EzySimplePackage in project ezyfox-server by youngmonkeys.
the class EzySendResponseImpl method execute.
@Override
public void execute(EzyResponse response, EzySession recipient, boolean encrypted, boolean immediate, EzyTransportType transportType) {
boolean success = false;
EzyResponseApi responseApi = server.getResponseApi();
EzyArray data = response.serialize();
EzySimplePackage pack = newPackage(data, encrypted, transportType);
pack.addRecipient(recipient);
try {
responseApi.response(pack, immediate);
success = true;
} catch (Exception e) {
logger.error("send data: {}, to client: {} error", pack.getData(), recipient.getName(), e);
} finally {
pack.release();
}
boolean debug = server.getSettings().isDebug();
if (debug && success && !ignoredLogCommands.contains(response.getCommand())) {
logger.debug("send to: {} data: {}", recipient.getName(), data);
}
}
use of com.tvd12.ezyfoxserver.socket.EzySimplePackage in project ezyfox-server by youngmonkeys.
the class EzySocketResponseApiTest method secureResponseTest.
@Test
public void secureResponseTest() throws Exception {
// given
EzyArray data = EzyEntityFactory.EMPTY_ARRAY;
byte[] bytes = RandomUtil.randomShortByteArray();
EzyObjectToByteEncoder encoder = mock(EzyObjectToByteEncoder.class);
when(encoder.toMessageContent(data)).thenReturn(bytes);
EzySocketResponseApi sut = new EzySocketResponseApi(encoder);
EzySimplePackage pack = new EzySimplePackage();
pack.setData(data);
pack.setEncrypted(true);
pack.setTransportType(EzyTransportType.TCP);
int sessionCount = RandomUtil.randomSmallInt() + 1;
List<EzySession> sessions = RandomUtil.randomList(sessionCount, () -> {
EzySession session = mock(EzySession.class);
when(session.getConnectionType()).thenReturn(EzyConnectionType.SOCKET);
return session;
});
pack.addRecipients(sessions);
// when
sut.response(pack);
// then
verify(encoder, times(1)).toMessageContent(data);
verify(encoder, times(sessionCount)).encryptMessageContent(any(byte[].class), any(byte[].class));
}
use of com.tvd12.ezyfoxserver.socket.EzySimplePackage in project ezyfox-server by youngmonkeys.
the class EzySimplePackageTest method test.
@Test
public void test() {
EzySimplePackage pack = new EzySimplePackage();
pack.setTransportType(EzyTransportType.TCP);
assert pack.getTransportType() == EzyTransportType.TCP;
}
use of com.tvd12.ezyfoxserver.socket.EzySimplePackage in project ezyfox-server by youngmonkeys.
the class EzySimpleNioUdpDataHandler method response.
protected void response(EzySession recipient, int responseCode) throws Exception {
EzyArray responseData = EzyEntityFactory.newArray();
responseData.add(responseCode);
EzyArray responseCommand = EzyEntityFactory.newArray();
responseCommand.add(EzyCommand.UDP_HANDSHAKE.getId());
responseCommand.add(responseData);
EzySimplePackage response = new EzySimplePackage();
response.addRecipient(recipient);
response.setTransportType(EzyTransportType.UDP);
response.setData(responseCommand);
responseApi.response(response);
logger.debug("response udp handshake to: {}, code: {}", recipient, responseCode);
}
Aggregations