In our application, we are using Spring Integration/Soap Web Service and Spring Boot.
We have flow in Spring integration which receives a input XML which has a tag called <content> which contains the data of the Document which we need to upload.
Since it is spring Integration we receive this XML data as Source Object.
we are converting this Source object into String xml. I see that the memory usage in JVM shoots upto 500MB when this Source to String transformation is happening though the content of the xml is just 20MB. Also in Visual VM I see huge memory usage by char [].
I have even tried with marshaller and marshaller inbound gateway but same issue.
**<int-ws:inbound-gateway id="uploadDocuments"
request-channel="uploaddoc" error-channel="errorChannel"
header-mapper="xyz"
marshaller="abcjaxbmarshaller"
unmarshaller="abcjaxbmarshaller"/>**
I even wrote a simple Filter just to see if the issue is related to Spring Integration but what i found is when i am reading the xml from the ServletRequest into String object the memory shoots up again to around 500MB.
@Component
public class UploadDocumentFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException { // TODO Auto-generated method stub
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
String test = request.getReader().lines().collect(Collectors.joining(System.lineSeparator()));
System.out.println("the input is " + test);
}
@Override
public void destroy() { // TODO Auto-generated method stub
}
}
The request xml is Base64 encoded. I am not able to justify the increase in size for 20MB file to 500MB usage of memory. Could someone please explain me why there is so much rise in memory and the possible solution to this ?