Search in sources :

Example 61 with LogEvent

use of org.jpos.util.LogEvent in project jPOS by jpos.

the class XMLPackager method unpack.

public synchronized void unpack(ISOComponent c, InputStream in) throws ISOException, IOException {
    LogEvent evt = new LogEvent(this, "unpack");
    try {
        if (!(c instanceof ISOMsg))
            throw new ISOException("Can't call packager on non Composite");
        while (// purge from possible previous error
        !stk.empty()) stk.pop();
        reader.parse(new InputSource(in));
        if (stk.empty())
            throw new ISOException("error parsing");
        ISOMsg m = (ISOMsg) c;
        ISOMsg m1 = (ISOMsg) stk.pop();
        m.merge(m1);
        m.setHeader(m1.getHeader());
        if (logger != null)
            evt.addMessage(m);
    } catch (ISOException e) {
        evt.addMessage(e);
        throw e;
    } catch (SAXException e) {
        evt.addMessage(e);
        throw new ISOException(e.toString());
    } finally {
        Logger.log(evt);
    }
}
Also used : InputSource(org.xml.sax.InputSource) LogEvent(org.jpos.util.LogEvent) SAXException(org.xml.sax.SAXException)

Example 62 with LogEvent

use of org.jpos.util.LogEvent in project jPOS by jpos.

the class XMLPackager method unpack.

public synchronized int unpack(ISOComponent c, byte[] b) throws ISOException {
    LogEvent evt = new LogEvent(this, "unpack");
    try {
        if (!(c instanceof ISOMsg))
            throw new ISOException("Can't call packager on non Composite");
        while (// purge from possible previous error
        !stk.empty()) stk.pop();
        InputSource src = new InputSource(new ByteArrayInputStream(b));
        reader.parse(src);
        if (stk.empty())
            throw new ISOException("error parsing");
        ISOMsg m = (ISOMsg) c;
        ISOMsg m1 = (ISOMsg) stk.pop();
        m.merge(m1);
        m.setHeader(m1.getHeader());
        if (logger != null)
            evt.addMessage(m);
        return b.length;
    } catch (ISOException e) {
        evt.addMessage(e);
        throw e;
    } catch (IOException e) {
        evt.addMessage(e);
        throw new ISOException(e.toString());
    } catch (SAXException e) {
        evt.addMessage(e);
        throw new ISOException(e.toString());
    } finally {
        Logger.log(evt);
    }
}
Also used : InputSource(org.xml.sax.InputSource) LogEvent(org.jpos.util.LogEvent) SAXException(org.xml.sax.SAXException)

Example 63 with LogEvent

use of org.jpos.util.LogEvent in project jPOS by jpos.

the class Q2 method waitForChanges.

private boolean waitForChanges(WatchService service) throws InterruptedException {
    WatchKey key = service.poll(SCAN_INTERVAL, TimeUnit.MILLISECONDS);
    if (key != null) {
        LogEvent evt = getLog().createInfo();
        for (WatchEvent<?> ev : key.pollEvents()) {
            if (ev.kind() == StandardWatchEventKinds.ENTRY_CREATE) {
                evt.addMessage(String.format("created %s/%s", deployDir.getName(), ev.context()));
            } else if (ev.kind() == StandardWatchEventKinds.ENTRY_DELETE) {
                evt.addMessage(String.format("removed %s/%s", deployDir.getName(), ev.context()));
            } else if (ev.kind() == StandardWatchEventKinds.ENTRY_MODIFY) {
                evt.addMessage(String.format("modified %s/%s", deployDir.getName(), ev.context()));
            }
        }
        Logger.log(evt);
        if (!key.reset()) {
            getLog().warn(String.format("deploy directory '%s' no longer valid", deployDir.getAbsolutePath()));
            // deploy directory no longer valid
            return false;
        }
    }
    return true;
}
Also used : LogEvent(org.jpos.util.LogEvent) WatchKey(java.nio.file.WatchKey)

Example 64 with LogEvent

use of org.jpos.util.LogEvent in project jPOS by jpos.

the class Q2 method deploy.

private boolean deploy(File f) {
    LogEvent evt = log != null ? log.createInfo() : null;
    try {
        QEntry qentry = dirMap.get(f);
        SAXBuilder builder = createSAXBuilder();
        Document doc;
        if (decorator != null && !f.getName().equals(LOGGER_CONFIG)) {
            doc = decrypt(builder.build(new StringReader(decorator.decorateFile(f))));
        } else {
            doc = decrypt(builder.build(f));
        }
        Element rootElement = doc.getRootElement();
        String iuuid = rootElement.getAttributeValue("instance");
        if (iuuid != null) {
            UUID uuid = UUID.fromString(iuuid);
            if (!uuid.equals(getInstanceId())) {
                deleteFile(f, iuuid);
                return false;
            }
        }
        String enabledAttribute = rootElement.getAttributeValue("enabled", "true");
        if ("true".equalsIgnoreCase(enabledAttribute) || "yes".equalsIgnoreCase(enabledAttribute)) {
            if (evt != null)
                evt.addMessage("deploy: " + f.getCanonicalPath());
            Object obj = factory.instantiate(this, rootElement);
            qentry.setObject(obj);
            ObjectInstance instance = factory.createQBean(this, doc.getRootElement(), obj);
            qentry.setInstance(instance);
        } else if (evt != null) {
            evt.addMessage("deploy ignored (enabled='" + enabledAttribute + "'): " + f.getCanonicalPath());
        }
    } catch (InstanceAlreadyExistsException e) {
        /*
            * Ok, the file we tried to deploy, holds an object
            *  that already has been deployed.
            *  
            * Rename it out of the way.
            * 
            */
        tidyFileAway(f, DUPLICATE_EXTENSION);
        if (evt != null)
            evt.addMessage(e);
        return false;
    } catch (Exception e) {
        if (evt != null)
            evt.addMessage(e);
        tidyFileAway(f, ERROR_EXTENSION);
        // This will also save deploy error repeats...
        return false;
    } catch (Error e) {
        if (evt != null)
            evt.addMessage(e);
        tidyFileAway(f, ENV_EXTENSION);
        // This will also save deploy error repeats...
        return false;
    } finally {
        if (evt != null)
            Logger.log(evt);
    }
    return true;
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) LogEvent(org.jpos.util.LogEvent) Element(org.jdom2.Element) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) ObjectInstance(javax.management.ObjectInstance) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) GeneralSecurityException(java.security.GeneralSecurityException) BundleException(org.osgi.framework.BundleException) UnrecognizedOptionException(org.apache.commons.cli.UnrecognizedOptionException) SAXException(org.xml.sax.SAXException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ISOException(org.jpos.iso.ISOException) MissingArgumentException(org.apache.commons.cli.MissingArgumentException)

Example 65 with LogEvent

use of org.jpos.util.LogEvent in project jPOS by jpos.

the class Q2 method logVersion.

private void logVersion() {
    long now = System.currentTimeMillis();
    if (now - lastVersionLog > 3600000L) {
        LogEvent evt = getLog().createLogEvent("version");
        evt.addMessage(getVersionString());
        Logger.log(evt);
        lastVersionLog = now;
        while ((PGPHelper.checkLicense() & 0xE0000) != 0) relax();
    }
}
Also used : LogEvent(org.jpos.util.LogEvent)

Aggregations

LogEvent (org.jpos.util.LogEvent)189 Test (org.junit.Test)78 ConfigurationException (org.jpos.core.ConfigurationException)51 ISOMsg (org.jpos.iso.ISOMsg)41 SimpleMsg (org.jpos.util.SimpleMsg)40 NotFoundException (org.jpos.util.NameRegistrar.NotFoundException)38 ArrayList (java.util.ArrayList)24 IOException (java.io.IOException)18 SimpleConfiguration (org.jpos.core.SimpleConfiguration)14 CSChannel (org.jpos.iso.channel.CSChannel)12 Loggeable (org.jpos.util.Loggeable)11 Map (java.util.Map)9 ISOChannel (org.jpos.iso.ISOChannel)9 PostChannel (org.jpos.iso.channel.PostChannel)9 CTCSubFieldPackager (org.jpos.iso.packager.CTCSubFieldPackager)9 ISOFilter (org.jpos.iso.ISOFilter)8 BASE24TCPChannel (org.jpos.iso.channel.BASE24TCPChannel)8 PADChannel (org.jpos.iso.channel.PADChannel)8 ISOBaseValidatingPackager (org.jpos.iso.packager.ISOBaseValidatingPackager)8 EOFException (java.io.EOFException)7