You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2013/05/28 14:14:46 UTC
git commit: ISIS-412: publishing service store json as zipped blobs.
Updated Branches:
refs/heads/master 6246363c5 -> 11f4c2e76
ISIS-412: publishing service store json as zipped blobs.
Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/11f4c2e7
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/11f4c2e7
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/11f4c2e7
Branch: refs/heads/master
Commit: 11f4c2e76adc61db33f33ab618f99b79adac2021
Parents: 6246363
Author: Dan Haywood <da...@apache.org>
Authored: Tue May 28 13:14:22 2013 +0100
Committer: Dan Haywood <da...@apache.org>
Committed: Tue May 28 13:14:22 2013 +0100
----------------------------------------------------------------------
.../jdo/applib/service/publish/IoUtils.java | 124 +++++++++++++++
.../jdo/applib/service/publish/PublishedEvent.java | 28 +++-
.../jdo/applib/service/publish/IoUtilsTest.java | 36 ++++
component/viewer/restfulobjects/applib/pom.xml | 6 +
..._restful_jdo-viewer-webapp-with-fixtures.launch | 2 +-
5 files changed, 190 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/isis/blob/11f4c2e7/component/objectstore/jdo/jdo-applib/src/main/java/org/apache/isis/objectstore/jdo/applib/service/publish/IoUtils.java
----------------------------------------------------------------------
diff --git a/component/objectstore/jdo/jdo-applib/src/main/java/org/apache/isis/objectstore/jdo/applib/service/publish/IoUtils.java b/component/objectstore/jdo/jdo-applib/src/main/java/org/apache/isis/objectstore/jdo/applib/service/publish/IoUtils.java
new file mode 100644
index 0000000..1d3c976
--- /dev/null
+++ b/component/objectstore/jdo/jdo-applib/src/main/java/org/apache/isis/objectstore/jdo/applib/service/publish/IoUtils.java
@@ -0,0 +1,124 @@
+/**
+ * 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.isis.objectstore.jdo.applib.service.publish;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.Charset;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+import java.util.zip.ZipOutputStream;
+
+import org.apache.isis.applib.ApplicationException;
+
+class IoUtils {
+
+ public static byte[] toUtf8ZippedBytes(String entryName, final String toZip) {
+ if(toZip == null) {
+ return null;
+ }
+ ZipOutputStream zos = null;
+ ByteArrayOutputStream baos = null;
+ try {
+ baos = new ByteArrayOutputStream();
+ zos = new ZipOutputStream(baos);
+ ZipEntry entry = new ZipEntry(entryName);
+ zos.putNextEntry(entry);
+
+ final byte[] utf8Bytes = toZip.getBytes(Charset.forName("UTF-8"));
+ zos.write(utf8Bytes);
+ zos.flush();
+ } catch (IOException e) {
+ throw new ApplicationException(e);
+ } finally {
+ closeSafely(zos);
+ }
+ return baos.toByteArray();
+ }
+
+ public static String fromUtf8ZippedBytes(String entryName, final byte[] toUnzip) {
+ if(toUnzip == null) {
+ return null;
+ }
+ ByteArrayInputStream bais = null;
+ ZipInputStream zis = null;
+ try {
+ bais = new ByteArrayInputStream(toUnzip);
+ zis = new ZipInputStream(bais);
+ ZipEntry entry;
+ while ((entry = zis.getNextEntry()) != null) {
+ if(!entry.getName().equals(entryName)) {
+ zis.closeEntry();
+ continue;
+ }
+ final byte[] utf8Bytes = IoUtils.readBytes(zis);
+ return new String(utf8Bytes, Charset.forName("UTF-8"));
+ }
+ return null;
+ } catch(IOException ex) {
+ throw new ApplicationException(ex);
+ } finally {
+ IoUtils.closeSafely(zis);
+ }
+ }
+
+ static byte[] readBytes(final InputStream zis) throws IOException {
+ final byte[] buffer = new byte[2048];
+ final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ int numBytes;
+ while ((numBytes = zis.read(buffer, 0, buffer.length)) != -1) {
+ baos.write(buffer, 0, numBytes);
+ }
+ baos.flush();
+ baos.close();
+ return baos.toByteArray();
+ }
+
+ static void closeSafely(ZipInputStream zis) {
+ if(zis != null) {
+ try {
+ zis.closeEntry();
+ } catch (IOException e) {
+ // ignore
+ }
+ try {
+ zis.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ }
+
+ static void closeSafely(ZipOutputStream zos) {
+ if(zos != null) {
+ try {
+ zos.closeEntry();
+ } catch (IOException e) {
+ // ignore
+ }
+ try {
+ zos.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/11f4c2e7/component/objectstore/jdo/jdo-applib/src/main/java/org/apache/isis/objectstore/jdo/applib/service/publish/PublishedEvent.java
----------------------------------------------------------------------
diff --git a/component/objectstore/jdo/jdo-applib/src/main/java/org/apache/isis/objectstore/jdo/applib/service/publish/PublishedEvent.java b/component/objectstore/jdo/jdo-applib/src/main/java/org/apache/isis/objectstore/jdo/applib/service/publish/PublishedEvent.java
index 1607f86..9ffc0c8 100644
--- a/component/objectstore/jdo/jdo-applib/src/main/java/org/apache/isis/objectstore/jdo/applib/service/publish/PublishedEvent.java
+++ b/component/objectstore/jdo/jdo-applib/src/main/java/org/apache/isis/objectstore/jdo/applib/service/publish/PublishedEvent.java
@@ -19,6 +19,7 @@
package org.apache.isis.objectstore.jdo.applib.service.publish;
+
import javax.jdo.annotations.IdentityType;
import org.apache.isis.applib.DomainObjectContainer;
@@ -171,21 +172,38 @@ public class PublishedEvent {
// {{ SerializedForm (property)
- @javax.jdo.annotations.Column(length=4000)
- private String serializedForm;
+ @javax.jdo.annotations.NotPersistent
@MultiLine(numberOfLines=20)
@Hidden(where=Where.ALL_TABLES)
@MemberOrder(sequence = "6")
public String getSerializedForm() {
- return serializedForm;
+ return IoUtils.fromUtf8ZippedBytes("serializedForm", getSerializedFormZipped());
+ }
+
+ public void setSerializedForm(final String serializedForm) {
+ final byte[] zippedBytes = IoUtils.toUtf8ZippedBytes("serializedForm", serializedForm);
+ setSerializedFormZipped(zippedBytes);
+ }
+ // }}
+
+
+ // {{ SerializedFormZipped (property)
+ @javax.jdo.annotations.Column
+ private byte[] serializedFormZipped;
+
+ @Programmatic // ignored by Isis
+ public byte[] getSerializedFormZipped() {
+ return serializedFormZipped;
}
- public void setSerializedForm(final String propertyName) {
- this.serializedForm = propertyName;
+ public void setSerializedFormZipped(final byte[] serializedFormZipped) {
+ this.serializedFormZipped = serializedFormZipped;
}
// }}
+
+
@Bulk
@ActionSemantics(Of.IDEMPOTENT)
@MemberOrder(sequence="10")
http://git-wip-us.apache.org/repos/asf/isis/blob/11f4c2e7/component/objectstore/jdo/jdo-applib/src/test/java/org/apache/isis/objectstore/jdo/applib/service/publish/IoUtilsTest.java
----------------------------------------------------------------------
diff --git a/component/objectstore/jdo/jdo-applib/src/test/java/org/apache/isis/objectstore/jdo/applib/service/publish/IoUtilsTest.java b/component/objectstore/jdo/jdo-applib/src/test/java/org/apache/isis/objectstore/jdo/applib/service/publish/IoUtilsTest.java
new file mode 100644
index 0000000..32cfde0
--- /dev/null
+++ b/component/objectstore/jdo/jdo-applib/src/test/java/org/apache/isis/objectstore/jdo/applib/service/publish/IoUtilsTest.java
@@ -0,0 +1,36 @@
+/**
+ * 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.isis.objectstore.jdo.applib.service.publish;
+
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class IoUtilsTest {
+
+ @Test
+ public void roundtrip() {
+ final String str = "3784y5hrfbdgkjh3qyri f£$%$YTRGFDGER$£\"Eu098987u'!\"£%^&*IO(LUKJM)";
+ final byte[] utf8ZippedBytes = IoUtils.toUtf8ZippedBytes("serializedForm", str);
+
+ final String str2 = IoUtils.fromUtf8ZippedBytes("serializedForm", utf8ZippedBytes);
+
+ assertThat(str, (is(str2)));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/11f4c2e7/component/viewer/restfulobjects/applib/pom.xml
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/applib/pom.xml b/component/viewer/restfulobjects/applib/pom.xml
index 678e83a..9bdcc74 100644
--- a/component/viewer/restfulobjects/applib/pom.xml
+++ b/component/viewer/restfulobjects/applib/pom.xml
@@ -66,6 +66,12 @@
</dependency>
<dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
</dependency>
http://git-wip-us.apache.org/repos/asf/isis/blob/11f4c2e7/example/application/quickstart_wicket_restful_jdo/viewer-webapp/ide/eclipse/launch/quickstart_wicket_restful_jdo-viewer-webapp-with-fixtures.launch
----------------------------------------------------------------------
diff --git a/example/application/quickstart_wicket_restful_jdo/viewer-webapp/ide/eclipse/launch/quickstart_wicket_restful_jdo-viewer-webapp-with-fixtures.launch b/example/application/quickstart_wicket_restful_jdo/viewer-webapp/ide/eclipse/launch/quickstart_wicket_restful_jdo-viewer-webapp-with-fixtures.launch
index f9c6788..02e8273 100644
--- a/example/application/quickstart_wicket_restful_jdo/viewer-webapp/ide/eclipse/launch/quickstart_wicket_restful_jdo-viewer-webapp-with-fixtures.launch
+++ b/example/application/quickstart_wicket_restful_jdo/viewer-webapp/ide/eclipse/launch/quickstart_wicket_restful_jdo-viewer-webapp-with-fixtures.launch
@@ -14,7 +14,7 @@
<booleanAttribute key="org.eclipse.jdt.debug.ui.INCLUDE_EXTERNAL_JARS" value="true"/>
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.m2e.launchconfig.classpathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.apache.isis.WebServer"/>
-<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="quickstart_wicket_restful_jdo-viewer-webapp"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="--port 8080 -D isis.persistor.datanucleus.install-fixtures=true -t SERVER_EXPLORATION"/>
+<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="quickstart_wicket_restful_jdo-viewer-webapp"/>
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.m2e.launchconfig.sourcepathProvider"/>
</launchConfiguration>