Skip to content

[BUG] <v2.5.1 param-mapping plugin FormDataOperator class can not handle multi-level query params> #4695

@coderf187

Description

@coderf187

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

when multi-level query params need param-mapping, FormDataOperator run with error: onError(com.jayway.jsonpath.PathNotFoundException: Missing property

eg:
param dto is
public class Student{
private String name;
private Integer age;
private Teacher teacher;
class Teacher{
private String name;
private Integer age;
}
}
url = http://localhost:8080?name=zs&age=1&teacher.name=ls&teacher.age=2

if i want to param-mapping change the teacher.name=realNameLs, run whith error:
onError(com.jayway.jsonpath.PathNotFoundException: Missing property in path $['teacher']))

Expected Behavior

url = http://localhost:8080?name=zs&age=1&teacher.name=ls&teacher.age=2

param-mapping handle the params rules :

name=zs -> name=realZs
age=1 -> realAge=1
teacher.name=ls -> teacher.name=realLs
teacher.age=2 -> teacher.realAgeKey=2

get result:
url = http://localhost:8080?name=zs&age=1&teacher.name=ls&teacher.realAgeKey=2

Steps To Reproduce

@ExtendWith(MockitoExtension.class)
public class FormDataOperatorTest {

@Mock
private ShenyuPluginChain chain;

private ServerWebExchange exchange;

private FormDataOperator formDataOperator;

private ParamMappingRuleHandle paramMappingRuleHandle;

@BeforeEach
public void setUp() {
    Set<String> remove = new HashSet<>();
    remove.add("$.r1");
    remove.add("$.teacher.r1");

    ParamMappingRuleHandle.ParamMapInfo add = new ParamMappingRuleHandle.ParamMapInfo();
    add.setPath("$");
    add.setKey("webName");
    add.setValue("SHENYU");

    ParamMappingRuleHandle.ParamMapInfo add1 = new ParamMappingRuleHandle.ParamMapInfo();
    add1.setPath("$");
    add1.setKey("teacher.add1");
    add1.setValue("teacher.add1Value");

    ParamMappingRuleHandle.ParamMapInfo replace = new ParamMappingRuleHandle.ParamMapInfo();
    replace.setPath("$");
    replace.setKey("name");
    replace.setValue("realName");

    ParamMappingRuleHandle.ParamMapInfo replace1 = new ParamMappingRuleHandle.ParamMapInfo();
    replace1.setPath("$");
    replace1.setKey("teacher.name");
    replace1.setValue("teacher.realName");

    String param = "name=zs&age=1&teacher.name=ls";
    this.paramMappingRuleHandle = new ParamMappingRuleHandle();
    this.paramMappingRuleHandle.setRemoveParameterKeys(remove);
    this.paramMappingRuleHandle.setAddParameterKeys(Arrays.asList(add, add1));
    this.paramMappingRuleHandle.setReplaceParameterKeys(Arrays.asList(replace, replace1));
    this.formDataOperator = new FormDataOperator();
    this.exchange = MockServerWebExchange.from(MockServerHttpRequest.method(HttpMethod.POST, "localhost")
            .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE).body(param));
}

@Test
public void testApply() {
    when(this.chain.execute(any())).thenReturn(Mono.empty());
    StepVerifier.create(formDataOperator.apply(this.exchange, this.chain, paramMappingRuleHandle)).expectSubscription().verifyComplete();
}

}

Environment

ShenYu version(s):2.5.1

Debug logs

No response

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions