Package org.apache.synapse.config

Examples of org.apache.synapse.config.Entry


        boolean reCreate = false;
        // if any of the schemas are not loaded, or have expired, load or re-load them
        for (Value schemaKey : schemaKeys) {
            // Derive actual key from message context
            String propKey = schemaKey.evaluateValue(synCtx);
            Entry dp = synCtx.getConfiguration().getEntryDefinition(propKey);
            if (dp != null && dp.isDynamic()) {
                if (!dp.isCached() || dp.isExpired()) {
                    reCreate = true;       // request re-initialization of Validator
                }
            }
        }
View Full Code Here


        // to access the registry entry during mediator initialization then for non-dynamic entries
        // this could be done just the once during mediator initialization.

        // Derive actual key from xpath expression or get static key
        String generatedScriptKey = key.evaluateValue(synCtx);
        Entry entry = synCtx.getConfiguration().getEntryDefinition(generatedScriptKey);
        boolean needsReload = (entry != null) && entry.isDynamic() &&
                (!entry.isCached() || entry.isExpired());
        synchronized (resourceLock) {
            if (scriptSourceCode == null || needsReload) {
                Object o = synCtx.getEntry(generatedScriptKey);
                if (o instanceof OMElement) {
                    scriptSourceCode = ((OMElement) (o)).getText();
                    scriptEngine.eval(scriptSourceCode);
                } else if (o instanceof String) {
                    scriptSourceCode = (String) o;
                    scriptEngine.eval(scriptSourceCode);
                } else if (o instanceof OMText) {

                    DataHandler dataHandler = (DataHandler) ((OMText) o).getDataHandler();
                    if (dataHandler != null) {
                        BufferedReader reader = null;
                        try {
                            reader = new BufferedReader(
                                    new InputStreamReader(dataHandler.getInputStream()));
                            scriptEngine.eval(reader);

                        } catch (IOException e) {
                            handleException("Error in reading script as a stream ", e, synCtx);
                        } finally {

                            if (reader != null) {
                                try {
                                    reader.close();
                                } catch (IOException e) {
                                    handleException("Error in closing input stream ", e, synCtx);
                                }
                            }

                        }
                    }
                }

            }
        }

        // load <include /> scripts; reload each script if needed
        for (Value includeKey : includes.keySet()) {

            String includeSourceCode = (String) includes.get(includeKey);

            String generatedKey = includeKey.evaluateValue(synCtx);

            Entry includeEntry = synCtx.getConfiguration().getEntryDefinition(generatedKey);
            boolean includeEntryNeedsReload = (includeEntry != null) && includeEntry.isDynamic()
                    && (!includeEntry.isCached() || includeEntry.isExpired());
            synchronized (resourceLock) {
                if (includeSourceCode == null || includeEntryNeedsReload) {
                    log.debug("Re-/Loading the include script with key " + includeKey);
                    Object o = synCtx.getEntry(generatedKey);
                    if (o instanceof OMElement) {
View Full Code Here

        entries.put(key, entry);
        return this;
    }
   
    public TestMessageContextBuilder addEntry(String key, URL url) {
        Entry entry = new Entry();
        entry.setType(Entry.URL_SRC);
        entry.setSrc(url);
        entries.put(key, entry);
        return this;
    }
View Full Code Here

        // get expression from generatedQueryKey
        XQPreparedExpression cachedPreparedExpression = null;

        if (generatedQueryKey != null && !"".equals(generatedQueryKey)) {

            Entry dp = synCtx.getConfiguration().getEntryDefinition(generatedQueryKey);
            // if the queryKey refers to a dynamic resource
            if (dp != null && dp.isDynamic()) {
                if (!dp.isCached() || dp.isExpired()) {
                    reLoad = true;
                }
            }
        }
View Full Code Here

                } else if (policyKey != null) {

                    // If the policy has specified as a registry key.
                    // load or re-load policy from registry or local entry if not already available

                    Entry entry = synCtx.getConfiguration().getEntryDefinition(policyKey);
                    if (entry == null) {
                        handleException("Cannot find throttling policy using key : "
                                + policyKey, synCtx);

                    } else {
                        boolean reCreate = false;
                        // if the key refers to a dynamic resource
                        if (entry.isDynamic()) {
                            if ((!entry.isCached() || entry.isExpired()) &&
                                    version != entry.getVersion()) {
                                reCreate = true;
                                version = entry.getVersion();
                            }
                        }
                        if (reCreate || throttle == null) {
                            Object entryValue = synCtx.getEntry(policyKey);
                            if (entryValue == null) {
View Full Code Here

        return proxy;
    }

    public static Entry defineEntry(SynapseConfiguration config, OMElement elem,
                                    Properties properties) {
        Entry entry = null;

        try {
            entry = EntryFactory.createEntry(elem, properties);
            if (entry != null) {
                config.addEntry(entry.getKey(), entry);
            }
        } catch (Exception e) {
            String msg = "Local entry configuration: " + elem.getAttributeValue((
                    new QName(XMLConfigConstants.NULL_NAMESPACE, "key"))) + " cannot be built";
            handleConfigurationError(SynapseConstants.FAIL_SAFE_MODE_LOCALENTRIES, msg, e);
View Full Code Here

                if (endpoint.getFileName() == null) {
                    OMElement endpointElem = EndpointSerializer.getElementFromEndpoint(endpoint);
                    definitions.addChild(endpointElem);
                }
            } else if (o instanceof Entry) {
                Entry entry = (Entry) o;
                if (entry.getFileName() == null) {
                    if ((SynapseConstants.SERVER_HOST.equals(entry.getKey())
                            || SynapseConstants.SERVER_IP.equals(entry.getKey()))
                            || entry.getType() == Entry.REMOTE_ENTRY) {
                        continue;
                    }

                    EntrySerializer.serializeEntry(entry, definitions);
                }
View Full Code Here

        } else if (o instanceof Template) {
            return serializeTemplate((Template) o, synapseConfig, parent);
        } else if (o instanceof Endpoint) {
            return serializeEndpoint((Endpoint) o, synapseConfig, parent);
        } else if (o instanceof Entry) {
            Entry entry = (Entry) o;
            if ((SynapseConstants.SERVER_HOST.equals(entry.getKey())
                    || SynapseConstants.SERVER_IP.equals(entry.getKey()))
                    || entry.getType() == Entry.REMOTE_ENTRY) {
                return null;
            }

            File entriesDir = createDirectory(currentDirectory,
                    MultiXMLConfigurationBuilder.LOCAL_ENTRY_DIR);
            OMElement entryElem = EntrySerializer.serializeEntry(entry, null);

            String fileName = entry.getFileName();
            if (fileName != null) {
                if (currentDirectory == rootDirectory) {
                    handleDeployment(entriesDir, fileName, entry.getKey(),
                            synapseConfig.getArtifactDeploymentStore());
                }
                File entryFile  = new File(entriesDir, fileName);
                writeToFile(entryElem, entryFile);
            } else if (parent != null) {
View Full Code Here

            handleException("The 'key' attribute is required for a local registry entry");
            return null;

        } else {

            Entry entry = new Entry(key.getAttributeValue());

            OMElement descriptionElem = elem.getFirstChildWithName(DESCRIPTION_Q);
            if (descriptionElem != null) {
                entry.setDescription(descriptionElem.getText());
                descriptionElem.detach();
            }

            String src  = elem.getAttributeValue(
                    new QName(XMLConfigConstants.NULL_NAMESPACE, "src"));

            // if a src attribute is present, this is a URL source resource,
            // it would now be loaded from the URL source, as all static properties
            // are initialized at startup
            if (src != null) {
                try {
                    entry.setSrc(new URL(src.trim()));
                    entry.setType(Entry.URL_SRC);
                    entry.setValue(SynapseConfigUtils.getObject(entry.getSrc(), properties));
                } catch (MalformedURLException e) {
                    handleException("The entry with key : " + key + " refers to an invalid URL");
                }

            } else {
                OMNode    nodeValue = elem.getFirstOMChild();
                OMElement elemValue = elem.getFirstElement();

                if (elemValue != null) {
                    entry.setType(Entry.INLINE_XML);
                    entry.setValue(elemValue);
                } else if (nodeValue != null && nodeValue instanceof OMText) {
                    entry.setType(Entry.INLINE_TEXT);
                  entry.setValue(elem.getText());
        }
            }

            return entry;
        }
View Full Code Here

        String serializedSrc = "<localEntry xmlns=\"http://ws.apache.org/ns/synapse\" " +
                "key=\"" + key + "\"><![CDATA[" + text + "]]></localEntry>";

        try {
            OMElement elem = parseXMLString(entrySrc, true);
            Entry entry = EntryFactory.createEntry(elem, new Properties());
            assertEquals(key, entry.getKey());
            assertEquals(Entry.INLINE_TEXT, entry.getType());
            assertEquals(text, (String) entry.getValue());

            OMElement serialization = EntrySerializer.serializeEntry(entry, null);
            OMElement expectedSerialization = parseXMLString(serializedSrc, false);
            assertTrue(compare(expectedSerialization, serialization));
        } catch (XMLStreamException e) {
View Full Code Here

TOP

Related Classes of org.apache.synapse.config.Entry

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.