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

JSON Array splitting #77

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

JSON Array splitting #77

wants to merge 15 commits into from

Conversation

51-code
Copy link

@51-code 51-code commented Oct 1, 2024

Adds a new splitting option: json_array. Takes HTTP requests with this kind of format:

[
{"a": 1},
{"b": 2}
]

and converts each of the JSON objects to their own syslog message and sends them forward.

Configuration had changes: payload.splitEnabled was changed to payload.splitType. Valid values are regex, json_array or none. none is the default.
payload.splitRegex was moved to payload.splitType.regex.pattern.

Regex splitting was already supported, but the design was not scalable. Therefore it was refactored as well to allow json_array to be implemented.

There was a problem with Jakarta's way of getting a JSON object as a string. It removes any whitespace from the String representation. This is okay as the content stays the same.

Tests most importantly include:

  • JsonPayloadTest for unit tests for the new functionality
  • JsonSplittingTest for end-to-end testing the functionality with actual HTTP-requests sent to the component

@51-code 51-code added assistance Extra attention, more information or help is needed enhancement New feature or request labels Oct 1, 2024
@51-code 51-code self-assigned this Oct 1, 2024
@51-code 51-code marked this pull request as ready for review October 2, 2024 10:02
@51-code 51-code requested a review from eemhu October 2, 2024 10:02
@51-code 51-code added review and removed assistance Extra attention, more information or help is needed labels Oct 2, 2024
IMessageHandler conversion = new RelpConversion(pool, securityConfig, basicAuthentication, lookupConfig);

// apply splitting if configured
switch (payloadConfig.splitType) { // payloadConfig is Validateable, no need to check wrong config here
Copy link

Choose a reason for hiding this comment

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

could switch-case be replaced with another object?

Copy link
Author

Choose a reason for hiding this comment

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

Tried to refactor code for creating a decorator for this in NettyHttpServer and even some other objects that use / forward the RelpConversion object. This was so that I could put the config checking code there so it doesn't clutter the other code. This however seems to be impossible now with objects extending and implementing 3rd party objects that are not immutable. Would need a complete refactoring really.

Would it be terrible to create an object just for creating this Conversion object with the config? Not really OOP style, but the code would be somewhere else than in the Main class.

splitRegex = propertiesReader.getStringProperty("payload.splitRegex");
splitEnabled = propertiesReader.getBooleanProperty("payload.splitEnabled");
this.regexPattern = propertiesReader.getStringProperty("payload.splitType.regex.pattern");
this.splitType = propertiesReader.getStringProperty("payload.splitType");
Copy link

Choose a reason for hiding this comment

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

in constructor code is not ideal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants