Search in sources :

Example 6 with Parameters

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

the class MQBrowserServlet method doAccept.

@Override
public void doAccept(SocketSession session, ParamedProtobaseFuture future, MQSessionAttachment attachment) throws Exception {
    Parameters param = future.getParameters();
    String messageId = param.getParameter("messageId");
    Message message = NullMessage.NULL_MESSAGE;
    MQContext context = getMQContext();
    String cmd = param.getParameter("cmd");
    if (StringUtil.isNullOrBlank(cmd)) {
        message = ErrorMessage.CMD_NOT_FOUND_MESSAGE;
    } else {
        if (SIZE.equals(cmd)) {
            future.write(String.valueOf(context.messageSize()));
        } else if (BROWSER.equals(cmd)) {
            if (!StringUtil.isNullOrBlank(messageId)) {
                message = context.browser(messageId);
                if (message == null) {
                    message = NullMessage.NULL_MESSAGE;
                    future.write(message.toString());
                } else {
                    int msgType = message.getMsgType();
                    String content = message.toString();
                    future.write(content);
                    if (msgType == 3) {
                        TextByteMessage byteMessage = (TextByteMessage) message;
                        byte[] bytes = byteMessage.getByteArray();
                        future.writeBinary(bytes);
                    }
                }
            }
        } else if (ONLINE.equals(cmd)) {
            boolean bool = context.isOnLine(param.getParameter("queueName"));
            future.write(String.valueOf(bool));
        }
    }
    session.flush(future);
}
Also used : TextByteMessage(com.generallycloud.baseio.container.jms.TextByteMessage) Parameters(com.generallycloud.baseio.component.Parameters) ErrorMessage(com.generallycloud.baseio.container.jms.ErrorMessage) NullMessage(com.generallycloud.baseio.container.jms.NullMessage) TextByteMessage(com.generallycloud.baseio.container.jms.TextByteMessage) Message(com.generallycloud.baseio.container.jms.Message)

Example 7 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 8 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)

Example 9 with Parameters

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

the class LoggerFilter method accept.

@Override
protected void accept(SocketSession session, NamedFuture future) throws Exception {
    String futureName = future.getFutureName();
    if (noneLoggerUrlSet.contains(futureName) || endContains(futureName)) {
        return;
    }
    String remoteAddr = session.getRemoteAddr();
    String readText = future.getReadText();
    if (!StringUtil.isNullOrBlank(readText)) {
        logger.info("request 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("request ip:{}, service name:{}, content: {}", new String[] { remoteAddr, futureName, parameters.toString() });
            return;
        }
    }
    logger.info("request 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