Search in sources :

Example 11 with ValueStack

use of com.roof.chain.api.ValueStack in project roof-im by madfroglx.

the class OfflineTest method testSuccess.

@Test
public void testSuccess() throws Exception {
    List<UserState> states = new ArrayList<>();
    UserState userState = new UserState();
    userState.setConnectId("1");
    userState.setClientType(ClientType.h5.name());
    userState.setUsername("abc");
    userState.setServerName(serverNameBuilder.getName());
    states.add(userState);
    UserState userState2 = new UserState();
    userState2.setConnectId("1");
    userState2.setClientType("applet");
    userState2.setUsername("abc");
    userState2.setServerName(serverNameBuilder.getName());
    states.add(userState2);
    userStateService.online("abc", states);
    OfflineRequest offlineRequest = createRequest();
    ValueStack valueStack = createValueStack(offlineRequest);
    enterChain.doChain(valueStack);
}
Also used : OfflineRequest(org.roof.im.request.OfflineRequest) UserState(org.roof.im.user.UserState) ValueStack(com.roof.chain.api.ValueStack) GenericValueStack(com.roof.chain.support.GenericValueStack) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 12 with ValueStack

use of com.roof.chain.api.ValueStack in project roof-im by madfroglx.

the class OpenSessionTest method testSuccess.

@Test
public void testSuccess() throws Exception {
    OpenSessionRequest openSessionRequest = new OpenSessionRequest();
    openSessionRequest.setSender("abc");
    openSessionRequest.setReceiver("def");
    openSessionRequest.setToken("ab");
    openSessionRequest.setRequestType(RequestType.openSession.name());
    ValueStack valueStack = new GenericValueStack();
    valueStack.set(ImConstant.TEXT_MESSAGE, JSON.toJSONString(openSessionRequest));
    JSONObject jsonObjectMessage = JSON.parseObject(JSON.toJSONString(openSessionRequest));
    valueStack.set(ImConstant.JSON_OBJECT_MESSAGE, jsonObjectMessage);
    enterChain.doChain(valueStack);
}
Also used : OpenSessionRequest(org.roof.im.request.OpenSessionRequest) ValueStack(com.roof.chain.api.ValueStack) GenericValueStack(com.roof.chain.support.GenericValueStack) JSONObject(com.alibaba.fastjson.JSONObject) GenericValueStack(com.roof.chain.support.GenericValueStack) Test(org.junit.Test)

Example 13 with ValueStack

use of com.roof.chain.api.ValueStack in project roof-im by madfroglx.

the class AbstractChainController method doChain.

protected Object doChain(@RequestBody String request, Logger logger) {
    ValueStack valueStack = new GenericValueStack();
    valueStack.set(ImConstant.TEXT_MESSAGE, request);
    JSONObject jsonObjectMessage;
    try {
        jsonObjectMessage = JSON.parseObject(request);
    } catch (Exception e) {
        logger.error("input json error: {}", request);
        return new Response<>(Response.ERROR, "json format error");
    }
    valueStack.set(ImConstant.JSON_OBJECT_MESSAGE, jsonObjectMessage);
    try {
        enterChain.doChain(valueStack);
        return valueStack.get(ImConstant.RESPONSE);
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        return new Response<>(Response.ERROR, e.getMessage());
    }
}
Also used : GenericValueStack(com.roof.chain.support.GenericValueStack) ValueStack(com.roof.chain.api.ValueStack) JSONObject(com.alibaba.fastjson.JSONObject) GenericValueStack(com.roof.chain.support.GenericValueStack)

Aggregations

ValueStack (com.roof.chain.api.ValueStack)13 GenericValueStack (com.roof.chain.support.GenericValueStack)13 JSONObject (com.alibaba.fastjson.JSONObject)7 Test (org.junit.Test)7 CloseSessionRequest (org.roof.im.request.CloseSessionRequest)2 MessageRequest (org.roof.im.request.MessageRequest)2 OfflineRequest (org.roof.im.request.OfflineRequest)2 ArrayList (java.util.ArrayList)1 OpenSessionRequest (org.roof.im.request.OpenSessionRequest)1 UserStateRequest (org.roof.im.request.UserStateRequest)1 Session (org.roof.im.session.Session)1 UserState (org.roof.im.user.UserState)1