We have our web API written using RESTEasy . We would like to provide support for batch requests processing the processing of the processing of a Google package .
The following is the approach currently being used,
We have a filter that accepts an incoming multi-page request. This filter then creates several mock requests and response objects, and then calls chain.doFilter using these mock requests.
public class BatchRequestProcessingFilter extends GenericFilterBean { @Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest)req; MockHttpServletRequest[] mockRequests = BatchRequestProcessorUtils.parseRequest(request); MockHttpServletResponse[] mockResponses = new MockHttpServletResponse[mockRequests.length]; for(int i=0 ; i <= mockRequests.length ; i++ ) { chain.doFilter(mockRequests[i], mockResponses[i], chain); } BatchRequestProcessingUtils.populateResponseFromMockResponses(res, mockResponses); } }
MockHttpServletResponse class returns a dummy OutputStream , which wraps a ByteArrayOutputStream .
BatchRequestProcessorUtils parses the multiple request and returns a mock request that wraps the actual request, but returns the header specified in the split block of the actual request body.
I could not find an existing library that supports batch request processing. So my question is is this the right approach to support a batch request or is there any standard way that should be used?
Please note that we are using Tomcat 8.
source share