Search in sources :

Example 41 with ConfigurationException

use of nl.nn.adapterframework.configuration.ConfigurationException in project iaf by ibissource.

the class SpringJmsConnector method configureEndpointConnection.

/* (non-Javadoc)
	 * @see nl.nn.adapterframework.configuration.IListenerConnector#configureReceiver(nl.nn.adapterframework.jms.PushingJmsListener)
	 */
public void configureEndpointConnection(final IPortConnectedListener jmsListener, ConnectionFactory connectionFactory, Destination destination, IbisExceptionListener exceptionListener, String cacheMode, int acknowledgeMode, boolean sessionTransacted, String messageSelector) throws ConfigurationException {
    super.configureEndpointConnection(jmsListener, connectionFactory, destination, exceptionListener);
    // Create the Message Listener Container manually.
    // This is needed, because otherwise the Spring Factory will
    // call afterPropertiesSet() on the object which will validate
    // that all required properties are set before we get a chance
    // to insert our dynamic values from the config. file.
    this.jmsContainer = createMessageListenerContainer();
    if (getReceiver().isTransacted()) {
        log.debug(getLogPrefix() + "setting transction manager to [" + txManager + "]");
        jmsContainer.setTransactionManager(txManager);
        if (getReceiver().getTransactionTimeout() > 0) {
            jmsContainer.setTransactionTimeout(getReceiver().getTransactionTimeout());
        }
        TX = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED);
    } else {
        log.debug(getLogPrefix() + "setting no transction manager");
    }
    if (sessionTransacted) {
        jmsContainer.setSessionTransacted(sessionTransacted);
    }
    if (StringUtils.isNotEmpty(messageSelector)) {
        jmsContainer.setMessageSelector(messageSelector);
    }
    // Initialize with a number of dynamic properties which come from the configuration file
    jmsContainer.setConnectionFactory(getConnectionFactory());
    jmsContainer.setDestination(getDestination());
    jmsContainer.setExceptionListener(this);
    if (getReceiver().getNumThreads() > 0) {
        jmsContainer.setMaxConcurrentConsumers(getReceiver().getNumThreads());
    } else {
        jmsContainer.setMaxConcurrentConsumers(1);
    }
    jmsContainer.setIdleTaskExecutionLimit(IDLE_TASK_EXECUTION_LIMIT);
    if (StringUtils.isNotEmpty(cacheMode)) {
        jmsContainer.setCacheLevelName(cacheMode);
    } else {
        if (getReceiver().isTransacted()) {
            jmsContainer.setCacheLevel(DEFAULT_CACHE_LEVEL_TRANSACTED);
        } else {
            jmsContainer.setCacheLevel(DEFAULT_CACHE_LEVEL_NON_TRANSACTED);
        }
    }
    if (acknowledgeMode >= 0) {
        jmsContainer.setSessionAcknowledgeMode(acknowledgeMode);
    }
    jmsContainer.setMessageListener(this);
    // and run the bean lifecycle methods.
    try {
        ((AutowireCapableBeanFactory) this.beanFactory).configureBean(this.jmsContainer, "proto-jmsContainer");
    } catch (BeansException e) {
        throw new ConfigurationException(getLogPrefix() + "Out of luck wiring up and configuring Default JMS Message Listener Container for JMS Listener [" + (getListener().getName() + "]"), e);
    }
    // Finally, set bean name to something we can make sense of
    if (getListener().getName() != null) {
        jmsContainer.setBeanName(getListener().getName());
    } else {
        jmsContainer.setBeanName(getReceiver().getName());
    }
}
Also used : DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) AutowireCapableBeanFactory(org.springframework.beans.factory.config.AutowireCapableBeanFactory) BeansException(org.springframework.beans.BeansException)

Example 42 with ConfigurationException

use of nl.nn.adapterframework.configuration.ConfigurationException in project iaf by ibissource.

the class SchemaUtils method xsdToXmlStreamWriter.

/**
 * Including a {@link nl.nn.adapterframework.validation.XSD} into an
 * {@link javax.xml.stream.XMLStreamWriter} while parsing it. It is parsed
 * (using a low level {@link javax.xml.stream.XMLEventReader} so that
 * certain things can be corrected on the fly.
 * @param xsd
 * @param xmlStreamWriter
 * @param standalone
 * When standalone the start and end document contants are ignored, hence
 * the xml declaration is ignored.
 * @param stripSchemaLocationFromImport
 * Useful when generating a WSDL which should contain all XSD's inline
 * (without includes or imports). The XSD might have an import with
 * schemaLocation to make it valid on it's own, when
 * stripSchemaLocationFromImport is true it will be removed.
 * @throws java.io.IOException
 * @throws javax.xml.stream.XMLStreamException
 */
public static void xsdToXmlStreamWriter(final XSD xsd, XMLStreamWriter xmlStreamWriter, boolean standalone, boolean stripSchemaLocationFromImport, boolean skipRootStartElement, boolean skipRootEndElement, List<Attribute> rootAttributes, List<Attribute> rootNamespaceAttributes, List<XMLEvent> imports, boolean noOutput) throws IOException, ConfigurationException {
    Map<String, String> namespacesToCorrect = new HashMap<String, String>();
    NamespaceCorrectingXMLStreamWriter namespaceCorrectingXMLStreamWriter = new NamespaceCorrectingXMLStreamWriter(xmlStreamWriter, namespacesToCorrect);
    final XMLStreamEventWriter streamEventWriter = new XMLStreamEventWriter(namespaceCorrectingXMLStreamWriter);
    InputStream in = null;
    in = xsd.getInputStream();
    if (in == null) {
        throw new IllegalStateException("" + xsd + " not found");
    }
    XMLEvent event = null;
    try {
        XMLEventReader er = XmlUtils.INPUT_FACTORY.createXMLEventReader(in, XmlUtils.STREAM_FACTORY_ENCODING);
        while (er.hasNext()) {
            event = er.nextEvent();
            switch(event.getEventType()) {
                case XMLStreamConstants.START_DOCUMENT:
                case XMLStreamConstants.END_DOCUMENT:
                    if (!standalone) {
                        continue;
                    }
                // fall through
                case XMLStreamConstants.SPACE:
                case XMLStreamConstants.COMMENT:
                    break;
                case XMLStreamConstants.START_ELEMENT:
                    StartElement startElement = event.asStartElement();
                    if (SCHEMA.equals(startElement.getName())) {
                        if (skipRootStartElement) {
                            continue;
                        }
                        if (rootAttributes != null) {
                            // Collect or write attributes of schema element.
                            if (noOutput) {
                                // First call to this method collecting
                                // schema attributes.
                                Iterator<Attribute> iterator = startElement.getAttributes();
                                while (iterator.hasNext()) {
                                    Attribute attribute = iterator.next();
                                    boolean add = true;
                                    for (Attribute attribute2 : rootAttributes) {
                                        if (XmlUtils.attributesEqual(attribute, attribute2)) {
                                            add = false;
                                        }
                                    }
                                    if (add) {
                                        rootAttributes.add(attribute);
                                    }
                                }
                                iterator = startElement.getNamespaces();
                                while (iterator.hasNext()) {
                                    Attribute attribute = iterator.next();
                                    boolean add = true;
                                    for (Attribute attribute2 : rootNamespaceAttributes) {
                                        if (XmlUtils.attributesEqual(attribute, attribute2)) {
                                            add = false;
                                        }
                                    }
                                    if (add) {
                                        rootNamespaceAttributes.add(attribute);
                                    }
                                }
                            } else {
                                // Second call to this method writing attributes
                                // from previous call.
                                startElement = XmlUtils.EVENT_FACTORY.createStartElement(startElement.getName().getPrefix(), startElement.getName().getNamespaceURI(), startElement.getName().getLocalPart(), rootAttributes.iterator(), rootNamespaceAttributes.iterator(), startElement.getNamespaceContext());
                            }
                        }
                        // (see http://www.w3.org/TR/xml-names/#ns-decl).
                        if (xsd.isAddNamespaceToSchema() && !xsd.getNamespace().equals("http://www.w3.org/XML/1998/namespace")) {
                            event = XmlUtils.mergeAttributes(startElement, Arrays.asList(new AttributeEvent(TNS, xsd.getNamespace()), new AttributeEvent(ELFORMDEFAULT, "qualified")).iterator(), Arrays.asList(XmlUtils.EVENT_FACTORY.createNamespace(xsd.getNamespace())).iterator(), XmlUtils.EVENT_FACTORY);
                            if (!event.equals(startElement)) {
                                Attribute tns = startElement.getAttributeByName(TNS);
                                if (tns != null) {
                                    String s = tns.getValue();
                                    if (!s.equals(xsd.getNamespace())) {
                                        namespacesToCorrect.put(s, xsd.getNamespace());
                                    }
                                }
                            }
                        } else {
                            event = startElement;
                        }
                        if (imports != null && !noOutput) {
                            // 2 on every iteration.
                            for (int i = 0; i < imports.size(); i = i + 2) {
                                boolean skip = false;
                                for (int j = 0; j < i; j = j + 2) {
                                    Attribute attribute1 = imports.get(i).asStartElement().getAttributeByName(NAMESPACE);
                                    Attribute attribute2 = imports.get(j).asStartElement().getAttributeByName(NAMESPACE);
                                    if (attribute1 != null && attribute2 != null && attribute1.getValue().equals(attribute2.getValue())) {
                                        skip = true;
                                    }
                                }
                                if (!skip) {
                                    streamEventWriter.add(event);
                                    event = imports.get(i);
                                    streamEventWriter.add(event);
                                    event = imports.get(i + 1);
                                }
                            }
                        }
                    } else if (startElement.getName().equals(INCLUDE)) {
                        continue;
                    // } else if (startElement.getName().equals(REDEFINE)) {
                    // continue;
                    } else if (startElement.getName().equals(IMPORT)) {
                        if (imports == null || noOutput) {
                            // Not collecting or writing import elements.
                            Attribute schemaLocation = startElement.getAttributeByName(SCHEMALOCATION);
                            if (schemaLocation != null) {
                                String location = schemaLocation.getValue();
                                if (stripSchemaLocationFromImport) {
                                    List<Attribute> attributes = new ArrayList<Attribute>();
                                    Iterator<Attribute> iterator = startElement.getAttributes();
                                    while (iterator.hasNext()) {
                                        Attribute a = iterator.next();
                                        if (!SCHEMALOCATION.equals(a.getName())) {
                                            attributes.add(a);
                                        }
                                    }
                                    event = new StartElementEvent(startElement.getName(), attributes.iterator(), startElement.getNamespaces(), startElement.getNamespaceContext(), startElement.getLocation(), startElement.getSchemaType());
                                } else {
                                    String relativeTo = xsd.getParentLocation();
                                    if (relativeTo.length() > 0 && location.startsWith(relativeTo)) {
                                        location = location.substring(relativeTo.length());
                                    }
                                    event = XMLStreamUtils.mergeAttributes(startElement, Collections.singletonList(new AttributeEvent(SCHEMALOCATION, location)).iterator(), XmlUtils.EVENT_FACTORY);
                                }
                            }
                        }
                        if (imports != null) {
                            // Collecting or writing import elements.
                            if (noOutput) {
                                // First call to this method collecting
                                // imports.
                                imports.add(event);
                            }
                            continue;
                        }
                    }
                    break;
                case XMLStreamConstants.END_ELEMENT:
                    EndElement endElement = event.asEndElement();
                    if (endElement.getName().equals(SCHEMA)) {
                        if (skipRootEndElement) {
                            continue;
                        }
                    } else if (endElement.getName().equals(INCLUDE)) {
                        continue;
                    // } else if (endElement.getName().equals(REDEFINE)) {
                    // continue;
                    } else if (imports != null) {
                        if (endElement.getName().equals(IMPORT)) {
                            if (noOutput) {
                                imports.add(event);
                            }
                            continue;
                        }
                    }
                    break;
                default:
            }
            if (!noOutput) {
                streamEventWriter.add(event);
            }
        }
        streamEventWriter.flush();
    } catch (XMLStreamException e) {
        throw new ConfigurationException(xsd.toString() + " (" + event.getLocation() + "): " + e.getMessage(), e);
    }
}
Also used : HashMap(java.util.HashMap) Attribute(javax.xml.stream.events.Attribute) StartElementEvent(javanet.staxutils.events.StartElementEvent) EndElement(javax.xml.stream.events.EndElement) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) XMLStreamEventWriter(javanet.staxutils.XMLStreamEventWriter) AttributeEvent(javanet.staxutils.events.AttributeEvent) StartElement(javax.xml.stream.events.StartElement) XMLStreamException(javax.xml.stream.XMLStreamException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) XMLEvent(javax.xml.stream.events.XMLEvent) XMLEventReader(javax.xml.stream.XMLEventReader)

Example 43 with ConfigurationException

use of nl.nn.adapterframework.configuration.ConfigurationException in project iaf by ibissource.

the class TransformerPool method configureTransformer0.

public static TransformerPool configureTransformer0(String logPrefix, ClassLoader classLoader, String namespaceDefs, String xPathExpression, String styleSheetName, String outputType, boolean includeXmlDeclaration, ParameterList params, boolean xslt2) throws ConfigurationException {
    TransformerPool result;
    if (logPrefix == null) {
        logPrefix = "";
    }
    if (StringUtils.isNotEmpty(xPathExpression)) {
        if (StringUtils.isNotEmpty(styleSheetName)) {
            throw new ConfigurationException(logPrefix + " cannot have both an xpathExpression and a styleSheetName specified");
        }
        try {
            List paramNames = null;
            if (params != null) {
                paramNames = new ArrayList();
                Iterator iterator = params.iterator();
                while (iterator.hasNext()) {
                    paramNames.add(((Parameter) iterator.next()).getName());
                }
            }
            result = TransformerPool.getInstance(XmlUtils.createXPathEvaluatorSource(namespaceDefs, xPathExpression, outputType, includeXmlDeclaration, paramNames), xslt2);
        } catch (TransformerConfigurationException te) {
            throw new ConfigurationException(logPrefix + " got error creating transformer from xpathExpression [" + xPathExpression + "] namespaceDefs [" + namespaceDefs + "]", te);
        }
    } else {
        if (StringUtils.isNotEmpty(namespaceDefs)) {
            throw new ConfigurationException(logPrefix + " cannot have namespaceDefs specified for a styleSheetName");
        }
        if (!StringUtils.isEmpty(styleSheetName)) {
            URL resource = ClassUtils.getResourceURL(classLoader, styleSheetName);
            if (resource == null) {
                throw new ConfigurationException(logPrefix + " cannot find [" + styleSheetName + "]");
            }
            try {
                result = TransformerPool.getInstance(resource, xslt2);
            } catch (IOException e) {
                throw new ConfigurationException(logPrefix + "cannot retrieve [" + styleSheetName + "], resource [" + resource.toString() + "]", e);
            } catch (TransformerConfigurationException te) {
                throw new ConfigurationException(logPrefix + " got error creating transformer from file [" + styleSheetName + "]", te);
            }
            if (XmlUtils.isAutoReload()) {
                result.reloadURL = resource;
            }
        } else {
            throw new ConfigurationException(logPrefix + " either xpathExpression or styleSheetName must be specified");
        }
    }
    return result;
}
Also used : TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) ParameterList(nl.nn.adapterframework.parameters.ParameterList) LinkedList(java.util.LinkedList) List(java.util.List) IOException(java.io.IOException) URL(java.net.URL)

Example 44 with ConfigurationException

use of nl.nn.adapterframework.configuration.ConfigurationException in project iaf by ibissource.

the class JarBytesClassLoader method readResources.

protected void readResources(byte[] jar, String configurationName) throws ConfigurationException {
    JarInputStream jarInputStream = null;
    try {
        jarInputStream = new JarInputStream(new ByteArrayInputStream(jar));
        JarEntry jarEntry;
        while ((jarEntry = jarInputStream.getNextJarEntry()) != null) {
            resources.put(jarEntry.getName(), Misc.streamToBytes(jarInputStream));
        }
    } catch (IOException e) {
        throw new ConfigurationException("Could not read resources from jar input stream for configuration '" + configurationName + "'", e);
    } finally {
        if (jarInputStream != null) {
            try {
                jarInputStream.close();
            } catch (IOException e) {
                log.warn("Could not close jar input stream for configuration '" + configurationName + "'", e);
            }
        }
    }
}
Also used : JarInputStream(java.util.jar.JarInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) IOException(java.io.IOException) JarEntry(java.util.jar.JarEntry)

Example 45 with ConfigurationException

use of nl.nn.adapterframework.configuration.ConfigurationException in project iaf by ibissource.

the class ServiceClassLoader method reload.

@Override
public void reload() throws ConfigurationException {
    super.reload();
    if (adapterName == null) {
        throw new ConfigurationException("Name of adapter to provide configuration jar not specified");
    }
    IAdapter adapter = ibisManager.getRegisteredAdapter(adapterName);
    if (adapter != null) {
        IPipeLineSession pipeLineSession = new PipeLineSessionBase();
        PipeLineResult processResult = adapter.processMessage(getCorrelationId(), configurationName, pipeLineSession);
        Object object = pipeLineSession.get("configurationJar");
        if (object != null) {
            if (object instanceof byte[]) {
                readResources((byte[]) object, configurationName);
            } else {
                throw new ConfigurationException("SessionKey configurationJar not a byte array");
            }
        } else {
            throw new ConfigurationException("SessionKey configurationJar not found");
        }
    } else {
        throw new ConfigurationException("Could not find adapter: " + adapterName);
    }
}
Also used : ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) PipeLineResult(nl.nn.adapterframework.core.PipeLineResult) IAdapter(nl.nn.adapterframework.core.IAdapter) IPipeLineSession(nl.nn.adapterframework.core.IPipeLineSession) PipeLineSessionBase(nl.nn.adapterframework.core.PipeLineSessionBase)

Aggregations

ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)113 IOException (java.io.IOException)26 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)20 PipeRunException (nl.nn.adapterframework.core.PipeRunException)17 ConfigurationWarnings (nl.nn.adapterframework.configuration.ConfigurationWarnings)16 URL (java.net.URL)13 ArrayList (java.util.ArrayList)12 Parameter (nl.nn.adapterframework.parameters.Parameter)12 ParameterList (nl.nn.adapterframework.parameters.ParameterList)11 File (java.io.File)7 Iterator (java.util.Iterator)6 ListenerException (nl.nn.adapterframework.core.ListenerException)6 PipeForward (nl.nn.adapterframework.core.PipeForward)6 PipeLineSessionBase (nl.nn.adapterframework.core.PipeLineSessionBase)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 StringTokenizer (java.util.StringTokenizer)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 FileNotFoundException (java.io.FileNotFoundException)4 LinkedList (java.util.LinkedList)4