예제 #1
0
  @Post
  public Reply<?> newProxy(Request<String> request) {
    String systemProxyHost = System.getProperty("http.proxyHost");
    String systemProxyPort = System.getProperty("http.proxyPort");
    String httpProxy = request.param("httpProxy");
    Hashtable<String, String> options = new Hashtable<String, String>();

    // If the upstream proxy is specified via query params that should override any default system
    // level proxy.
    if (httpProxy != null) {
      options.put("httpProxy", httpProxy);
    } else if ((systemProxyHost != null) && (systemProxyPort != null)) {
      options.put("httpProxy", String.format("%s:%s", systemProxyHost, systemProxyPort));
    }

    String paramBindAddr = request.param("bindAddress");
    Integer paramPort =
        request.param("port") == null ? null : Integer.parseInt(request.param("port"));
    String useEccString = request.param("useEcc");
    boolean useEcc = Boolean.parseBoolean(useEccString);
    LOG.debug("POST proxy instance on bindAddress `{}` & port `{}`", paramBindAddr, paramPort);
    LegacyProxyServer proxy;
    try {
      proxy = proxyManager.create(options, paramPort, paramBindAddr, useEcc);
    } catch (ProxyExistsException ex) {
      return Reply.with(new ProxyDescriptor(ex.getPort())).status(455).as(Json.class);
    } catch (ProxyPortsExhaustedException ex) {
      return Reply.saying().status(456);
    } catch (Exception ex) {
      StringWriter s = new StringWriter();
      ex.printStackTrace(new PrintWriter(s));
      return Reply.with(s).as(Text.class).status(550);
    }
    return Reply.with(new ProxyDescriptor(proxy.getPort())).as(Json.class);
  }
예제 #2
0
 @Get
 public Reply<?> getProxies() {
   Collection<ProxyDescriptor> proxyList = new ArrayList<ProxyDescriptor>();
   for (LegacyProxyServer proxy : proxyManager.get()) {
     proxyList.add(new ProxyDescriptor(proxy.getPort()));
   }
   return Reply.with(new ProxyListDescriptor(proxyList)).as(Json.class);
 }