Search in sources :

Example 6 with ConfigurationException

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

the class NetStorageSender method configure.

public void configure() throws ConfigurationException {
    super.configure();
    // Safety checks
    if (getAction() == null)
        throw new ConfigurationException(getLogPrefix() + "action must be specified");
    if (!actions.contains(getAction()))
        throw new ConfigurationException(getLogPrefix() + "unknown or invalid action [" + getAction() + "] supported actions are " + actions.toString() + "");
    if (getCpCode() == null)
        throw new ConfigurationException(getLogPrefix() + "cpCode must be specified");
    if (!getUrl().startsWith("http"))
        throw new ConfigurationException(getLogPrefix() + "url must be start with http(s)");
    if (hashAlgorithm != null && !hashAlgorithms.contains(hashAlgorithm))
        throw new ConfigurationException(getLogPrefix() + "unknown authenticationMethod [" + hashAlgorithm + "] supported methods are " + hashAlgorithms.toString() + "");
    if (getSignVersion() < 3 || getSignVersion() > 5)
        throw new ConfigurationException(getLogPrefix() + "signVersion must be either 3, 4 or 5");
    ParameterList parameterList = getParameterList();
    if (getAction().equals("upload") && parameterList.findParameter("file") == null)
        throw new ConfigurationException(getLogPrefix() + "the upload action requires a file parameter to be present");
    if (getAction().equals("rename") && parameterList.findParameter("destination") == null)
        throw new ConfigurationException(getLogPrefix() + "the rename action requires a destination parameter to be present");
    if (getAction().equals("mtime") && parameterList.findParameter("mtime") == null)
        throw new ConfigurationException(getLogPrefix() + "the mtime action requires a mtime parameter to be present");
    accessTokenCf = new CredentialFactory(getAuthAlias(), getNonce(), getAccessToken());
}
Also used : ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) CredentialFactory(nl.nn.adapterframework.util.CredentialFactory) ParameterList(nl.nn.adapterframework.parameters.ParameterList)

Example 7 with ConfigurationException

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

the class CoolGenWrapperPipe method doPipe.

/**
 * Transform the input (optionally), check the conformance to the schema (optionally),
 * call the required proxy, transform the output (optionally)
 */
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    Writer proxyResult;
    String proxypreProc = null;
    Variant inputVar;
    String wrapperResult = "";
    CoolGenXMLProxy proxy;
    ActionListener actionListener = new ActionListener() {

        /**
         * @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
         */
        public String errorMessage;

        public void actionPerformed(ActionEvent e) {
            errorMessage = e.toString();
        }

        public String toString() {
            return errorMessage;
        }
    };
    Source in;
    try {
        log.info(getLogPrefix(session) + "instantiating proxy [" + proxyClassName + "] as a temporary fix for broken comm-bridge connections");
        proxy = createProxy(proxyClassName);
    } catch (ConfigurationException ce) {
        String msg = getLogPrefix(session) + "cannot recreate proxy after exception";
        log.error(msg, ce);
        throw new PipeRunException(this, msg, ce);
    }
    proxy.addExceptionListener(actionListener);
    try {
        inputVar = new Variant(input);
        in = inputVar.asXmlSource();
        if (preProcTransformer != null) {
            proxypreProc = XmlUtils.transformXml(preProcTransformer, in);
            log.debug(getLogPrefix(session) + "] preprocessing transformed message into [" + proxypreProc + "]");
        } else
            proxypreProc = inputVar.asString();
        if (proxyInputFixTransformer != null)
            proxypreProc = XmlUtils.transformXml(proxyInputFixTransformer, proxypreProc);
        proxyResult = new StringWriter(10 * 1024);
        try {
            proxy.clear();
        } catch (PropertyVetoException e) {
            throw new PipeRunException(this, getLogPrefix(session) + "cannot clear CoolGen proxy", e);
        }
        try {
            proxy.executeXML(new StringReader(proxypreProc), proxyResult);
            proxy.removeExceptionListener(actionListener);
            String err = actionListener.toString();
            if (err != null) {
                // if an error occurs, recreate the proxy and throw an exception
                log.debug(getLogPrefix(session) + "got error, recreating proxy with class [" + proxyClassName + "]");
                try {
                    proxy = createProxy(proxyClassName);
                } catch (ConfigurationException e) {
                    throw new PipeRunException(this, getLogPrefix(session) + "cannot recreate proxy [" + proxyClassName + "]", e);
                }
                throw new PipeRunException(this, getLogPrefix(session) + "error excuting proxy [" + proxyClassName + "]:" + err);
            }
        } catch (XmlProxyException xpe) {
            try {
                proxy = createProxy(proxyClassName);
            } catch (ConfigurationException ce) {
                log.error(getLogPrefix(session) + "cannot recreate proxy", xpe);
            }
            throw new PipeRunException(this, getLogPrefix(session) + "error excecuting proxy", xpe);
        }
        if (postProcTransformer != null) {
            log.debug(getLogPrefix(session) + " CoolGen proxy returned: [" + proxyResult.toString() + "]");
            wrapperResult = XmlUtils.transformXml(postProcTransformer, proxyResult.toString());
        } else
            wrapperResult = proxyResult.toString();
    } catch (DomBuilderException e) {
        throw new PipeRunException(this, getLogPrefix(session) + "DomBuilderException excecuting proxy", e);
    } catch (IOException e) {
        throw new PipeRunException(this, getLogPrefix(session) + "IOException excecuting proxy", e);
    } catch (TransformerException e) {
        throw new PipeRunException(this, getLogPrefix(session) + "TransformerException excecuting proxy", e);
    }
    return new PipeRunResult(getForward(), wrapperResult);
}
Also used : CoolGenXMLProxy(nl.nn.coolgen.proxy.CoolGenXMLProxy) ActionEvent(java.awt.event.ActionEvent) IOException(java.io.IOException) Source(javax.xml.transform.Source) Variant(nl.nn.adapterframework.util.Variant) PropertyVetoException(java.beans.PropertyVetoException) PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) XmlProxyException(nl.nn.coolgen.proxy.XmlProxyException) ActionListener(java.awt.event.ActionListener) StringWriter(java.io.StringWriter) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) PipeRunException(nl.nn.adapterframework.core.PipeRunException) StringReader(java.io.StringReader) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) StringWriter(java.io.StringWriter) Writer(java.io.Writer) TransformerException(javax.xml.transform.TransformerException)

Example 8 with ConfigurationException

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

the class CoolGenWrapperPipe method createProxy.

public CoolGenXMLProxy createProxy(String proxyName) throws ConfigurationException {
    CoolGenXMLProxy proxy;
    try {
        Class klass = Class.forName(proxyName);
        proxy = (CoolGenXMLProxy) klass.newInstance();
        proxy.setClientId(getClientId());
        proxy.setClientPassword(getClientPassword());
        if (log.isDebugEnabled())
            proxy.setTracing(1);
        else
            proxy.setTracing(0);
    } catch (Exception e) {
        throw new ConfigurationException(getLogPrefix(null) + "could not create proxy [" + proxyName + "]", e);
    }
    return proxy;
}
Also used : CoolGenXMLProxy(nl.nn.coolgen.proxy.CoolGenXMLProxy) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) PipeRunException(nl.nn.adapterframework.core.PipeRunException) PipeStartException(nl.nn.adapterframework.core.PipeStartException) TransformerException(javax.xml.transform.TransformerException) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) XmlProxyException(nl.nn.coolgen.proxy.XmlProxyException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) PropertyVetoException(java.beans.PropertyVetoException)

Example 9 with ConfigurationException

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

the class ClassLoaderWSDLLocator method configure.

@Override
public void configure() throws ConfigurationException {
    addSoapEnvelopeToSchemaLocation = false;
    if (ConfigurationUtils.stubConfiguration()) {
        // warnings in IJA_API in DTAP
        if (StringUtils.isNotEmpty(getSchemaLocation()) && !isAddNamespaceToSchema()) {
            ConfigurationWarnings configWarnings = ConfigurationWarnings.getInstance();
            String msg = getLogPrefix(null) + "attribute [schemaLocation] for wsdl [" + getWsdl() + "] should only be set when addNamespaceToSchema=true";
            configWarnings.add(log, msg);
        }
    }
    if (StringUtils.isNotEmpty(getSoapBodyNamespace()) && StringUtils.isNotEmpty(getSchemaLocation())) {
        ConfigurationWarnings configWarnings = ConfigurationWarnings.getInstance();
        String msg = getLogPrefix(null) + "attribute [schemaLocation] for wsdl [" + getWsdl() + "] should only be set when attribute [soapBodyNamespace] is not set";
        configWarnings.add(log, msg);
    }
    if (StringUtils.isNotEmpty(getSoapBodyNamespace()) && !isAddNamespaceToSchema()) {
        ConfigurationWarnings configWarnings = ConfigurationWarnings.getInstance();
        String msg = getLogPrefix(null) + "attribute [soapBodyNamespace] for wsdl [" + getWsdl() + "] should only be set when addNamespaceToSchema=true";
        configWarnings.add(log, msg);
    }
    String wsdlSchemaLocation = null;
    StringBuilder sb = new StringBuilder();
    int counter = 0;
    boolean soapBodyFound = false;
    for (Object o : definition.getTypes().getExtensibilityElements()) {
        if (o instanceof Schema) {
            Schema schema = (Schema) o;
            String tns = schema.getElement().getAttribute("targetNamespace");
            if (StringUtils.isNotEmpty(getSoapBodyNamespace())) {
                NodeList childNodes = schema.getElement().getChildNodes();
                for (int i = 0; i < childNodes.getLength(); i++) {
                    Node n = childNodes.item(i);
                    if (n.getNodeType() == Node.ELEMENT_NODE && n.getLocalName().equals("element")) {
                        String name = n.getAttributes().getNamedItem("name").getNodeValue();
                        if (getSoapBody().equals(name)) {
                            if (soapBodyFound) {
                                throw new ConfigurationException(getLogPrefix(null) + "soapBody [" + getSoapBody() + "] exists multiple times, not possible to create schemaLocation from soapBodyNamespace");
                            }
                            tns = getSoapBodyNamespace();
                            soapBodyFound = true;
                        }
                    }
                }
            }
            if (sb.length() > 0) {
                sb.append(" ");
            }
            sb.append(tns);
            sb.append(" ");
            sb.append("schema" + ++counter);
        }
        if (sb.length() > 0) {
            wsdlSchemaLocation = sb.toString();
        }
        if (wsdlSchemaLocation != null) {
            if (ConfigurationUtils.stubConfiguration()) {
                // of warnings in IJA_API in DTAP
                if (StringUtils.isNotEmpty(getSchemaLocation()) && isAddNamespaceToSchema()) {
                    if (getSchemaLocation().replaceAll("\\s", " ").equals(wsdlSchemaLocation)) {
                        ConfigurationWarnings configWarnings = ConfigurationWarnings.getInstance();
                        String msg = getLogPrefix(null) + "attribute [schemaLocation] for wsdl [" + getWsdl() + "] already has a default value [" + wsdlSchemaLocation + "]";
                        configWarnings.add(log, msg);
                    }
                }
            }
            if (StringUtils.isNotEmpty(getSoapBodyNamespace())) {
                setSchemaLocation(wsdlSchemaLocation);
            }
        }
    }
    super.configure();
}
Also used : ConfigurationWarnings(nl.nn.adapterframework.configuration.ConfigurationWarnings) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) Schema(nl.nn.javax.wsdl.extensions.schema.Schema) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node)

Example 10 with ConfigurationException

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

the class ClassLoaderWSDLLocator method getXsds.

@Override
public Set<XSD> getXsds() throws ConfigurationException {
    Set<XSD> xsds = new HashSet<XSD>();
    if (getSoapVersion() == null || "1.1".equals(getSoapVersion()) || "any".equals(getSoapVersion())) {
        XSD xsd = new XSD();
        xsd.setClassLoader(classLoader);
        xsd.setNamespace(SoapValidator.SoapVersion.VERSION_1_1.namespace);
        xsd.setResource(SoapValidator.SoapVersion.VERSION_1_1.location);
        xsd.init();
        xsds.add(xsd);
    }
    if ("1.2".equals(getSoapVersion()) || "any".equals(getSoapVersion())) {
        XSD xsd = new XSD();
        xsd.setClassLoader(classLoader);
        xsd.setNamespace(SoapValidator.SoapVersion.VERSION_1_2.namespace);
        xsd.setResource(SoapValidator.SoapVersion.VERSION_1_2.location);
        xsd.init();
        xsds.add(xsd);
    }
    if (StringUtils.isNotEmpty(getSchemaLocationToAdd())) {
        StringTokenizer st = new StringTokenizer(getSchemaLocationToAdd(), ", \t\r\n\f");
        while (st.hasMoreTokens()) {
            XSD xsd = new XSD();
            xsd.setClassLoader(classLoader);
            xsd.setNamespace(st.nextToken());
            if (st.hasMoreTokens()) {
                xsd.setResource(st.nextToken());
            }
            xsd.init();
            xsds.add(xsd);
        }
    }
    List<Schema> schemas = new ArrayList<Schema>();
    List types = definition.getTypes().getExtensibilityElements();
    for (Iterator i = types.iterator(); i.hasNext(); ) {
        ExtensibilityElement type = (ExtensibilityElement) i.next();
        QName qn = type.getElementType();
        if (SchemaUtils.WSDL_SCHEMA.equals(qn)) {
            final Schema schema = (Schema) type;
            addNamespaces(schema, definition.getNamespaces());
            schemas.add(schema);
        }
    }
    List<Schema> filteredSchemas;
    Map<Schema, String> filteredReferences = null;
    Map<Schema, String> filteredNamespaces = null;
    if (StringUtils.isEmpty(schemaLocation)) {
        filteredSchemas = schemas;
    } else {
        filteredSchemas = new ArrayList<Schema>();
        filteredReferences = new HashMap<Schema, String>();
        filteredNamespaces = new HashMap<Schema, String>();
        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) {
            if (!split[i + 1].startsWith(RESOURCE_INTERNAL_REFERENCE_PREFIX)) {
                throw new ConfigurationException("Schema reference " + split[i + 1] + " should start with '" + RESOURCE_INTERNAL_REFERENCE_PREFIX + "'");
            }
            try {
                int j = Integer.parseInt(split[i + 1].substring(RESOURCE_INTERNAL_REFERENCE_PREFIX.length())) - 1;
                filteredSchemas.add(schemas.get(j));
                filteredReferences.put(schemas.get(j), RESOURCE_INTERNAL_REFERENCE_PREFIX + (j + 1));
                filteredNamespaces.put(schemas.get(j), split[i]);
            } catch (Exception e) {
                throw new ConfigurationException("Schema reference " + split[i + 1] + " not valid or not found");
            }
        }
    }
    for (Schema schema : filteredSchemas) {
        XSD xsd = new XSD();
        xsd.setClassLoader(classLoader);
        xsd.setWsdlSchema(definition, schema);
        xsd.setResource(getWsdl());
        if (StringUtils.isNotEmpty(schemaLocation)) {
            xsd.setResourceInternalReference(filteredReferences.get(schema));
            xsd.setNamespace(filteredNamespaces.get(schema));
        } else {
            xsd.setResourceInternalReference(RESOURCE_INTERNAL_REFERENCE_PREFIX + (filteredSchemas.indexOf(schema) + 1));
        }
        xsd.setAddNamespaceToSchema(isAddNamespaceToSchema());
        xsd.setImportedSchemaLocationsToIgnore(getImportedSchemaLocationsToIgnore());
        xsd.setUseBaseImportedSchemaLocationsToIgnore(isUseBaseImportedSchemaLocationsToIgnore());
        xsd.setImportedNamespacesToIgnore(getImportedNamespacesToIgnore());
        xsd.init();
        xsds.add(xsd);
    }
    return xsds;
}
Also used : QName(nl.nn.javax.xml.namespace.QName) Schema(nl.nn.javax.wsdl.extensions.schema.Schema) XSD(nl.nn.adapterframework.validation.XSD) ArrayList(java.util.ArrayList) ExtensibilityElement(nl.nn.javax.wsdl.extensions.ExtensibilityElement) WSDLException(nl.nn.javax.wsdl.WSDLException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) StringTokenizer(java.util.StringTokenizer) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) HashSet(java.util.HashSet)

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