Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,32 @@ public void testPayloadFactoryXMLToJson() throws IOException {
assertEquals(responseJSON, expectedJSON, "Response payload mismatched");
}

/**
* Issue #4623: PayloadFactory default template must not throw IllegalArgumentException when a
* variable value contains $ followed by a digit (e.g. Java stack traces such as
* NativeWorkerPool$1.run or ThreadPoolExecutor$Worker).
*/
@Test(groups = {"wso2.esb"}, description =
"Testing PayloadFactory with dollar sign followed by digit in variable values (Issue 4623)")
public void testPayloadFactoryWithDollarSignInVariableValues() throws IOException {

Comment on lines +186 to +187
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.

Log Improvement Suggestion No: 1

Suggested change
public void testPayloadFactoryWithDollarSignInVariableValues() throws IOException {
public void testPayloadFactoryWithDollarSignInVariableValues() throws IOException {
log.info("Testing PayloadFactory with dollar sign in variable values for Issue #4623");
String expectedResponse = "{" +

String expectedResponse = "{" +
"\"errorClass\":\"java.util.concurrent.ThreadPoolExecutor\"," +
"\"errorCode\":\"500\"," +
"\"message\":\"Internal Server Error\"," +
"\"detail\":\"ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)\"," +
"\"exception\":\"NativeWorkerPool$1.run(NativeWorkerPool.java:206)\"" +
"}";

String serviceURL = getMainSequenceURL() + "synapseExpressionPayload/dollar-in-vars";
HttpResponse httpResponse = httpClient.doGet(serviceURL, null);
Comment on lines +196 to +197
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.

Log Improvement Suggestion No: 2

Suggested change
String serviceURL = getMainSequenceURL() + "synapseExpressionPayload/dollar-in-vars";
HttpResponse httpResponse = httpClient.doGet(serviceURL, null);
String serviceURL = getMainSequenceURL() + "synapseExpressionPayload/dollar-in-vars";
if (log.isDebugEnabled()) {
log.debug("Sending GET request to URL: " + serviceURL);
}
HttpResponse httpResponse = httpClient.doGet(serviceURL, null);

String responsePayload = httpClient.getResponsePayload(httpResponse);
Assert.assertNotNull(responsePayload, "Response payload must not be null — server likely threw IllegalArgumentException");
JsonElement responseJSON = JsonParser.parseString(responsePayload);
JsonElement expectedJSON = JsonParser.parseString(expectedResponse);
assertEquals(responseJSON, expectedJSON, "Variable values containing $ were not preserved correctly");
}

@Test(groups = {"wso2.esb"}, description = "Testing Payload factory mediator with Freemarker template")
public void testPayloadFactoryFreemarker() throws IOException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,26 @@
<faultSequence>
</faultSequence>
</resource>
<!-- Issue #4623: variables whose runtime value contains $ followed by a digit -->
<resource methods="GET" uri-template="/dollar-in-vars">
<inSequence>
<variable name="ERR_CLASS" value="java.util.concurrent.ThreadPoolExecutor"/>
<variable name="ERR_CODE" value="500"/>
<variable name="ERR_MESSAGE" value="Internal Server Error"/>
<variable name="ERR_DETAIL" value="ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)"/>
<variable name="ERR_EXCEPTION" value="NativeWorkerPool$1.run(NativeWorkerPool.java:206)"/>
<payloadFactory media-type="json">
<format><![CDATA[{
"errorClass": "${vars.ERR_CLASS}",
"errorCode": "${vars.ERR_CODE}",
"message": "${vars.ERR_MESSAGE}",
"detail": "${vars.ERR_DETAIL}",
"exception": "${vars.ERR_EXCEPTION}"
}]]></format>
</payloadFactory>
<respond/>
</inSequence>
</resource>
<resource methods="POST GET" uri-template="/payload-freemarker">
<inSequence>
<variable name="user_name" value="123" type="INTEGER"/>
Expand Down
Loading