Search in sources :

Example 1 with Binary

use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.

the class TMLSerializer method parseProperty.

private final Property parseProperty(String type, boolean partOfArrayElement, int propertyIndex, int arrayEltIndex, InputStream is, boolean longLength) throws IOException {
    String name = propertyIndex + "";
    byte[] array = null;
    if (arrayEltIndex == 0 || !partOfArrayElement) {
        array = new byte[bytesToShort(is)];
        is.read(array, 0, array.length);
        name = new String(array);
    }
    int size = (longLength ? bytesToInt(is) : bytesToShort(is));
    array = new byte[size];
    is.read(array, 0, array.length);
    if (type.equals(Property.BINARY_PROPERTY)) {
        Property p = NavajoFactory.getInstance().createProperty(myNavajo, name, type, null, 0, "", "");
        p.setAnyValue(new Binary(array));
        return p;
    } else {
        String value = new String(array);
        return NavajoFactory.getInstance().createProperty(myNavajo, name, type, value, 0, "", "");
    }
}
Also used : Binary(com.dexels.navajo.document.types.Binary) Property(com.dexels.navajo.document.Property)

Example 2 with Binary

use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.

the class BaseRequestImpl method writeOutput.

@Override
public void writeOutput(Navajo inDoc, Navajo outDoc, long scheduledAt, long startedAt, String threadStatus) throws IOException {
    long finishedScriptAt = System.currentTimeMillis();
    // postTime =
    long postTime = scheduledAt - connectedAt;
    long queueTime = startedAt - scheduledAt;
    long serverTime = finishedScriptAt - startedAt;
    if (dataPath != null) {
        Property data = outDoc.getProperty(dataPath);
        Object dataObject = data.getTypedValue();
        if (dataObject instanceof Binary) {
            Binary b = (Binary) dataObject;
            if (contentType != null) {
                response.setContentType(contentType);
            } else {
                response.setContentType(b.guessContentType());
            }
            if (this.fileName != null) {
                response.setHeader("Content-Disposition", "attachment; filename=" + this.fileName);
            }
            OutputStream out = getOutputStream(acceptEncoding, response.getOutputStream());
            CountingOutputStream cos = new CountingOutputStream(out);
            b.write(cos);
            cos.close();
            logResponseSize(cos.getCount());
            return;
        } else {
            response.setContentType("text/plain; charset=UTF-8");
            OutputStream out = getOutputStream(acceptEncoding, response.getOutputStream());
            OutputStreamWriter osw = new OutputStreamWriter(out);
            osw.write("" + dataObject);
            osw.close();
        }
    }
    OutputStream out = getOutputStream(acceptEncoding, response.getOutputStream());
    response.setContentType("text/xml; charset=UTF-8");
    if (outDoc == null) {
        logger.warn("Null outDoc. This is going to hurt");
        response.sendError(500, "No response received, possible scheduling problem.");
        return;
    } else if (outDoc.getHeader() == null) {
        logger.warn("Null outDoc header. This is going to hurt");
        response.sendError(500, "No response header received, possible scheduling problem.");
        return;
    }
    outDoc.getHeader().setHeaderAttribute("postTime", "" + postTime);
    outDoc.getHeader().setHeaderAttribute("queueTime", "" + queueTime);
    outDoc.getHeader().setHeaderAttribute("serverTime", "" + serverTime);
    outDoc.getHeader().setHeaderAttribute("threadName", "" + Thread.currentThread().getName());
    CountingOutputStream cos = new CountingOutputStream(out);
    outDoc.write(cos);
    cos.close();
    logResponseSize(cos.getCount());
    if (inDoc != null && inDoc.getHeader() != null && outDoc.getHeader() != null) {
        statLogger.info("Finished {} ({}) in {}ms - {}", outDoc.getHeader().getHeaderAttribute("accessId"), inDoc.getHeader().getRPCName(), (System.currentTimeMillis() - connectedAt), threadStatus);
    }
}
Also used : CountingOutputStream(org.apache.commons.io.output.CountingOutputStream) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) CountingOutputStream(org.apache.commons.io.output.CountingOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) Binary(com.dexels.navajo.document.types.Binary) Property(com.dexels.navajo.document.Property)

Example 3 with Binary

use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.

the class BirtHandler method doService.

@Override
public final Navajo doService(Access a) {
    Navajo inDoc = getInDoc(a);
    inDoc.removeInternalMessages();
    Binary birtBinary = getBirtBinary(inDoc);
    Navajo navajoBirt = makeNavajoBirt(birtBinary);
    return navajoBirt;
}
Also used : Navajo(com.dexels.navajo.document.Navajo) Binary(com.dexels.navajo.document.types.Binary)

Example 4 with Binary

use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.

the class BirtHandler method getBirtBinary.

public Binary getBirtBinary(Navajo n) {
    Binary template = null;
    BirtUtils report = new BirtUtils();
    Binary result = new Binary();
    try {
        result = report.createEmptyReport(n, template);
    } catch (Exception e) {
        logger.error("Unable to create report.", e);
    }
    return result;
}
Also used : Binary(com.dexels.navajo.document.types.Binary)

Example 5 with Binary

use of com.dexels.navajo.document.types.Binary in project navajo by Dexels.

the class Security method decryptBinary.

public Binary decryptBinary(String encryptedData) throws Exception {
    Key key = generateKey();
    Cipher c = Cipher.getInstance(ALGO);
    c.init(Cipher.DECRYPT_MODE, key);
    byte[] decordedValue = Base64.decode(encryptedData);
    byte[] decValue = c.doFinal(decordedValue);
    Binary b = new Binary(decValue);
    return b;
}
Also used : Cipher(javax.crypto.Cipher) Binary(com.dexels.navajo.document.types.Binary) Key(java.security.Key)

Aggregations

Binary (com.dexels.navajo.document.types.Binary)139 Test (org.junit.Test)38 IOException (java.io.IOException)32 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)26 File (java.io.File)25 Ignore (org.junit.Ignore)17 Property (com.dexels.navajo.document.Property)16 URL (java.net.URL)16 UserException (com.dexels.navajo.script.api.UserException)14 OutputStream (java.io.OutputStream)13 FileOutputStream (java.io.FileOutputStream)12 Navajo (com.dexels.navajo.document.Navajo)11 MappableException (com.dexels.navajo.script.api.MappableException)11 FileInputStream (java.io.FileInputStream)9 InputStream (java.io.InputStream)9 Message (com.dexels.navajo.document.Message)8 StringWriter (java.io.StringWriter)8 OutputStreamWriter (java.io.OutputStreamWriter)7 NavajoException (com.dexels.navajo.document.NavajoException)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6