extensions/http/src/main/java/uk/co/tfd/sm/http/batch/BatchProcessor.java
protected void batchRequest(HttpServletRequest request,
			HttpServletResponse response, String jsonRequest,
			boolean allowModify) throws IOException, ServletException {
		JsonParser jsonParser = new JsonParser();
		JsonElement element = jsonParser.parse(jsonRequest);
		if (!element.isJsonArray()) {
			response.sendError(HttpServletResponse.SC_BAD_REQUEST,
					"Failed to parse the requests parameter");
			return;
		}

		JsonArray arr = element.getAsJsonArray();
		response.setContentType("application/json");
		response.setCharacterEncoding("UTF-8");

		String key = null;
		try {
			MessageDigest md = MessageDigest.getInstance("SHA-1");
			key = Base64.encodeBase64URLSafeString(md.digest(jsonRequest
					.getBytes("UTF-8")));
			String cachedResult = responseCache.get(key);
			if (cachedResult != null) {
				LOGGER.debug("Using Cache");
				response.getWriter().write(cachedResult);
				return;
			}
		} catch (Exception e) {
			LOGGER.warn(e.getMessage(), e);
		}

		boolean cache = (key != null);
		CaptureResponseWriter captureResponseWriter = new CaptureResponseWriter(
				response.getWriter());
		JsonWriter write = new JsonWriter(captureResponseWriter);
		write.beginObject();
		write.name("results");
		write.beginArray();
		for (int i = 0; i < arr.size(); i++) {
			JsonObject obj = arr.get(i).getAsJsonObject();
			try {
				RequestInfo r = new RequestInfo(obj);
				if (r.isValid() && (allowModify || r.isSafe())) {
					cache = doRequest(request, response, r, write) && cache;
				} else {
					outputFailure("Bad request, ignored " + obj.toString(),
							write);
				}
			} catch (MalformedURLException e) {
				outputFailure("Bad request, ignored " + obj.toString(), write);
			}
		}
		write.endArray();
		write.endObject();
		write.flush();
		if (cache) {
			responseCache.put(key, captureResponseWriter.toString());
		}
	}
protected void batchRequest(HttpServletRequest request,
			HttpServletResponse response, String jsonRequest,
			boolean allowModify) throws IOException, ServletException {
		JsonParser jsonParser = new JsonParser();
		JsonElement element = jsonParser.parse(jsonRequest);
		if (!element.isJsonArray()) {
			response.sendError(HttpServletResponse.SC_BAD_REQUEST,
					"Failed to parse the requests parameter");
			return;
		}

		JsonArray arr = element.getAsJsonArray();
		response.setContentType("application/json");
		response.setCharacterEncoding("UTF-8");

		String key = null;
		try {
			MessageDigest md = MessageDigest.getInstance("SHA-1");
			key = Base64.encodeBase64URLSafeString(md.digest(jsonRequest
					.getBytes("UTF-8")));
			String cachedResult = responseCache.get(key);
			if (cachedResult != null) {
				LOGGER.debug("Using Cache");
				response.getWriter().write(cachedResult);
				return;
			}
		} catch (Exception e) {
			LOGGER.warn(e.getMessage(), e);
		}

		boolean cache = (key != null);
		CaptureResponseWriter captureResponseWriter = new CaptureResponseWriter(
				response.getWriter());
		JsonWriter write = new JsonWriter(captureResponseWriter);
		write.beginObject();
		write.name("results");
		write.beginArray();
		for (int i = 0; i < arr.size(); i++) {
			JsonObject obj = arr.get(i).getAsJsonObject();
			try {
				RequestInfo r = new RequestInfo(obj);
				if (r.isValid() && (allowModify || r.isSafe())) {
					cache = doRequest(request, response, r, write) && cache;
				} else {
					outputFailure("Bad request, ignored " + obj.toString(),
							write);
				}
			} catch (MalformedURLException e) {
				outputFailure("Bad request, ignored " + obj.toString(), write);
			}
		}
		write.endArray();
		write.endObject();
		write.flush();
		if (cache) {
			responseCache.put(key, captureResponseWriter.toString());
		}
	}
protected void batchRequest ( HttpServletRequest request , HttpServletResponse response , String jsonRequest , boolean allowModify ) throws IOException , ServletException { JsonParser jsonParser = new JsonParser ( ) ; JsonElement element = jsonParser . parse ( jsonRequest ) ; if ( ! element . isJsonArray ( ) ) { response . sendError ( HttpServletResponse . SC_BAD_REQUEST , "Failed to parse the requests parameter" ) ; return ; } JsonArray arr = element . getAsJsonArray ( ) ; response . setContentType ( "application/json" ) ; response . setCharacterEncoding ( "UTF-8" ) ; String key = null ; try { MessageDigest md = MessageDigest . getInstance ( "SHA-1" ) ; key = Base64 . encodeBase64URLSafeString ( md . digest ( jsonRequest . getBytes ( "UTF-8" ) ) ) ; String cachedResult = responseCache . get ( key ) ; if ( cachedResult != null ) { LOGGER . debug ( "Using Cache" ) ; response . getWriter ( ) . write ( cachedResult ) ; return ; } } catch ( Exception e ) { LOGGER . warn ( e . getMessage ( ) , e ) ; } boolean cache = ( key != null ) ; CaptureResponseWriter captureResponseWriter = new CaptureResponseWriter ( response . getWriter ( ) ) ; JsonWriter write = new JsonWriter ( captureResponseWriter ) ; write . beginObject ( ) ; write . name ( "results" ) ; write . beginArray ( ) ; for ( int i = 0 ; i < arr . size ( ) ; i ++ ) { JsonObject obj = arr . get ( i ) . getAsJsonObject ( ) ; try { RequestInfo r = new RequestInfo ( obj ) ; if ( r . isValid ( ) && ( allowModify || r . isSafe ( ) ) ) { cache = doRequest ( request , response , r , write ) && cache ; } else { outputFailure ( "Bad request, ignored " + obj . toString ( ) , write ) ; } } catch ( MalformedURLException e ) { outputFailure ( "Bad request, ignored " + obj . toString ( ) , write ) ; } } write . endArray ( ) ; write . endObject ( ) ; write . flush ( ) ; if ( cache ) { responseCache . put ( key , captureResponseWriter . toString ( ) ) ; } }
Takes the original request and starts the batching.

@param request
@param response
@throws IOException
@throws ServletException
Takes the original request and starts the batching .