Custom BinaryStore deployed as jboss-module
thomas.newman.redflex.com.au Aug 30, 2016 11:50 PMHello,
I have checked these forums and google/stackoverflow.
I can't find a <pre> or <code> tag in this editor so apologies for the formatting below.
I am trying to develop a custom binary store and deploy as a jboss-module and then configure a repository within standalone-modeshape.xml
I am extending FileSystemBinary and overriding storeValue and getInputStream. I am basically encrypting the stream in storeValue and decrypting in getInputStream. Whether or not this is a good approach I don't know. My intention is that the nodes / metadata is unencrypted, allowing normal operation, yet the actual binary on the fs will be encrypted. This should, I hope, allow for the modeshape-rest and modeshape-explorer to operate normally and actually show the image.
Using smartics-jboss-modules-maven-plugin - Overview I am creating a jboss-modules zip containing my custom binary store and supporting 3rd party libs. Perhaps I haven't done this correct which is causing the problem I will eventually get to
The module.xml is:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="com.asdf.backoffice.imageserver.encryptedstore" slot="asdf1">
<resources>
<resource-root path="encryptedstore-1.0-SNAPSHOT.jar" />
</resources>
<dependencies>
<module name="net.sf.jsignature.io-tools.easystream" slot="asdf1" />
</dependencies>
</module>
This is deployed to wildfly.../modules with the jar and supporting libs as per my understanding of how to do this.
The config in standalone-modeshape.xml is:
<?xml version="1.0" encoding="UTF-8"?>
<repository name="asdfEncrypted">
<workspaces allow-workspace-creation="false">
<workspace name="images"/>
</workspaces>
<custom-binary-storage classname="com.asdf.imageserver.encryptedstore.EncryptedBinaryStore" module="com.asdf.backoffice.imageserver.encryptedstore"/>
<sequencers>
<sequencer name="image-sequencer" classname="image" module="org.modeshape.sequencer.image" path-expression="/files(//*.(png|jpg|jpeg|gif)[*])/jcr:content[@jcr:data] => /derived/image/$1"/>
</sequencers>
</repository>
The error I am getting is:
13:12:03,857 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC000001: Failed to start service jboss.modeshape.asdfEncrypted.repository: org.jboss.msc.service.StartException in service jboss.modeshape.asdfEncrypted.repository: org.modeshape.jcr.ConfigurationException: The configuration for the 'asdfEncrypted' repository has problems: ERROR: Error at storage.binaryStorage.classname : Field value for 'storage.binaryStorage.classname' expected to be of type string but was of type unknown
ERROR: Error at storage.binaryStorage.classloader : Field value for 'storage.binaryStorage.classloader' expected to be of type string but was of type unknown
at org.modeshape.jboss.service.RepositoryService.start(RepositoryService.java:221)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.modeshape.jcr.ConfigurationException: The configuration for the 'asdfEncrypted' repository has problems: ERROR: Error at storage.binaryStorage.classname : Field value for 'storage.binaryStorage.classname' expected to be of type string but was of type unknown
ERROR: Error at storage.binaryStorage.classloader : Field value for 'storage.binaryStorage.classloader' expected to be of type string but was of type unknown
at org.modeshape.jcr.ModeShapeEngine.deploy(ModeShapeEngine.java:469)
at org.modeshape.jcr.ModeShapeEngine.deploy(ModeShapeEngine.java:441)
at org.modeshape.jboss.service.RepositoryService.start(RepositoryService.java:219)
... 5 more
Going by the documentation on Custom - ModeShape 5 - Project Documentation Editor
classloader is only relevant to JSON config.
classname very much seems like a string to me.
There is no easily found end to end instructions to create a custom binary store and deploy/configure to wildfly. Perhaps there is something in the modeshape git repo but I can't find what I am looking for.
Perhaps my usage of jboss-module slots is wrong.
Please point me towards an end to end example to develop, deploy, configure modeshape custombinarystore in a Wildfly environment.
Regards,
Thomas.
CustomBinaryStore:
@ThreadSafe
public class EncryptedBinaryStore extends FileSystemBinaryStore {
public EncryptedBinaryStore(File directory) {
super(directory);
}
public EncryptedBinaryStore(File directory, File trash) {
super(directory, trash);
}
@Override
public BinaryValue storeValue(InputStream stream, boolean markAsUnused) throws BinaryStoreException {
final FileSystemBinaryStore superDuper = this;
final InputStream superInputStream = stream;
final BinaryValue binaryValue;
try (final OutputStreamToInputStream<BinaryValue> outputStream = new OutputStreamToInputStream<BinaryValue>() {
@Override
protected BinaryValue doRead(final InputStream istream) throws Exception {
return superDuper.storeValue(istream, markAsUnused);
}
}) {
new Encryptor().encryptFile(superInputStream, outputStream);
binaryValue = outputStream.getResult();
} catch (Exception e) {
throw new RuntimeException(e);
}
return binaryValue;
}
@Override
public InputStream getInputStream(BinaryKey key) throws BinaryStoreException {
final FileSystemBinaryStore superDuper = this;
final InputStream inputStream;
try (final OutputStreamToInputStream<InputStream> outputStream = new OutputStreamToInputStream<InputStream>() {
@Override
protected InputStream doRead(final InputStream istream) throws Exception {
return superDuper.getInputStream(key);
}
}) {
new Encryptor().decryptFile(superDuper.getInputStream(key), outputStream);
inputStream = outputStream.getResult();
} catch (Exception e) {
throw new RuntimeException(e);
}
return inputStream;
}
}