use of com.tvd12.ezyfoxserver.response.EzyPackage in project ezyfox-server by youngmonkeys.
the class EzyAbstractResponseApi method normalResponse.
protected final void normalResponse(EzyPackage pack, boolean immediate) throws Exception {
EzyConstant connectionType = getConnectionType();
Collection<EzySession> recipients = pack.getRecipients(connectionType);
if (recipients.isEmpty()) {
return;
}
Object bytes = encodeData(pack.getData());
if (immediate) {
for (EzySession session : recipients) {
session.sendNow(createPacket(bytes, pack));
}
} else {
for (EzySession session : recipients) {
session.send(createPacket(bytes, pack));
}
}
}
use of com.tvd12.ezyfoxserver.response.EzyPackage in project ezyfox-server by youngmonkeys.
the class EzyAbstractResponseApi method createPacket.
protected EzySimplePacket createPacket(Object bytes, EzyPackage pack) {
EzySimplePacket packet = new EzySimplePacket();
packet.setTransportType(pack.getTransportType());
packet.setData(bytes);
return packet;
}
use of com.tvd12.ezyfoxserver.response.EzyPackage in project ezyfox-server by youngmonkeys.
the class EzyWsResponseApi method createPacket.
@Override
protected EzySimplePacket createPacket(Object bytes, EzyPackage pack) {
EzySimplePacket packet = super.createPacket(bytes, pack);
packet.setBinary(false);
return packet;
}
use of com.tvd12.ezyfoxserver.response.EzyPackage in project ezyfox-server by youngmonkeys.
the class EzyAbstractResponseApi method secureResponse.
protected final void secureResponse(EzyPackage pack, boolean immediate) throws Exception {
EzyConstant connectionType = getConnectionType();
Collection<EzySession> recipients = pack.getRecipients(connectionType);
if (recipients.isEmpty()) {
return;
}
byte[] messageContent = dataToMessageContent(pack.getData());
if (immediate) {
for (EzySession session : recipients) {
byte[] bytes = encryptMessageContent(messageContent, session.getSessionKey());
session.sendNow(createPacket(bytes, pack));
}
} else {
for (EzySession session : recipients) {
byte[] bytes = encryptMessageContent(messageContent, session.getSessionKey());
session.send(createPacket(bytes, pack));
}
}
}
use of com.tvd12.ezyfoxserver.response.EzyPackage in project ezyfox-server by youngmonkeys.
the class EzyAbstractResponseApiTest method secureResponseNoRecipients.
@Test
public void secureResponseNoRecipients() {
// given
EzyPackage packet = mock(EzyPackage.class);
when(packet.getRecipients(EzyConnectionType.SOCKET)).thenReturn(Collections.emptyList());
InternalResponseApi sut = new InternalResponseApi();
// when
MethodInvoker.create().object(sut).method("secureResponse").param(EzyPackage.class, packet).param(boolean.class, true).invoke();
// then
verify(packet, times(1)).getRecipients(EzyConnectionType.SOCKET);
}
Aggregations