Search in sources :

Example 1 with IReceiver

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

the class ShowAdapterStatistics method getStatistics.

@GET
@RolesAllowed({ "IbisObserver", "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/adapters/{adapterName}/statistics")
@Relation("statistics")
@Produces(MediaType.APPLICATION_JSON)
public Response getStatistics(@PathParam("adapterName") String adapterName) throws ApiException {
    initBase(servletConfig);
    Map<String, Object> statisticsMap = new HashMap<String, Object>();
    Adapter adapter = (Adapter) ibisManager.getRegisteredAdapter(adapterName);
    if (adapter == null) {
        throw new ApiException("Adapter not found!");
    }
    StatisticsKeeper sk = adapter.getStatsMessageProcessingDuration();
    statisticsMap.put("totalMessageProccessingTime", statisticsKeeperToMapBuilder(sk));
    long[] numOfMessagesStartProcessingByHour = adapter.getNumOfMessagesStartProcessingByHour();
    List<Map<String, Object>> hourslyStatistics = new ArrayList<Map<String, Object>>();
    for (int i = 0; i < numOfMessagesStartProcessingByHour.length; i++) {
        Map<String, Object> item = new HashMap<String, Object>(2);
        String startTime;
        if (i < 10) {
            startTime = "0" + i + ":00";
        } else {
            startTime = i + ":00";
        }
        item.put("time", startTime);
        item.put("count", numOfMessagesStartProcessingByHour[i]);
        hourslyStatistics.add(item);
    }
    statisticsMap.put("hourly", hourslyStatistics);
    List<Map<String, Object>> receivers = new ArrayList<Map<String, Object>>();
    Iterator<?> recIt = adapter.getReceiverIterator();
    if (recIt.hasNext()) {
        while (recIt.hasNext()) {
            IReceiver receiver = (IReceiver) recIt.next();
            Map<String, Object> receiverMap = new HashMap<String, Object>();
            receiverMap.put("name", receiver.getName());
            receiverMap.put("class", receiver.getClass().getName());
            receiverMap.put("messagesReceived", receiver.getMessagesReceived());
            receiverMap.put("messagesRetried", receiver.getMessagesRetried());
            if (receiver instanceof IReceiverStatistics) {
                IReceiverStatistics statReceiver = (IReceiverStatistics) receiver;
                Iterator<?> statsIter;
                statsIter = statReceiver.getProcessStatisticsIterator();
                if (statsIter != null) {
                    ArrayList<Map<String, Object>> procStatsMap = new ArrayList<Map<String, Object>>();
                    // procStatsXML.addSubElement(statisticsKeeperToXmlBuilder(statReceiver.getResponseSizeStatistics(), "stat"));
                    while (statsIter.hasNext()) {
                        StatisticsKeeper pstat = (StatisticsKeeper) statsIter.next();
                        procStatsMap.add(statisticsKeeperToMapBuilder(pstat));
                    }
                    receiverMap.put("processing", procStatsMap);
                }
                statsIter = statReceiver.getIdleStatisticsIterator();
                if (statsIter != null) {
                    ArrayList<Map<String, Object>> idleStatsMap = new ArrayList<Map<String, Object>>();
                    while (statsIter.hasNext()) {
                        StatisticsKeeper pstat = (StatisticsKeeper) statsIter.next();
                        idleStatsMap.add(statisticsKeeperToMapBuilder(pstat));
                    }
                    receiverMap.put("idle", idleStatsMap);
                }
                receivers.add(receiverMap);
            }
        }
    }
    statisticsMap.put("receivers", receivers);
    Map<String, Object> tmp = new HashMap<String, Object>();
    StatisticsKeeperToXml handler = new StatisticsKeeperToXml(tmp);
    handler.configure();
    Object handle = handler.start(null, null, null);
    try {
        adapter.getPipeLine().iterateOverStatistics(handler, tmp, HasStatistics.STATISTICS_ACTION_FULL);
        statisticsMap.put("durationPerPipe", tmp.get("pipeStats"));
        statisticsMap.put("sizePerPipe", tmp.get("sizeStats"));
    } catch (SenderException e) {
        log.error(e);
    } finally {
        handler.end(handle);
    }
    return Response.status(Response.Status.CREATED).entity(statisticsMap).build();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Adapter(nl.nn.adapterframework.core.Adapter) IReceiver(nl.nn.adapterframework.core.IReceiver) StatisticsKeeper(nl.nn.adapterframework.statistics.StatisticsKeeper) IReceiverStatistics(nl.nn.adapterframework.core.IReceiverStatistics) SenderException(nl.nn.adapterframework.core.SenderException) HashMap(java.util.HashMap) Map(java.util.Map) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with IReceiver

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

the class Webservices method getLogDirectory.

@GET
@RolesAllowed({ "IbisObserver", "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/webservices")
@Relation("webservices")
@Produces(MediaType.APPLICATION_JSON)
public Response getLogDirectory() throws ApiException {
    initBase(servletConfig);
    Map<String, Object> returnMap = new HashMap<String, Object>();
    List<Map<String, Object>> webServices = new ArrayList<Map<String, Object>>();
    for (IAdapter a : ibisManager.getRegisteredAdapters()) {
        Adapter adapter = (Adapter) a;
        Iterator<IReceiver> recIt = adapter.getReceiverIterator();
        while (recIt.hasNext()) {
            IReceiver receiver = 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()) {
                        Map<String, Object> service = new HashMap<String, Object>(2);
                        service.put("name", rb.getName());
                        service.put("uriPattern", rl.getUriPattern());
                        webServices.add(service);
                    }
                }
            }
        }
    }
    returnMap.put("services", webServices);
    List<Map<String, Object>> wsdls = new ArrayList<Map<String, Object>>();
    for (IAdapter a : ibisManager.getRegisteredAdapters()) {
        Map<String, Object> wsdlMap = new HashMap<String, Object>(2);
        try {
            Adapter adapter = (Adapter) a;
            Wsdl wsdl = new Wsdl(adapter.getPipeLine());
            wsdlMap.put("name", wsdl.getName());
            wsdlMap.put("extention", getWsdlExtention());
        } catch (Exception e) {
            wsdlMap.put("name", a.getName());
            if (e.getMessage() != null) {
                wsdlMap.put("error", e.getMessage());
            } else {
                wsdlMap.put("error", e.toString());
            }
        }
        wsdls.add(wsdlMap);
    }
    returnMap.put("wsdls", wsdls);
    return Response.status(Response.Status.OK).entity(returnMap).build();
}
Also used : ReceiverBase(nl.nn.adapterframework.receivers.ReceiverBase) HashMap(java.util.HashMap) IListener(nl.nn.adapterframework.core.IListener) ArrayList(java.util.ArrayList) Adapter(nl.nn.adapterframework.core.Adapter) IAdapter(nl.nn.adapterframework.core.IAdapter) Wsdl(nl.nn.adapterframework.soap.Wsdl) RestListener(nl.nn.adapterframework.http.RestListener) IReceiver(nl.nn.adapterframework.core.IReceiver) HashMap(java.util.HashMap) Map(java.util.Map) IAdapter(nl.nn.adapterframework.core.IAdapter) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with IReceiver

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

the class ShowSecurityItems method addRegisteredAdapters.

private void addRegisteredAdapters(XmlBuilder securityItems) {
    XmlBuilder registeredAdapters = new XmlBuilder("registeredAdapters");
    securityItems.addSubElement(registeredAdapters);
    for (IAdapter iAdapter : ibisManager.getRegisteredAdapters()) {
        Adapter adapter = (Adapter) iAdapter;
        XmlBuilder adapterXML = new XmlBuilder("adapter");
        registeredAdapters.addSubElement(adapterXML);
        adapterXML.addAttribute("name", adapter.getName());
        Iterator recIt = adapter.getReceiverIterator();
        if (recIt.hasNext()) {
            XmlBuilder receiversXML = new XmlBuilder("receivers");
            while (recIt.hasNext()) {
                IReceiver receiver = (IReceiver) recIt.next();
                XmlBuilder receiverXML = new XmlBuilder("receiver");
                receiversXML.addSubElement(receiverXML);
                receiverXML.addAttribute("name", receiver.getName());
                if (receiver instanceof HasSender) {
                    ISender sender = ((HasSender) receiver).getSender();
                    if (sender != null) {
                        receiverXML.addAttribute("senderName", sender.getName());
                    }
                }
            }
            adapterXML.addSubElement(receiversXML);
        }
        // make list of pipes to be displayed in configuration status
        XmlBuilder pipesElem = new XmlBuilder("pipes");
        adapterXML.addSubElement(pipesElem);
        PipeLine pipeline = adapter.getPipeLine();
        for (int i = 0; i < pipeline.getPipes().size(); i++) {
            IPipe pipe = pipeline.getPipe(i);
            String pipename = pipe.getName();
            if (pipe instanceof MessageSendingPipe) {
                MessageSendingPipe msp = (MessageSendingPipe) pipe;
                XmlBuilder pipeElem = new XmlBuilder("pipe");
                pipeElem.addAttribute("name", pipename);
                ISender sender = msp.getSender();
                pipeElem.addAttribute("sender", ClassUtils.nameOf(sender));
                pipesElem.addSubElement(pipeElem);
                if (sender instanceof WebServiceSender) {
                    WebServiceSender s = (WebServiceSender) sender;
                    String certificate = s.getCertificate();
                    if (StringUtils.isNotEmpty(certificate)) {
                        XmlBuilder certElem = new XmlBuilder("certificate");
                        certElem.addAttribute("name", certificate);
                        String certificateAuthAlias = s.getCertificateAuthAlias();
                        certElem.addAttribute("authAlias", certificateAuthAlias);
                        URL certificateUrl = ClassUtils.getResourceURL(this, certificate);
                        if (certificateUrl == null) {
                            certElem.addAttribute("url", "");
                            pipeElem.addSubElement(certElem);
                            XmlBuilder infoElem = new XmlBuilder("info");
                            infoElem.setCdataValue("*** ERROR ***");
                            certElem.addSubElement(infoElem);
                        } else {
                            certElem.addAttribute("url", certificateUrl.toString());
                            pipeElem.addSubElement(certElem);
                            String certificatePassword = s.getCertificatePassword();
                            CredentialFactory certificateCf = new CredentialFactory(certificateAuthAlias, null, certificatePassword);
                            String keystoreType = s.getKeystoreType();
                            addCertificateInfo(certElem, certificateUrl, certificateCf.getPassword(), keystoreType, "Certificate chain");
                        }
                    }
                } else {
                    if (sender instanceof HttpSender) {
                        HttpSender s = (HttpSender) sender;
                        String certificate = s.getCertificate();
                        if (StringUtils.isNotEmpty(certificate)) {
                            XmlBuilder certElem = new XmlBuilder("certificate");
                            certElem.addAttribute("name", certificate);
                            String certificateAuthAlias = s.getCertificateAuthAlias();
                            certElem.addAttribute("authAlias", certificateAuthAlias);
                            URL certificateUrl = ClassUtils.getResourceURL(this, certificate);
                            if (certificateUrl == null) {
                                certElem.addAttribute("url", "");
                                pipeElem.addSubElement(certElem);
                                XmlBuilder infoElem = new XmlBuilder("info");
                                infoElem.setCdataValue("*** ERROR ***");
                                certElem.addSubElement(infoElem);
                            } else {
                                certElem.addAttribute("url", certificateUrl.toString());
                                pipeElem.addSubElement(certElem);
                                String certificatePassword = s.getCertificatePassword();
                                CredentialFactory certificateCf = new CredentialFactory(certificateAuthAlias, null, certificatePassword);
                                String keystoreType = s.getKeystoreType();
                                addCertificateInfo(certElem, certificateUrl, certificateCf.getPassword(), keystoreType, "Certificate chain");
                            }
                        }
                    } else {
                        if (sender instanceof FtpSender) {
                            FtpSender s = (FtpSender) sender;
                            String certificate = s.getCertificate();
                            if (StringUtils.isNotEmpty(certificate)) {
                                XmlBuilder certElem = new XmlBuilder("certificate");
                                certElem.addAttribute("name", certificate);
                                String certificateAuthAlias = s.getCertificateAuthAlias();
                                certElem.addAttribute("authAlias", certificateAuthAlias);
                                URL certificateUrl = ClassUtils.getResourceURL(this, certificate);
                                if (certificateUrl == null) {
                                    certElem.addAttribute("url", "");
                                    pipeElem.addSubElement(certElem);
                                    XmlBuilder infoElem = new XmlBuilder("info");
                                    infoElem.setCdataValue("*** ERROR ***");
                                    certElem.addSubElement(infoElem);
                                } else {
                                    certElem.addAttribute("url", certificateUrl.toString());
                                    pipeElem.addSubElement(certElem);
                                    String certificatePassword = s.getCertificatePassword();
                                    CredentialFactory certificateCf = new CredentialFactory(certificateAuthAlias, null, certificatePassword);
                                    String keystoreType = s.getCertificateType();
                                    addCertificateInfo(certElem, certificateUrl, certificateCf.getPassword(), keystoreType, "Certificate chain");
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : MessageSendingPipe(nl.nn.adapterframework.pipes.MessageSendingPipe) CredentialFactory(nl.nn.adapterframework.util.CredentialFactory) Adapter(nl.nn.adapterframework.core.Adapter) IAdapter(nl.nn.adapterframework.core.IAdapter) FtpSender(nl.nn.adapterframework.ftp.FtpSender) HttpSender(nl.nn.adapterframework.http.HttpSender) HasSender(nl.nn.adapterframework.core.HasSender) URL(java.net.URL) IReceiver(nl.nn.adapterframework.core.IReceiver) ISender(nl.nn.adapterframework.core.ISender) Iterator(java.util.Iterator) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) WebServiceSender(nl.nn.adapterframework.http.WebServiceSender) PipeLine(nl.nn.adapterframework.core.PipeLine) IAdapter(nl.nn.adapterframework.core.IAdapter) IPipe(nl.nn.adapterframework.core.IPipe)

Example 4 with IReceiver

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

the class EjbListenerPortConnector method getListenerPortName.

/**
 * Get the name of the ListenerPort to look up as WebSphere MBean.
 *
 * Construct the name of the WebSphere listenerport according to the
 * following logic:
 * <ol>
 * <li>If the property 'listenerPort' is set in the configuration, then use that</li>
 * <li>Otherwise, concatenate the configuration-name with the receiver-name, replaces all spaces with minus-signs, and append 'ListenerPort'
 * </ol>
 */
protected String getListenerPortName(IPortConnectedListener listener) {
    String name = listener.getListenerPort();
    if (name == null) {
        IReceiver receiver = listener.getReceiver();
        name = configuration.getConfigurationName() + '-' + receiver.getName() + LISTENER_PORTNAME_SUFFIX;
        name = name.replace(' ', '-').replaceAll("(:|\\(|\\)|\\\\|/|\\||<|>|&|\\^|%)", "");
    }
    return name;
}
Also used : IReceiver(nl.nn.adapterframework.core.IReceiver)

Example 5 with IReceiver

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

the class FxfListener method warn.

private void warn(String msg, Throwable t) {
    log.warn(msg, t);
    IReceiver iReceiver = getReceiver();
    if (iReceiver != null && iReceiver instanceof ReceiverBase) {
        ReceiverBase rb = (ReceiverBase) iReceiver;
        IAdapter iAdapter = rb.getAdapter();
        if (iAdapter != null) {
            iAdapter.getMessageKeeper().add("WARNING: " + msg + (t != null ? ": " + t.getMessage() : ""), MessageKeeperMessage.WARN_LEVEL);
        }
    }
}
Also used : IReceiver(nl.nn.adapterframework.core.IReceiver) ReceiverBase(nl.nn.adapterframework.receivers.ReceiverBase) IAdapter(nl.nn.adapterframework.core.IAdapter)

Aggregations

IReceiver (nl.nn.adapterframework.core.IReceiver)15 IAdapter (nl.nn.adapterframework.core.IAdapter)10 ReceiverBase (nl.nn.adapterframework.receivers.ReceiverBase)10 Adapter (nl.nn.adapterframework.core.Adapter)9 Iterator (java.util.Iterator)8 IListener (nl.nn.adapterframework.core.IListener)8 RestListener (nl.nn.adapterframework.http.RestListener)5 ArrayList (java.util.ArrayList)4 RunStateEnum (nl.nn.adapterframework.util.RunStateEnum)4 XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)4 HashMap (java.util.HashMap)3 Configuration (nl.nn.adapterframework.configuration.Configuration)3 HasSender (nl.nn.adapterframework.core.HasSender)3 ISender (nl.nn.adapterframework.core.ISender)3 IThreadCountControllable (nl.nn.adapterframework.core.IThreadCountControllable)3 ITransactionalStorage (nl.nn.adapterframework.core.ITransactionalStorage)3 EsbJmsListener (nl.nn.adapterframework.extensions.esb.EsbJmsListener)3 Map (java.util.Map)2 RolesAllowed (javax.annotation.security.RolesAllowed)2 GET (javax.ws.rs.GET)2