package com.indeed.demo.proctor;

import java.util.UUID;
import java.util.HashMap;
import java.util.Map;

import com.google.common.collect.Maps;
import com.indeed.demo.ProctorGroups;
import com.indeed.proctor.common.*;
import com.indeed.proctor.common.model.*;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

@Component
public class DefinitionManager {
    private static final Logger logger = Logger.getLogger(DefinitionManager.class);

    private static final String DEFAULT_SPEC = "/com/indeed/demo/ProctorGroups.json";
    public static final String DEFAULT_DEFINITION = "https://gist.github.com/youknowjack/6549712/raw";

    private Map<String, Proctor> proctorCache = Maps.newHashMap();

    public Proctor load(String definitionUrl, boolean forceReload) {
        Proctor proctor = proctorCache.get(definitionUrl);
        if (proctor != null && !forceReload) {
            return proctor;
        }
        try {
            ProctorSpecification spec = ProctorUtils.readSpecification(DefinitionManager.class.getResourceAsStream(DEFAULT_SPEC));
            UrlProctorLoader loader = new UrlProctorLoader(spec, definitionUrl);
            proctor = loader.doLoad();
            proctorCache.put(definitionUrl, proctor);
        } catch (Throwable t) {
            logger.error("Failed to load test spec/definition", t);
            t.printStackTrace();
        }
        return proctor;
    }
}

@@ -27,16 +27,51 @@
 octor;%0A%0A
+import java.net.HttpURLConnection;%0A
 import j
@@ -85,16 +85,16 @@
 l.UUID;%0A
-
 import j
@@ -244,17 +244,23 @@
 .common.
-*
+Proctor
 ;%0Aimport
@@ -290,15 +290,126 @@
 mon.
-model.*
+ProctorSpecification;%0Aimport com.indeed.proctor.common.ProctorUtils;%0Aimport com.indeed.proctor.common.UrlProctorLoader
 ;%0Aim
@@ -843,46 +843,20 @@
 ://g
-ist.github.com/youknowjack/6549712/raw
+oo.gl/WCWBRJ
 %22;%0A%0A
@@ -1128,32 +1128,32 @@
 ctor;%0A        %7D%0A
-
         try %7B%0A  
@@ -1150,16 +1150,125 @@
   try %7B%0A
+            HttpURLConnection.setFollowRedirects(true); // for demo purposes, allow Java to follow redirects%0A
         

use a shortened URL that points to JSON directly in proctor-demo project