FileProcessHandler.java 1.1 KB

123456789101112131415161718192021222324252627
  1. package cn.nosum.gateway.handler;
  2. import cn.nosum.common.constant.CommonConstants;
  3. import cn.nosum.common.http.entity.Context;
  4. import cn.nosum.common.util.LinuxCmd;
  5. import cn.nosum.common.util.NettyFileUtil;
  6. import cn.nosum.common.util.PropertiesUtil;
  7. import com.alibaba.fastjson.JSON;
  8. import io.netty.channel.ChannelHandlerContext;
  9. import io.netty.channel.SimpleChannelInboundHandler;
  10. public class FileProcessHandler extends SimpleChannelInboundHandler<Context> {
  11. @Override
  12. protected void channelRead0(ChannelHandlerContext ctx, Context context) throws Exception {
  13. NettyFileUtil.dataToFile(JSON.toJSONString(context.getRequest().getParameters()),
  14. PropertiesUtil.getProperty(CommonConstants.REQUEST_FILE_SAVE_FOLDER_NAME) + context.getRequest().getUrl(),
  15. true);
  16. context.setResult(LinuxCmd.executeLinuxCmd("stat "+context.getRequest().getUrl()));
  17. ctx.fireChannelRead(context);
  18. }
  19. @Override
  20. public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
  21. ctx.close();
  22. }
  23. }