Author: tomekopo
Date: Tue Jul 27 12:13:00 2010
New Revision: 979661
URL: http://svn.apache.org/viewvc?rev=979661&view=rev
Log:
Moved configuration of JSONProvider to BootstrapStorage. Removed
"CHECKSTYLE:OFF" attribute from classes.
Modified:
cxf/sandbox/logbrowser/distribution/src/main/release/samples/logbrowser/src/demo/logbrowser/App.java
cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/bootstrapping/BootstrapStorage.java
cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/helper/Base64.java
cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/settings/LocalStorageImpl.java
cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/settings/RemoteStorageImpl.java
cxf/sandbox/logbrowser/rt/management-web/src/test/java/org/apache/cxf/management/web/logging/MockApp.java
Modified:
cxf/sandbox/logbrowser/distribution/src/main/release/samples/logbrowser/src/demo/logbrowser/App.java
URL:
http://svn.apache.org/viewvc/cxf/sandbox/logbrowser/distribution/src/main/release/samples/logbrowser/src/demo/logbrowser/App.java?rev=979661&r1=979660&r2=979661&view=diff
==============================================================================
---
cxf/sandbox/logbrowser/distribution/src/main/release/samples/logbrowser/src/demo/logbrowser/App.java
(original)
+++
cxf/sandbox/logbrowser/distribution/src/main/release/samples/logbrowser/src/demo/logbrowser/App.java
Tue Jul 27 12:13:00 2010
@@ -19,7 +19,6 @@
package demo.logbrowser;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
@@ -28,7 +27,6 @@ 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.bootstrapping.BootstrapStorage;
import
org.apache.cxf.management.web.logging.bootstrapping.SimpleAuthenticationFilter;
@@ -61,25 +59,8 @@ public class App extends Application {
private static final BootstrapStorage.StaticFileProvider STATIC_FILE =
new BootstrapStorage.StaticFileProvider();
- 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"));
- }
+ private static final BootstrapStorage.SettingsProvider SETTINGS =
+ new BootstrapStorage.SettingsProvider();
@Override
public Set<Class<?>> getClasses() {
@@ -90,7 +71,7 @@ public class App extends Application {
classes.add(BootstrapStorage.class);
classes.add(SimpleAuthenticationFilter.class);
classes.add(BootstrapStorage.StaticFileProvider.class);
- classes.add(JSONProvider.class);
+ classes.add(BootstrapStorage.SettingsProvider.class);
return classes;
}
@@ -103,7 +84,7 @@ public class App extends Application {
classes.add(BOOTSTRAP_STORAGE);
classes.add(AUTHENTICATION);
classes.add(STATIC_FILE);
- classes.add(JSON);
+ classes.add(SETTINGS);
return classes;
}
}
\ No newline at end of file
Modified:
cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/bootstrapping/BootstrapStorage.java
URL:
http://svn.apache.org/viewvc/cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/bootstrapping/BootstrapStorage.java?rev=979661&r1=979660&r2=979661&view=diff
==============================================================================
---
cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/bootstrapping/BootstrapStorage.java
(original)
+++
cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/bootstrapping/BootstrapStorage.java
Tue Jul 27 12:13:00 2010
@@ -26,6 +26,8 @@ import java.lang.reflect.Type;
import java.net.JarURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.Arrays;
+import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.GZIPOutputStream;
@@ -48,6 +50,7 @@ import org.apache.commons.lang.Validate;
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.helpers.IOUtils;
import org.apache.cxf.jaxrs.ext.MessageContext;
+import org.apache.cxf.jaxrs.provider.JSONProvider;
@Path("/bootstrapstorage")
public class BootstrapStorage {
@@ -65,8 +68,6 @@ public class BootstrapStorage {
@Produces("application/json")
@AuthenticationRequired
public Settings getSettings(@PathParam("username") final String username) {
- assert storage != null;
-
Validate.notNull(username, "username is null");
Validate.notEmpty(username, "username is empty");
@@ -80,8 +81,6 @@ public class BootstrapStorage {
@Consumes("application/json")
@AuthenticationRequired
public Response setSettings(@PathParam("username") final String username,
final Settings settings) {
- assert storage != null;
-
Validate.notNull(username, "username is null");
Validate.notEmpty(username, "username is empty");
Validate.notNull(settings, "settings is null");
@@ -100,16 +99,12 @@ public class BootstrapStorage {
return Response.notModified().build();
}
- URL url;
- URL jar =
getClass().getProtectionDomain().getCodeSource().getLocation();
-
try {
+ URL url;
+ URL jar =
getClass().getProtectionDomain().getCodeSource().getLocation();
+
url = new
URL(String.format("jar:%s!/static-content/logbrowser/%s", jar, resource));
- } catch (MalformedURLException e) {
- return Response.status(Status.BAD_REQUEST).build();
- }
- try {
JarURLConnection connection = (JarURLConnection)
url.openConnection();
if (connection.getContentLength() == -1 ||
connection.getJarEntry() == null) {
return Response.status(Status.NOT_FOUND).build();
@@ -124,6 +119,8 @@ public class BootstrapStorage {
return builder.build();
}
+ } catch (MalformedURLException e) {
+ return Response.status(Status.BAD_REQUEST).build();
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Error occur while retrieve static file",
e);
return Response.serverError().build();
@@ -148,9 +145,8 @@ public class BootstrapStorage {
private boolean isGzipEnabled;
private StaticFile(URL url, boolean acceptsGzip, MediaType mime) {
- Validate.notNull(url, "url is null");
- Validate.notNull(acceptsGzip, "acceptsGzip is null");
- Validate.notNull(mime, "mime is null");
+ assert url != null;
+ assert mime != null;
this.url = url;
this.isGzipEnabled = acceptsGzip && "text".equals(mime.getType());
@@ -168,19 +164,21 @@ public class BootstrapStorage {
@Provider
public static class StaticFileProvider implements
MessageBodyWriter<StaticFile> {
- public boolean isWriteable(Class<?> type, Type genericType,
- Annotation[] annotations, MediaType
mediaType) {
+ public boolean isWriteable(final Class<?> type, final Type genericType,
+ final Annotation[] annotations, final
MediaType mediaType) {
return StaticFile.class.isAssignableFrom(type);
}
- public long getSize(StaticFile staticFile, Class<?> type, Type
genericType,
- Annotation[] annotations, MediaType mediaType) {
+ public long getSize(final StaticFile staticFile, final Class<?> type,
final Type genericType,
+ final Annotation[] annotations, final MediaType
mediaType) {
return -1;
}
- public void writeTo(StaticFile staticFile, Class<?> clazz, Type
genericType,
- Annotation[] annotations, MediaType type,
- MultivaluedMap<String, Object> headers,
OutputStream os) throws IOException {
+ public void writeTo(final StaticFile staticFile, final Class<?> clazz,
final Type genericType,
+ final Annotation[] annotations, final MediaType
type,
+ final MultivaluedMap<String, Object> headers,
final OutputStream os)
+ throws IOException {
+
if (staticFile.isGzipEnabled()) {
GZIPOutputStream gzip = new GZIPOutputStream(os);
try {
@@ -193,4 +191,32 @@ public class BootstrapStorage {
}
}
}
+
+ @Provider
+ public static class SettingsProvider extends JSONProvider {
+ private static final String LOGGING_NAMESPACE =
"http://cxf.apache.org/log";
+ private static final String SUBSCRIPTIONS_ARRAY = "subscriptions";
+
+ public SettingsProvider() {
+ setIgnoreNamespaces(true);
+
+ // Solved common JSON's problem with parsing array, which has only
one element
+ setSerializeAsArray(true);
+ setArrayKeys(Arrays.asList(SUBSCRIPTIONS_ARRAY));
+
+ // Removes namespace from output
+ setOutTransformElements(new HashMap<String, String>() {
+ {
+ put("{" + LOGGING_NAMESPACE + "}*", "*");
+ }
+ });
+
+ // Adds namespace to input
+ setInTransformElements(new HashMap<String, String>() {
+ {
+ put("*", "{" + LOGGING_NAMESPACE + "}*");
+ }
+ });
+ }
+ }
}
Modified:
cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/helper/Base64.java
URL:
http://svn.apache.org/viewvc/cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/helper/Base64.java?rev=979661&r1=979660&r2=979661&view=diff
==============================================================================
---
cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/helper/Base64.java
(original)
+++
cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/helper/Base64.java
Tue Jul 27 12:13:00 2010
@@ -1,7 +1,3 @@
-// CHECKSTYLE:OFF
-
-//TODO this class isn't mine write appropriate comment
-
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -23,13 +19,15 @@
package org.apache.cxf.management.web.logging.browser.client.helper;
+//TODO this class isn't mine write appropriate comment
+
/**
* Custom Base64 encode/decode implementation suitable for use in GWT
applications (uses only translatable
* classes).
*/
-public class Base64 {
+public final class Base64 {
- private static final String etab =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
+ private static final String ETAB =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
private static byte[] dtab = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1,
@@ -40,6 +38,9 @@ public class Base64 {
-1, -1, -1, -1, -1, -1, -1, -1
};
+ private Base64() {
+ }
+
public static String decode(String data) {
StringBuffer out = new StringBuffer();
@@ -80,8 +81,13 @@ public class Base64 {
int i = 0;
int r = data.length();
while (r > 0) {
- byte d0, d1, d2;
- byte e0, e1, e2, e3;
+ byte d0;
+ byte d1;
+ byte d2;
+ byte e0;
+ byte e1;
+ byte e2;
+ byte e3;
d0 = (byte)data.charAt(i++);
--r;
@@ -105,10 +111,10 @@ public class Base64 {
} else {
e3 = 64;
}
- out.append(etab.charAt(e0));
- out.append(etab.charAt(e1));
- out.append(etab.charAt(e2));
- out.append(etab.charAt(e3));
+ out.append(ETAB.charAt(e0));
+ out.append(ETAB.charAt(e1));
+ out.append(ETAB.charAt(e2));
+ out.append(ETAB.charAt(e3));
}
return out.toString();
Modified:
cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/settings/LocalStorageImpl.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/LocalStorageImpl.java?rev=979661&r1=979660&r2=979661&view=diff
==============================================================================
---
cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/settings/LocalStorageImpl.java
(original)
+++
cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/settings/LocalStorageImpl.java
Tue Jul 27 12:13:00 2010
@@ -1,5 +1,3 @@
-// CHECKSTYLE:OFF
-
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -80,6 +78,9 @@ public class LocalStorageImpl implements
private static final class Converter {
+ private Converter() {
+ }
+
public static Settings convertToSettings(final LocalSettings src) {
if (src == null) {
return null;
@@ -135,14 +136,17 @@ public class LocalStorageImpl implements
return null;
}
- LocalSettings dst = (LocalSettings)JavaScriptObject.createObject();
+ LocalSettings dst = (LocalSettings)
JavaScriptObject.createObject();
dst.setCredentials(convertToLocalCredentials(src.getCredentials()));
- JsArray<LocalSubscription> dstSubscriptions =
(JsArray<LocalSubscription>)JavaScriptObject.createArray();
+ JsArray<LocalSubscription> dstSubscriptions =
+ (JsArray<LocalSubscription>) JavaScriptObject.createArray();
+
for (Subscription subscription : src.getSubscriptions()) {
dstSubscriptions.push(convertToLocalSubscription(subscription));
}
+
dst.setSubscriptions(dstSubscriptions);
return dst;
Modified:
cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/settings/RemoteStorageImpl.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?rev=979661&r1=979660&r2=979661&view=diff
==============================================================================
---
cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/settings/RemoteStorageImpl.java
(original)
+++
cxf/sandbox/logbrowser/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/browser/client/settings/RemoteStorageImpl.java
Tue Jul 27 12:13:00 2010
@@ -1,5 +1,3 @@
-// CHECKSTYLE:OFF
-
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -135,6 +133,10 @@ public class RemoteStorageImpl implement
this.subscriptions = subscriptions;
}-*/;
+ /*
+ TODO in connection with improvents introduced by SettingsProvider,
+ this hack isn't no more required
+ */
public final native JsArray<RemoteSubscription> getSubscriptions() /*-{
if (this.subscriptions != null) {
try { //hack
@@ -175,6 +177,9 @@ public class RemoteStorageImpl implement
protected static final class Converter {
+ private Converter() {
+ }
+
public static Settings convertToSettings(final RemoteSettings
remoteSettings) {
assert remoteSettings != null;
@@ -199,6 +204,7 @@ public class RemoteStorageImpl implement
return subscription;
}
+ @SuppressWarnings("unchecked")
public static RemoteSettings convertToRemoteSettings(final Settings
settings) {
assert settings != null;
@@ -228,7 +234,7 @@ public class RemoteStorageImpl implement
}
}
- public static abstract class Callback extends AbstractCallback<Settings> {
+ public abstract static class Callback extends AbstractCallback<Settings> {
@Override
protected Settings parse(final Response response) {
@@ -244,9 +250,12 @@ public class RemoteStorageImpl implement
return result != null ? Converter.convertToSettings(result) : null;
}
+ // TODO check if this method must be final regardless to GWT's
guidelines
+ // CHECKSTYLE:OFF
private final native JavaScriptObject convertFromJSON(final String
json) /*-{
return $wnd.JSON.parse(json);
}-*/;
+ // CHECKSTYLE:ON
}
public static class NoActionCallback extends Callback {
Modified:
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=979661&r1=979660&r2=979661&view=diff
==============================================================================
---
cxf/sandbox/logbrowser/rt/management-web/src/test/java/org/apache/cxf/management/web/logging/MockApp.java
(original)
+++
cxf/sandbox/logbrowser/rt/management-web/src/test/java/org/apache/cxf/management/web/logging/MockApp.java
Tue Jul 27 12:13:00 2010
@@ -19,7 +19,6 @@
package org.apache.cxf.management.web.logging;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
@@ -28,7 +27,6 @@ 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;
@@ -59,26 +57,8 @@ public class MockApp extends Application
}
});
-
- 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"));
- }
+ private static final BootstrapStorage.SettingsProvider SETTINGS =
+ new BootstrapStorage.SettingsProvider();
@Override
public Set<Class<?>> getClasses() {
@@ -88,7 +68,7 @@ public class MockApp extends Application
classes.add(AtomEntryProvider.class);
classes.add(BootstrapStorage.class);
classes.add(SimpleAuthenticationFilter.class);
- classes.add(JSONProvider.class);
+ classes.add(BootstrapStorage.SettingsProvider.class);
return classes;
}
@@ -100,7 +80,7 @@ public class MockApp extends Application
classes.add(ENTRY);
classes.add(BOOTSTRAP_STORAGE);
classes.add(AUTHENTICATION);
- classes.add(JSON);
+ classes.add(SETTINGS);
return classes;
}
}