Skip to content

Commit 8d3b766

Browse files
sanagaraj-pivotalravigkant
authored andcommitted
We support only dwl set payload transformations, any other transformation used to error with null pointer exception. This commit fixes that (spring-projects-experimental#86)
1 parent 57e2116 commit 8d3b766

File tree

2 files changed

+70
-7
lines changed

2 files changed

+70
-7
lines changed

components/sbm-recipes-mule-to-boot/src/main/java/org/springframework/sbm/mule/actions/javadsl/translators/dwl/DwlTransformTranslator.java

+13-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import javax.xml.namespace.QName;
2727
import java.util.Collections;
28+
import java.util.Set;
2829

2930
@Component
3031
public class DwlTransformTranslator implements MuleComponentToSpringIntegrationDslTranslator<TransformMessageType> {
@@ -57,11 +58,20 @@ public DslSnippet translate(
5758
String flowName
5859
) {
5960

60-
if (isComponentReferencingAnExternalFile(component)) {
61-
return formExternalFileBasedDSLSnippet(component);
61+
if (component.getSetPayload() != null) {
62+
if (isComponentReferencingAnExternalFile(component)) {
63+
return formExternalFileBasedDSLSnippet(component);
64+
}
65+
66+
return formEmbeddedDWLBasedDSLSnippet(component, Helper.sanitizeForBeanMethodName(flowName));
6267
}
6368

64-
return formEmbeddedDWLBasedDSLSnippet(component, Helper.sanitizeForBeanMethodName(flowName));
69+
return noSupportDslSnippet();
70+
}
71+
72+
private DslSnippet noSupportDslSnippet() {
73+
String noSupport = "// FIXME: No support for following DW transformation: <dw:set-property/> <dw:set-session-variable /> <dw:set-variable />";
74+
return new DslSnippet(noSupport, Set.of(), Set.of(), Set.of());
6575
}
6676

6777
private DslSnippet formEmbeddedDWLBasedDSLSnippet(TransformMessageType component, String flowName) {

components/sbm-recipes-mule-to-boot/src/test/java/org/springframework/sbm/mule/actions/MuleToJavaDSLDwlTransformTest.java

+57-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
public class MuleToJavaDSLDwlTransformTest extends JavaDSLActionBaseTest {
2323

24-
private static final String muleXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
24+
private static final String muleXmlSetPayload = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
2525
"\n" +
2626
"<mule xmlns:dw=\"http://www.mulesoft.org/schema/mule/ee/dw\" xmlns:http=\"http://www.mulesoft.org/schema/mule/http\" xmlns=\"http://www.mulesoft.org/schema/mule/core\" xmlns:doc=\"http://www.mulesoft.org/schema/mule/documentation\"\n" +
2727
" xmlns:spring=\"http://www.springframework.org/schema/beans\" \n" +
@@ -78,8 +78,8 @@ public class MuleToJavaDSLDwlTransformTest extends JavaDSLActionBaseTest {
7878
"</mule>";
7979

8080
@Test
81-
public void shouldTranslateDwlTransformation() {
82-
addXMLFileToResource(muleXml);
81+
public void shouldTranslateDwlTransformationWithSetPayload() {
82+
addXMLFileToResource(muleXmlSetPayload);
8383
runAction();
8484
assertThat(projectContext.getProjectJavaSources().list()).hasSize(2);
8585
assertThat(projectContext.getProjectJavaSources().list().get(0).print())
@@ -127,7 +127,7 @@ public void shouldTranslateDwlTransformation() {
127127
}
128128

129129
@Test
130-
public void shouldTransformDWLWithFile() {
130+
public void shouldTransformDWLWithFileWithSetPayload() {
131131
addXMLFileToResource(dwlXMLWithExternalFile);
132132
runAction();
133133
assertThat(projectContext.getProjectJavaSources().list()).hasSize(2);
@@ -168,4 +168,57 @@ public void shouldTransformDWLWithFile() {
168168
" }\n" +
169169
"}");
170170
}
171+
172+
@Test
173+
public void shouldTranslateDWLTransformationWithOnlyOneSetVariable() {
174+
String muleXMLSetVariable = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
175+
"\n" +
176+
"<mule xmlns:dw=\"http://www.mulesoft.org/schema/mule/ee/dw\" xmlns:http=\"http://www.mulesoft.org/schema/mule/http\" xmlns=\"http://www.mulesoft.org/schema/mule/core\" xmlns:doc=\"http://www.mulesoft.org/schema/mule/documentation\"\n" +
177+
" xmlns:spring=\"http://www.springframework.org/schema/beans\" \n" +
178+
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
179+
" xsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd\n" +
180+
"http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd\n" +
181+
"http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd\n" +
182+
"http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd\">\n" +
183+
" <flow name=\"dwlFlow\">\n" +
184+
" <http:listener config-ref=\"HTTP_Listener_Configuration\" path=\"/dwl\" doc:name=\"HTTP\"/>\n" +
185+
" \n" +
186+
" <dw:transform-message doc:name=\"action transform\">\n" +
187+
" <dw:set-variable variableName=\"temp\"><![CDATA[%dw 1.0\n" +
188+
"%output application/json\n" +
189+
"---\n" +
190+
"{\n" +
191+
" action_Code: 10,\n" +
192+
" returnCode: 20\n" +
193+
"}]]>\n" +
194+
" \n" +
195+
" </dw:set-variable>\n" +
196+
" </dw:transform-message>\n" +
197+
" \n" +
198+
" <logger message=\"Hello World: #[flowVars.temp]\" level=\"INFO\" doc:name=\"Log the message content to be sent\"/>\n" +
199+
" </flow>\n" +
200+
"</mule>";
201+
addXMLFileToResource(muleXMLSetVariable);
202+
runAction();
203+
assertThat(projectContext.getProjectJavaSources().list()).hasSize(1);
204+
assertThat(projectContext.getProjectJavaSources().list().get(0).print())
205+
.isEqualTo(
206+
"package com.example.javadsl;\n" +
207+
"import org.springframework.context.annotation.Bean;\n" +
208+
"import org.springframework.context.annotation.Configuration;\n" +
209+
"import org.springframework.integration.dsl.IntegrationFlow;\n" +
210+
"import org.springframework.integration.dsl.IntegrationFlows;\n" +
211+
"import org.springframework.integration.handler.LoggingHandler;\n" +
212+
"import org.springframework.integration.http.dsl.Http;\n" +
213+
"\n" +
214+
"@Configuration\n" +
215+
"public class FlowConfigurations {\n" +
216+
" @Bean\n" +
217+
" IntegrationFlow dwlFlow() {\n" +
218+
" return IntegrationFlows.from(Http.inboundChannelAdapter(\"/dwl\")).handle((p, h) -> p)\n" +
219+
" // FIXME: No support for following DW transformation: <dw:set-property/> <dw:set-session-variable /> <dw:set-variable />\n" +
220+
" .log(LoggingHandler.Level.INFO, \"Hello World: ${flowVars.temp}\")\n" +
221+
" .get();\n" +
222+
" }}");
223+
}
171224
}

0 commit comments

Comments
 (0)