Skip to content

refactor(core): move StringUtil to text package, extend XSLT tran…#2636

Merged
christiangoerdes merged 11 commits into
masterfrom
xslt-transform-prolog-error-msg
Jan 22, 2026
Merged

refactor(core): move StringUtil to text package, extend XSLT tran…#2636
christiangoerdes merged 11 commits into
masterfrom
xslt-transform-prolog-error-msg

Conversation

@predic8

@predic8 predic8 commented Jan 19, 2026

Copy link
Copy Markdown
Member

…sformation support, and add tutorial examples

Summary by CodeRabbit

  • New Features

    • Added an XSLT-based XML→JSON transformation and a tutorial/example.
  • Improvements

    • Centralized XSLT request/response handling and standardized user-facing error responses for malformed inputs.
  • Documentation

    • Updated roadmap and XSLT tutorial descriptions and examples.
  • Tests

    • Added/updated tests for XML→JSON transformation and XSLT error scenarios, including prolog-content handling.

✏️ Tip: You can customize this high-level summary in your review settings.

…sformation support, and add tutorial examples
@coderabbitai

coderabbitai Bot commented Jan 19, 2026

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@christiangoerdes has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 10 minutes and 23 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📝 Walkthrough

Walkthrough

Relocates StringUtil to package com.predic8.membrane.core.util.text and updates static imports; refactors XSLTInterceptor to a unified handleInternal flow with standardized error handling; adds XML→JSON XSLT, tutorials, and tests; minor docs and tutorial YAML/name updates.

Changes

Cohort / File(s) Summary
StringUtil Package Migration
core/src/main/java/com/predic8/membrane/core/util/text/StringUtil.java
Moved StringUtil from com.predic8.membrane.core.utilcom.predic8.membrane.core.util.text without functional changes.
Static Import Updates
core/src/main/java/com/predic8/membrane/core/interceptor/templating/AbstractTemplateInterceptor.java, core/src/main/java/com/predic8/membrane/core/interceptor/templating/TemplateInterceptor.java, core/src/main/java/com/predic8/membrane/core/lang/jsonpath/JsonpathExchangeExpression.java, core/src/main/java/com/predic8/membrane/core/interceptor/xml/Json2XmlInterceptor.java, core/src/main/java/com/predic8/membrane/core/openapi/serviceproxy/APIProxy.java, core/src/main/java/com/predic8/membrane/core/transport/http/HttpServerHandler.java, core/src/test/java/com/predic8/membrane/core/util/StringUtilTest.java
Updated static imports to com.predic8.membrane.core.util.text.StringUtil (import paths only).
XSLTInterceptor Core Refactor
core/src/main/java/com/predic8/membrane/core/interceptor/xslt/XSLTInterceptor.java
Consolidated request/response handling into handleInternal(Exchange, Flow), added createErrorResponse and transformMsg, flow-aware message retrieval, and special TransformerException prolog handling (produces ABORT). Public API signatures unchanged.
XSLTInterceptor Tests
core/src/test/java/com/predic8/membrane/core/interceptor/xslt/XSLTInterceptorTest.java
Reworked imports and visibility (tests package-private), added noContentInProlog test asserting ABORT and specific error content; minor test restructuring.
New XSLT Tutorial & Tests
distribution/tutorials/xml/to-json.xsl, distribution/tutorials/xml/35-XSLT-Transformation-to-json.yaml, distribution/src/test/java/com/predic8/membrane/tutorials/xml/XsltXML2JSONTransformationTutorialTest.java
Added XSLT that emits JSON-like text, tutorial YAML wiring (transform → set Content-Type → beautify), and a JUnit test validating XML→JSON output.
Tutorial Adjustments
distribution/src/test/java/.../XsltTransformationTutorialTest.java, distribution/tutorials/xml/40-XSLT-Transformation-group.yaml
Updated referenced tutorial YAML name and refined title/description/curl example.
Docs
docs/ROADMAP.md
Added PRIO 1 "Reverse" subsection and small wording change.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant XSLTInterceptor as XSLT
  participant Transformer
  participant Exchange
  participant Backend

  Client->>XSLT: send request
  XSLT->>Exchange: getMessage(REQUEST)
  XSLT->>Transformer: transform(input)
  alt TransformerException (prolog)
    Transformer-->>XSLT: throws TransformerException
    XSLT->>Exchange: createErrorResponse(exception, REQUEST) / abort
    XSLT-->>Client: ABORT response (error message, truncated input)
  else success
    Transformer-->>XSLT: transformed payload
    XSLT->>Exchange: set transformed message (REQUEST)
    XSLT->>Backend: forward exchange
    Backend-->>XSLT: response
    XSLT->>Exchange: getMessage(RESPONSE)
    XSLT->>Transformer: transform(response)
    XSLT-->>Client: return transformed response
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested labels

7.x

Suggested reviewers

  • rrayst
  • christiangoerdes

Poem

🐰 A hop of code beneath the snows,
StringUtil found a new path to go.
XSLT now guards both out and in,
XML to JSON — let the tests begin.
Cheers from this rabbit and a tiny carrot show.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.55% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: moving StringUtil to a text package and extending XSLT transformation, matching the primary refactoring work across the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Fix all issues with AI agents
In
`@core/src/main/java/com/predic8/membrane/core/interceptor/xslt/XSLTInterceptor.java`:
- Around line 70-78: The catch block handling TransformerException should guard
against a null message before calling e.getMessage().contains(...); change the
conditional to check e.getMessage() != null (e.g. e.getMessage() != null &&
e.getMessage().contains("not allowed in prolog")) so the
user(...).title(...).detail(...).internal(...).buildAndSetResponse(exc) branch
still runs for prolog errors without risking a NullPointerException; leave the
existing log.debug("", e) and the ABORT return intact.
- Around line 80-93: The createErrorResponse currently always sets the detail
message to "Error transforming request!" which is misleading for response
transformations; update XSLTInterceptor.createErrorResponse to produce a
context-aware message (e.g. "Error transforming request!" vs "Error transforming
response!") by either adding a boolean/direction parameter (e.g. isRequest) or
by inspecting the Exchange (exc) to determine whether the transformation was for
the request or response, then update all call sites in XSLTInterceptor that call
createErrorResponse to pass the correct direction so the user(...).detail(...)
call contains the appropriate, flow-aware text.

In `@distribution/tutorials/xml/to-json.xsl`:
- Around line 7-18: The templates produce raw XML nodes via the identity
template (match="@*|node()") and use <xsl:apply-templates/> so the output is not
valid JSON (missing commas and leaking XML); change the stylesheet to emit text
JSON explicitly (set output method="text" or use xsl:text), update the "books"
template to open an array and join book items with commas, update the "book"
template to render JSON object fields (use xsl:text and apply-templates only for
values) and remove or restrict the identity template so it does not copy XML
nodes into the output, and ensure proper escaping of text content when rendering
values (refer to the templates matching "books", "book", and the identity
template match="@*|node()" to locate and modify).
🧹 Nitpick comments (1)
distribution/src/test/java/com/predic8/membrane/tutorials/xml/XsltJson2XMLTransformationTutorialTest.java (1)

11-15: Align class name with XML→JSON transformation

The test posts XML and expects JSON, but the class name reads JSON→XML. Consider renaming the class (and file) to match the actual direction.

🔧 Proposed rename
-public class XsltJson2XMLTransformationTutorialTest extends AbstractXmlTutorialTest{
+public class XsltXml2JsonTransformationTutorialTest extends AbstractXmlTutorialTest{

Comment thread distribution/tutorials/xml/to-json.xsl Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In
`@distribution/src/test/java/com/predic8/membrane/tutorials/xml/XsltXML2JSONTransformationTutorialTest.java`:
- Around line 12-15: In XsltXML2JSONTransformationTutorialTest, the
getTutorialYaml() method returns a hardcoded filename with incorrect casing;
update the return value in getTutorialYaml() to
"35-XSLT-transformation-to-json.yaml" (lowercase 't') so it matches the actual
resource name and avoids failures on case-sensitive filesystems.
🧹 Nitpick comments (1)
core/src/test/java/com/predic8/membrane/core/interceptor/xslt/XSLTInterceptorTest.java (1)

84-88: Remove stdout debug output from tests.

Line 87 prints the response body to stdout, which can clutter CI logs. Consider removing it or switching to a logger with an appropriate level.

♻️ Proposed cleanup
-        System.out.println(body);
         assertTrue(body.contains("rubbish"));
         assertTrue(body.contains("not allowed in prolog"));

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In
`@core/src/test/java/com/predic8/membrane/core/interceptor/xslt/XSLTInterceptorTest.java`:
- Around line 77-89: Rename the test method noConentInProlog to
noContentInProlog to correct the typo; locate the JUnit test method in class
XSLTInterceptorTest and update the method name signature (the method annotated
with `@Test` that builds the exchange and asserts ABORT and 400) so it uses the
correct spelling, ensuring any references (e.g., test runner or IDE) reflect the
new name.

In
`@distribution/src/test/java/com/predic8/membrane/tutorials/xml/XsltTransformationTutorialTest.java`:
- Around line 12-15: Update the getTutorialYaml() override to reference the
actual YAML filename used in the repo: replace the returned string
"40-XSLT-Transformation.yaml" with the correct
"40-XSLT-Transformation-group.yaml" inside the getTutorialYaml() method so the
XsltTransformationTutorialTest points to the existing tutorial file.
🧹 Nitpick comments (1)
distribution/tutorials/xml/35-XSLT-Transformation-to-json.yaml (1)

20-24: Consider adjusting comment indentation for clarity.

The comment on line 23 explains the beautifier but appears at the same indentation level as setHeader, which may cause confusion. Consider moving it to align with beautifier.

📝 Suggested fix
         - setHeader:
             name: Content-Type
             value: application/json
-          # The beautifier needs the right Content-Type to format the output of the transform
-        - beautifier: {}
+        # The beautifier needs the right Content-Type to format the output of the transform
+        - beautifier: {}

@membrane-ci-server

Copy link
Copy Markdown

This pull request needs "/ok-to-test" from an authorized committer.

@christiangoerdes

Copy link
Copy Markdown
Collaborator

/ok-to-test

rrayst
rrayst previously approved these changes Jan 21, 2026
@christiangoerdes christiangoerdes merged commit 6ebc49f into master Jan 22, 2026
4 checks passed
@christiangoerdes christiangoerdes deleted the xslt-transform-prolog-error-msg branch January 22, 2026 08:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants