Search in sources :

Example 1 with IListener

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

the class ShowConfigurationStatus method mapAdapterPipes.

private ArrayList<Object> mapAdapterPipes(Adapter adapter) {
    if (!adapter.configurationSucceeded())
        return null;
    PipeLine pipeline = adapter.getPipeLine();
    int totalPipes = pipeline.getPipes().size();
    ArrayList<Object> pipes = new ArrayList<Object>(totalPipes);
    for (int i = 0; i < totalPipes; i++) {
        Map<String, Object> pipesInfo = new HashMap<String, Object>();
        IPipe pipe = pipeline.getPipe(i);
        Map<String, PipeForward> pipeForwards = pipe.getForwards();
        String pipename = pipe.getName();
        Map<String, String> forwards = new HashMap<String, String>();
        for (PipeForward fwrd : pipeForwards.values()) {
            forwards.put(fwrd.getName(), fwrd.getPath());
        }
        pipesInfo.put("name", pipename);
        pipesInfo.put("type", pipe.getType());
        pipesInfo.put("forwards", forwards);
        if (pipe instanceof MessageSendingPipe) {
            MessageSendingPipe msp = (MessageSendingPipe) pipe;
            ISender sender = msp.getSender();
            pipesInfo.put("sender", ClassUtils.nameOf(sender));
            if (sender instanceof WebServiceSender) {
                WebServiceSender s = (WebServiceSender) sender;
                Map<String, Object> certInfo = addCertificateInfo(s);
                if (certInfo != null)
                    pipesInfo.put("certificate", certInfo);
            }
            if (sender instanceof HttpSender) {
                HttpSender s = (HttpSender) sender;
                Map<String, Object> certInfo = addCertificateInfo(s);
                if (certInfo != null)
                    pipesInfo.put("certificate", certInfo);
            }
            if (sender instanceof FtpSender) {
                FtpSender s = (FtpSender) sender;
                Map<String, Object> certInfo = addCertificateInfo(s);
                if (certInfo != null)
                    pipesInfo.put("certificate", certInfo);
            }
            if (sender instanceof HasPhysicalDestination) {
                pipesInfo.put("destination", ((HasPhysicalDestination) sender).getPhysicalDestinationName());
            }
            if (sender instanceof JdbcSenderBase) {
                pipesInfo.put("isJdbcSender", true);
            }
            IListener listener = msp.getListener();
            if (listener != null) {
                pipesInfo.put("listenerName", listener.getName());
                pipesInfo.put("listenerClass", ClassUtils.nameOf(listener));
                if (listener instanceof HasPhysicalDestination) {
                    String pd = ((HasPhysicalDestination) listener).getPhysicalDestinationName();
                    pipesInfo.put("listenerDestination", pd);
                }
            }
            ITransactionalStorage messageLog = msp.getMessageLog();
            if (messageLog != null) {
                pipesInfo.put("hasMessageLog", true);
                String messageLogCount;
                try {
                    if (showCountMessageLog) {
                        messageLogCount = "" + messageLog.getMessageCount();
                    } else {
                        messageLogCount = "?";
                    }
                } catch (Exception e) {
                    log.warn(e);
                    messageLogCount = "error";
                }
                pipesInfo.put("messageLogCount", messageLogCount);
                Map<String, Object> message = new HashMap<String, Object>();
                message.put("name", messageLog.getName());
                message.put("type", "log");
                message.put("slotId", messageLog.getSlotId());
                message.put("count", messageLogCount);
                pipesInfo.put("message", message);
            }
        }
        pipes.add(pipesInfo);
    }
    return pipes;
}
Also used : MessageSendingPipe(nl.nn.adapterframework.pipes.MessageSendingPipe) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IListener(nl.nn.adapterframework.core.IListener) ArrayList(java.util.ArrayList) FtpSender(nl.nn.adapterframework.ftp.FtpSender) HttpSender(nl.nn.adapterframework.http.HttpSender) PipeForward(nl.nn.adapterframework.core.PipeForward) ITransactionalStorage(nl.nn.adapterframework.core.ITransactionalStorage) ISender(nl.nn.adapterframework.core.ISender) WebServiceSender(nl.nn.adapterframework.http.WebServiceSender) PipeLine(nl.nn.adapterframework.core.PipeLine) IPipe(nl.nn.adapterframework.core.IPipe) JdbcSenderBase(nl.nn.adapterframework.jdbc.JdbcSenderBase) HasPhysicalDestination(nl.nn.adapterframework.core.HasPhysicalDestination)

Example 2 with IListener

use of nl.nn.adapterframework.core.IListener 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 IListener

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

the class ShowConfigurationStatus method toPipesXml.

private XmlBuilder toPipesXml(Adapter adapter) {
    XmlBuilder pipesElem = new XmlBuilder("pipes");
    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);
            pipesElem.addSubElement(pipeElem);
            ISender sender = msp.getSender();
            pipeElem.addAttribute("sender", ClassUtils.nameOf(sender));
            if (sender instanceof HasPhysicalDestination) {
                pipeElem.addAttribute("destination", ((HasPhysicalDestination) sender).getPhysicalDestinationName());
            }
            if (sender instanceof JdbcSenderBase) {
                pipeElem.addAttribute("isJdbcSender", "true");
            }
            IListener listener = msp.getListener();
            if (listener != null) {
                pipeElem.addAttribute("listenerName", listener.getName());
                pipeElem.addAttribute("listenerClass", ClassUtils.nameOf(listener));
                if (listener instanceof HasPhysicalDestination) {
                    String pd = ((HasPhysicalDestination) listener).getPhysicalDestinationName();
                    pipeElem.addAttribute("listenerDestination", pd);
                }
            }
            ITransactionalStorage messageLog = msp.getMessageLog();
            if (messageLog != null) {
                pipeElem.addAttribute("hasMessageLog", "true");
                String messageLogCount;
                try {
                    if (SHOW_COUNT_MESSAGELOG) {
                        messageLogCount = "" + messageLog.getMessageCount();
                    } else {
                        messageLogCount = "?";
                    }
                } catch (Exception e) {
                    log.warn(e);
                    messageLogCount = "error";
                }
                pipeElem.addAttribute("messageLogCount", messageLogCount);
                XmlBuilder browserElem = new XmlBuilder("browser");
                browserElem.addAttribute("name", messageLog.getName());
                browserElem.addAttribute("type", "log");
                browserElem.addAttribute("slotId", messageLog.getSlotId());
                browserElem.addAttribute("count", messageLogCount);
                pipeElem.addSubElement(browserElem);
            }
        }
    }
    return pipesElem;
}
Also used : MessageSendingPipe(nl.nn.adapterframework.pipes.MessageSendingPipe) ISender(nl.nn.adapterframework.core.ISender) IListener(nl.nn.adapterframework.core.IListener) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) PipeLine(nl.nn.adapterframework.core.PipeLine) IPipe(nl.nn.adapterframework.core.IPipe) JdbcSenderBase(nl.nn.adapterframework.jdbc.JdbcSenderBase) PipeRunException(nl.nn.adapterframework.core.PipeRunException) HasPhysicalDestination(nl.nn.adapterframework.core.HasPhysicalDestination) ITransactionalStorage(nl.nn.adapterframework.core.ITransactionalStorage)

Example 4 with IListener

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

the class Browse method executeSub.

public ActionForward executeSub(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    // Initialize action
    initAction(request);
    DynaActionForm browseForm = getPersistentForm(mapping, form, request);
    String submit = request.getParameter("submit");
    log.debug("submit param [" + submit + "]");
    String maxMessagesStr = getAndSetProperty(request, browseForm, "maxMessages", getMaxMessages() + "");
    String skipMessagesStr = getAndSetProperty(request, browseForm, "skipMessages", "0");
    String action = getAndSetProperty(request, browseForm, "action");
    String storageType = getAndSetProperty(request, browseForm, "storageType");
    String adapterName = getAndSetProperty(request, browseForm, "adapterName");
    String receiverName = getAndSetProperty(request, browseForm, "receiverName");
    String pipeName = getAndSetProperty(request, browseForm, "pipeName");
    String messageId = getAndSetProperty(request, browseForm, "messageId");
    String typeMask = getAndSetProperty(request, browseForm, "typeMask");
    String hostMask = getAndSetProperty(request, browseForm, "hostMask");
    String currentIdMask = getAndSetProperty(request, browseForm, "currentIdMask");
    String messageIdMask = getAndSetProperty(request, browseForm, "messageIdMask");
    String correlationIdMask = getAndSetProperty(request, browseForm, "correlationIdMask");
    String commentMask = getAndSetProperty(request, browseForm, "commentMask");
    String messageTextMask = getAndSetProperty(request, browseForm, "messageTextMask");
    String labelMask = getAndSetProperty(request, browseForm, "labelMask");
    String startDateStr = getAndSetProperty(request, browseForm, "insertedAfter");
    String startDateClipStr = getAndSetProperty(request, browseForm, "insertedAfterClip");
    // not yet supported in actionForm
    String endDateStr = request.getParameter("insertedBefore");
    // not yet supported in actionForm
    String forceDescStr = request.getParameter("forceDescending");
    String viewAs = getAndSetProperty(request, browseForm, "viewAs", request.getParameter("type"));
    String[] selected = (String[]) browseForm.get("selected");
    boolean startDateClip = "on".equals(startDateClipStr);
    if (StringUtils.isNotEmpty(submit)) {
        action = submit;
    }
    Date startDate = null;
    Date endDate = null;
    String formattedStartDate = null;
    if (StringUtils.isNotEmpty(startDateStr)) {
        try {
            startDate = DateUtils.parseAnyDate(startDateStr);
            if (startDate != null) {
                formattedStartDate = DateUtils.formatOptimal(startDate);
                log.debug("parsed start date to [" + formattedStartDate + "]");
                browseForm.set("insertedAfter", formattedStartDate);
                if (startDateClip) {
                    endDate = DateUtils.nextHigherValue(startDate);
                }
            } else {
                warn("could not parse date from [" + startDateStr + "]");
            }
        } catch (CalendarParserException e) {
            warn("could not parse date from [" + startDateStr + "]", e);
        }
    }
    if (StringUtils.isNotEmpty(endDateStr)) {
        try {
            endDate = DateUtils.parseAnyDate(endDateStr);
            if (startDate == null) {
                warn("could not parse date from [" + endDateStr + "]");
            }
        } catch (CalendarParserException e) {
            warn("could not parse date from [" + startDateStr + "]", e);
        }
    }
    ArrayList viewAsList = new ArrayList();
    viewAsList.add("html");
    viewAsList.add("text");
    browseForm.set("viewAsList", viewAsList);
    log.debug("selected [" + browseForm.get("selected") + "]");
    // ArrayList selected=(ArrayList)browseForm.get("selected");
    // for (int i=0; i<selected.size(); i++) {
    // log.debug("selected "+i+" = ["+selected.get(i));
    // }
    maxMessages = Integer.parseInt(maxMessagesStr);
    skipMessages = Integer.parseInt(skipMessagesStr);
    // commandIssuedBy containes information about the location the
    // command is sent from
    String commandIssuedBy = HttpUtils.getCommandIssuedBy(request);
    log.debug("storageType [" + storageType + "] action [" + action + "] submit [" + submit + "] adapterName [" + adapterName + "] receiverName [" + receiverName + "] pipeName [" + pipeName + "] issued by [" + commandIssuedBy + "]");
    Adapter adapter = (Adapter) ibisManager.getRegisteredAdapter(adapterName);
    IMessageBrowser mb;
    IListener listener = null;
    String logCount;
    if ("messagelog".equals(storageType)) {
        if (StringUtils.isNotEmpty(pipeName)) {
            MessageSendingPipe pipe = (MessageSendingPipe) adapter.getPipeLine().getPipe(pipeName);
            mb = pipe.getMessageLog();
        } else {
            ReceiverBase receiver = (ReceiverBase) adapter.getReceiverByName(receiverName);
            mb = receiver.getMessageLog();
        }
        // actions 'deletemessage' and 'resendmessage' not allowed for messageLog
        if ("export selected".equalsIgnoreCase(action)) {
            performAction(adapter, null, action, mb, messageId, selected, request, response);
        }
    } else {
        ReceiverBase receiver = (ReceiverBase) adapter.getReceiverByName(receiverName);
        if (receiver == null) {
            error("cannot find Receiver [" + receiverName + "]", null);
            return null;
        }
        mb = receiver.getErrorStorage();
        if (performAction(adapter, receiver, action, mb, messageId, selected, request, response))
            return null;
        listener = receiver.getListener();
    }
    try {
        logCount = "(" + ((ITransactionalStorage) mb).getMessageCount() + ")";
    } catch (Exception e) {
        log.warn(e);
        logCount = "(?)";
    }
    try {
        if ("showmessage".equalsIgnoreCase(action)) {
            Object rawmsg = mb.browseMessage(messageId);
            String msg = null;
            if (listener != null) {
                msg = listener.getStringFromRawMessage(rawmsg, null);
            } else {
                msg = (String) rawmsg;
            }
            if (StringUtils.isEmpty(msg)) {
                msg = "<no message found>";
            }
            String type = request.getParameter("type");
            if (StringUtils.isEmpty(type)) {
                type = viewAs;
            }
            FileViewerServlet.showReaderContents(new StringReader(msg), "msg" + messageId, type, response, "message [" + messageId + "]");
            return null;
        } else {
            IMessageBrowsingIterator mbi = mb.getIterator(startDate, endDate, "true".equals(forceDescStr));
            try {
                XmlBuilder messages = new XmlBuilder("messages");
                messages.addAttribute("storageType", storageType);
                messages.addAttribute("action", action);
                messages.addAttribute("adapterName", XmlUtils.encodeChars(adapterName));
                if ("messagelog".equals(storageType) && StringUtils.isNotEmpty(pipeName)) {
                    messages.addAttribute("object", "pipe [" + XmlUtils.encodeChars(pipeName) + "] of adapter [" + XmlUtils.encodeChars(adapterName) + "] " + logCount);
                    messages.addAttribute("pipeName", XmlUtils.encodeChars(pipeName));
                } else {
                    messages.addAttribute("object", "receiver [" + XmlUtils.encodeChars(receiverName) + "] of adapter [" + XmlUtils.encodeChars(adapterName) + "] " + logCount);
                    messages.addAttribute("receiverName", XmlUtils.encodeChars(receiverName));
                }
                int messageCount;
                for (messageCount = 0; mbi.hasNext(); ) {
                    IMessageBrowsingIteratorItem iterItem = mbi.next();
                    try {
                        String cType = iterItem.getType();
                        String cHost = iterItem.getHost();
                        String cId = iterItem.getId();
                        String cMessageId = iterItem.getOriginalId();
                        String cCorrelationId = iterItem.getCorrelationId();
                        String comment = iterItem.getCommentString();
                        Date insertDate = iterItem.getInsertDate();
                        String cLabel = iterItem.getLabel();
                        if (StringUtils.isNotEmpty(typeMask) && !cType.startsWith(typeMask)) {
                            continue;
                        }
                        if (StringUtils.isNotEmpty(hostMask) && !cHost.startsWith(hostMask)) {
                            continue;
                        }
                        if (StringUtils.isNotEmpty(currentIdMask) && !cId.startsWith(currentIdMask)) {
                            continue;
                        }
                        if (StringUtils.isNotEmpty(messageIdMask) && !cMessageId.startsWith(messageIdMask)) {
                            continue;
                        }
                        if (StringUtils.isNotEmpty(correlationIdMask) && !cCorrelationId.startsWith(correlationIdMask)) {
                            continue;
                        }
                        if (startDate != null && insertDate != null) {
                            if (insertDate.before(startDate)) {
                                continue;
                            }
                            if (startDateClip) {
                                String formattedInsertDate = DateUtils.formatOptimal(insertDate);
                                if (!formattedInsertDate.startsWith(formattedStartDate)) {
                                    continue;
                                }
                            }
                        }
                        if (StringUtils.isNotEmpty(commentMask) && (StringUtils.isEmpty(comment) || comment.indexOf(commentMask) < 0)) {
                            continue;
                        }
                        if (StringUtils.isNotEmpty(messageTextMask)) {
                            Object rawmsg = mb.browseMessage(cId);
                            String msg = null;
                            if (listener != null) {
                                msg = listener.getStringFromRawMessage(rawmsg, new HashMap());
                            } else {
                                msg = (String) rawmsg;
                            }
                            if (msg == null || msg.indexOf(messageTextMask) < 0) {
                                continue;
                            }
                        }
                        if (StringUtils.isNotEmpty(labelMask) && (StringUtils.isEmpty(cLabel) || !cLabel.startsWith(labelMask))) {
                            continue;
                        }
                        messageCount++;
                        if (messageCount > skipMessages) {
                            XmlBuilder message = new XmlBuilder("message");
                            message.addAttribute("id", cId);
                            message.addAttribute("pos", Integer.toString(messageCount));
                            message.addAttribute("originalId", cMessageId);
                            message.addAttribute("correlationId", cCorrelationId);
                            message.addAttribute("type", cType);
                            message.addAttribute("host", cHost);
                            message.addAttribute("insertDate", DateUtils.format(insertDate, DateUtils.FORMAT_FULL_GENERIC));
                            if (iterItem.getExpiryDate() != null) {
                                message.addAttribute("expiryDate", DateUtils.format(iterItem.getExpiryDate(), DateUtils.FORMAT_FULL_GENERIC));
                            }
                            message.addAttribute("comment", XmlUtils.encodeChars(iterItem.getCommentString()));
                            message.addAttribute("label", cLabel);
                            messages.addSubElement(message);
                        }
                        if (getMaxMessages() > 0 && messageCount >= (getMaxMessages() + skipMessages)) {
                            log.warn("stopped iterating messages after [" + messageCount + "]: limit reached");
                            break;
                        }
                    } finally {
                        iterItem.release();
                    }
                }
                messages.addAttribute("messageCount", Integer.toString(messageCount - skipMessages));
                request.setAttribute("messages", messages.toXML());
            } finally {
                mbi.close();
            }
        }
    } catch (Throwable e) {
        error("Caught Exception", e);
        throw new ServletException(e);
    }
    if (!errors.isEmpty()) {
        saveErrors(request, errors);
    }
    log.debug("forward to success");
    return (mapping.findForward("success"));
}
Also used : ReceiverBase(nl.nn.adapterframework.receivers.ReceiverBase) DynaActionForm(org.apache.struts.action.DynaActionForm) MessageSendingPipe(nl.nn.adapterframework.pipes.MessageSendingPipe) HashMap(java.util.HashMap) IMessageBrowsingIteratorItem(nl.nn.adapterframework.core.IMessageBrowsingIteratorItem) IMessageBrowser(nl.nn.adapterframework.core.IMessageBrowser) IListener(nl.nn.adapterframework.core.IListener) ArrayList(java.util.ArrayList) Adapter(nl.nn.adapterframework.core.Adapter) IMessageBrowsingIterator(nl.nn.adapterframework.core.IMessageBrowsingIterator) Date(java.util.Date) ServletException(javax.servlet.ServletException) CalendarParserException(nl.nn.adapterframework.util.CalendarParserException) IOException(java.io.IOException) CalendarParserException(nl.nn.adapterframework.util.CalendarParserException) ServletException(javax.servlet.ServletException) StringReader(java.io.StringReader) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder)

Example 5 with IListener

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

the class BrowseExecute method exportMessage.

private void exportMessage(IMessageBrowser mb, String id, ReceiverBase receiver, ZipOutputStream zipOutputStream) {
    IListener listener = null;
    if (receiver != null) {
        listener = receiver.getListener();
    }
    try {
        Object rawmsg = mb.browseMessage(id);
        IMessageBrowsingIteratorItem msgcontext = mb.getContext(id);
        try {
            String msg = null;
            String msgId = msgcontext.getId();
            String msgMid = msgcontext.getOriginalId();
            String msgCid = msgcontext.getCorrelationId();
            HashMap context = new HashMap();
            if (listener != null) {
                msg = listener.getStringFromRawMessage(rawmsg, context);
            } else {
                msg = (String) rawmsg;
            }
            if (StringUtils.isEmpty(msg)) {
                msg = "<no message found>";
            }
            if (msgId == null) {
                msgId = "";
            }
            if (msgMid == null) {
                msgMid = "";
            }
            if (msgCid == null) {
                msgCid = "";
            }
            String filename = "msg_" + id + "_id[" + msgId.replace(':', '-') + "]" + "_mid[" + msgMid.replace(':', '-') + "]" + "_cid[" + msgCid.replace(':', '-') + "]";
            ZipEntry zipEntry = new ZipEntry(filename + ".txt");
            String sentDateString = (String) context.get(IPipeLineSession.tsSentKey);
            if (StringUtils.isNotEmpty(sentDateString)) {
                try {
                    Date sentDate = DateUtils.parseToDate(sentDateString, DateUtils.FORMAT_FULL_GENERIC);
                    zipEntry.setTime(sentDate.getTime());
                } catch (Throwable e) {
                    error(", ", "errors.generic", "Could not set date for message [" + id + "]", e);
                }
            } else {
                Date insertDate = msgcontext.getInsertDate();
                if (insertDate != null) {
                    zipEntry.setTime(insertDate.getTime());
                }
            }
            // String comment=msgcontext.getCommentString();
            // if (StringUtils.isNotEmpty(comment)) {
            // zipEntry.setComment(comment);
            // }
            zipOutputStream.putNextEntry(zipEntry);
            String encoding = Misc.DEFAULT_INPUT_STREAM_ENCODING;
            if (msg.startsWith("<?xml")) {
                int lastpos = msg.indexOf("?>");
                if (lastpos > 0) {
                    String prefix = msg.substring(6, lastpos);
                    int encodingStartPos = prefix.indexOf("encoding=\"");
                    if (encodingStartPos > 0) {
                        int encodingEndPos = prefix.indexOf('"', encodingStartPos + 10);
                        if (encodingEndPos > 0) {
                            encoding = prefix.substring(encodingStartPos + 10, encodingEndPos);
                            log.debug("parsed encoding [" + encoding + "] from prefix [" + prefix + "]");
                        }
                    }
                }
            }
            zipOutputStream.write(msg.getBytes(encoding));
            if (listener != null && listener instanceof IBulkDataListener) {
                IBulkDataListener bdl = (IBulkDataListener) listener;
                String bulkfilename = bdl.retrieveBulkData(rawmsg, msg, context);
                zipOutputStream.closeEntry();
                File bulkfile = new File(bulkfilename);
                zipEntry = new ZipEntry(filename + "_" + bulkfile.getName());
                zipEntry.setTime(bulkfile.lastModified());
                zipOutputStream.putNextEntry(zipEntry);
                StreamUtil.copyStream(new FileInputStream(bulkfile), zipOutputStream, 32000);
                bulkfile.delete();
            }
            zipOutputStream.closeEntry();
        } finally {
            msgcontext.release();
        }
    } catch (Throwable e) {
        error(", ", "errors.generic", "Could not export message with id [" + id + "]", e);
    }
}
Also used : IBulkDataListener(nl.nn.adapterframework.core.IBulkDataListener) HashMap(java.util.HashMap) IMessageBrowsingIteratorItem(nl.nn.adapterframework.core.IMessageBrowsingIteratorItem) IListener(nl.nn.adapterframework.core.IListener) ZipEntry(java.util.zip.ZipEntry) File(java.io.File) Date(java.util.Date) FileInputStream(java.io.FileInputStream)

Aggregations

IListener (nl.nn.adapterframework.core.IListener)16 ReceiverBase (nl.nn.adapterframework.receivers.ReceiverBase)10 IReceiver (nl.nn.adapterframework.core.IReceiver)8 ArrayList (java.util.ArrayList)6 Iterator (java.util.Iterator)6 IAdapter (nl.nn.adapterframework.core.IAdapter)6 ITransactionalStorage (nl.nn.adapterframework.core.ITransactionalStorage)6 HashMap (java.util.HashMap)5 Adapter (nl.nn.adapterframework.core.Adapter)5 ISender (nl.nn.adapterframework.core.ISender)5 RestListener (nl.nn.adapterframework.http.RestListener)5 HasPhysicalDestination (nl.nn.adapterframework.core.HasPhysicalDestination)4 XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)4 IThreadCountControllable (nl.nn.adapterframework.core.IThreadCountControllable)3 PipeRunException (nl.nn.adapterframework.core.PipeRunException)3 EsbJmsListener (nl.nn.adapterframework.extensions.esb.EsbJmsListener)3 MessageSendingPipe (nl.nn.adapterframework.pipes.MessageSendingPipe)3 IOException (java.io.IOException)2 Date (java.util.Date)2 LinkedHashMap (java.util.LinkedHashMap)2