Package org.fto.jthink.exception

Examples of org.fto.jthink.exception.JThinkRuntimeException


      Constructor homeCR = homeClass.getConstructor(new Class[]{ResourceManager.class});
      Object homeObj = homeCR.newInstance(new Object[]{resManager});
      return homeObj;
    }
    catch (Exception ex) {
      throw new JThinkRuntimeException(JThinkErrorCode.ERRCODE_JB_LOOKUP_EJB_FAILURE,
          "Look up ejb failure! jndi = " + jndi, ex);
    }
  }
View Full Code Here


      }else{
        ds = getDataSource(jndi);
      }
      return ds.getConnection();
    } catch (SQLException ex) {
      throw new JThinkRuntimeException(
          JThinkErrorCode.ERRCODE_DB_CANNOT_GET_CONNECTION,
        "Cannot get connection! JNDI = "+jndi,ex);
    }
  }
View Full Code Here

    try {
      ctx = new InitialContext();
      return (DataSource) ctx.lookup(jndi);
    }
    catch (Exception ex) {
      throw new JThinkRuntimeException(
          JThinkErrorCode.ERRCODE_DB_CANNOT_GET_DATASOURCE,
          "DataSource JNDI = " + jndi,ex);
    }finally{
      if(ctx!=null){
        try {
          ctx.close();
        }
        catch (NamingException ne) {
          throw new JThinkRuntimeException(
              JThinkErrorCode.ERRCODE_DB_CANNOT_GET_DATASOURCE,
              "关闭Context对象失败, DataSource JNDI = " + jndi, ne);
        }
      }
    }
View Full Code Here

            }
            rses.add(fieldMap);
          }
        }
        catch (SQLException ex) {
          throw new JThinkRuntimeException(JThinkErrorCode.ERRCODE_DB_EXEC_SQL_EXCEPTION, ex);
        }
        return rses;
      }
View Full Code Here

          }
          rses.add(fieldMap);
        }
      }
      catch (SQLException ex) {
        throw new JThinkRuntimeException(JThinkErrorCode.ERRCODE_DB_EXEC_SQL_EXCEPTION, ex);
      }
      return rses;
    }
View Full Code Here

        int count = raf.read(bs, 0, bcount);
        fileOut.write(bs, 0, count);
      }
     
    } catch (IOException e) {
      throw new JThinkRuntimeException("File can't be saved (1120).", e);
    }finally{
      if(fileOut!=null){
        try {
          fileOut.close();
        } catch (IOException e1) {
          logger.error("关闭FileOutputStream时异常!", e1);
          throw new JThinkRuntimeException(e1);
        }
      }
     
      if(raf!=null){
        try {
          raf.close();
        } catch (IOException e1) {
          logger.error("关闭RandomAccessFile时异常!", e1);
          throw new JThinkRuntimeException(e1);
        }
      }
    }
  }
View Full Code Here

      /* 返回总字节数量 */
      totalBytes = request.getServletRequest().getContentLength();
//      logger.debug("流失时间: "+(System.currentTimeMillis()-time));
      if (maxContentLength > (long)0   && totalBytes > maxContentLength){
        request.getServletRequest().getInputStream().close();
        throw new JThinkRuntimeException("Total request content size exceeded.")//请求的内容太大,不允许上传文件
      }
     
      /* 读入所有字节数据,并保存到临时文件 */
      InputStream is = request.getServletRequest().getInputStream();
      int readBytes = 1024*256;
      if(totalBytes>1024*256 && totalBytes<=1024*512){
        readBytes = 1024*512;
      }else if(totalBytes>1024*512 && totalBytes<=1048576){
        readBytes = 1048576;
      }else if(totalBytes>1048576 && totalBytes<=1048576*5){
        readBytes = 1048576*2;
      }else if(totalBytes>=1048576*5){
        readBytes = 1048576*5;
      }

      int tmpReadBytes = 0;
      byte[] bs = new byte[readBytes];
      for(int currBytes=0;currBytes<totalBytes;){
        int count = is.read(bs, tmpReadBytes, readBytes-tmpReadBytes);
        currBytes += count;
        tmpReadBytes += count;
        if(tmpReadBytes==readBytes || currBytes>=totalBytes){
          raf.write(bs, 0, tmpReadBytes);
          tmpReadBytes = 0;
        }
      }

      /* 查找请求数据的开始索引位置和请求数据块间的分隔串 */
      raf.seek(0);
      int v = raf.read();
      boundary = "";
      while(v!=13 && raf.getFilePointer() < totalBytes){
        boundary += (char)v;
        v = raf.read();
      }
     
      /* 如果没有任何请求信息, 直接返回 */
      if(raf.getFilePointer()==1 || raf.getFilePointer()>=raf.length()){
        return;
      }
      while(true){
        if (raf.getFilePointer() >= totalBytes){
          break;
        }
        /* 返回字段头信息 */
        String dataHeader = getDataHeader(raf);
        boolean isFile = dataHeader.indexOf("filename") > 0;
        String fieldName = getDataFieldValue(dataHeader, "name");
        if (isFile) {
          filePathName = getDataFieldValue(dataHeader, "filename");
          fileName = preName + getFileName(filePathName);
          fileExt = getFileExt(fileName);
          contentType = getContentType(dataHeader);
          contentDisp = getContentDisp(dataHeader);
          typeMIME = getTypeMIME(contentType);
          subTypeMIME = getSubTypeMIME(contentType);
        }

        /* 处理数据片段 */
        getDataSection(raf);
       
        /* 判断文件是否被允许上传 */
        if (isFile && fileName.length() > 0) {
          if (deniedFilesList!=null && deniedFilesList.contains(fileExt)){
            throw new JThinkRuntimeException(
                "The extension of the file is denied to be uploaded.");//不允许上传此种类型的文件
          }
          if (allowedFilesList!=null && !allowedFilesList.contains(fileExt)){
            throw new JThinkRuntimeException(
                "The extension of the file is not allowed to be uploaded.");//不允许上传此种类型的文件
          }
         
          if (maxFileSize > (long) && (long) ((endData - startData) + 1) > maxFileSize){
            throw new JThinkRuntimeException(String.valueOf(
                (new StringBuffer("Size exceeded for this file : ")).append(fileName)));//文件太大,不允许上传
          }
        }
       
        if (isFile) {
          /* 生成被上传的单个临时文件 */
          org.fto.jthink.j2ee.web.fileload.File newFile = new org.fto.jthink.j2ee.web.fileload.File();
          newFile.setParent(this);
          newFile.setFieldName(fieldName);
          newFile.setFileName(fileName);
          newFile.setFileExt(fileExt);
          newFile.setFilePathName(filePathName);
          newFile.setIsMissing(filePathName.length() == 0);
          newFile.setContentType(contentType);
          newFile.setContentDisp(contentDisp);
          newFile.setTypeMIME(typeMIME);
          newFile.setSubTypeMIME(subTypeMIME);
          if (contentType.indexOf("application/x-macbinary") > 0){
            startData = startData + 128;
          }
          newFile.setSize((endData - startData));
          newFile.setStartData(startData);
          newFile.setEndData(endData);
          files.add(newFile);
         
        } else {
          /* 生成非文件的请求信息数据 */
          long tmpPointer = raf.getFilePointer();
          raf.seek(startData);
          byte[] values = new byte[(endData - startData)];
          raf.read(values);
          String value;
          if(encode==null){
            value = new String(values);
          }else{
            value = new String(values, encode);
          }
          request.putParameter(fieldName, value);
          raf.seek(tmpPointer);
        }
       
        raf.skipBytes(1);
        char c = (char)raf.read();
        /* 如果遇到'-'字符,跳出循环 */
        if (c == '-'){
          raf.skipBytes(-1);
          break;
        }
      }
     
     
    }catch(JThinkRuntimeException e){
      logger.error("上传文件时异常!", e);
      throw e;
    }catch(Exception e){
      close();
      logger.error("上传文件时异常!", e);
      throw new JThinkRuntimeException(e);
     
    }finally{
      closeSmartAccessFile(raf);
//      logger.debug("总流失时间: "+(System.currentTimeMillis()-time));
    }
View Full Code Here

    if(saf!=null){
      try {
        saf.close();
      } catch (IOException e1) {
        logger.error("关闭RandomAccessFile时异常!", e1);
        throw new JThinkRuntimeException(e1);
      }
    }
  }
View Full Code Here

      }
      condition.add(new ConditionItem(pk.getKey().toString(), "=", (Object)value));
    }
     
    if(condition.size()==0){
      throw new JThinkRuntimeException("The condition size cannot be 0");
    }
    return constructSQLForUpdate(data.getTableName(), data.getValues(), condition);
  }
View Full Code Here

      }
      condition.add(new ConditionItem(pk.getKey().toString(), "=", (Object)value));
    }
     
    if(condition.size()==0){
      throw new JThinkRuntimeException("The condition size cannot be 0");
    }
   
    return constructSQLForDelete(data.getTableName(), condition);
  }
View Full Code Here

TOP

Related Classes of org.fto.jthink.exception.JThinkRuntimeException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.