Search in sources :

Example 91 with PipeRunException

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

the class ValidatorTestBase method getSchemasProvider.

public SchemasProvider getSchemasProvider(final String schemaLocation, final boolean addNamespaceToSchema) {
    return new SchemasProvider() {

        public Set<XSD> getXsds() throws ConfigurationException {
            Set<XSD> xsds = new HashSet<XSD>();
            // if (StringUtils.isNotEmpty(getNoNamespaceSchemaLocation())) {
            // XSD xsd = new XSD();
            // xsd.setClassLoader(classLoader);
            // xsd.setNoNamespaceSchemaLocation(getNoNamespaceSchemaLocation());
            // xsd.setResource(getNoNamespaceSchemaLocation());
            // xsd.init();
            // xsds.add(xsd);
            // } else {
            String[] split = schemaLocation.trim().split("\\s+");
            if (split.length % 2 != 0)
                throw new ConfigurationException("The schema must exist from an even number of strings, but it is " + schemaLocation);
            for (int i = 0; i < split.length; i += 2) {
                XSD xsd = new XSD();
                xsd.setClassLoader(this.getClass().getClassLoader());
                xsd.setNamespace(split[i]);
                xsd.setResource(split[i + 1]);
                xsd.setAddNamespaceToSchema(addNamespaceToSchema);
                // xsd.setImportedSchemaLocationsToIgnore(getImportedSchemaLocationsToIgnore());
                // xsd.setUseBaseImportedSchemaLocationsToIgnore(isUseBaseImportedSchemaLocationsToIgnore());
                // xsd.setImportedNamespacesToIgnore(getImportedNamespacesToIgnore());
                xsd.init();
                xsds.add(xsd);
            }
            // }
            return xsds;
        }

        @Override
        public List<Schema> getSchemas() throws ConfigurationException {
            Set<XSD> xsds = getXsds();
            xsds = SchemaUtils.getXsdsRecursive(xsds);
            // checkRootValidations(xsds);
            try {
                Map<String, Set<XSD>> xsdsGroupedByNamespace = SchemaUtils.getXsdsGroupedByNamespace(xsds, false);
                xsds = SchemaUtils.mergeXsdsGroupedByNamespaceToSchemasWithoutIncludes(this.getClass().getClassLoader(), xsdsGroupedByNamespace, null);
            } catch (Exception e) {
                throw new ConfigurationException("could not merge schema's", e);
            }
            List<Schema> schemas = new ArrayList<Schema>();
            SchemaUtils.sortByDependencies(xsds, schemas);
            return schemas;
        }

        @Override
        public String getSchemasId() throws ConfigurationException {
            return schemaLocation;
        }

        @Override
        public String getSchemasId(IPipeLineSession session) throws PipeRunException {
            return null;
        }

        @Override
        public List<Schema> getSchemas(IPipeLineSession session) throws PipeRunException {
            return null;
        }
    };
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ArrayList(java.util.ArrayList) PipeRunException(nl.nn.adapterframework.core.PipeRunException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) IPipeLineSession(nl.nn.adapterframework.core.IPipeLineSession) HashSet(java.util.HashSet)

Example 92 with PipeRunException

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

the class AbstractXmlValidator method validate.

public String validate(Object input, IPipeLineSession session, String logPrefix, XMLReader parser, XMLFilterImpl filter, ValidationContext context) throws XmlValidatorException, PipeRunException, ConfigurationException {
    if (filter != null) {
        filter.setContentHandler(context.getContentHandler());
        filter.setErrorHandler(context.getErrorHandler());
    } else {
        parser.setContentHandler(context.getContentHandler());
        parser.setErrorHandler(context.getErrorHandler());
    }
    InputSource is = getInputSource(input);
    try {
        parser.parse(is);
    } catch (Exception e) {
        return finalizeValidation(context, session, e);
    }
    return finalizeValidation(context, session, null);
}
Also used : InputSource(org.xml.sax.InputSource) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) FileNotFoundException(java.io.FileNotFoundException) SAXParseException(org.xml.sax.SAXParseException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 93 with PipeRunException

use of nl.nn.adapterframework.core.PipeRunException 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 94 with PipeRunException

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

the class TestPipeline method postTestPipeLine.

@POST
@RolesAllowed({ "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/test-pipeline")
@Relation("pipeline")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response postTestPipeLine(MultipartFormDataInput input) throws ApiException, PipeRunException {
    Map<String, Object> result = new HashMap<String, Object>();
    IbisManager ibisManager = getIbisManager();
    if (ibisManager == null) {
        throw new ApiException("Config not found!");
    }
    String message = null, fileEncoding = null, fileName = null;
    InputStream file = null;
    IAdapter adapter = null;
    Map<String, List<InputPart>> inputDataMap = input.getFormDataMap();
    try {
        if (inputDataMap.get("message") != null)
            message = inputDataMap.get("message").get(0).getBodyAsString();
        if (inputDataMap.get("encoding") != null)
            fileEncoding = inputDataMap.get("encoding").get(0).getBodyAsString();
        if (inputDataMap.get("adapter") != null) {
            String adapterName = inputDataMap.get("adapter").get(0).getBodyAsString();
            adapter = ibisManager.getRegisteredAdapter(adapterName);
        }
        if (inputDataMap.get("file") != null) {
            file = inputDataMap.get("file").get(0).getBody(InputStream.class, null);
            MultivaluedMap<String, String> headers = inputDataMap.get("file").get(0).getHeaders();
            String[] contentDispositionHeader = headers.getFirst("Content-Disposition").split(";");
            for (String name : contentDispositionHeader) {
                if ((name.trim().startsWith("filename"))) {
                    String[] tmp = name.split("=");
                    fileName = tmp[1].trim().replaceAll("\"", "");
                }
            }
            if (fileEncoding == null || fileEncoding.isEmpty())
                fileEncoding = Misc.DEFAULT_INPUT_STREAM_ENCODING;
            if (StringUtils.endsWithIgnoreCase(fileName, ".zip")) {
                try {
                    processZipFile(result, file, fileEncoding, adapter, secLogMessage);
                } catch (Exception e) {
                    throw new PipeRunException(this, getLogPrefix(null) + "exception on processing zip file", e);
                }
            } else {
                message = Misc.streamToString(file, "\n", fileEncoding, false);
            }
        }
    } catch (IOException e) {
        return Response.status(Response.Status.BAD_REQUEST).build();
    }
    if (fileEncoding == null || StringUtils.isEmpty(fileEncoding))
        fileEncoding = Misc.DEFAULT_INPUT_STREAM_ENCODING;
    if (adapter == null && (message == null && file == null)) {
        return Response.status(Response.Status.BAD_REQUEST).build();
    }
    if (StringUtils.isNotEmpty(message)) {
        try {
            PipeLineResult plr = processMessage(adapter, message, secLogMessage);
            result.put("state", plr.getState());
            result.put("result", plr.getResult());
        } catch (Exception e) {
            throw new PipeRunException(this, getLogPrefix(null) + "exception on sending message", e);
        }
    }
    return Response.status(Response.Status.CREATED).entity(result).build();
}
Also used : IbisManager(nl.nn.adapterframework.configuration.IbisManager) HashMap(java.util.HashMap) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) PipeRunException(nl.nn.adapterframework.core.PipeRunException) IOException(java.io.IOException) PipeLineResult(nl.nn.adapterframework.core.PipeLineResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException) List(java.util.List) IAdapter(nl.nn.adapterframework.core.IAdapter) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Example 95 with PipeRunException

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

the class ShowConfig method retrieveAllConfigs.

private String retrieveAllConfigs(IPipeLineSession session) throws PipeRunException {
    List<String> jmsRealms = JmsRealmFactory.getInstance().getRegisteredDatasourceRealmNamesAsList();
    XmlBuilder configsXML = new XmlBuilder("configs");
    for (int i = 0; i < jmsRealms.size(); i++) {
        XmlBuilder configXML = new XmlBuilder("config");
        String jr = jmsRealms.get(i);
        configXML.addAttribute("jmsRealm", jr);
        FixedQuerySender qs = (FixedQuerySender) ibisContext.createBeanAutowireByName(FixedQuerySender.class);
        try {
            qs.setName("QuerySender");
            qs.setJmsRealm(jr);
            qs.setQueryType("select");
            qs.setQuery("SELECT NAME, VERSION, FILENAME, CRE_TYDST, RUSER, ACTIVECONFIG, AUTORELOAD FROM IBISCONFIG WHERE ACTIVECONFIG = '" + qs.getDbmsSupport().getBooleanValue(true) + "' ORDER BY NAME");
            qs.setBlobSmartGet(true);
            qs.setIncludeFieldDefinition(false);
            qs.configure();
            qs.open();
            ParameterResolutionContext prc = new ParameterResolutionContext("dummy", session);
            String queryResult = qs.sendMessage("dummy", "dummy", prc);
            configXML.setValue(queryResult, false);
        } catch (Throwable t) {
            throw new PipeRunException(this, getLogPrefix(session) + "Error occured on executing jdbc query", t);
        } finally {
            qs.close();
        }
        configsXML.addSubElement(configXML);
    }
    return configsXML.toXML();
}
Also used : PipeRunException(nl.nn.adapterframework.core.PipeRunException) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) FixedQuerySender(nl.nn.adapterframework.jdbc.FixedQuerySender)

Aggregations

PipeRunException (nl.nn.adapterframework.core.PipeRunException)101 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)65 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)40 IOException (java.io.IOException)34 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)32 PipeForward (nl.nn.adapterframework.core.PipeForward)20 ParameterException (nl.nn.adapterframework.core.ParameterException)16 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)13 Parameter (nl.nn.adapterframework.parameters.Parameter)12 InputStream (java.io.InputStream)10 File (java.io.File)9 Map (java.util.Map)9 ParameterList (nl.nn.adapterframework.parameters.ParameterList)8 FixedQuerySender (nl.nn.adapterframework.jdbc.FixedQuerySender)7 DomBuilderException (nl.nn.adapterframework.util.DomBuilderException)7 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)6 PipeStartException (nl.nn.adapterframework.core.PipeStartException)6 ArrayList (java.util.ArrayList)5 ZipInputStream (java.util.zip.ZipInputStream)5 IAdapter (nl.nn.adapterframework.core.IAdapter)5