Search in sources :

Example 1 with Parameters

use of com.generallycloud.baseio.component.Parameters in project baseio by generallycloud.

the class MapByteMessageDecoder method decode.

@Override
public Message decode(ParamedProtobaseFuture future) {
    Parameters param = future.getParameters();
    String messageId = param.getParameter("msgId");
    String queueName = param.getParameter("queueName");
    JSONObject map = param.getJSONObject("map");
    byte[] array = future.getReadBinary();
    return new MapByteMessage(messageId, queueName, map, array);
}
Also used : Parameters(com.generallycloud.baseio.component.Parameters) JSONObject(com.alibaba.fastjson.JSONObject) MapByteMessage(com.generallycloud.baseio.container.jms.MapByteMessage)

Example 2 with Parameters

use of com.generallycloud.baseio.component.Parameters in project baseio by generallycloud.

the class TextMessageDecoder method decode.

@Override
public Message decode(ParamedProtobaseFuture future) {
    Parameters param = future.getParameters();
    String messageId = param.getParameter("msgId");
    String queueName = param.getParameter("queueName");
    String text = param.getParameter("text");
    return new TextMessage(messageId, queueName, text);
}
Also used : Parameters(com.generallycloud.baseio.component.Parameters) TextMessage(com.generallycloud.baseio.container.jms.TextMessage)

Example 3 with Parameters

use of com.generallycloud.baseio.component.Parameters in project baseio by generallycloud.

the class RTPServerDPAcceptor method execute.

@Override
protected void execute(DatagramSession dSession, DatagramRequest request) {
    String serviceName = request.getFutureName();
    if (BIND_SESSION.equals(serviceName)) {
        Parameters parameters = request.getParameters();
        ApplicationContext context = ApplicationContext.getInstance();
        LoginCenter loginCenter = AuthorityContext.getInstance().getLoginCenter();
        if (!loginCenter.isValidate(parameters)) {
            return;
        }
        // FIXME udp
        SocketChannelContext channelContext = context.getChannelContext();
        SocketSessionManager sessionManager = channelContext.getSessionManager();
        // Session session = factory.getSession(username);
        SocketSession session = null;
        if (session == null) {
            return;
        }
        // session.setDatagramChannel(channel); //FIXME udp
        ProtobaseFuture future = new ProtobaseFutureImpl(session.getContext(), BIND_SESSION_CALLBACK);
        logger.debug("___________________bind___session___{}", session);
        future.write("1");
        session.flush(future);
    } else {
        logger.debug(">>>> {}", request.getFutureName());
    }
}
Also used : ApplicationContext(com.generallycloud.baseio.container.ApplicationContext) Parameters(com.generallycloud.baseio.component.Parameters) ProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture) SocketSession(com.generallycloud.baseio.component.SocketSession) SocketSessionManager(com.generallycloud.baseio.component.SocketSessionManager) LoginCenter(com.generallycloud.baseio.container.LoginCenter) ProtobaseFutureImpl(com.generallycloud.baseio.codec.protobase.future.ProtobaseFutureImpl) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext)

Example 4 with Parameters

use of com.generallycloud.baseio.component.Parameters in project baseio by generallycloud.

the class FileReceiveUtil method accept.

public void accept(SocketSession session, ParamedProtobaseFuture future, boolean callback) throws Exception {
    Parameters parameters = future.getParameters();
    OutputStream outputStream = (OutputStream) session.getAttribute(ACCEPT_FILE);
    if (outputStream == null) {
        String fileName = prefix + parameters.getParameter(FILE_NAME);
        outputStream = new FileOutputStream(new File(fileName));
        session.setAttribute(ACCEPT_FILE, outputStream);
        logger.info("accept...................open,file={}", fileName);
    }
    byte[] data = future.getReadBinary();
    outputStream.write(data, 0, future.getReadBinarySize());
    logger.info("accept...................{},{}", future.getReadBinarySize(), (num++));
    boolean isEnd = parameters.getBooleanParameter(IS_END);
    if (isEnd) {
        logger.info("accept...................close,stream={}", outputStream);
        CloseUtil.close(outputStream);
        session.removeAttribute(ACCEPT_FILE);
        if (callback) {
            future.write("传输成功!");
            session.flush(future);
        }
    }
}
Also used : Parameters(com.generallycloud.baseio.component.Parameters) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 5 with Parameters

use of com.generallycloud.baseio.component.Parameters in project baseio by generallycloud.

the class AuthorityFilter method accept.

@Override
protected void accept(SocketSession session, NamedFuture future) throws Exception {
    AuthorityContext authorityContext = AuthorityContext.getInstance();
    AuthoritySessionAttachment attachment = authorityContext.getSessionAttachment(session);
    AuthorityManager authorityManager = attachment.getAuthorityManager();
    if (authorityManager == null) {
        RoleManager roleManager = authorityContext.getRoleManager();
        authorityManager = roleManager.getAuthorityManager(Authority.GUEST);
        attachment.setAuthorityManager(authorityManager);
    }
    if (!authorityManager.isInvokeApproved(future.getFutureName())) {
        future.write(RESMessage.UNAUTH.toString());
        session.flush(future);
        String futureName = future.getFutureName();
        String remoteAddr = session.getRemoteAddr();
        String readText = future.getReadText();
        if (!StringUtil.isNullOrBlank(readText)) {
            logger.info("refuse connection, ip:{}, service name:{}, content: {}", new String[] { remoteAddr, futureName, readText });
            return;
        }
        if (future instanceof ParametersFuture) {
            Parameters parameters = ((ParametersFuture) future).getParameters();
            if (parameters.size() > 0) {
                logger.info("refuse connection, ip:{}, service name:{}, content: {}", new String[] { remoteAddr, futureName, parameters.toString() });
                return;
            }
        }
        logger.info("refuse connection, ip:{}, service name:{}", remoteAddr, futureName);
    }
}
Also used : Parameters(com.generallycloud.baseio.component.Parameters) ParametersFuture(com.generallycloud.baseio.protocol.ParametersFuture)

Aggregations

Parameters (com.generallycloud.baseio.component.Parameters)9 JSONObject (com.alibaba.fastjson.JSONObject)2 TextByteMessage (com.generallycloud.baseio.container.jms.TextByteMessage)2 ParametersFuture (com.generallycloud.baseio.protocol.ParametersFuture)2 ProtobaseFuture (com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture)1 ProtobaseFutureImpl (com.generallycloud.baseio.codec.protobase.future.ProtobaseFutureImpl)1 SocketChannelContext (com.generallycloud.baseio.component.SocketChannelContext)1 SocketSession (com.generallycloud.baseio.component.SocketSession)1 SocketSessionManager (com.generallycloud.baseio.component.SocketSessionManager)1 ApplicationContext (com.generallycloud.baseio.container.ApplicationContext)1 LoginCenter (com.generallycloud.baseio.container.LoginCenter)1 ErrorMessage (com.generallycloud.baseio.container.jms.ErrorMessage)1 MapByteMessage (com.generallycloud.baseio.container.jms.MapByteMessage)1 MapMessage (com.generallycloud.baseio.container.jms.MapMessage)1 Message (com.generallycloud.baseio.container.jms.Message)1 NullMessage (com.generallycloud.baseio.container.jms.NullMessage)1 TextMessage (com.generallycloud.baseio.container.jms.TextMessage)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1