示例#1
0
 public UploadingContext setBufferSize(int bufferSize) {
   this.bufferSize = bufferSize;
   if (bufferSize < 128 && log.isWarnEnabled()) {
     log.warn("Uploading buffer is less than 128!! Auto-fix to 128!! 8192 will be much better!!");
     this.bufferSize = 128;
   }
   return this;
 }
示例#2
0
 @Override
 public void init(NutConfig config, ActionInfo ai) throws Throwable {
   // 需要特别提醒一下使用jsonView,但方法的返回值是String的!!
   if ("json".equals(ai.getOkView()) && String.class.equals(ai.getMethod().getReturnType())) {
     log.warn(
         "Not a good idea : Return String ,and using JsonView!! (Using @Ok(\"raw\") or return map/list/pojo)--> "
             + Lang.simpleMetodDesc(ai.getMethod()));
   }
   view = evalView(config, ai, ai.getOkView());
 }
示例#3
0
 public AnnotationIocLoader(String... packages) {
   for (String packageZ : packages)
     for (Class<?> classZ : Scans.me().scanPackage(packageZ)) addClass(classZ);
   if (map.size() > 0) {
     if (log.isInfoEnabled())
       log.infof(
           "Scan complete ! Found %s classes in %s base-packages!\nbeans = %s",
           map.size(), packages.length, Castors.me().castToString(map.keySet()));
   } else {
     log.warn(
         "NONE Annotation-Class found!! Check your configure or report a bug!! packages="
             + Arrays.toString(packages));
   }
 }
示例#4
0
 public Map<String, Object> getReferObject(
     ServletContext sc,
     HttpServletRequest request,
     HttpServletResponse response,
     String[] pathArgs) {
   try {
     if (!"POST".equals(request.getMethod()) && !"PUT".equals(request.getMethod())) {
       String str = "Not POST or PUT, Wrong HTTP method! --> " + request.getMethod();
       throw Lang.makeThrow(IllegalArgumentException.class, str);
     }
     // 看看是不是传统的上传
     String contentType = request.getContentType();
     if (contentType == null) {
       throw Lang.makeThrow(IllegalArgumentException.class, "Content-Type is NULL!!");
     }
     if (contentType.contains("multipart/form-data")) { // 普通表单上传
       if (log.isDebugEnabled())
         log.debug("Select Html4 Form upload parser --> " + request.getRequestURI());
       Uploading ing = new FastUploading();
       return ing.parse(request, context);
     }
     if (contentType.contains("application/octet-stream")) { // Html5
       // 流式上传
       if (log.isDebugEnabled())
         log.debug("Select Html5 Stream upload parser --> " + request.getRequestURI());
       Uploading ing = new Html5Uploading();
       return ing.parse(request, context);
     }
     // 100%是没写enctype='multipart/form-data'
     if (contentType.contains("application/x-www-form-urlencoded")) {
       log.warn("Using form upload ? You forgot this --> enctype='multipart/form-data' ?");
     }
     throw Lang.makeThrow(IllegalArgumentException.class, "Unknow Content-Type : " + contentType);
   } catch (UploadException e) {
     throw Lang.wrapThrow(e);
   } finally {
     Uploads.removeInfo(request);
   }
 }
  @SuppressWarnings("serial")
  public void init(NutConfig nc) {
    NutShiro.DefaultLoginURL = "/admin/logout";
    // 检查环境
    if (!Charset.defaultCharset().name().equalsIgnoreCase(Encoding.UTF8)) {
      log.warn("This project must run in UTF-8, pls add -Dfile.encoding=UTF-8 to JAVA_OPTS");
    }

    // 获取Ioc容器及Dao对象
    Ioc ioc = nc.getIoc();
    // 加载freemarker自定义标签 自定义宏路径
    ioc.get(Configuration.class)
        .setAutoImports(
            new HashMap<String, String>(2) {
              {
                put("p", "/ftl/pony/index.ftl");
                put("s", "/ftl/spring.ftl");
              }
            });
    ioc.get(FreeMarkerConfigurer.class, "mapTags");
    Dao dao = ioc.get(Dao.class);

    // 为全部标注了@Table的bean建表
    Daos.createTablesInPackage(dao, getClass().getPackage().getName() + ".bean", false);

    // 获取配置对象
    PropertiesProxy conf = ioc.get(PropertiesProxy.class, "conf");

    // 初始化SysLog,触发全局系统日志初始化
    ioc.get(SysLogService.class);

    // 初始化默认根用户
    User admin = dao.fetch(User.class, "admin");
    if (admin == null) {
      UserService us = ioc.get(UserService.class);
      admin = us.add("admin", "123456");
    }
    // 初始化游客用户
    User guest = dao.fetch(User.class, "guest");
    if (guest == null) {
      UserService us = ioc.get(UserService.class);
      guest = us.add("guest", "123456");
      UserProfile profile = dao.fetch(UserProfile.class, guest.getId());
      profile.setNickname("游客");
      dao.update(profile, "nickname");
    }

    // 获取NutQuartzCronJobFactory从而触发计划任务的初始化与启动
    ioc.get(NutQuartzCronJobFactory.class);

    // 权限系统初始化
    AuthorityService as = ioc.get(AuthorityService.class);
    as.initFormPackage("net.wendal.nutzbook");
    as.checkBasicRoles(admin);

    // 检查一下Ehcache CacheManager 是否正常.
    CacheManager cacheManager = ioc.get(CacheManager.class);
    log.debug("Ehcache CacheManager = " + cacheManager);
    // CachedNutDaoExecutor.DEBUG = true;

    // 启用FastClass执行入口方法
    Mvcs.disableFastClassInvoker = false;

    // 设置Markdown缓存
    if (cacheManager.getCache("markdown") == null) cacheManager.addCache("markdown");
    Markdowns.cache = cacheManager.getCache("markdown");
    if (conf.getBoolean("cdn.enable", false) && !Strings.isBlank(conf.get("cdn.urlbase"))) {
      MarkdownFunction.cdnbase = conf.get("cdn.urlbase");
    }
  }