package com.perforce.spark.site; import java.net.MalformedURLException; import java.net.URI; import java.net.URL; import java.util.Set; import javax.servlet.http.HttpServletResponse; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.HttpClientBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import spark.Request; import spark.Response; import com.perforce.p4java.server.IOptionsServer; import com.perforce.spark.artifact.proxy.ProxyArtifact; import com.perforce.spark.repository.RepoFactory; import com.perforce.spark.repository.RepoFormID; import com.perforce.spark.repository.RepoInterface; import com.perforce.spark.store.DefaultStore; public class ProxySite extends DefaultStore { private static Logger logger = LoggerFactory.getLogger(ProxySite.class); private final URL url; public ProxySite(Request request) throws MalformedURLException { super(request); String siteStr = RepoFormID.SITE.get(request); this.site = SiteType.parse(siteStr); this.url = new URL(RepoFormID.URL.get(request)); } @Override public String toString() { StringBuffer sb = new StringBuffer(); sb.append("name: " + name + "\n"); sb.append("url: " + url.toString() + "\n"); return sb.toString(); } @Override public String getSummaryPattern() { type = getArtifactType(); RepoInterface repo = RepoFactory.createStore(type); return repo.getSummaryPattern(); } @Override public String getPath(Request request) { type = getArtifactType(); RepoInterface repo = RepoFactory.createStore(type); return repo.getPath(request); } @Override public HttpServletResponse fetch(IOptionsServer p4, Request request, Response response) throws Exception { // try to cache file if missing String path = getPath(request); if (!isFile(p4, path)) { logger.info("view: missing file: [" + name + "] " + path); ProxyArtifact artifact = new ProxyArtifact(p4, url, name, path); artifact.proxyUpload(); artifact.index(); } return getFile(p4, path, response); } @Override public HttpResponse query(IOptionsServer p4, Request request, Response response) throws Exception { Set<String> map = request.queryParams(); String param = ""; for (String key : map) { param += (param.isEmpty()) ? "?" : "&"; String value = request.queryParams(key); param += key + "=" + value; } String path = getPath(request); URI uri = new URI(url.toString() + "/" + path + param); logger.info("view: query: [" + name + "] " + uri); HttpClient client = HttpClientBuilder.create().build(); HttpGet get = new HttpGet(uri); HttpResponse r = client.execute(get); return r; } public URL getUrl() { return url; } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#6 | 15371 | Paul Allen | Query support for index. | ||
#5 | 15313 | Paul Allen |
Added Client Workspace pool to manage parallel upload requests by the proxy (configuration set to 50). User uploads are restricted to only one per user. |
||
#4 | 15295 | Paul Allen | Remap 'orbit' -> 'jar' extension. | ||
#3 | 15252 | Paul Allen | Added create/edit support for repo configs. | ||
#2 | 15221 | Paul Allen | Generate Gem index and submit after a deploy or proxy fetch event. | ||
#1 | 15094 | Paul Allen | Added support for Proxy and Group. | ||
//guest/paul_allen/p4am/src/main/java/com/perforce/spark/site/Site.java | |||||
#1 | 15012 | Paul Allen | Proxy configuration. |