Skip to content

Commit

Permalink
fixed
Browse files Browse the repository at this point in the history
Issue #112
  • Loading branch information
rsoika committed Sep 18, 2020
1 parent 887778a commit be468d8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
* The ArchiveRemoteService provides a method to load a file form a remote
* cassandra archive.
* <p>
* The service is triggered by the ArchivePushService on a scheduled basis.
* The service is called by Imixs-Office-Workflow to load documents from the
* cassandra archive.
*
* @version 1.2
* @author [email protected]
Expand All @@ -47,8 +48,8 @@ public class ArchiveRemoteService {
Optional<String> archiveServicePassword;

@Inject
@ConfigProperty(name = SnapshotService.ARCHIVE_SERVICE_AUTHMETHOD, defaultValue = "Basic")
String archiveServiceAuthMethod;
@ConfigProperty(name = SnapshotService.ARCHIVE_SERVICE_AUTHMETHOD)
Optional<String> archiveServiceAuthMethod;

private static Logger logger = Logger.getLogger(ArchiveRemoteService.class.getName());

Expand All @@ -70,6 +71,11 @@ public byte[] loadFileFromArchive(FileData fileData) throws RestAPIException {
return null;
}

if (!archiveServiceEndpoint.isPresent() || archiveServiceEndpoint.get().isEmpty()) {
logger.warning("missing archive service endpoint - verify configuration!");
return null;
}

boolean debug = logger.isLoggable(Level.FINE);

// first we lookup the FileData object
Expand All @@ -81,19 +87,22 @@ public byte[] loadFileFromArchive(FileData fileData) throws RestAPIException {

try {
DocumentClient documentClient = initDocumentClient();
Client rsClient = documentClient.newClient();
String url = archiveServiceEndpoint + "/archive/md5/" + md5;
Response reponse = rsClient.target(url).request(MediaType.APPLICATION_OCTET_STREAM).get();

// InputStream is = reponse.readEntity(InputStream.class);
byte[] fileContent = reponse.readEntity(byte[].class);
if (fileContent != null && fileContent.length > 0) {
if (debug) {
logger.finest("......md5 data object found");
if (documentClient == null) {
logger.warning("Unable to initalize document client!");
} else {
Client rsClient = documentClient.newClient();
String url = archiveServiceEndpoint.get() + "/archive/md5/" + md5;
Response reponse = rsClient.target(url).request(MediaType.APPLICATION_OCTET_STREAM).get();

// InputStream is = reponse.readEntity(InputStream.class);
byte[] fileContent = reponse.readEntity(byte[].class);
if (fileContent != null && fileContent.length > 0) {
if (debug) {
logger.finest("......md5 data object found");
}
return fileContent;
}
return fileContent;
}

} catch (ProcessingException e) {
String message = null;
if (e.getCause() != null) {
Expand All @@ -108,9 +117,7 @@ public byte[] loadFileFromArchive(FileData fileData) throws RestAPIException {
} else {
return null;
}

}

return null;

}
Expand All @@ -119,25 +126,34 @@ public byte[] loadFileFromArchive(FileData fileData) throws RestAPIException {
* Helper method to initalize a Melman Workflow Client based on the current
* archive configuration.
*/
public DocumentClient initDocumentClient() {
private DocumentClient initDocumentClient() {
boolean debug = logger.isLoggable(Level.FINE);
if (debug) {
logger.finest("...... ARCHIVE_SERVICE_ENDPOINT = " + archiveServiceEndpoint);
}
DocumentClient documentClient = new DocumentClient(archiveServiceEndpoint.get());
// Test authentication method
if ("Form".equalsIgnoreCase(archiveServiceAuthMethod)) {
// default basic authenticator
FormAuthenticator formAuth = new FormAuthenticator(archiveServiceEndpoint.get(), archiveServiceUser.get(),
archiveServicePassword.get());
// register the authenticator
documentClient.registerClientRequestFilter(formAuth);
} else {
// default basic authenticator
BasicAuthenticator basicAuth = new BasicAuthenticator(archiveServiceUser.get(), archiveServicePassword.get());
// register the authenticator
documentClient.registerClientRequestFilter(basicAuth);
// test if authentication is needed?
if (archiveServiceAuthMethod.isPresent()) {
// Test authentication method
if ("form".equalsIgnoreCase(archiveServiceAuthMethod.get())) {
if (debug) {
logger.finest("......Form Based authentication");
}
// form authenticator
FormAuthenticator formAuth = new FormAuthenticator(archiveServiceEndpoint.get(),
archiveServiceUser.get(), archiveServicePassword.get());
// register the authenticator
documentClient.registerClientRequestFilter(formAuth);
}
if ("basic".equalsIgnoreCase(archiveServiceAuthMethod.get())) {
if (debug) {
logger.finest("......Basic authentication");
}
// basic authenticator
BasicAuthenticator basicAuth = new BasicAuthenticator(archiveServiceUser.get(),
archiveServicePassword.get());
// register the authenticator
documentClient.registerClientRequestFilter(basicAuth);
}
}

return documentClient;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ public void saveSnapshot(ItemCollection snapshot) throws ArchiveException {
// verify if this snapshot is already stored - if so, we do not overwrite
// the origin data. See issue #40
if (existSnapshot(snapshotID)) {
// skipp!
logger.warning("...snapshot '" + snapshot.getUniqueID() + "' already exits....");
// skip!
logger.info("...snapshot '" + snapshot.getUniqueID() + "' already exits....");
return;
}

Expand Down

0 comments on commit be468d8

Please sign in to comment.