Search in sources :

Example 56 with Binary

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

the class TestHttpResource method testHead.

@Test
@Ignore
public void testHead() throws IOException, MappableException, UserException {
    BinaryStoreAdapter bsa = new BinaryStoreAdapter();
    bsa.load(access);
    Binary b = createBinary();
    b.setMimeType("text/plain");
    boolean exists = bsa.headBinary(b.getHexDigest(), "binstore", "junit");
    Assert.assertFalse(exists);
}
Also used : Binary(com.dexels.navajo.document.types.Binary) BinaryStoreAdapter(com.dexels.navajo.resource.http.adapter.BinaryStoreAdapter) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 57 with Binary

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

the class TestHttpResource method testPut.

@Test
@Ignore
public void testPut() throws IOException, MappableException, UserException {
    BinaryStoreAdapter bsa = new BinaryStoreAdapter();
    bsa.load(access);
    Binary b = createBinary();
    bsa.storeBinary(b, "binstore", "junit", false);
}
Also used : Binary(com.dexels.navajo.document.types.Binary) BinaryStoreAdapter(com.dexels.navajo.resource.http.adapter.BinaryStoreAdapter) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 58 with Binary

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

the class TestHttpResource method testStoreAdapterBasics.

@Test
@Ignore
public void testStoreAdapterBasics() throws IOException, MappableException, UserException, InterruptedException {
    BinaryStoreAdapter bsa = new BinaryStoreAdapter();
    bsa.load(access);
    Binary b = createBinary();
    String bb = bsa.storeBinary(b, "binstore", "junit", false);
    System.err.println("Result of put: " + bb);
    boolean existsNow = bsa.headBinary(b.getHexDigest(), "binstore", "junit");
    Assert.assertTrue(existsNow);
    System.err.println("exists after insert: " + existsNow);
    ReactiveReply result = bsa.deleteBinary(b.getHexDigest(), "binstore", "junit", false);
    System.err.println("Delete: " + result.status());
    boolean exists = bsa.headBinary(b.getHexDigest(), "binstore", "junit");
    Assert.assertFalse(exists);
    System.err.println("exists after delete: " + exists);
}
Also used : ReactiveReply(com.dexels.navajo.client.stream.ReactiveReply) Binary(com.dexels.navajo.document.types.Binary) BinaryStoreAdapter(com.dexels.navajo.resource.http.adapter.BinaryStoreAdapter) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 59 with Binary

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

the class TmlHttpServlet method sendResponse.

private static void sendResponse(HttpServletRequest request, HttpServletResponse response, Navajo resultMessage) {
    ServletOutputStream outputStream = null;
    try {
        String dataPath = request.getParameter("dataPath");
        outputStream = response.getOutputStream();
        if (dataPath != null) {
            Property bin = resultMessage.getProperty(dataPath);
            if (bin == null) {
                java.io.OutputStreamWriter out = new java.io.OutputStreamWriter(outputStream, "UTF-8");
                response.setContentType("text/xml; charset=UTF-8");
                resultMessage.write(out);
                out.flush();
                out.close();
            } else {
                // Will throw cce when not a binary?
                if (bin.getTypedValue() instanceof Binary) {
                    Binary b = (Binary) bin.getTypedValue();
                    response.setContentType(b.getMimeType());
                    if (b.getLength() > 0) {
                        response.setContentLength((int) b.getLength());
                        response.setHeader("Accept-Ranges", "none");
                        response.setHeader("Connection", "close");
                    }
                    copyResource(outputStream, b.getDataAsStream());
                } else {
                    outputStream.write(bin.getValue().getBytes());
                }
                outputStream.flush();
            }
        } else {
            java.io.OutputStreamWriter out = new java.io.OutputStreamWriter(outputStream, "UTF-8");
            response.setContentType("text/xml; charset=UTF-8");
            resultMessage.write(out);
            out.flush();
            out.close();
        }
    } catch (NavajoException e) {
        logger.error("Error handling response: ", e);
    } catch (IOException e) {
        logger.error("Error handling response: ", e);
    } finally {
        if (outputStream != null) {
            try {
                outputStream.close();
            } catch (IOException e) {
                logger.warn("Stream closing problem", e);
            }
        }
    }
}
Also used : ServletOutputStream(javax.servlet.ServletOutputStream) NavajoException(com.dexels.navajo.document.NavajoException) OutputStreamWriter(java.io.OutputStreamWriter) OutputStreamWriter(java.io.OutputStreamWriter) Binary(com.dexels.navajo.document.types.Binary) IOException(java.io.IOException) Property(com.dexels.navajo.document.Property)

Example 60 with Binary

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

the class Access method getRequestNavajo.

public Binary getRequestNavajo() throws UserException {
    Binary b = new Binary();
    if (inDoc != null) {
        try {
            OutputStream os = b.getOutputStream();
            inDoc.write(os);
            os.close();
        } catch (IOException t) {
            throw new UserException(-1, t.getMessage(), t);
        }
    }
    return b;
}
Also used : OutputStream(java.io.OutputStream) Binary(com.dexels.navajo.document.types.Binary) IOException(java.io.IOException)

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