Пример #1
0
  /**
   * Method description
   *
   * @param request
   * @param response
   */
  @Override
  public void doPost(HttpServletRequest request, HttpServletResponse response) {
    BufferedInputStream webToProxyBuf = null;
    BufferedOutputStream proxyToClientBuf = null;
    HttpURLConnection con;

    try {
      URL url = urlProvider.getProxyURL();

      AssertUtil.assertIsNotNull(url);

      if (logger.isInfoEnabled()) {
        logger.info("proxy request for {}", url.toString());
      }

      con = (HttpURLConnection) url.openConnection();
      con.setDoOutput(true);
      con.setDoInput(true);
      con.setUseCaches(true);

      for (Enumeration e = request.getHeaderNames(); e.hasMoreElements(); ) {
        String headerName = e.nextElement().toString();

        con.setRequestProperty(headerName, request.getHeader(headerName));
      }

      con.connect();
      response.setStatus(con.getResponseCode());

      for (Iterator i = con.getHeaderFields().entrySet().iterator(); i.hasNext(); ) {
        Map.Entry mapEntry = (Map.Entry) i.next();

        if (mapEntry.getKey() != null) {
          response.setHeader(
              mapEntry.getKey().toString(), ((List) mapEntry.getValue()).get(0).toString());
        }
      }

      webToProxyBuf = new BufferedInputStream(con.getInputStream());
      proxyToClientBuf = new BufferedOutputStream(response.getOutputStream());

      int oneByte;

      while ((oneByte = webToProxyBuf.read()) != -1) {
        proxyToClientBuf.write(oneByte);
      }

      con.disconnect();
    } catch (Exception ex) {
      logger.error("could not proxy request", ex);
    } finally {
      IOUtil.close(webToProxyBuf);
      IOUtil.close(proxyToClientBuf);
    }
  }
Пример #2
0
  /**
   * Method description
   *
   * @param user
   */
  @Override
  protected void preUpate(User user) {
    if (DUMMY_PASSWORT.equals(user.getPassword())) {
      User o = manager.get(user.getName());

      AssertUtil.assertIsNotNull(o);
      user.setPassword(o.getPassword());
    } else {
      encryptPassword(user);
    }
  }