Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CU-85ztrjkqe_Make-the-metadata-extractor-lenient #169

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Prowide Core - CHANGELOG

#### 9.3.18-SNAPSHOT
* Updating the message setter in order to handle case-insensitive XML prolog for lenient parsing.

#### 9.3.17 - July 2023
* (PW-1405) Trim original String payload when creating an AbstractSwiftMessage

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@
import com.prowidesoftware.deprecation.ProwideDeprecated;
import com.prowidesoftware.deprecation.TargetYear;
import com.prowidesoftware.swift.utils.Lib;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.math.BigDecimal;
import java.text.NumberFormat;
import java.util.*;

import javax.persistence.*;
import javax.xml.bind.annotation.XmlTransient;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

/**
* Base entity for MT and MX message persistence.
Expand Down Expand Up @@ -168,7 +170,7 @@ public AbstractSwiftMessage() {}
@Deprecated
@ProwideDeprecated(phase3 = TargetYear.SRU2023)
protected AbstractSwiftMessage(final String content) {
this.message = content;
setMessage(content);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

El mensaje original no hay que alterarlo. Aca en el entity hay que guardar el payload tal cual como se recibe. Estas clases son JPA entities.

El hack ese hay que hacerlo al momento de usarlo, cuando falla, que es puntualmente en el default metadata extractor.

PD : Ademas, no esta bueno que un setter modifique datos, en general se asume que los accesos (get set) son triviales. Incluso si tuviéramos Lombok en el proyecto, serian métodos generados.

updateFromMessage();
}

Expand All @@ -178,7 +180,7 @@ protected AbstractSwiftMessage(final String content) {
@Deprecated
@ProwideDeprecated(phase3 = TargetYear.SRU2023)
protected AbstractSwiftMessage(final String content, final FileFormat fileFormat) {
this.message = content;
setMessage(content);
this.fileFormat = fileFormat;
updateFromMessage();
}
Expand All @@ -197,7 +199,7 @@ protected AbstractSwiftMessage(final String content, final FileFormat fileFormat
protected AbstractSwiftMessage(
final String content, final FileFormat fileFormat, final MessageMetadataStrategy metadataStrategy) {
Objects.requireNonNull(metadataStrategy, "the strategy for metadata extraction cannot be null");
this.message = StringUtils.trim(content);
setMessage(StringUtils.trim(content));
this.fileFormat = fileFormat;
updateFromMessage(metadataStrategy);
}
Expand All @@ -209,7 +211,7 @@ protected AbstractSwiftMessage(
@Deprecated
@ProwideDeprecated(phase3 = TargetYear.SRU2023)
protected AbstractSwiftMessage(final InputStream stream) throws IOException {
this.message = Lib.readStream(stream);
setMessage(Lib.readStream(stream));
updateFromMessage();
}

Expand All @@ -220,7 +222,7 @@ protected AbstractSwiftMessage(final InputStream stream) throws IOException {
@Deprecated
@ProwideDeprecated(phase3 = TargetYear.SRU2023)
protected AbstractSwiftMessage(final InputStream stream, final FileFormat fileFormat) throws IOException {
this.message = Lib.readStream(stream);
setMessage(Lib.readStream(stream));
this.fileFormat = fileFormat;
updateFromMessage();
}
Expand All @@ -240,7 +242,7 @@ protected AbstractSwiftMessage(
final InputStream stream, final FileFormat fileFormat, final MessageMetadataStrategy metadataStrategy)
throws IOException {
Objects.requireNonNull(metadataStrategy, "the strategy for metadata extraction cannot be null");
this.message = Lib.readStream(stream);
setMessage(Lib.readStream(stream));
this.fileFormat = fileFormat;
updateFromMessage(metadataStrategy);
}
Expand All @@ -252,7 +254,7 @@ protected AbstractSwiftMessage(
@Deprecated
@ProwideDeprecated(phase3 = TargetYear.SRU2023)
protected AbstractSwiftMessage(final File file) throws IOException {
this.message = Lib.readFile(file);
setMessage(Lib.readFile(file));
this.filename = file.getAbsolutePath();
updateFromMessage();
}
Expand All @@ -264,7 +266,7 @@ protected AbstractSwiftMessage(final File file) throws IOException {
@Deprecated
@ProwideDeprecated(phase3 = TargetYear.SRU2023)
protected AbstractSwiftMessage(final File file, final FileFormat fileFormat) throws IOException {
this.message = Lib.readFile(file);
setMessage(Lib.readFile(file));
this.filename = file.getAbsolutePath();
this.fileFormat = fileFormat;
updateFromMessage();
Expand All @@ -287,7 +289,7 @@ protected AbstractSwiftMessage(
throws IOException {
Objects.requireNonNull(file, "the file parameter cannot be null");
Objects.requireNonNull(metadataStrategy, "the strategy for metadata extraction cannot be null");
this.message = Lib.readFile(file);
setMessage(Lib.readFile(file));
this.filename = file.getAbsolutePath();
this.fileFormat = fileFormat;
updateFromMessage(metadataStrategy);
Expand Down Expand Up @@ -347,7 +349,11 @@ public String getMessage() {
* @param message raw content of the message
*/
public void setMessage(String message) {
this.message = message;
this.message = makeXmlLenient(message);
}

private String makeXmlLenient(String xml) {
return xml.replaceFirst("(?i)<\\?XML", "<?xml");
Copy link
Member Author

@zubri zubri Aug 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cuando pongas el hack en el extractor, fíjate que el parametro no sea null

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

El hack de hecho va al proyecto ISO, no habria que tocar nada en Core

}

/**
Expand Down Expand Up @@ -1497,4 +1503,5 @@ public String getMessageType() {
return getIdentifier();
}
}

}