[java-idp-testbed COMMIT] in /trunk/src/main: java/storage/SimpleStorageRecordSerializer.java java/storage/StorageSer...

noreply at shibboleth.net noreply at shibboleth.net
Tue Sep 1 17:07:21 EDT 2015


Author: tzeller
Date: Tue Sep  1 17:07:21 2015
New Revision: 319

URL: http://svn.shibboleth.net/view/java-idp-testbed?rev=319&view=rev
Log:
IDP-594 - Interact with storage via testbed

Add forms to testbed to read and write to a storage service.
Provide /storage servlet by default in web-override.xml.
Comment local-storage forms prior to removal.
Update storage controller and serializer for Selenium tests.

Modified:
    trunk/src/main/java/storage/SimpleStorageRecordSerializer.java
    trunk/src/main/java/storage/StorageServiceWrapperController.java
    trunk/src/main/resources/system/conf/web-override.xml
    trunk/src/main/webapp/index.html

Modified: trunk/src/main/java/storage/SimpleStorageRecordSerializer.java
URL: http://svn.shibboleth.net/view/java-idp-testbed/trunk/src/main/java/storage/SimpleStorageRecordSerializer.java?rev=319&r1=318&r2=319&view=diff
==============================================================================
--- trunk/src/main/java/storage/SimpleStorageRecordSerializer.java	(original)
+++ trunk/src/main/java/storage/SimpleStorageRecordSerializer.java	Tue Sep  1 17:07:21 2015
@@ -18,74 +18,127 @@
 package storage;
 
 import java.io.IOException;
+import java.io.StringReader;
 import java.io.StringWriter;
 import java.util.HashMap;
 import java.util.Map;
 
 import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 import javax.json.Json;
+import javax.json.JsonNumber;
+import javax.json.JsonObject;
+import javax.json.JsonReader;
+import javax.json.JsonReaderFactory;
+import javax.json.JsonStructure;
 import javax.json.stream.JsonGenerator;
 import javax.json.stream.JsonGeneratorFactory;
 
+import org.opensaml.storage.MutableStorageRecord;
 import org.opensaml.storage.StorageRecord;
 import org.opensaml.storage.StorageSerializer;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
+import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
+import net.shibboleth.utilities.java.support.annotation.constraint.Positive;
 import net.shibboleth.utilities.java.support.component.AbstractInitializableComponent;
 
 /**
- * A simple storage record serializer.
- * 
- * TODO implement deserialize
+ * A simple {@link StorageRecord} serializer.
  */
 public class SimpleStorageRecordSerializer extends AbstractInitializableComponent
         implements StorageSerializer<StorageRecord> {
 
-    /** Class logger. */
-    private final Logger log = LoggerFactory.getLogger(SimpleStorageRecordSerializer.class);
-
     /** JSON generator factory. */
     @Nonnull private final JsonGeneratorFactory generatorFactory;
+
+    /** JSON reader factory. */
+    @Nonnull private JsonReaderFactory readerFactory;
 
     public SimpleStorageRecordSerializer() {
         final Map<String, String> generatorConfig = new HashMap<>();
         generatorConfig.put(JsonGenerator.PRETTY_PRINTING, "true");
         generatorFactory = Json.createGeneratorFactory(generatorConfig);
+        readerFactory = Json.createReaderFactory(null);
     }
 
     /** {@inheritDoc} */
-    public String serialize(
-            @Nonnull final StorageRecord instance) throws IOException {
+    public String serialize(@Nonnull final StorageRecord instance) throws IOException {
 
-        final StringWriter sink = new StringWriter(128);
+        final StringWriter sink = new StringWriter();
         final JsonGenerator gen = generatorFactory.createGenerator(sink);
 
         gen.writeStartObject();
         gen.write("value", instance.getValue());
         gen.write("version", instance.getVersion());
         final Long expiration = instance.getExpiration();
-        if (expiration == null) {
-            gen.writeNull("expiration");
-        } else {
+        if (expiration != null) {
             gen.write("expiration", expiration);
         }
         gen.writeEnd().close();
 
-        final String serialized = sink.toString();
-        log.debug("Serialized '{}' as '{}'", instance, serialized);
-        return serialized;
+        return sink.toString();
     }
 
     /** {@inheritDoc} */
-    public StorageRecord deserialize(
-            long version,
-            String context,
-            String key,
-            String value,
-            Long expiration) throws IOException {
-        // TODO Auto-generated method stub
-        return null;
+    @Nonnull public StorageRecord deserialize(final long version, @Nonnull @NotEmpty final String context,
+            @Nonnull @NotEmpty final String key, @Nonnull @NotEmpty final String value, @Nullable Long expiration)
+                    throws IOException {
+        final VersionableStorageRecord record = new VersionableStorageRecord(value, expiration);
+        record.setVersion(version);
+        return record;
+    }
+
+    /**
+     * Returns an object recovered from the context, key, and string produced through the {@link #serialize} method.
+     * 
+     * @param context storage record context
+     * @param key storage record key
+     * @param serialized serialized storage record
+     * @return a deserialized object

[... 342 lines stripped ...]


More information about the commits mailing list