Exemplo n.º 1
0
  /**
   * 上传文件
   *
   * @param param
   * @return
   */
  public int upLoadFile(HttpRequestParam param) {
    // 创建请求响应的返回对象
    final HttpRequestResult httpRequestResult = createHttpRequestResult(param);

    int handle = createHttpHandle(param, httpRequestResult);

    // 如果创建Handle失败,则直接返回请求失败
    if (httpRequestResult.getStatus() == HttpRequestStatus.FAILED) {
      return -1;
    }

    pool.put(handle, param);
    Logger.beginDebug(EspaceService.TAG).p("HttpManager:pool:" + pool).end();
    int httpRet =
        httpUploadFile(
            handle, param.getMethod(), param.getUrl(), param.getBody(), param.getFilePath());

    // 发送失败
    if (HttpParam.EN_HTTP_ERRORCODE.EN_HTTP_OK != httpRet) {
      pool.remove(handle);
      Logger.beginDebug(EspaceService.TAG)
          .p("HttpManager:SENDREQUEST ERROR:httpRet:" + httpRet)
          .end();
      httpRequestResult.setStatus(HttpRequestStatus.FAILED);
      return -1;
    }

    return handle;
  }
Exemplo n.º 2
0
 /** 方法名称:httpUninit 作者: zhang dong 00199735 创建时间:2012-08-30 方法描述:http反初始化 输入参数: 备注: */
 public int httpUninit() {
   if (httpSdk != null) {
     int iRet = httpSdk.HttpUninit();
     Logger.debug(EspaceService.TAG, "HttpManager:httpUninit:" + iRet);
   }
   return 0;
 }
Exemplo n.º 3
0
 /** 释放所有 http 句柄 */
 public void httpReleaseAllHandle() {
   for (int handle : pool.getMap().keySet()) {
     Logger.debug(EspaceService.TAG, "HttpManager:httpReleaseAllHandle:handle:" + handle);
     httpReleaseHandle(handle);
     pool.remove(handle);
   }
 }
Exemplo n.º 4
0
  /**
   * 方法名称:httpUploadFile 作者: zhang dong 00199735 创建时间:2012-08-30 方法描述:上传文件 输入参数:filepath 文件路径 备注:
   */
  private int httpUploadFile(int handle, String method, String url, String body, String filePath) {

    StringBuffer strParam = new StringBuffer();
    strParam.append("<httpsdk>");
    strParam.append("<handle>").append(handle).append("</handle>");
    strParam.append("<method>").append(method).append("</method>");
    strParam.append("<url>").append(url).append("</url>");
    strParam.append("<heads>");
    //        strParam.append("<Content-Type>").append("text/xml")
    //                .append("</Content-Type>");
    //        strParam.append("<Cache-Control>").append("non-cache")
    //                .append("</Cache-Control>");
    //        strParam.append("<User-Agent>")
    //                .append("Mozilla/4.0 (compatible; MSIE 60; Windows.NT)")
    //                .append("</User-Agent>");
    //        strParam.append("<Accept-Encoding>").append("gzip, deflate")
    //                .append("</Accept-Encoding>");
    strParam.append("<Connection>").append("Keep-Alive").append("</Connection>");
    //        strParam.append("<Accept>").append("*/*").append("</Accept>");
    strParam.append("</heads>");
    //        strParam.append("<body>").append(body).append("</body>");
    strParam.append("<filepath>").append(filePath).append("</filepath>");
    strParam.append("<needprogress>").append("1").append("</needprogress>");
    strParam.append("</httpsdk>");

    int iRet = httpSdk.HttpUploadFile(strParam.toString());

    Logger.beginDebug(EspaceService.TAG).p("HttpManager:httpUploadFile:" + iRet).end();

    return iRet;
  }
 public void download() {
   if (curStatus == STATUS_UM) {
     UmFunc.getIns().downloadFile(message, resource);
   } else if (curStatus == STATUS_GROUP_ZONE) {
     GroupZoneFunc.ins().downloadFile(groupFile);
   } else if (curStatus == STATUS_PREVIEW) {
     // do nothing
     Logger.error(LocalLog.APPTAG, "local file, don't download.");
   }
 }
Exemplo n.º 6
0
  /**
   * httpSdk 初始化
   *
   * @param logPath
   */
  public void initHttpSdk(String logPath) {

    this.logPath = logPath;
    // 全局唯一,只初始化一次
    if (httpSdk == null) {
      Logger.debug(EspaceService.TAG, "httpsdk init:logPath:" + logPath);

      httpSdk = HttpSdk.registerCallback(this);
    }
  }
 public void cancelTransfer() {
   if (curStatus == STATUS_UM) {
     AutoCancelStack.getIns().cancelAuto(message.getMessageId());
     UmFunc.getIns().cancelTransFile(message.getId(), resource.getMediaId(), false);
   } else if (curStatus == STATUS_GROUP_ZONE) {
     GroupZoneFunc.ins().cancelDownload(groupFile);
   } else if (curStatus == STATUS_PREVIEW) {
     // do nothing
     Logger.error(LocalLog.APPTAG, "local file, don't download.");
   }
 }
  /**
   * 发送消息给ui,打开文件。
   *
   * @param filePath
   */
  private void openFile(String filePath) {
    Logger.debug(LocalLog.APPTAG, "file path = " + filePath);

    Bundle mBundle = new Bundle();
    mBundle.putString(IntentData.PATH, filePath);

    Message msg = handler.obtainMessage();
    msg.what = OPEN_FILE;
    msg.setData(mBundle);
    handler.sendMessage(msg);
  }
    @Override
    public void run() {
      try {
        // 延迟1.5s处理,如果还不存在公众号,
        // 则不处理这个公众号的消息
        Thread.sleep(1500);
      } catch (InterruptedException e) {
        Logger.error(EspaceService.TAG, e);
      }

      handleMsgLists(msgLists, null);
    }
Exemplo n.º 10
0
  public void write(Logger record) {
    String body = record.body();

    writeAndroidLog(record.tag(), record.level(), body);

    writeLogFile(record.tag(), record.level(), record.head() + body);
  }
Exemplo n.º 11
0
  /**
   * 创建请求Handle, 有可能失败
   *
   * @param param
   * @param httpRequestResult
   * @return
   */
  private int createHttpHandle(HttpRequestParam param, final HttpRequestResult httpRequestResult) {
    if (!init) {
      httpInit(HttpParam.EN_HTTP_LOG_LEVEL.EN_HTTP_LOG_DEBUG, 10, logPath, 50);
    }

    String strRet =
        httpCreateHandle(
            param.getIpAddress(),
            param.getPort(),
            param.getTlsMode(),
            param.getAuthMode(),
            param.getAccount(),
            param.getPassword(),
            param.getFullnumber());

    int iRet =
        StringUtil.findIntElement(
            strRet, "<ret>", "</ret>", HttpParam.EN_HTTP_ERRORCODE.EN_HTTP_OK);

    // 是否创建成功
    if (HttpParam.EN_HTTP_ERRORCODE.EN_HTTP_OK != iRet) {
      Logger.beginDebug(EspaceService.TAG).p("HttpManager:httpCreateHandle FAIL:" + strRet).end();

      httpRequestResult.setStatus(HttpRequestStatus.FAILED);
    }

    int handle = StringUtil.findIntElement(strRet, "<handle>", "</handle>", -1);
    // 是否创建成功
    if (0 > handle) {
      Logger.beginDebug(EspaceService.TAG)
          .p("HttpManager:httpCreateHandle is ERROR:" + strRet)
          .end();

      httpRequestResult.setStatus(HttpRequestStatus.FAILED);
    }
    return handle;
  }
Exemplo n.º 12
0
 /**
  * 方法名称:httpInit 作者: zhang dong 00199735 创建时间:2012-08-30 方法描述:http初始化 输入参数: 备注:
  *
  * @param handlenum
  */
 private int httpInit(int logLevel, int logSize, String logPath, int handlenum) {
   StringBuffer strParam = new StringBuffer();
   strParam.append("<httpsdk>");
   strParam.append("<level>").append(logLevel).append("</level>");
   strParam.append("<size>").append(logSize).append("</size>");
   strParam.append("<logpath>").append(logPath).append("</logpath>");
   strParam.append("<handlenum>").append(handlenum).append("</handlenum>");
   strParam.append("<usesvn>").append("0").append("</usesvn>"); // svn
   strParam.append("<usesvnfile>").append("1").append("</usesvnfile>"); // svn
   strParam.append("</httpsdk>");
   int iRet = httpSdk.HttpInit(strParam.toString());
   Logger.debug(EspaceService.TAG, "httpSdk init:ret" + iRet + ")");
   init = true;
   return iRet;
 }
  public void updateByGroupId(int imId, int groupId) {
    if (imId <= 0 || groupId <= 0) {
      Logger.error(EspaceService.TAG, "id is 0, not update.");
      return;
    }

    String[] objs = new String[] {String.valueOf(imId), String.valueOf(groupId)};

    StringBuffer buffer = new StringBuffer("update ");
    buffer.append(TABLE_NAME);
    buffer.append(" set ");
    buffer.append(INSTANTMESSAGEID);
    buffer.append(" = ? ");
    buffer.append(" where ");
    buffer.append(GROUPFILEID);
    buffer.append(" = ?");

    execSql(buffer.toString(), objs);
  }
Exemplo n.º 14
0
  public void releaseHandle(int handle) {
    Logger.debug(EspaceService.TAG, "HttpManager:httpReleaseHandle:" + handle);

    pool.remove(handle);
    httpReleaseHandle(handle);
  }