private static final int MAX_FONTSIZE = 60;\r
private static final String IMAGES_TO_CREATE_PROP = "imagesToCreate";\r
private static final int DEFAULT_IMAGES_TO_CREATE = 1;\r
+ private static final int DEFAULT_IMAGES_TO_GET = 1024;\r
private static final String GENERATED_IMAGES = "target/generated_images";\r
\r
private static Random generator = new Random(System.currentTimeMillis());\r
return result;\r
}\r
\r
+ @Test(dataProvider = "testName", dependsOnMethods = {"scaleTest"})\r
+ public void scaleGETTest(String testName) throws MalformedURLException {\r
+ this.setupRead();\r
+ String blobToGetID = getKnowResourceId();\r
+ BlobClient client = new BlobClient();\r
+ \r
+ for (int i = 0; i < DEFAULT_IMAGES_TO_GET; i++) {\r
+ ClientResponse<Response> res = client.getDerivativeContent(blobToGetID, "Thumbnail");\r
+ assertStatusCode(res, testName);\r
+ }\r
+ \r
+ logger.debug(String.format("Performed %d GET operations on blob = %s.", \r
+ DEFAULT_IMAGES_TO_GET, blobToGetID));\r
+ }\r
+ \r
@Test(dataProvider = "testName")\r
public void scaleTest(String testName) throws MalformedURLException {\r
this.createDirectory(GENERATED_IMAGES);\r
URL url = jpegFile.toURI().toURL();\r
\r
profiler.start();\r
- ClientResponse<Response> res = client.createBlobFromURI(url.toString());\r
+ ClientResponse<Response> res = client.createBlobFromURI("http://farm6.static.flickr.com/5289/5688023100_15e00cde47_o.jpg");//url.toString());\r
try {\r
profiler.stop();\r
assertStatusCode(res, testName);\r
+ jpegFile.getAbsolutePath());\r
\r
String csid = extractId(res);\r
- allResourceIdsCreated.add(csid);\r
+ //allResourceIdsCreated.add(csid);\r
+ this.knownResourceId = csid;\r
} finally {\r
if (res != null) {\r
res.releaseConnection();\r
*/\r
package org.collectionspace.services.common.imaging.nuxeo;\r
\r
+import java.io.ByteArrayInputStream;\r
import java.io.File;\r
import java.io.ByteArrayOutputStream;\r
import java.io.FileNotFoundException;\r
import org.nuxeo.ecm.platform.picture.api.ImagingDocumentConstants;\r
import org.nuxeo.ecm.platform.picture.api.ImagingService;\r
import org.nuxeo.ecm.platform.picture.api.PictureView;\r
-\r
import org.nuxeo.ecm.platform.mimetype.MimetypeDetectionException;\r
import org.nuxeo.ecm.platform.mimetype.interfaces.MimetypeRegistry;\r
import org.nuxeo.ecm.platform.picture.api.adapters.PictureBlobHolder;\r
import org.nuxeo.ecm.platform.filemanager.service.extension.FileImporter;\r
import org.nuxeo.ecm.platform.filemanager.utils.FileManagerUtils;\r
import org.nuxeo.ecm.platform.types.TypeManager;\r
-\r
import org.nuxeo.ecm.core.repository.RepositoryDescriptor;\r
import org.nuxeo.ecm.core.repository.RepositoryManager;\r
-\r
import org.nuxeo.ecm.core.repository.RepositoryService;\r
import org.nuxeo.ecm.core.storage.sql.BinaryManager;\r
import org.nuxeo.ecm.core.storage.sql.DefaultBinaryManager;\r
import org.nuxeo.ecm.core.api.DocumentModel;\r
import org.nuxeo.ecm.core.api.DocumentRef;\r
import org.nuxeo.ecm.core.event.EventServiceAdmin;\r
-\r
import org.nuxeo.ecm.core.schema.SchemaManager;\r
import org.nuxeo.ecm.core.schema.types.Schema;\r
-\r
import org.slf4j.Logger;\r
import org.slf4j.LoggerFactory;\r
//import org.nuxeo.ecm.core.repository.jcr.testing.RepositoryOSGITestCase;\r
\r
+import org.apache.commons.io.IOUtils;\r
import org.collectionspace.services.client.PoxPayloadIn;\r
import org.collectionspace.services.client.PoxPayloadOut;\r
import org.collectionspace.services.common.FileUtils;\r
private static final Logger logger = LoggerFactory\r
.getLogger(NuxeoBlobUtils.class);\r
\r
+ //\r
+ // A maximum byte size for the byte array used to hold an image. Images larger than this will\r
+ // be returned as FileInputStreams rather than ByteArrayInputStreams\r
+ //\r
+ private static final int MAX_IMAGE_BUFFER = 256 * 1024; // REM: 11/26/2013 - This should be set in a config/property file.\r
+ \r
//\r
// File name constants\r
//\r
\r
static private BlobsCommon createBlobsCommon(DocumentModel documentModel,\r
Blob nuxeoBlob) {\r
+ return createBlobsCommon(documentModel, nuxeoBlob, false);\r
+ }\r
+ \r
+ static private BlobsCommon createBlobsCommon(DocumentModel documentModel,\r
+ Blob nuxeoBlob, Boolean getContentFlag) {\r
BlobsCommon result = new BlobsCommon();\r
\r
if (documentModel != null) {\r
result.setName(nuxeoBlob.getFilename());\r
result.setLength(Long.toString(nuxeoBlob.getLength()));\r
result.setRepositoryId(documentModel.getId());\r
- MeasuredPartGroupList measuredPartGroupList = getDimensions(\r
- documentModel, nuxeoBlob);\r
- if (measuredPartGroupList != null) {\r
- result.setMeasuredPartGroupList(measuredPartGroupList);\r
+ \r
+ //\r
+ // If getContentFlag is true then we're being asked for the blob's content, so we don't\r
+ // need the measurement info. Getting the measurement info requires a call to Nuxeo which in turn\r
+ // calls ImageMagick.\r
+ //\r
+ if (getContentFlag.booleanValue() == false) {\r
+ MeasuredPartGroupList measuredPartGroupList = getDimensions(\r
+ documentModel, nuxeoBlob);\r
+ if (measuredPartGroupList != null) {\r
+ result.setMeasuredPartGroupList(measuredPartGroupList);\r
+ }\r
}\r
\r
// Check to see if a thumbnail preview was created by Nuxeo\r
- // REM: 11/26/2013 - This looks like dead code? What are we looking for a thumbnail?\r
if (documentModel.hasFacet(ThumbnailConstants.THUMBNAIL_FACET)) {\r
String errorMsg = null;\r
String thumbnailName = null;\r
return result;\r
}\r
\r
+ //\r
+ // If the blob is not too big, we return a ByteArrayInputStream. Otherwise, we return Nuxeo's InputStream\r
+ // which is usually a FileInputStream.\r
+ //\r
+ static private InputStream getInputStream(BlobsCommon blobsCommon, Blob blob) {\r
+ InputStream result = null;\r
+ \r
+ try {\r
+ InputStream blobStream = blob.getStream(); // By default, the result will be whatever stream Nuxeo returns to us.\r
+ int blobSize = blobsCommon.getLength() != null ? Integer.parseInt(blobsCommon.getLength()) : 0;\r
+ if (blobSize > 0 && blobSize < MAX_IMAGE_BUFFER) {\r
+ byte[] bytes = IOUtils.toByteArray(blobStream);\r
+ blobStream.close(); // Close the InputStream that we got from Nuxeo since it's usually a FileInputStream -we definitely want FileInputStreams closed.\r
+ result = new ByteArrayInputStream(bytes);\r
+ } else {\r
+ result = blobStream; // The blob is too large to put into a ByteArrayStream.\r
+ }\r
+ } catch (Exception e) {\r
+ logger.error(String.format("Error getting the InputStream content for file %s.", blobsCommon.getName()), e);\r
+ if (result != null) {\r
+ try {\r
+ result.close();\r
+ result = null;\r
+ } catch (Exception x) {\r
+ logger.debug(String.format("Exception encountered during InputStream cleanup of file %s", blobsCommon.getName()), x);\r
+ }\r
+ } \r
+ }\r
+ \r
+ return result;\r
+ }\r
+ \r
/**\r
* Gets the image.\r
* \r
// and an InputStream with the bits if the 'getContentFlag' is\r
// set.\r
//\r
- BlobsCommon blobsCommon = createBlobsCommon(documentModel, docBlob);\r
+ BlobsCommon blobsCommon = createBlobsCommon(documentModel, docBlob, getContentFlag);\r
result.setBlobsCommon(blobsCommon);\r
if (getContentFlag == true) {\r
InputStream remoteStream = null;\r
if (isNonImageDerivative == false) {\r
- remoteStream = docBlob.getStream(); // This will fail if the blob's file has been deleted. FileNotFoundException thrown.\r
+ //remoteStream = docBlob.getStream();\r
+ remoteStream = getInputStream(blobsCommon, docBlob); // CSPACE-6110 - For small files, return a byte array instead of a file stream\r
} else {\r
remoteStream = getResource(DOCUMENT_PLACEHOLDER_IMAGE);\r
outMimeType.append(MIME_JPEG);\r
}\r
- BufferedInputStream bufferedInputStream = new BufferedInputStream(\r
- remoteStream); \r
- result.setBlobInputStream(bufferedInputStream);\r
+// BufferedInputStream bufferedInputStream = new BufferedInputStream(\r
+// remoteStream); \r
+// result.setBlobInputStream(bufferedInputStream);\r
+ result.setBlobInputStream(remoteStream);\r
}\r
} catch (Exception e) {\r
if (logger.isErrorEnabled() == true) {\r