Search in sources :

Example 91 with Navajo

use of com.dexels.navajo.document.Navajo in project navajo by Dexels.

the class BaseNavajoImpl method appendDocBuffer.

/**
 * @deprecated
 */
@Override
@Deprecated
public void appendDocBuffer(Object d) {
    Navajo n = (Navajo) d;
    List<Message> msgs = n.getAllMessages();
    for (int i = 0; i < msgs.size(); i++) {
        Message m = msgs.get(i);
        addMessage(m.copy(this));
    }
}
Also used : Message(com.dexels.navajo.document.Message) Navajo(com.dexels.navajo.document.Navajo)

Example 92 with Navajo

use of com.dexels.navajo.document.Navajo in project navajo by Dexels.

the class BaseHeaderImpl method main.

public static void main(String[] args) {
    System.setProperty("com.dexels.navajo.DocumentImplementation", "com.dexels.navajo.document.nanoimpl.NavajoFactoryImpl");
    Navajo n = NavajoFactory.getInstance().createNavajo();
    Header h = NavajoFactory.getInstance().createHeader(n, "aap", "noot", "mies", -1);
    n.addHeader(h);
}
Also used : Header(com.dexels.navajo.document.Header) Navajo(com.dexels.navajo.document.Navajo)

Example 93 with Navajo

use of com.dexels.navajo.document.Navajo in project navajo by Dexels.

the class BirtUtils method main.

public static void main(String[] args) throws Exception {
    System.out.println("***IS IT A BIRT?***");
    // Change the path to the file to match your filesystem
    FileInputStream fis = new java.io.FileInputStream("C:/Users/Robin/Documents/Test.xml");
    Navajo navajo = NavajoFactory.getInstance().createNavajo(fis);
    Binary template = null;
    BirtUtils report = new BirtUtils();
    Binary result = report.createEmptyReport(navajo, template);
    BinaryOpener bo = BinaryOpenerFactory.getInstance();
    bo.open(result);
}
Also used : Navajo(com.dexels.navajo.document.Navajo) Binary(com.dexels.navajo.document.types.Binary) FileInputStream(java.io.FileInputStream) BinaryOpener(com.dexels.navajo.document.BinaryOpener)

Example 94 with Navajo

use of com.dexels.navajo.document.Navajo in project navajo by Dexels.

the class NavajoContextInstanceFactory method readResources.

private Map<String, Message> readResources(File resource, Map<String, Set<String>> aliases) {
    Map<String, Message> result = new HashMap<String, Message>();
    FileReader fr = null;
    String deployment = repositoryInstance.getDeployment();
    try {
        fr = new FileReader(resource);
        Navajo n = NavajoFactory.getInstance().createNavajo(fr);
        Message resources = n.getMessage("datasources");
        Message deployments = n.getMessage("deployments");
        Message aliasMessage = n.getMessage("alias");
        if (resources != null) {
            logger.warn("In datasource definitions, please use 'resources' instead of 'datasources' as top level message name");
        } else {
            resources = n.getMessage("resources");
        }
        appendResources(aliases, result, resources, aliasMessage, null);
        logger.info("# of (deployment independent): resources {}", result.size());
        if (deployment != null && deployments != null) {
            for (Message deploymentMessage : deployments.getAllMessages()) {
                String name = deploymentMessage.getName();
                if (name.equals(deployment)) {
                    Message deploymentResources = deploymentMessage.getMessage("resources");
                    Message deploymentAliasMessage = deploymentMessage.getMessage("alias");
                    Message aliasConditionalMessage = deploymentMessage.getMessage("alias_conditional");
                    appendResources(aliases, result, deploymentResources, deploymentAliasMessage, aliasConditionalMessage);
                } else {
                    logger.debug("Ignoring not-matching datasource ({} vs {})", name, deployment);
                }
            }
        } else {
            logger.warn("No deployment whatsoever, ignoring all deployment specific sources. My deployment: {}", deployment);
            if (deployments != null) {
                deployments.write(System.err);
            } else {
                logger.warn("No deployments message either!");
            }
        }
    } catch (FileNotFoundException e) {
        logger.debug("Problem reading file: {}", resource, e);
    } finally {
        if (fr != null) {
            try {
                fr.close();
            } catch (IOException e) {
                logger.debug("Problem closing file: {}", resource, e);
            }
        }
    }
    return result;
}
Also used : Message(com.dexels.navajo.document.Message) HashMap(java.util.HashMap) FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) Navajo(com.dexels.navajo.document.Navajo) IOException(java.io.IOException)

Example 95 with Navajo

use of com.dexels.navajo.document.Navajo in project navajo by Dexels.

the class TmlHttpServlet method doPost.

/**
 * Handle a request.
 *
 * @param request
 * @param response
 * @throws IOException
 * @throws ServletException
 */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    MDC.clear();
    Date created = new java.util.Date();
    long start = created.getTime();
    String sendEncoding = request.getHeader("Accept-Encoding");
    String recvEncoding = request.getHeader("Content-Encoding");
    if (sendEncoding != null) {
        MDC.put("Accept-Encoding", sendEncoding);
    }
    if (recvEncoding != null) {
        MDC.put("Content-Encoding", recvEncoding);
    }
    DispatcherInterface dis = null;
    BufferedReader r = null;
    BufferedWriter out = null;
    try {
        Navajo in = null;
        if (streamingMode) {
            if (sendEncoding != null && sendEncoding.equals(COMPRESS_JZLIB)) {
                r = new BufferedReader(new java.io.InputStreamReader(new InflaterInputStream(request.getInputStream()), "UTF-8"));
            } else if (sendEncoding != null && sendEncoding.equals(COMPRESS_GZIP)) {
                r = new BufferedReader(new java.io.InputStreamReader(new java.util.zip.GZIPInputStream(request.getInputStream()), "UTF-8"));
            } else {
                r = new BufferedReader(request.getReader());
            }
            in = NavajoFactory.getInstance().createNavajo(r);
            r.close();
            r = null;
        } else {
            logger.info("Warning: Using non-streaming mode for " + request.getRequestURI() + ", file written: " + logfileIndex + ", total size: " + bytesWritten);
            InputStream is = request.getInputStream();
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            copyResource(bos, is);
            is.close();
            bos.close();
            byte[] bytes = bos.toByteArray();
            try {
                if (sendEncoding != null && sendEncoding.equals(COMPRESS_JZLIB)) {
                    r = new BufferedReader(new java.io.InputStreamReader(new InflaterInputStream(new ByteArrayInputStream(bytes)), "UTF-8"));
                } else if (sendEncoding != null && sendEncoding.equals(COMPRESS_GZIP)) {
                    r = new BufferedReader(new java.io.InputStreamReader(new java.util.zip.GZIPInputStream(new ByteArrayInputStream(bytes)), "UTF-8"));
                } else {
                    r = new BufferedReader(new java.io.InputStreamReader(new ByteArrayInputStream(bytes), "UTF-8"));
                }
                in = NavajoFactory.getInstance().createNavajo(r);
                if (in == null) {
                    throw new Exception("Invalid Navajo");
                }
                r.close();
                r = null;
            } catch (Throwable t) {
                // Write request to temp file.
                File f = DispatcherFactory.getInstance().getTempDir();
                if (f != null) {
                    bytesWritten += bytes.length;
                    logfileIndex++;
                    FileOutputStream fos = new FileOutputStream(new File(f, "request-" + logfileIndex));
                    copyResource(fos, new ByteArrayInputStream(bytes));
                    fos.close();
                    PrintWriter fw = new PrintWriter(new FileWriter(new File(f, "exception-" + logfileIndex)));
                    t.printStackTrace(fw);
                    fw.flush();
                    fw.close();
                }
                dumHttp(request, logfileIndex, f);
                throw new ServletException(t);
            }
        }
        long stamp = System.currentTimeMillis();
        int pT = (int) (stamp - start);
        if (in == null) {
            throw new ServletException("Invalid request.");
        }
        Header header = in.getHeader();
        if (header == null) {
            throw new ServletException("Empty Navajo header.");
        }
        dis = DispatcherFactory.getInstance();
        if (dis == null) {
            System.err.println("SERIOUS: No dispatcher found. The navajo context did not initialize properly, check the logs to find out why!");
            return;
        }
        // Check for certificate.
        Object certObject = request.getAttribute("javax.servlet.request.X509Certificate");
        // Call Dispatcher with parsed TML document as argument.
        String ip = request.getHeader("X-Forwarded-For");
        if (ip == null || ip.equals("")) {
            ip = request.getRemoteAddr();
        }
        ClientInfo clientInfo = new ClientInfo(ip, "unknown", recvEncoding, pT, (recvEncoding != null && (recvEncoding.equals(COMPRESS_GZIP) || recvEncoding.equals(COMPRESS_JZLIB))), (sendEncoding != null && (sendEncoding.equals(COMPRESS_GZIP) || sendEncoding.equals(COMPRESS_JZLIB))), request.getContentLength(), created);
        String instance = determineInstanceFromRequest(request);
        Navajo outDoc = handleTransaction(instance, dis, in, certObject, clientInfo);
        response.setContentType("text/xml; charset=UTF-8");
        response.setHeader("Accept-Ranges", "none");
        if (recvEncoding != null && recvEncoding.equals(COMPRESS_JZLIB)) {
            response.setHeader("Content-Encoding", COMPRESS_JZLIB);
            out = new BufferedWriter(new OutputStreamWriter(new DeflaterOutputStream(response.getOutputStream()), "UTF-8"));
        } else if (recvEncoding != null && recvEncoding.equals(COMPRESS_GZIP)) {
            response.setHeader("Content-Encoding", COMPRESS_GZIP);
            out = new BufferedWriter(new OutputStreamWriter(new java.util.zip.GZIPOutputStream(response.getOutputStream()), "UTF-8"));
        } else {
            out = new BufferedWriter(response.getWriter());
        }
        outDoc.write(out);
        out.flush();
        out.close();
        if (in.getHeader() != null && outDoc.getHeader() != null && !Dispatcher.isSpecialwebservice(in.getHeader().getRPCName())) {
            statLogger.info("Finished {} ({}) in {}ms", outDoc.getHeader().getHeaderAttribute("accessId"), in.getHeader().getRPCName(), (System.currentTimeMillis() - start));
        }
        out = null;
    } catch (Throwable e) {
        logger.error("Error: ", e);
        dumHttp(request, -1, null);
        if (e instanceof FatalException) {
            FatalException fe = (FatalException) e;
            if (fe.getMessage().equals("500.13")) {
                // Server too busy.
                throw new ServletException("500.13", e);
            }
        }
        throw new ServletException(e);
    } finally {
        dis = null;
        if (r != null) {
            try {
                r.close();
            } catch (Exception e) {
            // NOT INTERESTED.
            }
        }
        if (out != null) {
            try {
                out.close();
            } catch (Exception e) {
            // NOT INTERESTED.
            }
        }
    }
}
Also used : FileWriter(java.io.FileWriter) BufferedWriter(java.io.BufferedWriter) ServletException(javax.servlet.ServletException) DeflaterOutputStream(com.jcraft.jzlib.DeflaterOutputStream) PrintWriter(java.io.PrintWriter) FatalException(com.dexels.navajo.script.api.FatalException) InflaterInputStream(com.jcraft.jzlib.InflaterInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InflaterInputStream(com.jcraft.jzlib.InflaterInputStream) InputStream(java.io.InputStream) Navajo(com.dexels.navajo.document.Navajo) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Date(java.util.Date) FatalException(com.dexels.navajo.script.api.FatalException) ServletException(javax.servlet.ServletException) NavajoException(com.dexels.navajo.document.NavajoException) IOException(java.io.IOException) Header(com.dexels.navajo.document.Header) DispatcherInterface(com.dexels.navajo.server.DispatcherInterface) ByteArrayInputStream(java.io.ByteArrayInputStream) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) OutputStreamWriter(java.io.OutputStreamWriter) ClientInfo(com.dexels.navajo.script.api.ClientInfo) File(java.io.File)

Aggregations

Navajo (com.dexels.navajo.document.Navajo)258 Message (com.dexels.navajo.document.Message)131 Test (org.junit.Test)109 Property (com.dexels.navajo.document.Property)86 NavajoException (com.dexels.navajo.document.NavajoException)31 Access (com.dexels.navajo.script.api.Access)30 IOException (java.io.IOException)28 StringWriter (java.io.StringWriter)27 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)26 FunctionInterface (com.dexels.navajo.expression.api.FunctionInterface)25 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)22 Selection (com.dexels.navajo.document.Selection)22 Header (com.dexels.navajo.document.Header)20 Operand (com.dexels.navajo.document.Operand)20 InputStream (java.io.InputStream)17 UserException (com.dexels.navajo.script.api.UserException)16 Optional (java.util.Optional)16 FatalException (com.dexels.navajo.script.api.FatalException)14 SystemException (com.dexels.navajo.script.api.SystemException)14 ContextExpression (com.dexels.navajo.expression.api.ContextExpression)13