Skip to content

Commit

Permalink
Store message-context in ErrorStorage (#6352)
Browse files Browse the repository at this point in the history
  • Loading branch information
tnleeuw authored Feb 26, 2024
1 parent fa7235a commit f4f9c9d
Show file tree
Hide file tree
Showing 13 changed files with 183 additions and 81 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020-2022 WeAreFrank!
Copyright 2020-2024 WeAreFrank!
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,9 +30,6 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.apache.logging.log4j.Logger;
import org.xml.sax.SAXException;

import lombok.Lombok;
import org.frankframework.filesystem.FileSystemActor.FileSystemAction;
import org.frankframework.stream.MessageContext;
import org.frankframework.stream.document.DocumentBuilderFactory;
Expand All @@ -44,6 +41,9 @@
import org.frankframework.util.Misc;
import org.frankframework.util.UUIDUtil;
import org.frankframework.util.WildCardFilter;
import org.xml.sax.SAXException;

import lombok.Lombok;

public class FileSystemUtils {
protected static Logger log = LogUtil.getLogger(FileSystemUtils.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020-2022 WeAreFrank!
Copyright 2020-2024 WeAreFrank!
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,6 +28,11 @@
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.frankframework.configuration.ConfigurationException;
import org.frankframework.http.PartMessage;
import org.frankframework.util.CredentialFactory;
import org.frankframework.util.StringUtil;
import org.frankframework.xml.SaxElementBuilder;
import org.xml.sax.SAXException;

import com.sun.mail.imap.AppendUID;
Expand All @@ -53,11 +58,6 @@
import jakarta.mail.internet.MimeMessage;
import jakarta.mail.internet.MimeMultipart;
import lombok.Getter;
import org.frankframework.configuration.ConfigurationException;
import org.frankframework.http.PartMessage;
import org.frankframework.util.CredentialFactory;
import org.frankframework.util.StringUtil;
import org.frankframework.xml.SaxElementBuilder;

public class ImapFileSystem extends MailFileSystemBase<Message, MimeBodyPart, IMAPFolder> {
private final @Getter(onMethod = @__(@Override)) String domain = "IMAP";
Expand Down
25 changes: 6 additions & 19 deletions core/src/main/java/org/frankframework/http/PartMessage.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021, 2022 WeAreFrank!
Copyright 2021, 2022, 2024 WeAreFrank!
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -15,16 +15,14 @@
*/
package org.frankframework.http;

import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.frankframework.stream.Message;
import org.frankframework.stream.MessageContext;

import jakarta.mail.MessagingException;
import jakarta.mail.Part;
import org.frankframework.stream.Message;
import org.frankframework.stream.MessageContext;

public class PartMessage extends Message {

Expand All @@ -35,25 +33,14 @@ public class PartMessage extends Message {
private final transient Part part;

public PartMessage(Part part) throws MessagingException {
this(new MessageContext(), part);
this(part, new MessageContext());
}

public PartMessage(Part part, String charset) throws MessagingException {
this(new MessageContext(charset), part);
}

public PartMessage(Part part, Map<String, Object> context) throws MessagingException {
this(toMessageContext(context), part);
}

private static MessageContext toMessageContext(Map<String, Object> context) {
if(context instanceof MessageContext) {
return (MessageContext)context;
}
return (context == null) ? new MessageContext() : new MessageContext(context);
this(part, new MessageContext(charset));
}

private PartMessage(MessageContext context, Part part) throws MessagingException {
public PartMessage(Part part, MessageContext context) throws MessagingException {
super(part::getInputStream, context.withName(part.getFileName()), part.getClass());
this.part = part;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2017-2023 WeAreFrank!
Copyright 2017-2024 WeAreFrank!
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -35,27 +35,12 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.ThreadContext;
import org.frankframework.http.mime.MultipartUtils;
import org.springframework.util.InvalidMimeTypeException;
import org.springframework.util.MimeType;

import com.nimbusds.jose.util.JSONObjectUtils;

import jakarta.json.Json;
import jakarta.json.JsonObject;
import jakarta.json.JsonWriter;
import jakarta.json.JsonWriterFactory;
import jakarta.json.stream.JsonGenerator;
import jakarta.mail.BodyPart;
import jakarta.mail.MessagingException;
import jakarta.mail.internet.MimeMultipart;

import org.frankframework.core.PipeLineSession;
import org.frankframework.http.HttpSecurityHandler;
import org.frankframework.http.HttpServletBase;
import org.frankframework.http.InputStreamDataSource;
import org.frankframework.http.PartMessage;

import org.frankframework.http.mime.MultipartUtils;
import org.frankframework.jwt.AuthorizationException;
import org.frankframework.jwt.JwtSecurityHandler;
import org.frankframework.lifecycle.IbisInitializer;
Expand All @@ -70,6 +55,19 @@
import org.frankframework.util.MessageUtils;
import org.frankframework.util.StreamUtil;
import org.frankframework.util.XmlBuilder;
import org.springframework.util.InvalidMimeTypeException;
import org.springframework.util.MimeType;

import com.nimbusds.jose.util.JSONObjectUtils;

import jakarta.json.Json;
import jakarta.json.JsonObject;
import jakarta.json.JsonWriter;
import jakarta.json.JsonWriterFactory;
import jakarta.json.stream.JsonGenerator;
import jakarta.mail.BodyPart;
import jakarta.mail.MessagingException;
import jakarta.mail.internet.MimeMultipart;

/**
*
Expand Down
19 changes: 10 additions & 9 deletions core/src/main/java/org/frankframework/jms/JMSFacade.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2013, 2015, 2018 Nationale-Nederlanden, 2020-2023 WeAreFrank!
Copyright 2013, 2015, 2018 Nationale-Nederlanden, 2020-2024 WeAreFrank!
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -20,6 +20,7 @@
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.util.Enumeration;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
Expand All @@ -45,13 +46,6 @@

import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.util.Supplier;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import org.xml.sax.SAXException;

import lombok.Getter;
import lombok.Setter;
import lombok.SneakyThrows;
import org.frankframework.configuration.ConfigurationException;
import org.frankframework.configuration.ConfigurationWarnings;
import org.frankframework.core.HasPhysicalDestination;
Expand All @@ -71,6 +65,13 @@
import org.frankframework.util.DateFormatUtils;
import org.frankframework.util.EnumUtils;
import org.frankframework.util.XmlException;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import org.xml.sax.SAXException;

import lombok.Getter;
import lombok.Setter;
import lombok.SneakyThrows;


/**
Expand Down Expand Up @@ -733,7 +734,7 @@ public MessageContext getContext(javax.jms.Message message) throws JMSException
Enumeration<String> names = message.getPropertyNames();
while (names.hasMoreElements()) {
String name = names.nextElement();
result.put(name, message.getObjectProperty(name));
result.put(name, (Serializable) message.getObjectProperty(name));
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.OptionalDataException;
import java.io.Serializable;
import java.util.Map;
import java.util.stream.Collectors;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -30,6 +31,7 @@
import org.frankframework.stream.Message;

import lombok.Getter;
import lombok.extern.log4j.Log4j2;

/**
* Wrapper for messages that are not serializable.
Expand All @@ -38,6 +40,7 @@
* @since 4.3
*/
@SuppressWarnings({"deprecation", "unchecked"})
@Log4j2
public class MessageWrapper<M> extends RawMessageWrapper<M> implements Serializable {

private static final long serialVersionUID = -8251009650246241025L;
Expand Down Expand Up @@ -70,7 +73,16 @@ public MessageWrapper(@Nonnull RawMessageWrapper<M> rawMessageWrapper, @Nonnull
* this method is used by Serializable, to serialize objects to a stream.
*/
private void writeObject(ObjectOutputStream stream) throws IOException {
stream.writeObject(context);
Map<String, Serializable> serializableData = context.entrySet().stream()
.filter(e -> {
if (e.getValue() instanceof Serializable) return true;
else {
log.warn("Cannot write non-serializable MessageWrapper context entry to stream: [{}] -> [{}]", e::getKey, e::getValue);
return false;
}
})
.collect(Collectors.toMap(Map.Entry::getKey, e -> (Serializable)(e.getValue())));
stream.writeObject(serializableData);
stream.writeObject(id);
stream.writeObject(message);
stream.writeObject(correlationId);
Expand Down
29 changes: 20 additions & 9 deletions core/src/main/java/org/frankframework/stream/Message.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2019-2023 WeAreFrank!
Copyright 2019-2024 WeAreFrank!
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -934,6 +934,7 @@ private void writeObject(ObjectOutputStream stream) throws IOException {
stream.writeObject(getCharset());
stream.writeObject(request);
stream.writeObject(requestClass);
stream.writeObject(context);
}

/*
Expand All @@ -943,22 +944,32 @@ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFo
String charset = (String) stream.readObject();
request = stream.readObject();
try {
Object requestClass = stream.readObject();
if (requestClass != null) {
if (requestClass instanceof Class<?>) {
this.requestClass = ((Class<?>) requestClass).getTypeName();
Object requestClassFromStream = stream.readObject();
if (requestClassFromStream != null) {
if (requestClassFromStream instanceof Class<?>) {
this.requestClass = ((Class<?>) requestClassFromStream).getTypeName();
} else {
this.requestClass = requestClass.toString();
this.requestClass = requestClassFromStream.toString();
}
} else {
this.requestClass = ClassUtils.nameOf(request);
}
} catch (Exception e) {
requestClass = ClassUtils.nameOf(request);
LOG.warn("Could not read requestClass, using ClassUtils.nameOf(request) [" + requestClass + "], (" + ClassUtils.nameOf(e) + "): " + e.getMessage());
LOG.warn("Could not read requestClass, using ClassUtils.nameOf(request) [{}], ({}): {}", ()->requestClass, ()->ClassUtils.nameOf(e), e::getMessage);
}

context = new MessageContext().withCharset(charset);
MessageContext contextFromStream;
try {
contextFromStream = (MessageContext) stream.readObject();
} catch (Exception e) {
// Old version of object, does not yet have the MessageContext stored?
LOG.debug("Could not read MessageContext of message {}, old format message? Exception: {}", requestClass, e.getMessage());
contextFromStream = null;
}
if (contextFromStream == null) {
contextFromStream = new MessageContext().withCharset(charset);
}
context = contextFromStream;
}

/**
Expand Down
Loading

0 comments on commit f4f9c9d

Please sign in to comment.