--- F:/Users/Jarek/workspace/apache-jmeter-2.12/src/protocol/http/org/apache/jmeter/protocol/http/proxy/ProxyControl.java	Wed Nov 05 20:17:58 2014
+++ F:/Users/Jarek/workspace/LoadTestAutomationFX/src/proxy/ProxyControl.java	Tue Dec 02 19:55:59 2014
@@ -202,6 +202,8 @@
     // If this is defined, it is assumed to be the alias of a user-supplied certificate; overrides dynamic mode
     static final String CERT_ALIAS = JMeterUtils.getProperty("proxy.cert.alias"); // $NON-NLS-1$
 
+    private static JMeterTreeModel treeModel = null;
+    
     public static enum KeystoreMode {
         USER_KEYSTORE,   // user-provided keystore
         JMETER_KEYSTORE, // keystore generated by JMeter; single entry
@@ -226,6 +228,10 @@
                 log.warn("HTTP(S) Test Script Recorder SSL Proxy will use keys that may not work for embedded resources in file " + CERT_PATH_ABS);
             }
         }
+        
+        if (GuiPackage.getInstance() != null) {
+        	treeModel = GuiPackage.getInstance().getTreeModel();
+        }
     }
 
     // Whether to use the redirect disabling feature (can be switched off if it does not work)
@@ -280,6 +286,14 @@
         setCaptureHttpHeaders(true); // maintain original behaviour
     }
 
+    /**
+     * When working without GUI required for operation
+     * @param treeModel JMeterTreeModel used for recording
+     */
+    public static void setGlobalTreeRoot(JMeterTreeModel treeModel) {
+    	ProxyControl.treeModel = treeModel;
+    }
+
     public void setPort(int port) {
         this.setProperty(new IntegerProperty(PORT, port));
     }
@@ -457,6 +471,7 @@
         try {
             server = new Daemon(getPort(), this);
             server.start();
+            if (GuiPackage.getInstance() != null)
             GuiPackage.getInstance().register(server);
         } catch (IOException e) {
             log.error("Could not create Proxy daemon", e);
@@ -571,6 +586,7 @@
     public void stopProxy() {
         if (server != null) {
             server.stopServer();
+            if (GuiPackage.getInstance() != null)
             GuiPackage.getInstance().unregister(server);
             try {
                 server.join(1000); // wait for server to stop
@@ -844,7 +860,6 @@
      *         <code>null</code> if none was found.
      */
     private JMeterTreeNode findFirstNodeOfType(Class<?> type) {
-        JMeterTreeModel treeModel = GuiPackage.getInstance().getTreeModel();
         List<JMeterTreeNode> nodes = treeModel.getNodesOfType(type);
         for (JMeterTreeNode node : nodes) {
             if (node.isEnabled()) {
@@ -910,7 +925,6 @@
      */
     // TODO - could be converted to generic class?
     private Collection<?> findApplicableElements(JMeterTreeNode myTarget, Class<? extends TestElement> myClass, boolean ascending) {
-        JMeterTreeModel treeModel = GuiPackage.getInstance().getTreeModel();
         LinkedList<TestElement> elements = new LinkedList<TestElement>();
 
         // Look for elements directly within the HTTP proxy:
@@ -968,8 +982,6 @@
     private void placeSampler(final HTTPSamplerBase sampler, final TestElement[] subConfigs,
             JMeterTreeNode myTarget) {
         try {
-            final JMeterTreeModel treeModel = GuiPackage.getInstance().getTreeModel();
-
             boolean firstInBatch = false;
             long now = System.currentTimeMillis();
             long deltaT = now - lastTime;
@@ -1163,7 +1175,6 @@
      *            sampling event to be delivered
      */
     private void notifySampleListeners(SampleEvent event) {
-        JMeterTreeModel treeModel = GuiPackage.getInstance().getTreeModel();
         JMeterTreeNode myNode = treeModel.getNodeOf(this);
         Enumeration<JMeterTreeNode> kids = myNode.children();
         while (kids.hasMoreElements()) {
@@ -1182,7 +1193,6 @@
      * (here meaning the proxy recording) has started.
      */
     private void notifyTestListenersOfStart() {
-        JMeterTreeModel treeModel = GuiPackage.getInstance().getTreeModel();
         JMeterTreeNode myNode = treeModel.getNodeOf(this);
         Enumeration<JMeterTreeNode> kids = myNode.children();
         while (kids.hasMoreElements()) {
@@ -1201,7 +1211,6 @@
      * (here meaning the proxy recording) has ended.
      */
     private void notifyTestListenersOfEnd() {
-        JMeterTreeModel treeModel = GuiPackage.getInstance().getTreeModel();
         JMeterTreeNode myNode = treeModel.getNodeOf(this);
         Enumeration<JMeterTreeNode> kids = myNode.children();
         while (kids.hasMoreElements()) {
