Search in sources :

Example 16 with IPipeLineSession

use of nl.nn.adapterframework.core.IPipeLineSession in project iaf by ibissource.

the class Json2XmlValidatorSmileyTest method xmlToJsonViaPipe.

public String xmlToJsonViaPipe(String xml) throws ConfigurationException, PipeStartException, PipeRunException {
    Json2XmlValidator json2xml = new Json2XmlValidator();
    json2xml.setWarn(false);
    json2xml.setSchema(xsd);
    json2xml.setRoot("x");
    json2xml.setOutputFormat(json2xml.FORMAT_JSON);
    json2xml.setThrowException(true);
    json2xml.registerForward(new PipeForward("success", null));
    json2xml.configure();
    json2xml.start();
    IPipeLineSession pipeLineSession = new PipeLineSessionBase();
    PipeRunResult prr = json2xml.doPipe(xml, pipeLineSession);
    return (String) prr.getResult();
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) Json2XmlValidator(nl.nn.adapterframework.pipes.Json2XmlValidator) PipeForward(nl.nn.adapterframework.core.PipeForward) IPipeLineSession(nl.nn.adapterframework.core.IPipeLineSession) PipeLineSessionBase(nl.nn.adapterframework.core.PipeLineSessionBase)

Example 17 with IPipeLineSession

use of nl.nn.adapterframework.core.IPipeLineSession in project iaf by ibissource.

the class Json2XmlValidatorSmileyTest method jsonToXmlViaPipe.

public String jsonToXmlViaPipe(String json) throws ConfigurationException, PipeStartException, PipeRunException {
    Json2XmlValidator json2xml = new Json2XmlValidator();
    json2xml.setWarn(false);
    json2xml.setSchema(xsd);
    json2xml.setRoot("x");
    json2xml.setThrowException(true);
    json2xml.registerForward(new PipeForward("success", null));
    json2xml.configure();
    json2xml.start();
    IPipeLineSession pipeLineSession = new PipeLineSessionBase();
    PipeRunResult prr = json2xml.doPipe(json, pipeLineSession);
    return (String) prr.getResult();
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) Json2XmlValidator(nl.nn.adapterframework.pipes.Json2XmlValidator) PipeForward(nl.nn.adapterframework.core.PipeForward) IPipeLineSession(nl.nn.adapterframework.core.IPipeLineSession) PipeLineSessionBase(nl.nn.adapterframework.core.PipeLineSessionBase)

Example 18 with IPipeLineSession

use of nl.nn.adapterframework.core.IPipeLineSession in project iaf by ibissource.

the class GetTibcoQueues method doPipeWithTimeoutGuarded.

public String doPipeWithTimeoutGuarded(Object input, IPipeLineSession session) throws PipeRunException {
    String result;
    String url_work;
    String authAlias_work;
    String userName_work;
    String password_work;
    String queueName_work = null;
    ParameterValueList pvl = null;
    if (getParameterList() != null) {
        ParameterResolutionContext prc = new ParameterResolutionContext((String) input, session);
        try {
            pvl = prc.getValues(getParameterList());
        } catch (ParameterException e) {
            throw new PipeRunException(this, getLogPrefix(session) + "exception on extracting parameters", e);
        }
    }
    url_work = getParameterValue(pvl, "url");
    if (url_work == null) {
        url_work = getUrl();
    }
    authAlias_work = getParameterValue(pvl, "authAlias");
    if (authAlias_work == null) {
        authAlias_work = getAuthAlias();
    }
    userName_work = getParameterValue(pvl, "userName");
    if (userName_work == null) {
        userName_work = getUserName();
    }
    password_work = getParameterValue(pvl, "password");
    if (password_work == null) {
        password_work = getPassword();
    }
    CredentialFactory cf = new CredentialFactory(authAlias_work, userName_work, password_work);
    Connection connection = null;
    Session jSession = null;
    TibjmsAdmin admin = null;
    try {
        admin = TibcoUtils.getActiveServerAdmin(url_work, cf);
        if (admin == null) {
            throw new PipeRunException(this, "could not find an active server");
        }
        String ldapUrl = getParameterValue(pvl, "ldapUrl");
        LdapSender ldapSender = null;
        if (StringUtils.isNotEmpty(ldapUrl)) {
            ldapSender = retrieveLdapSender(ldapUrl, cf);
        }
        queueName_work = getParameterValue(pvl, "queueName");
        if (StringUtils.isNotEmpty(queueName_work)) {
            String countOnly_work = getParameterValue(pvl, "countOnly");
            boolean countOnly = ("true".equalsIgnoreCase(countOnly_work) ? true : false);
            if (countOnly) {
                return getQueueMessageCountOnly(admin, queueName_work);
            }
        }
        ConnectionFactory factory = new com.tibco.tibjms.TibjmsConnectionFactory(url_work);
        connection = factory.createConnection(cf.getUsername(), cf.getPassword());
        jSession = connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
        if (StringUtils.isNotEmpty(queueName_work)) {
            String queueItem_work = getParameterValue(pvl, "queueItem");
            int qi;
            if (StringUtils.isNumeric(queueItem_work)) {
                qi = Integer.parseInt(queueItem_work);
            } else {
                qi = 1;
            }
            result = getQueueMessage(jSession, admin, queueName_work, qi, ldapSender);
        } else {
            String showAge_work = getParameterValue(pvl, "showAge");
            boolean showAge = ("true".equalsIgnoreCase(showAge_work) ? true : false);
            result = getQueuesInfo(jSession, admin, showAge, ldapSender);
        }
    } catch (Exception e) {
        String msg = getLogPrefix(session) + "exception on showing Tibco queues, url [" + url_work + "]" + (StringUtils.isNotEmpty(queueName_work) ? " queue [" + queueName_work + "]" : "");
        throw new PipeRunException(this, msg, e);
    } finally {
        if (admin != null) {
            try {
                admin.close();
            } catch (TibjmsAdminException e) {
                log.warn(getLogPrefix(session) + "exception on closing Tibjms Admin", e);
            }
        }
        if (connection != null) {
            try {
                connection.close();
            } catch (JMSException e) {
                log.warn(getLogPrefix(session) + "exception on closing connection", e);
            }
        }
    }
    return result;
}
Also used : ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) LdapSender(nl.nn.adapterframework.ldap.LdapSender) CredentialFactory(nl.nn.adapterframework.util.CredentialFactory) Connection(javax.jms.Connection) JMSException(javax.jms.JMSException) TibjmsAdmin(com.tibco.tibjms.admin.TibjmsAdmin) PipeRunException(nl.nn.adapterframework.core.PipeRunException) TibjmsAdminInvalidNameException(com.tibco.tibjms.admin.TibjmsAdminInvalidNameException) URISyntaxException(java.net.URISyntaxException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) UnknownHostException(java.net.UnknownHostException) JMSException(javax.jms.JMSException) TibjmsAdminException(com.tibco.tibjms.admin.TibjmsAdminException) ParameterException(nl.nn.adapterframework.core.ParameterException) ConnectionFactory(javax.jms.ConnectionFactory) TibjmsAdminException(com.tibco.tibjms.admin.TibjmsAdminException) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ParameterException(nl.nn.adapterframework.core.ParameterException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) Session(javax.jms.Session) IPipeLineSession(nl.nn.adapterframework.core.IPipeLineSession)

Example 19 with IPipeLineSession

use of nl.nn.adapterframework.core.IPipeLineSession in project iaf by ibissource.

the class TestPipeline method processMessage.

@SuppressWarnings({ "rawtypes", "unchecked" })
private PipeLineResult processMessage(IAdapter adapter, String message, boolean writeSecLogMessage) {
    String messageId = "testmessage" + Misc.createSimpleUUID();
    IPipeLineSession pls = new PipeLineSessionBase();
    Map ibisContexts = XmlUtils.getIbisContext(message);
    String technicalCorrelationId = null;
    if (ibisContexts != null) {
        String contextDump = "ibisContext:";
        for (Iterator it = ibisContexts.keySet().iterator(); it.hasNext(); ) {
            String key = (String) it.next();
            String value = (String) ibisContexts.get(key);
            if (log.isDebugEnabled()) {
                contextDump = contextDump + "\n " + key + "=[" + value + "]";
            }
            if (key.equals(IPipeLineSession.technicalCorrelationIdKey)) {
                technicalCorrelationId = value;
            } else {
                pls.put(key, value);
            }
        }
        if (log.isDebugEnabled()) {
            log.debug(contextDump);
        }
    }
    Date now = new Date();
    PipeLineSessionBase.setListenerParameters(pls, messageId, technicalCorrelationId, now, now);
    if (writeSecLogMessage) {
        secLog.info("message [" + message + "]");
    }
    return adapter.processMessage(messageId, message, pls);
}
Also used : Iterator(java.util.Iterator) IPipeLineSession(nl.nn.adapterframework.core.IPipeLineSession) HashMap(java.util.HashMap) Map(java.util.Map) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) Date(java.util.Date) PipeLineSessionBase(nl.nn.adapterframework.core.PipeLineSessionBase)

Example 20 with IPipeLineSession

use of nl.nn.adapterframework.core.IPipeLineSession in project iaf by ibissource.

the class XmlValidatorTest2 method validate.

@Override
public String validate(String rootNamespace, String schemaLocation, boolean addNamespaceToSchema, boolean ignoreUnknownNamespaces, String inputfile, String[] expectedFailureReasons) throws ConfigurationException, InstantiationException, IllegalAccessException, XmlValidatorException, PipeRunException, IOException {
    String testXml = inputfile != null ? getTestXml(inputfile + ".xml") : null;
    IPipeLineSession session = new PipeLineSessionBase();
    try {
        XmlValidator validator = getValidator(schemaLocation, addNamespaceToSchema, implementation);
        validator.setIgnoreUnknownNamespaces(ignoreUnknownNamespaces);
        PipeForward forward = validator.validate(testXml, session);
        evaluateResult(forward.getName(), session, null, expectedFailureReasons);
    } catch (Exception e) {
        evaluateResult(null, session, e, expectedFailureReasons);
        return "Invalid XML";
    }
    return null;
}
Also used : AbstractXmlValidator(nl.nn.adapterframework.validation.AbstractXmlValidator) XercesXmlValidator(nl.nn.adapterframework.validation.XercesXmlValidator) JavaxXmlValidator(nl.nn.adapterframework.validation.JavaxXmlValidator) IPipeLineSession(nl.nn.adapterframework.core.IPipeLineSession) PipeForward(nl.nn.adapterframework.core.PipeForward) PipeRunException(nl.nn.adapterframework.core.PipeRunException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) XmlValidatorException(nl.nn.adapterframework.validation.XmlValidatorException) PipeLineSessionBase(nl.nn.adapterframework.core.PipeLineSessionBase)

Aggregations

IPipeLineSession (nl.nn.adapterframework.core.IPipeLineSession)20 PipeLineSessionBase (nl.nn.adapterframework.core.PipeLineSessionBase)12 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)7 SenderException (nl.nn.adapterframework.core.SenderException)6 IOException (java.io.IOException)5 Iterator (java.util.Iterator)4 Map (java.util.Map)4 PipeRunException (nl.nn.adapterframework.core.PipeRunException)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 ParameterException (nl.nn.adapterframework.core.ParameterException)3 PipeForward (nl.nn.adapterframework.core.PipeForward)3 TimeOutException (nl.nn.adapterframework.core.TimeOutException)3 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)3 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)3 TibjmsAdmin (com.tibco.tibjms.admin.TibjmsAdmin)2 TibjmsAdminException (com.tibco.tibjms.admin.TibjmsAdminException)2 Enumeration (java.util.Enumeration)2 Connection (javax.jms.Connection)2