@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); }
@Put @At("/:port/har") public Reply<?> newHar(@Named("port") int port, Request<String> request) { LegacyProxyServer proxy = proxyManager.get(port); if (proxy == null) { return Reply.saying().notFound(); } String initialPageRef = request.param("initialPageRef"); String initialPageTitle = request.param("initialPageTitle"); Har oldHar = proxy.newHar(initialPageRef, initialPageTitle); String captureHeaders = request.param("captureHeaders"); String captureContent = request.param("captureContent"); String captureBinaryContent = request.param("captureBinaryContent"); proxy.setCaptureHeaders(Boolean.parseBoolean(captureHeaders)); proxy.setCaptureContent(Boolean.parseBoolean(captureContent)); proxy.setCaptureBinaryContent(Boolean.parseBoolean(captureBinaryContent)); if (oldHar != null) { return Reply.with(oldHar).as(Json.class); } else { return Reply.saying().noContent(); } }
@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); }
@Get @At("/:port/limit") public Reply<?> getLimits(@Named("port") int port, Request<String> request) { LegacyProxyServer proxy = proxyManager.get(port); if (proxy == null) { return Reply.saying().notFound(); } return Reply.with(new BandwidthLimitDescriptor(proxy.getStreamManager())).as(Json.class); }
@Get @At("/:port/whitelist") public Reply<?> getWhitelist(@Named("port") int port, Request<String> request) { LegacyProxyServer proxy = proxyManager.get(port); if (proxy == null) { return Reply.saying().notFound(); } return Reply.with(proxy.getWhitelistUrls()).as(Json.class); }
@Get @At("/:port/har") public Reply<?> getHar(@Named("port") int port) { LegacyProxyServer proxy = proxyManager.get(port); if (proxy == null) { return Reply.saying().notFound(); } Har har = proxy.getHar(); return Reply.with(har).as(Json.class); }
@Get public Reply<String> get() { String runId = request.getParameter("runId"); if (StringUtils.isBlank(runId)) { return Reply.with(StringUtils.EMPTY); } LogBus logBus = LogBus.get(runId); synchronized (logBus.getLock()) { if (logBus.size() > 0) { log.debug("Found logs from cache, size={}", logBus.size()); StringBuffer logs = new StringBuffer(); for (String log : logBus) { logs.append(log).append("\n"); } // Clean log cache after get all logs logBus.clear(); return Reply.with(logs.toString()); } } return Reply.with(StringUtils.EMPTY); }
public Reply<?> reply() { FormResponse response = get(); return Reply.with(response).as(Json.class); }