Skip to content

Request Parameters doubled #321

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

Closed
JohannesFluegel opened this issue Oct 26, 2016 · 4 comments
Closed

Request Parameters doubled #321

JohannesFluegel opened this issue Oct 26, 2016 · 4 comments
Labels
status: duplicate Duplicate of another issue

Comments

@JohannesFluegel
Copy link

JohannesFluegel commented Oct 26, 2016

I use Spring REST Docs 1.1.1.RELEASE.

My url contains request parameters as described in
Spring REST Docs documentation: Request parameters:

this.mockMvc.perform(get("/devices?page=2&per_page=100")).andDo(document("document"));

http-request.adoc contains

GET /devices?page=2&per_page=100&page=2&per_page=100 HTTP/1.1

The request parameters are doubled.

@wilkinsona
Copy link
Member

wilkinsona commented Oct 26, 2016

Duplicates #286. The problem's fixed in 1.1.2.RELEASE. It's always worth trying the latest version before reporting an issue.

@wilkinsona wilkinsona added the status: duplicate Duplicate of another issue label Oct 26, 2016
@JohannesFluegel
Copy link
Author

JohannesFluegel commented Oct 26, 2016

In 1.1.2.RELEASE the error occurs again if I want to change the parameter values.

private static OperationPreprocessor myPreprocessor() {
    return new OperationPreprocessor() {

        @Override
        public OperationResponse preprocess(OperationResponse response) {
            return new OperationResponseFactory().create(response.getStatus(), response.getHeaders(),
                    response.getContent());
        }

        @Override
        public OperationRequest preprocess(OperationRequest request) {
            return new OperationRequestFactory().create(
                    URI.create(request.getUri().toString().replaceFirst("change-me", "changed")),
                    request.getMethod(), request.getContent(), request.getHeaders(), request.getParameters(),
                    request.getParts());
        }
    };
}

@Test
public void myTest() {
    this.mockMvc.perform(get("/devices?param=change-me"))
            .andDo(document("nok", preprocessRequest(myPreprocessor())));
...

returns
GET /devices?param=changed&param=change-me HTTP/1.1

@wilkinsona
Copy link
Member

I suspect that's because param=change-me has already made it into the Map returned by request.getParameters(). What happens if you update the parameters map too?

@JohannesFluegel
Copy link
Author

With

@Override
public OperationRequest preprocess(OperationRequest request) {
    request.getParameters().clear();
    return new OperationRequestFactory().create(
    ...

it works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate Duplicate of another issue
Projects
None yet
Development

No branches or pull requests

2 participants