Search in sources :

Example 1 with EzyPackage

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));
        }
    }
}
Also used : EzyConstant(com.tvd12.ezyfox.constant.EzyConstant) EzySession(com.tvd12.ezyfoxserver.entity.EzySession)

Example 2 with EzyPackage

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;
}
Also used : EzySimplePacket(com.tvd12.ezyfoxserver.socket.EzySimplePacket)

Example 3 with EzyPackage

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;
}
Also used : EzySimplePacket(com.tvd12.ezyfoxserver.socket.EzySimplePacket)

Example 4 with EzyPackage

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));
        }
    }
}
Also used : EzyConstant(com.tvd12.ezyfox.constant.EzyConstant) EzySession(com.tvd12.ezyfoxserver.entity.EzySession)

Example 5 with EzyPackage

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);
}
Also used : EzyPackage(com.tvd12.ezyfoxserver.response.EzyPackage) Test(org.testng.annotations.Test)

Aggregations

EzyConstant (com.tvd12.ezyfox.constant.EzyConstant)3 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)2 EzyPackage (com.tvd12.ezyfoxserver.response.EzyPackage)2 EzySimplePacket (com.tvd12.ezyfoxserver.socket.EzySimplePacket)2 Test (org.testng.annotations.Test)2 EzyObjectToByteEncoder (com.tvd12.ezyfox.codec.EzyObjectToByteEncoder)1 EzyObjectToStringEncoder (com.tvd12.ezyfox.codec.EzyObjectToStringEncoder)1 EzyProxyResponseApi (com.tvd12.ezyfoxserver.api.EzyProxyResponseApi)1 EzyCodecFactory (com.tvd12.ezyfoxserver.codec.EzyCodecFactory)1 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)1 EzyImmediateDeliver (com.tvd12.ezyfoxserver.entity.EzyImmediateDeliver)1 BaseTest (com.tvd12.test.base.BaseTest)1