cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tomek...@apache.org
Subject svn commit: r979031 [2/2] - in /cxf/sandbox/logbrowser: distribution/src/main/release/samples/logbrowser/ distribution/src/main/release/samples/logbrowser/src/demo/logbrowser/ distribution/src/main/release/samples/logbrowser/src/demo/logbrowser/servlet...
Date Sun, 25 Jul 2010 12:20:38 GMT
Copied: cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/settings/RemoteStorageImpl.java
(from r959377, cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/settings/BootstrapStorageProxyImpl.java)
URL: http://svn.apache.org/viewvc/cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/settings/RemoteStorageImpl.java?p2=cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/settings/RemoteStorageImpl.java&p1=cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/settings/BootstrapStorageProxyImpl.java&r1=959377&r2=979031&rev=979031&view=diff
==============================================================================
--- cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/settings/BootstrapStorageProxyImpl.java
(original)
+++ cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/settings/RemoteStorageImpl.java
Sun Jul 25 12:20:36 2010
@@ -1,3 +1,5 @@
+// CHECKSTYLE:OFF
+
 /**
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements. See the NOTICE file
@@ -19,46 +21,242 @@
 
 package org.apache.cxf.management.web.logging.browser.client.settings;
 
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.core.client.JavaScriptObject;
+import com.google.gwt.core.client.JsArray;
 import com.google.gwt.http.client.RequestBuilder;
 import com.google.gwt.http.client.RequestCallback;
+import com.google.gwt.http.client.RequestException;
+import com.google.gwt.http.client.Response;
 import com.google.gwt.http.client.URL;
+import com.google.gwt.json.client.JSONObject;
+import com.google.gwt.json.client.JSONValue;
+
+import org.apache.cxf.management.web.logging.browser.client.helper.AbstractCallback;
+import org.apache.cxf.management.web.logging.browser.client.helper.Base64;
 
-import org.apache.cxf.management.web.logging.browser.client.helper.JSONWebService;
-import org.apache.cxf.management.web.logging.browser.client.model.Credentials;
-import org.apache.cxf.management.web.logging.browser.client.model.Settings;
+public class RemoteStorageImpl implements RemoteStorage {
+    private static final String DEFAULT_SERVICE_URL = "/log/bootstrapstorage/settings/";
+    private static final String RESOURCES_ENDPOINT_SUFFIX = "/resources/";
+    private static final String SETTINGS_ENDPOINT_SUFFIX = "/settings/";
+    
+    private static final String AUTHORIZATION_HEADER = "Authorization";
+    private static final String CONTENT_TYPE_HEADER = "Content-Type";
+    private static final String ACCEPT_HEADER = "Accept";    
+    private static final String JSON_TYPE = "application/json";
 
-public class BootstrapStorageProxyImpl implements BootstrapStorageProxy {
-    private static final String SERVICE_URL = "/rest/bootstrapstorage/";
+    private static final String SETTINGS_KEY = "settings";
 
-    private JSONWebService webservice = new JSONWebService();
+    private String serviceURL;
 
     public void getSettings(Credentials credentials, RequestCallback callback) {
-        isValid(credentials, callback);
-        RequestBuilder builder = webservice
-            .buildRequest(RequestBuilder.GET, getURL(credentials), credentials);
-        webservice.execute(builder, callback);
+        RequestBuilder builder = buildRequest(RequestBuilder.GET, getURL(credentials), credentials);
+        execute(null, builder, callback);
     }
 
     public void setSettings(Credentials credentials, Settings settings, RequestCallback callback)
{
-        isValid(credentials, callback);
-        RequestBuilder builder = webservice
-            .buildRequest(RequestBuilder.PUT, getURL(credentials), credentials);
-        webservice.execute("settings", JSOConverter.convert(settings), builder, callback);
+        RequestBuilder builder = buildRequest(RequestBuilder.PUT, getURL(credentials), credentials);
+        execute(Converter.convertToRemoteSettings(settings), builder, callback);
     }
 
-    private void isValid(Credentials credentials, RequestCallback callback) {
-        if (credentials == null) {
-            throw new IllegalArgumentException("'credentials' can't be null");
-        } else if (credentials.getUsername() == null || "".equals(credentials.getUsername()))
{
-            throw new IllegalArgumentException("'username' can't be null or empty");
-        } else if (callback == null) {
-            throw new IllegalArgumentException("'callback' can't be null");
+    //TODO rename function
+    private String getURL(final Credentials credentials) {
+        assert credentials != null
+            && credentials.getUsername() != null
+            && !"".equals(credentials.getUsername());
+
+        return URL.encode(getServiceURL() + credentials.getUsername());
+    }
+
+    //TODO rename function
+    private String getServiceURL() {
+        if (serviceURL == null) {
+            String baseURL = GWT.getHostPageBaseURL();
+            if (baseURL.endsWith(RESOURCES_ENDPOINT_SUFFIX)) {
+
+                //TODO move to external function
+                // compute URL by remove "resources" suffix and add "settings" suffix
+                serviceURL = baseURL.substring(0, baseURL.lastIndexOf(RESOURCES_ENDPOINT_SUFFIX))
+                    + SETTINGS_ENDPOINT_SUFFIX;
+            } else {
+
+                // it ought to execute only in hosted mode, because there is diffrent base
URL
+                serviceURL = DEFAULT_SERVICE_URL;
+            }
         }
+        return serviceURL;
     }
 
-    private String getURL(final Credentials credentials) {
-        assert credentials != null && credentials.getUsername() != null
-               && !"".equals(credentials.getUsername());
-        return URL.encode(SERVICE_URL + credentials.getUsername());
+    public RequestBuilder buildRequest(final RequestBuilder.Method method, final String url,
+                                       final Credentials credentials) {
+        assert method != null;
+        assert url != null && !"".equals(url);
+        
+        RequestBuilder builder = new RequestBuilder(method, url);
+        builder.setHeader(CONTENT_TYPE_HEADER, JSON_TYPE);
+        builder.setHeader(ACCEPT_HEADER, JSON_TYPE);
+        
+        if (credentials != null) {
+            builder.setHeader(AUTHORIZATION_HEADER, getAuthorization(credentials));
+        }
+        
+        return builder;
+    }
+
+    //TODO rename function
+    private String getAuthorization(final Credentials credentials) {
+        assert credentials != null;
+
+        return "Basic " + Base64.encode(credentials.getUsername() + ":" + credentials.getPassword());
+    }
+
+    private void execute(final RemoteSettings remoteSettings, final RequestBuilder builder,
+                         final RequestCallback callback) {
+        String json = null;
+        if (remoteSettings != null) {
+            JSONObject rootElement = new JSONObject();
+            rootElement.put(SETTINGS_KEY, new JSONObject(remoteSettings));
+            json = rootElement.toString();
+        }
+
+        try {
+            builder.sendRequest(json, callback);
+        } catch (RequestException ex) {
+            throw new RuntimeException(ex);
+        }
+    }
+
+    protected static class RemoteSettings extends JavaScriptObject {
+
+        protected RemoteSettings() {
+        }
+
+        public final native void setSubscriptions(JsArray<RemoteSubscription> subscriptions)
/*-{
+            this.subscriptions = subscriptions;
+        }-*/;
+
+        public final native JsArray<RemoteSubscription> getSubscriptions() /*-{
+            if (this.subscriptions != null) {
+                try { //hack
+                    this.subscriptions.concat([]);
+                } catch(error) {
+                    var temp = this.subscriptions;
+                    this.subscriptions = new Array();
+                    this.subscriptions.push(temp);
+                }
+                return this.subscriptions;
+            } else {
+                return [];
+            }
+        }-*/;
+    }
+
+    protected static class RemoteSubscription extends JavaScriptObject {
+
+        protected RemoteSubscription() {
+        }
+
+        public final native void setUrl(final String url) /*-{
+            this.url = url;
+        }-*/;
+
+        public final native String getUrl() /*-{
+            return this.url;
+        }-*/;        
+
+        public final native void setName(final String name) /*-{
+            this.name = name;
+        }-*/;
+
+        public final native String getName() /*-{
+            return this.name;
+        }-*/;
+    }
+
+    protected static final class Converter {
+
+        public static Settings convertToSettings(final RemoteSettings remoteSettings) {
+            assert remoteSettings != null;
+
+            Settings settings = new Settings();
+
+            JsArray<RemoteSubscription> remoteSubscriptions = remoteSettings.getSubscriptions();
+            for (int i = 0; i < remoteSubscriptions.length(); i++) {
+                settings.getSubscriptions().add(convertToSubscription(remoteSubscriptions.get(i)));
+            }
+
+            return settings;
+        }
+
+        public static Subscription convertToSubscription(RemoteSubscription remoteSubscription)
{
+            assert remoteSubscription != null;
+
+            Subscription subscription = new Subscription();
+
+            subscription.setName(remoteSubscription.getName());
+            subscription.setUrl(remoteSubscription.getUrl());
+
+            return subscription;
+        }
+
+        public static RemoteSettings convertToRemoteSettings(final Settings settings) {
+            assert settings != null;
+
+            RemoteSettings remoteSettings = (RemoteSettings) JavaScriptObject.createObject();
+
+            JsArray<RemoteSubscription> remoteSubscriptions =
+                (JsArray<RemoteSubscription>) JavaScriptObject.createArray();
+
+            for (Subscription subscription : settings.getSubscriptions()) {
+                remoteSubscriptions.push(convertToRemoteSubscription(subscription));
+            }
+
+            remoteSettings.setSubscriptions(remoteSubscriptions);
+
+            return remoteSettings;
+        }
+
+        public static RemoteSubscription convertToRemoteSubscription(final Subscription subscription)
{
+            assert subscription != null;
+
+            RemoteSubscription remoteSubscription = (RemoteSubscription) JavaScriptObject.createObject();
+
+            remoteSubscription.setName(subscription.getName());
+            remoteSubscription.setUrl(subscription.getUrl());
+
+            return remoteSubscription;
+        }
+    }
+
+    public static abstract class Callback extends AbstractCallback<Settings> {
+
+        @Override
+        protected Settings parse(final Response response) {
+            RemoteSettings result = null;
+
+            if (response.getText() != null && !"".equals(response.getText())) {
+                JSONValue rootElement = new JSONObject(convertFromJSON(response.getText())).get(SETTINGS_KEY);
+                if (rootElement != null && rootElement.isObject() != null) {
+                    result = (RemoteSettings) rootElement.isObject().getJavaScriptObject();
+                }
+            }
+
+            return result != null ? Converter.convertToSettings(result) : null;
+        }
+
+        private final native JavaScriptObject convertFromJSON(final String json) /*-{
+            return $wnd.JSON.parse(json);
+        }-*/;
+    }
+
+    public static class NoActionCallback extends Callback {
+
+        @Override
+        public void onAccessDenied() {
+        }
+
+        @Override
+        public void onSuccess(Settings obj) {
+        }
     }
 }

Copied: cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/settings/Settings.java
(from r959377, cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/model/Settings.java)
URL: http://svn.apache.org/viewvc/cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/settings/Settings.java?p2=cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/settings/Settings.java&p1=cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/model/Settings.java&r1=959377&r2=979031&rev=979031&view=diff
==============================================================================
--- cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/model/Settings.java
(original)
+++ cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/settings/Settings.java
Sun Jul 25 12:20:36 2010
@@ -17,19 +17,19 @@
  * under the License.
  */
 
-package org.apache.cxf.management.web.logging.browser.client.model;
+package org.apache.cxf.management.web.logging.browser.client.settings;
 
-import java.io.Serializable;
 import java.util.LinkedHashSet;
 import java.util.Set;
 
-public class Settings implements Serializable {
-    private static final long serialVersionUID = -5974005840345852594L;
-
+public class Settings {
     private Credentials credentials;
     private Set<Subscription> subscriptions;
 
     public Credentials getCredentials() {
+        if (credentials == null) {
+            credentials = new Credentials();
+        }
         return credentials;
     }
 
@@ -47,4 +47,10 @@ public class Settings implements Seriali
     public void setSubscriptions(Set<Subscription> subscriptions) {
         this.subscriptions = subscriptions;
     }
+
+    public void merge(final Settings newSettings) {
+        if (newSettings == null) {
+            return;
+        }
+    }
 }

Modified: cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/settings/SettingsManager.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/settings/SettingsManager.java?rev=979031&r1=979030&r2=979031&view=diff
==============================================================================
--- cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/settings/SettingsManager.java
(original)
+++ cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/settings/SettingsManager.java
Sun Jul 25 12:20:36 2010
@@ -22,156 +22,241 @@ package org.apache.cxf.management.web.lo
 import java.util.ArrayList;
 import java.util.List;
 
-import com.google.gwt.core.client.JavaScriptObject;
 import com.google.inject.Inject;
 import com.google.inject.Singleton;
 
 import org.apache.cxf.management.web.logging.browser.client.event.AccessDeniedEvent;
 import org.apache.cxf.management.web.logging.browser.client.event.BrowseEvent;
-import org.apache.cxf.management.web.logging.browser.client.exception.SettingsUnavailableException;
 import org.apache.cxf.management.web.logging.browser.client.helper.EventBus;
-import org.apache.cxf.management.web.logging.browser.client.helper.JSONCallback;
-import org.apache.cxf.management.web.logging.browser.client.model.Credentials;
-import org.apache.cxf.management.web.logging.browser.client.model.Settings;
-import org.apache.cxf.management.web.logging.browser.client.model.Subscription;
 
 @Singleton
 public class SettingsManager {
-    private static final String SETTINGS_KEY = "logBrowser.settings";
+    private final RemoteStorage remoteStorage;
+    private final LocalStorage localStorage;
+    private final EventBus eventBus;
 
-    private BootstrapStorageProxy remoteStorage;
-    private Settings settings;
-    private LocalStorage localStorage;
-    private StorageStrategy strategy;
-    private EventBus eventBus;
+    private StorageLayer storageLayer;
+    private boolean initialized;
 
     public enum StorageStrategy {
-        STORE_LOCALLY_AND_REMOTELY,
-        STORE_REMOTELY
-    }
+        LOCAL_AND_REMOTE,
+        REMOTE
+    }    
 
     @Inject
-    public SettingsManager(BootstrapStorageProxy bootstrapStorage, LocalStorage localStorage,
-                           EventBus eventBus) {
-        this.remoteStorage = bootstrapStorage;
+    public SettingsManager(final RemoteStorage remoteStorage, final LocalStorage localStorage,
+                           final EventBus eventBus) {
+        assert remoteStorage != null;
+        assert localStorage != null;
+        assert eventBus != null;
+
+        this.remoteStorage = remoteStorage;
         this.localStorage = localStorage;
         this.eventBus = eventBus;
-        strategy = localStorage.isAvailable()
-            ? StorageStrategy.STORE_LOCALLY_AND_REMOTELY : StorageStrategy.STORE_REMOTELY;
-        fetchLocally();
+    }
+
+    public boolean isSettingsAlreadyInLocalStorage() {
+        return localStorage.isAvailable() && localStorage.retrieveSettings() != null;
+    }    
+
+    public void initialize(final StorageStrategy strategy, final Credentials credentials)
{
+        storageLayer = createStorageLayers(strategy);
+        storageLayer.initialize(credentials);
+        initialized = true;
+    }
+
+    public void cleanMemoryAndLocalStorage() {
+        storageLayer.removeAll();
+        initialized = false;
     }
 
     public void updateSubscription(final Subscription subscription) {
-        if (!isFetched()) {
-            throw new SettingsUnavailableException();
-        } else if (subscription == null) {
-            throw new IllegalArgumentException("'subscription' can't be null");
-        } else if (subscription.getUrl() == null) {
-            throw new IllegalArgumentException("'subscription.url' can't be null");
-        }
-        settings.getSubscriptions().remove(subscription);
-        settings.getSubscriptions().add(subscription);
-        saveSettings();
+        assert subscription != null;
+        assert subscription.getUrl() != null;
+
+        isValid();
+
+        storageLayer.getSettings().getSubscriptions().remove(subscription);
+        storageLayer.getSettings().getSubscriptions().add(subscription);
+
+        storageLayer.update();
     }
 
     public void removeSubscription(final Subscription subscription) {
-        if (!isFetched()) {
-            throw new SettingsUnavailableException();
-        } else if (subscription == null) {
-            throw new IllegalArgumentException("'subscription' can't be null");
-        } else if (subscription.getUrl() == null) {
-            throw new IllegalArgumentException("'subscription.url' can't be null");
-        }
-        settings.getSubscriptions().remove(subscription);
-        saveSettings();
+        assert subscription != null;
+        assert subscription.getUrl() != null;
+
+        isValid();
+
+        storageLayer.getSettings().getSubscriptions().remove(subscription);
+
+        storageLayer.update();
     }
 
-    public void setGlobalCredentials(final Credentials credentials) {
-        if (!isFetched()) {
-            throw new SettingsUnavailableException();
-        }
-        settings.setCredentials(credentials);
-        saveSettings();
+    public List<Subscription> getSubscriptions() {
+        isValid();
+
+        return new ArrayList<Subscription>(storageLayer.getSettings().getSubscriptions());
     }
 
-    public Credentials getGlobalCredentials() {
-        if (!isFetched()) {
-            throw new SettingsUnavailableException();
+    private void isValid() {
+        if (!initialized) {
+            throw new RuntimeException("Storage layers not initialized");
         }
-        return settings.getCredentials();
     }
-
-    public List<Subscription> getSubscriptions() {
-        if (!isFetched()) {
-            throw new SettingsUnavailableException();
+        
+    private StorageLayer createStorageLayers(final StorageStrategy storageStrategy) {
+        assert storageStrategy != null;
+        
+        switch(storageStrategy) {
+        case LOCAL_AND_REMOTE:
+            return new RemoteStorageLayer(remoteStorage,
+                new LocalStorageLayer(localStorage, new MemoryStorageLayer()));
+        case REMOTE:
+            return new RemoteStorageLayer(remoteStorage, new MemoryStorageLayer());
+        default:
+            throw new RuntimeException("Unknown storage strategy type");
         }
-        return new ArrayList<Subscription>(settings.getSubscriptions());
     }
 
-    private void fetchLocally() {
-        if (localStorage.isAvailable()) {
-            JSOSettings jsoSettings = (JSOSettings)localStorage.get(SETTINGS_KEY);
-            if (jsoSettings != null) {
-                settings = JOConverter.convert(jsoSettings);
-            }
+    private interface StorageLayer {
+        boolean initialize(Credentials credentials);
+        Settings getSettings();
+        void update(Settings settings);
+        void update();
+        void removeAll();
+    }
+
+    private class MemoryStorageLayer implements StorageLayer {
+        private Settings settings;
+
+        public boolean initialize(final Credentials credentials) {
+            this.settings = new Settings();
+            this.settings.setCredentials(credentials);
+            return false;
+        }
+
+        public Settings getSettings() {
+            return this.settings;
+        }
+
+        public void update(final Settings newSettings) {
+            this.settings = newSettings;
+        }
+
+        public void update() {
+        }
+
+        public void removeAll() {
+            this.settings = new Settings();
         }
     }
 
-    public void fetchRemotely(final Credentials credentials) {
-        remoteStorage.getSettings(credentials, new JSONCallback() {
+    private class LocalStorageLayer implements StorageLayer {
+        private final MemoryStorageLayer parent;
+        private final LocalStorage localStorage;
 
-            @Override
-            public void onAccessDenied() {
-                eventBus.fireEvent(new AccessDeniedEvent());
-            }
+        public LocalStorageLayer(final LocalStorage localStorage, final MemoryStorageLayer
parent) {
+            assert parent != null;
+            assert localStorage != null;
+
+            this.parent = parent;
+            this.localStorage = localStorage;
+        }
+
+        public boolean initialize(final Credentials credentials) {
+            boolean isSuccess = parent.initialize(credentials);
+            
+            assert !isSuccess;
 
-            @Override
-            public void onSuccess(JavaScriptObject obj) {
-                Settings result = JOConverter.convert((JSOSettings) obj);
-                settings = result != null ? result : new Settings();
-                settings.setCredentials(credentials);
-                if (strategy == StorageStrategy.STORE_LOCALLY_AND_REMOTELY && localStorage.isAvailable())
{
-                    localStorage.set(SETTINGS_KEY, JSOConverter.convert(settings));
-                }
-                eventBus.fireEvent(new BrowseEvent());
+            Settings settings = localStorage.retrieveSettings();
+            if (settings != null) {
+                parent.update(settings);
+                return true;
+            } else {
+                return false;
             }
-        });
+        }
+
+        public Settings getSettings() {
+            return parent.getSettings();
+        }
+
+        public void update(final Settings settings) {
+            parent.update(settings);
+            localStorage.saveSettings(settings);
+        }
+
+        public void update() {
+            update(parent.getSettings());
+        }
+
+        public void removeAll() {
+            parent.removeAll();
+            localStorage.flush();
+        }
     }
 
-    private void saveSettings() {
-        if (strategy == StorageStrategy.STORE_LOCALLY_AND_REMOTELY && localStorage.isAvailable())
{
-            localStorage.set(SETTINGS_KEY, JSOConverter.convert(settings));
+    private class RemoteStorageLayer implements StorageLayer {
+        private final StorageLayer parent;
+        private final RemoteStorage remoteStorage;
+
+        public RemoteStorageLayer(final RemoteStorage remoteStorage, final StorageLayer parent)
{
+            assert parent != null;
+            assert remoteStorage != null;
+
+            this.parent = parent;
+            this.remoteStorage = remoteStorage;
         }
-        remoteStorage.setSettings(settings.getCredentials(), settings, new JSONCallback()
{
 
-            @Override
-            public void onAccessDenied() {
+        public boolean initialize(final Credentials credentials) {
+            assert credentials != null;
+            
+            boolean isSuccess = parent.initialize(credentials);
+            
+            if (!isSuccess) {
+                remoteStorage.getSettings(credentials, new RemoteStorageImpl.Callback() {
 
-            }
+                    @Override
+                    public void onAccessDenied() {
+                        eventBus.fireEvent(new AccessDeniedEvent());
+                    }
+
+                    @Override
+                    public void onSuccess(Settings retrievedSettings) {
+                        Settings settings = retrievedSettings != null ? retrievedSettings
: new Settings();
+                        settings.setCredentials(credentials);
 
-            @Override
-            public void onSuccess(JavaScriptObject obj) {
-                
+                        parent.update(settings);
+
+                        eventBus.fireEvent(new BrowseEvent());
+                    }
+                });
             }
-        });
-    }
 
-    public void flush() {
-        settings = null;
-        if (localStorage.isAvailable()) {
-            localStorage.deleteKey(SETTINGS_KEY);
+            return true;
         }
-    }
 
-    public boolean isFetched() {
-        return settings != null;
-    }
+        public Settings getSettings() {
+            return parent.getSettings();
+        }
 
-    public StorageStrategy getStorageStrategy() {
-        return strategy;
-    }
+        public void update(final Settings settings) {
+            assert settings != null;
+
+            parent.update(settings);
 
-    public void setStorageStrategy(StorageStrategy s) {
-        this.strategy = s;
+            remoteStorage.setSettings(settings.getCredentials(), settings,
+                new RemoteStorageImpl.NoActionCallback());
+        }
+        
+        public void update() {
+            update(parent.getSettings());
+        }
+
+        public void removeAll() {
+            parent.removeAll();
+        }
     }
 }
+

Copied: cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/settings/Subscription.java
(from r959377, cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/model/Subscription.java)
URL: http://svn.apache.org/viewvc/cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/settings/Subscription.java?p2=cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/settings/Subscription.java&p1=cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/model/Subscription.java&r1=959377&r2=979031&rev=979031&view=diff
==============================================================================
--- cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/model/Subscription.java
(original)
+++ cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/settings/Subscription.java
Sun Jul 25 12:20:36 2010
@@ -17,13 +17,9 @@
  * under the License.
  */
 
-package org.apache.cxf.management.web.logging.browser.client.model;
-
-import java.io.Serializable;
-
-public class Subscription implements Serializable {
-    private static final long serialVersionUID = 8937465727379798835L;
+package org.apache.cxf.management.web.logging.browser.client.settings;
 
+public class Subscription {
     private String name;
     private String url;
     private AccessControl accessControl;

Modified: cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/view/BrowseView.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/view/BrowseView.java?rev=979031&r1=979030&r2=979031&view=diff
==============================================================================
--- cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/view/BrowseView.java
(original)
+++ cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/view/BrowseView.java
Sun Jul 25 12:20:36 2010
@@ -23,7 +23,7 @@ import java.util.List;
 
 import org.apache.cxf.management.web.logging.browser.client.browser.Entry;
 import org.apache.cxf.management.web.logging.browser.client.browser.Links;
-import org.apache.cxf.management.web.logging.browser.client.model.Subscription;
+import org.apache.cxf.management.web.logging.browser.client.settings.Subscription;
 
 public interface BrowseView extends View {
     public interface Presenter {

Modified: cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/view/BrowseViewImpl.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/view/BrowseViewImpl.java?rev=979031&r1=979030&r2=979031&view=diff
==============================================================================
--- cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/view/BrowseViewImpl.java
(original)
+++ cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/view/BrowseViewImpl.java
Sun Jul 25 12:20:36 2010
@@ -40,7 +40,7 @@ import com.google.gwt.user.client.ui.Wid
 
 import org.apache.cxf.management.web.logging.browser.client.browser.Entry;
 import org.apache.cxf.management.web.logging.browser.client.browser.Links;
-import org.apache.cxf.management.web.logging.browser.client.model.Subscription;
+import org.apache.cxf.management.web.logging.browser.client.settings.Subscription;
 
 public class BrowseViewImpl extends Composite implements BrowseView {
     private static final DateTimeFormat DT_FORMATTER =

Modified: cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/view/EditSubcriptionWidget.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/view/EditSubcriptionWidget.java?rev=979031&r1=979030&r2=979031&view=diff
==============================================================================
--- cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/view/EditSubcriptionWidget.java
(original)
+++ cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/view/EditSubcriptionWidget.java
Sun Jul 25 12:20:36 2010
@@ -33,8 +33,8 @@ import com.google.gwt.user.client.ui.Com
 import com.google.gwt.user.client.ui.TextBox;
 import com.google.gwt.user.client.ui.Widget;
 
-import org.apache.cxf.management.web.logging.browser.client.model.AccessControl;
-import org.apache.cxf.management.web.logging.browser.client.model.Subscription;
+import org.apache.cxf.management.web.logging.browser.client.settings.AccessControl;
+import org.apache.cxf.management.web.logging.browser.client.settings.Subscription;
 
 public abstract class EditSubcriptionWidget extends Composite {
 

Modified: cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/view/SettingsView.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/view/SettingsView.java?rev=979031&r1=979030&r2=979031&view=diff
==============================================================================
--- cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/view/SettingsView.java
(original)
+++ cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/view/SettingsView.java
Sun Jul 25 12:20:36 2010
@@ -21,7 +21,7 @@ package org.apache.cxf.management.web.lo
 
 import java.util.List;
 
-import org.apache.cxf.management.web.logging.browser.client.model.Subscription;
+import org.apache.cxf.management.web.logging.browser.client.settings.Subscription;
 
 public interface SettingsView extends View {
 

Modified: cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/view/SettingsViewImpl.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/view/SettingsViewImpl.java?rev=979031&r1=979030&r2=979031&view=diff
==============================================================================
--- cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/view/SettingsViewImpl.java
(original)
+++ cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/view/SettingsViewImpl.java
Sun Jul 25 12:20:36 2010
@@ -34,9 +34,9 @@ import com.google.gwt.user.client.ui.Fle
 import com.google.gwt.user.client.ui.Hyperlink;
 import com.google.gwt.user.client.ui.Widget;
 
-import org.apache.cxf.management.web.logging.browser.client.model.AccessControl;
-import org.apache.cxf.management.web.logging.browser.client.model.Credentials;
-import org.apache.cxf.management.web.logging.browser.client.model.Subscription;
+import org.apache.cxf.management.web.logging.browser.client.settings.AccessControl;
+import org.apache.cxf.management.web.logging.browser.client.settings.Credentials;
+import org.apache.cxf.management.web.logging.browser.client.settings.Subscription;
 
 public class SettingsViewImpl extends Composite implements SettingsView {
 

Added: cxf/sandbox/logbrowser/rt/management-web/src/test/java/org/apache/cxf/management/web/logging/MockApp.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/logbrowser/rt/management-web/src/test/java/org/apache/cxf/management/web/logging/MockApp.java?rev=979031&view=auto
==============================================================================
--- cxf/sandbox/logbrowser/rt/management-web/src/test/java/org/apache/cxf/management/web/logging/MockApp.java
(added)
+++ cxf/sandbox/logbrowser/rt/management-web/src/test/java/org/apache/cxf/management/web/logging/MockApp.java
Sun Jul 25 12:20:36 2010
@@ -0,0 +1,106 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.management.web.logging;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Set;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.ext.Provider;
+
+import org.apache.cxf.jaxrs.provider.AtomEntryProvider;
+import org.apache.cxf.jaxrs.provider.AtomFeedProvider;
+import org.apache.cxf.jaxrs.provider.JSONProvider;
+import org.apache.cxf.management.web.logging.atom.AtomPullServer;
+import org.apache.cxf.management.web.logging.atom.MockReadableLogStorage;
+import org.apache.cxf.management.web.logging.bootstrapping.BootstrapStorage;
+import org.apache.cxf.management.web.logging.bootstrapping.SimpleAuthenticationFilter;
+import org.apache.cxf.management.web.logging.bootstrapping.SimpleXMLSettingsStorage;
+
+@Provider
+public class MockApp extends Application {
+    private static final AtomPullServer LOGS;
+
+    static {
+        LOGS = new AtomPullServer();
+        LOGS.setPageSize(30);
+        LOGS.setStorage(new MockReadableLogStorage());
+        LOGS.init();
+    }
+
+    private static final AtomFeedProvider FEED = new AtomFeedProvider();
+    private static final AtomEntryProvider ENTRY = new AtomEntryProvider();
+
+    private static final BootstrapStorage BOOTSTRAP_STORAGE =
+        new BootstrapStorage(new SimpleXMLSettingsStorage());
+
+    private static final SimpleAuthenticationFilter AUTHENTICATION =
+        new SimpleAuthenticationFilter(new HashMap<String, String>() {
+            {
+                put("admin", "admin");
+            }
+        });
+
+
+    private static final JSONProvider JSON = new JSONProvider();
+
+    static {
+        JSON.setIgnoreNamespaces(true);
+        
+        JSON.setOutTransformElements(new HashMap<String, String>() {
+            {
+                put("{http://cxf.apache.org/log}*", "*");
+            }
+        });
+        JSON.setInTransformElements(new HashMap<String, String>() {
+            {
+                put("*", "{http://cxf.apache.org/log}*");
+            }
+        });
+        
+        JSON.setSerializeAsArray(true);
+        JSON.setArrayKeys(Arrays.asList("subscriptions"));
+    }
+    
+    @Override
+    public Set<Class<?>> getClasses() {        
+        Set<Class<?>> classes = new HashSet<Class<?>>();
+        classes.add(AtomPullServer.class);
+        classes.add(AtomFeedProvider.class);
+        classes.add(AtomEntryProvider.class);
+        classes.add(BootstrapStorage.class);
+        classes.add(SimpleAuthenticationFilter.class);
+        classes.add(JSONProvider.class);
+        return classes;
+    }
+
+    @Override
+    public Set<Object> getSingletons() {
+        Set<Object> classes = new HashSet<Object>();
+        classes.add(LOGS);
+        classes.add(FEED);
+        classes.add(ENTRY);
+        classes.add(BOOTSTRAP_STORAGE);
+        classes.add(AUTHENTICATION);
+        classes.add(JSON);
+        return classes;
+    }
+}

Modified: cxf/sandbox/logbrowser/rt/management-web/src/test/resources/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/cxf/sandbox/logbrowser/rt/management-web/src/test/resources/WEB-INF/web.xml?rev=979031&r1=979030&r2=979031&view=diff
==============================================================================
--- cxf/sandbox/logbrowser/rt/management-web/src/test/resources/WEB-INF/web.xml (original)
+++ cxf/sandbox/logbrowser/rt/management-web/src/test/resources/WEB-INF/web.xml Sun Jul 25
12:20:36 2010
@@ -1,51 +1,43 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE web-app
-    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
-    "http://java.sun.com/dtd/web-app_2_3.dtd">
+        PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+        "http://java.sun.com/dtd/web-app_2_3.dtd">
 
 <web-app>
 
-	<welcome-file-list>
-		<welcome-file>logbrowser/LogBrowser.html</welcome-file>
-	</welcome-file-list>
-  
-	<servlet>
-		<servlet-name>BootstrapStorage</servlet-name>
-		<display-name>BootstrapStorage</display-name>
-		<servlet-class>
-			org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet
-		</servlet-class>
-		<init-param>
-			<param-name>javax.ws.rs.Application</param-name>
-			<param-value>
-                org.apache.cxf.management.web.logging.bootstrapping.MockBootstrapStorageApp
-            </param-value>
-		</init-param>
-		<load-on-startup>1</load-on-startup>
-	</servlet>
+    <welcome-file-list>
+        <welcome-file>logbrowser/LogBrowser.html</welcome-file>
+    </welcome-file-list>
 
-	<servlet-mapping>
-		<servlet-name>BootstrapStorage</servlet-name>
-		<url-pattern>/rest/*</url-pattern>
-	</servlet-mapping>
-	
-	<servlet>
-		<servlet-name>AtomPullServer</servlet-name>
-		<display-name>AtomPullServer</display-name>
-		<servlet-class>
-			org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet
-		</servlet-class>
-		<init-param>
-			<param-name>javax.ws.rs.Application</param-name>
-			<param-value>
-                org.apache.cxf.management.web.logging.atom.MockAtomPullServerApp
+    <servlet>
+        <servlet-name>MockApp</servlet-name>
+        <display-name>MockApp</display-name>
+        <servlet-class>
+            org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet
+        </servlet-class>
+        <init-param>
+            <param-name>javax.ws.rs.Application</param-name>
+            <param-value>
+                org.apache.cxf.management.web.logging.MockApp
+            </param-value>
+        </init-param>
+        <init-param>
+            <param-name>jaxrs.inInterceptors</param-name>
+            <param-value>
+                org.apache.cxf.interceptor.LoggingInInterceptor
+            </param-value>
+        </init-param>
+        <init-param>
+            <param-name>jaxrs.outInterceptors</param-name>
+            <param-value>
+                org.apache.cxf.interceptor.LoggingOutInterceptor
             </param-value>
-		</init-param>
-		<load-on-startup>2</load-on-startup>
-	</servlet>
+        </init-param>
+        <load-on-startup>1</load-on-startup>
+    </servlet>
 
-	<servlet-mapping>
-		<servlet-name>AtomPullServer</servlet-name>
-		<url-pattern>/log/*</url-pattern>
-	</servlet-mapping>
+    <servlet-mapping>
+        <servlet-name>MockApp</servlet-name>
+        <url-pattern>/log/*</url-pattern>
+    </servlet-mapping>
 </web-app>



Mime
View raw message