Skip to content
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

SpringResponseWrapper question ,response message loss on interceptor! #57

Open
SYanalyser opened this issue Jun 29, 2023 · 3 comments
Assignees
Labels
question Further information is requested

Comments

@SYanalyser
Copy link

SYanalyser commented Jun 29, 2023

add interceptor the example, response message loss (no {"msg": "error"})

public class MainInterceptor implements AsyncHandlerInterceptor {
    final ObjectMapper objectMapper = new ObjectMapper();

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException {
        Map<String, Object> map = new HashMap<>();
        map.put("msg", "error");
        response.setStatus(200);
        response.setContentType("application/json;charset=UTF-8");
        response.getWriter().append(objectMapper.writeValueAsString(map));
        return false;
    }
}

`@Configuration
public class MainMvcConfig implements WebMvcConfigurer {

@Override
public void addInterceptors(InterceptorRegistry registry) {
    registry.addInterceptor(new MainInterceptor())
            .addPathPatterns("/**")
            .excludePathPatterns("/req-param");
}

}`

>curl http:https://localhost:8080/

@piomin
Copy link
Owner

piomin commented Oct 3, 2023

I'm not very sure what's your question...

@piomin piomin added the question Further information is requested label Oct 3, 2023
@SYanalyser
Copy link
Author

HttpServletResponse -> loss data

@SYanalyser
Copy link
Author

If I return a response in the interceptor, the data will be lost.@piomin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants