Search in sources :

Example 36 with IAdapter

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

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

the class ShowConfigurationStatus method toAdaptersXml.

private XmlBuilder toAdaptersXml(IbisManager ibisManager, List<Configuration> configurations, Configuration configurationSelected, List<IAdapter> registeredAdapters, ShowConfigurationStatusManager showConfigurationStatusManager) {
    XmlBuilder adapters = new XmlBuilder("registeredAdapters");
    if (configurationSelected != null) {
        adapters.addAttribute("all", false);
    } else {
        adapters.addAttribute("all", true);
    }
    if (showConfigurationStatusManager.alert != null) {
        adapters.addAttribute("alert", showConfigurationStatusManager.alert);
    }
    XmlBuilder configurationMessagesXml = toConfigurationMessagesXml(ibisManager, configurationSelected);
    adapters.addSubElement(configurationMessagesXml);
    XmlBuilder configurationExceptionsXml = toConfigurationExceptionsXml(configurations, configurationSelected);
    if (configurationExceptionsXml != null) {
        adapters.addSubElement(configurationExceptionsXml);
    }
    XmlBuilder configurationWarningsXml = toConfigurationWarningsXml(configurations, configurationSelected);
    if (configurationWarningsXml != null) {
        adapters.addSubElement(configurationWarningsXml);
    }
    for (IAdapter iAdapter : registeredAdapters) {
        Adapter adapter = (Adapter) iAdapter;
        XmlBuilder adapterXml = toAdapterXml(configurationSelected, adapter, showConfigurationStatusManager);
        adapters.addSubElement(adapterXml);
    }
    XmlBuilder summaryXml = toSummaryXml(showConfigurationStatusManager);
    adapters.addSubElement(summaryXml);
    return adapters;
}
Also used : XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) Adapter(nl.nn.adapterframework.core.Adapter) IAdapter(nl.nn.adapterframework.core.IAdapter) IAdapter(nl.nn.adapterframework.core.IAdapter)

Example 38 with IAdapter

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

the class TestPipeLine method doPost.

private String doPost(IPipeLineSession session) throws PipeRunException {
    Object form_file = session.get("file");
    String form_message = null;
    form_message = (String) session.get("message");
    if (form_file == null && (StringUtils.isEmpty(form_message))) {
        throw new PipeRunException(this, getLogPrefix(session) + "Nothing to send or test");
    }
    String form_adapterName = (String) session.get("adapterName");
    if (StringUtils.isEmpty(form_adapterName)) {
        throw new PipeRunException(this, getLogPrefix(session) + "No adapter selected");
    }
    IAdapter adapter = RestListenerUtils.retrieveIbisManager(session).getRegisteredAdapter(form_adapterName);
    if (adapter == null) {
        throw new PipeRunException(this, getLogPrefix(session) + "Adapter with specified name [" + form_adapterName + "] could not be retrieved");
    }
    boolean writeSecLogMessage = false;
    if (secLogMessage) {
        writeSecLogMessage = (Boolean) session.get("writeSecLogMessage");
    }
    if (form_file != null) {
        if (form_file instanceof InputStream) {
            InputStream inputStream = (InputStream) form_file;
            String form_fileName = (String) session.get("fileName");
            String form_fileEncoding = (String) session.get("fileEncoding");
            try {
                if (inputStream.available() > 0) {
                    String fileEncoding;
                    if (StringUtils.isNotEmpty(form_fileEncoding)) {
                        fileEncoding = form_fileEncoding;
                    } else {
                        fileEncoding = Misc.DEFAULT_INPUT_STREAM_ENCODING;
                    }
                    if (StringUtils.endsWithIgnoreCase(form_fileName, ".zip")) {
                        try {
                            form_message = processZipFile(session, inputStream, fileEncoding, adapter, writeSecLogMessage);
                        } catch (Exception e) {
                            throw new PipeRunException(this, getLogPrefix(session) + "exception on processing zip file", e);
                        }
                    } else {
                        form_message = Misc.streamToString(inputStream, "\n", fileEncoding, false);
                    }
                }
            } catch (IOException e) {
                throw new PipeRunException(this, getLogPrefix(session) + "exception on converting stream to string", e);
            }
        } else {
            form_message = form_file.toString();
        }
        session.put("message", form_message);
    }
    if (StringUtils.isNotEmpty(form_message)) {
        try {
            PipeLineResult plr = processMessage(adapter, form_message, writeSecLogMessage);
            session.put("state", plr.getState());
            session.put("result", plr.getResult());
        } catch (Exception e) {
            throw new PipeRunException(this, getLogPrefix(session) + "exception on sending message", e);
        }
    }
    return "<dummy/>";
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) PipeLineResult(nl.nn.adapterframework.core.PipeLineResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException) IOException(java.io.IOException) IAdapter(nl.nn.adapterframework.core.IAdapter) PipeRunException(nl.nn.adapterframework.core.PipeRunException) IOException(java.io.IOException)

Example 39 with IAdapter

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

the class Webservices method list.

private String list(IbisManager ibisManager) {
    XmlBuilder webservicesXML = new XmlBuilder("webservices");
    // RestListeners
    XmlBuilder restsXML = new XmlBuilder("rests");
    for (IAdapter a : ibisManager.getRegisteredAdapters()) {
        Adapter adapter = (Adapter) a;
        Iterator recIt = adapter.getReceiverIterator();
        while (recIt.hasNext()) {
            IReceiver receiver = (IReceiver) recIt.next();
            if (receiver instanceof ReceiverBase) {
                ReceiverBase rb = (ReceiverBase) receiver;
                IListener listener = rb.getListener();
                if (listener instanceof RestListener) {
                    RestListener rl = (RestListener) listener;
                    if (rl.isView()) {
                        XmlBuilder restXML = new XmlBuilder("rest");
                        restXML.addAttribute("name", rb.getName());
                        restXML.addAttribute("uriPattern", rl.getUriPattern());
                        restsXML.addSubElement(restXML);
                    }
                }
            }
        }
    }
    webservicesXML.addSubElement(restsXML);
    // WSDL's
    XmlBuilder wsdlsXML = new XmlBuilder("wsdls");
    for (IAdapter a : ibisManager.getRegisteredAdapters()) {
        XmlBuilder wsdlXML = new XmlBuilder("wsdl");
        try {
            Adapter adapter = (Adapter) a;
            Wsdl wsdl = new Wsdl(adapter.getPipeLine());
            wsdlXML.addAttribute("name", wsdl.getName());
            wsdlXML.addAttribute("extention", getWsdlExtention());
        } catch (Exception e) {
            wsdlXML.addAttribute("name", a.getName());
            XmlBuilder errorXML = new XmlBuilder("error");
            if (e.getMessage() != null) {
                errorXML.setCdataValue(e.getMessage());
            } else {
                errorXML.setCdataValue(e.toString());
            }
            wsdlXML.addSubElement(errorXML);
        }
        wsdlsXML.addSubElement(wsdlXML);
    }
    webservicesXML.addSubElement(wsdlsXML);
    // ApiListeners
    XmlBuilder apiListenerXML = new XmlBuilder("apiListeners");
    SortedMap<String, ApiDispatchConfig> patternClients = ApiServiceDispatcher.getInstance().getPatternClients();
    for (Entry<String, ApiDispatchConfig> client : patternClients.entrySet()) {
        XmlBuilder apiXML = new XmlBuilder("apiListener");
        ApiDispatchConfig config = client.getValue();
        Set<String> methods = config.getMethods();
        for (String method : methods) {
            ApiListener listener = config.getApiListener(method);
            XmlBuilder methodXML = new XmlBuilder(method);
            String name = listener.getName();
            if (name.contains("listener of ["))
                name = name.substring(13, name.length() - 1);
            methodXML.addAttribute("name", name);
            methodXML.addAttribute("updateEtag", listener.getUpdateEtag());
            methodXML.addAttribute("isRunning", listener.isRunning());
            apiXML.addSubElement(methodXML);
        }
        apiXML.addAttribute("uriPattern", config.getUriPattern());
        apiListenerXML.addSubElement(apiXML);
    }
    webservicesXML.addSubElement(apiListenerXML);
    return webservicesXML.toXML();
}
Also used : ReceiverBase(nl.nn.adapterframework.receivers.ReceiverBase) IListener(nl.nn.adapterframework.core.IListener) Adapter(nl.nn.adapterframework.core.Adapter) IAdapter(nl.nn.adapterframework.core.IAdapter) Wsdl(nl.nn.adapterframework.soap.Wsdl) PipeRunException(nl.nn.adapterframework.core.PipeRunException) NamingException(javax.naming.NamingException) XMLStreamException(javax.xml.stream.XMLStreamException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) RestListener(nl.nn.adapterframework.http.RestListener) IReceiver(nl.nn.adapterframework.core.IReceiver) ApiListener(nl.nn.adapterframework.http.rest.ApiListener) Iterator(java.util.Iterator) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) ApiDispatchConfig(nl.nn.adapterframework.http.rest.ApiDispatchConfig) IAdapter(nl.nn.adapterframework.core.IAdapter)

Example 40 with IAdapter

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

the class Webservices method doGet.

private String doGet(IPipeLineSession session) throws PipeRunException {
    IbisManager ibisManager = RestListenerUtils.retrieveIbisManager(session);
    String uri = (String) session.get("uri");
    String indent = (String) session.get("indent");
    String useIncludes = (String) session.get("useIncludes");
    if (StringUtils.isNotEmpty(uri) && (uri.endsWith(getWsdlExtention()) || uri.endsWith(".zip"))) {
        String adapterName = StringUtils.substringBeforeLast(StringUtils.substringAfterLast(uri, "/"), ".");
        IAdapter adapter = ibisManager.getRegisteredAdapter(adapterName);
        if (adapter == null) {
            throw new PipeRunException(this, getLogPrefix(session) + "adapter [" + adapterName + "] doesn't exist");
        }
        try {
            if (uri.endsWith(getWsdlExtention())) {
                RestListenerUtils.setResponseContentType(session, "application/xml");
                wsdl((Adapter) adapter, session, indent, useIncludes);
            } else {
                RestListenerUtils.setResponseContentType(session, "application/octet-stream");
                zip((Adapter) adapter, session);
            }
        } catch (Exception e) {
            throw new PipeRunException(this, getLogPrefix(session) + "exception on retrieving wsdl", e);
        }
        return "";
    } else {
        return list(ibisManager);
    }
}
Also used : IbisManager(nl.nn.adapterframework.configuration.IbisManager) PipeRunException(nl.nn.adapterframework.core.PipeRunException) IAdapter(nl.nn.adapterframework.core.IAdapter) PipeRunException(nl.nn.adapterframework.core.PipeRunException) NamingException(javax.naming.NamingException) XMLStreamException(javax.xml.stream.XMLStreamException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException)

Aggregations

IAdapter (nl.nn.adapterframework.core.IAdapter)41 Adapter (nl.nn.adapterframework.core.Adapter)15 Iterator (java.util.Iterator)13 ArrayList (java.util.ArrayList)12 ReceiverBase (nl.nn.adapterframework.receivers.ReceiverBase)11 IReceiver (nl.nn.adapterframework.core.IReceiver)10 IOException (java.io.IOException)8 List (java.util.List)8 Configuration (nl.nn.adapterframework.configuration.Configuration)7 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)7 HashMap (java.util.HashMap)6 LinkedList (java.util.LinkedList)6 IListener (nl.nn.adapterframework.core.IListener)6 PipeRunException (nl.nn.adapterframework.core.PipeRunException)6 ITransactionalStorage (nl.nn.adapterframework.core.ITransactionalStorage)5 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 IPipe (nl.nn.adapterframework.core.IPipe)4 PipeLineResult (nl.nn.adapterframework.core.PipeLineResult)4 XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)4