Ejemplo n.º 1
0
  private Map<String, Object> getHttpCleint() {
    request = ServletActionContext.getRequest();
    try {
      request.setCharacterEncoding("UTF-8");
    } catch (UnsupportedEncodingException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    session = request.getSession();
    // 业务编号
    String businessNUM = request.getParameter(ParamsKeyUtil.URL_PARAMS_KEY_BUSINESSNUM);
    // 获取client
    HttpRequestSender httpRequestSender = new HttpRequestSenderImpl();
    HttpClient client = null;
    client = httpRequestSender.getHttpClient(request);
    if (client == null) {

      this.addActionMessage("登录已超时,请重新登录");
      msg = "timeout";
    } else {
      map = remote(businessNUM, client);
    }
    return map;
  }
Ejemplo n.º 2
0
  /**
   * 下载文件
   *
   * @return
   */
  public void download() {
    request = ServletActionContext.getRequest();
    HttpServletResponse response = ServletActionContext.getResponse();
    try {
      request.setCharacterEncoding("UTF-8");
    } catch (UnsupportedEncodingException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    session = request.getSession();
    // 业务编号
    String businessNUM = request.getParameter(ParamsKeyUtil.URL_PARAMS_KEY_BUSINESSNUM);
    // 获取client
    HttpRequestSender httpRequestSender = new HttpRequestSenderImpl();
    HttpClient client = null;
    client = httpRequestSender.getHttpClient(request);
    if (client == null) {
      this.addActionMessage("登录已超时,请重新登录");
      msg = "timeout";
    } else {
      // 获取URL
      URLService urlService = new URLServiceImpl();
      String url = urlService.getURL(request, businessNUM);
      String filename = request.getParameter("fileName");
      String filepath = FilePathConfigUtil.getValue("oa.filePath") + filename;
      if (httpRequestSender.fromRemoteDownloadFile(client, url, filepath)) {
        File downloadFile = new File(filepath);
        if (downloadFile.exists()) {
          response.setContentType("application/octet-stream");
          Long length = downloadFile.length();
          response.setContentLength(length.intValue());
          response.addHeader("Content-Disposition", "attachment; filename=" + filename);
          try {
            FileInputStream inputStream = new FileInputStream(filepath);
            ServletOutputStream sopt = response.getOutputStream();
            int b = 0;
            byte[] buffer = new byte[1024];
            while (b != -1) {
              b = inputStream.read(buffer);
              // 4.写到输出流(out)中
              sopt.write(buffer, 0, b);
            }
            inputStream.close();
            sopt.close();
            sopt.flush();
          } catch (IOException e) {
            e.printStackTrace();
          }

        } else {

        }
      }
    }
  }
Ejemplo n.º 3
0
  /**
   * 上传文件
   *
   * @return
   */
  public void upload() {

    request = ServletActionContext.getRequest();
    session = request.getSession();
    String filepath = FilePathConfigUtil.getValue("oa.filePath") + getImageFileName();
    String filename = getImageFileName();
    String index = request.getParameter("index");
    // 业务编号
    String businessNUM = request.getParameter(ParamsKeyUtil.URL_PARAMS_KEY_BUSINESSNUM);
    // 获取client
    HttpRequestSender httpRequestSender = new HttpRequestSenderImpl();
    HttpClient client = httpRequestSender.getHttpClient(request);
    if (uploadFile(filepath)) {
      if (client == null) {
        this.addActionMessage("登录已超时,请重新登录");
        msg = "timeout";
      } else {
        // 获取URL
        URLService urlService = new URLServiceImpl();
        String url = urlService.getURL(request, businessNUM);
        // 请求
        String htmlsource =
            httpRequestSender.uploadFileToRemote(client, url, filepath, filename, index);

        HttpServletResponse response = ServletActionContext.getResponse();
        response.setContentType("text/xml;charset=utf-8");
        response.setCharacterEncoding("UTF-8");
        response.setHeader("Cache-Control", "no-cache");
        PrintWriter out = null;
        try {
          out = response.getWriter();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
        out.println(htmlsource);
        out.flush();
        out.close();
      }
    }
  }
Ejemplo n.º 4
0
  /** ajax请求 获取地址信息 */
  public void noLoginAjax() {

    String htmlSource = "";
    request = ServletActionContext.getRequest();
    session = request.getSession();
    // 业务编号
    String businessNUM = request.getParameter(ParamsKeyUtil.URL_PARAMS_KEY_BUSINESSNUM);

    // 获取client
    HttpRequestSender httpRequestSender = new HttpRequestSenderImpl();
    HttpClient client = httpRequestSender.getHttpClient(request);
    if (client == null) {
      this.addActionMessage("登录已超时,请重新登录");

    } else {
      // 获取URL
      URLService urlService = new URLServiceImpl();
      String url = urlService.getURL(request, businessNUM);

      // 请求
      htmlSource = httpRequestSender.getMethodResuest(client, url);
    }
    ajaxResponse(htmlSource);
  }