Class CombineRequest

java.lang.Object
org.frontcache.include.combine.CombineRequest

public final class CombineRequest extends Object
The origin's half of the combine contract: read a combined request. This is not used by the edge. It exists so a JVM origin implements the contract by calling the same code that defines it, rather than by re-reading section 5 of the proposal and getting the parameter names nearly right. A non-JVM origin implements about thirty lines - decode n values, batch, emit JSON. Typical handler:
List<Map<String, String[]>> parts = CombineRequest.parseParameters(request);
if (null == parts)
    return renderSingle(request);            // ordinary single-fragment request

// ONE batched query over every part's keys - this is the entire point of the feature
Map<Long, Coin> coins = dao.getByIds(idsOf(parts));

CombineResponse out = new CombineResponse();
for (Map<String, String[]> part : parts)
    out.add(CombineRequest.queryOf(part), render(coins, part), headersFor(part));
out.writeTo(response);
  • Method Details

    • isCombined

      public static boolean isCombined(jakarta.servlet.http.HttpServletRequest request)
      Is this a combined request? Cheap enough to call at the top of a handler.
    • version

      public static int version(jakarta.servlet.http.HttpServletRequest request)
      The protocol version the edge is speaking, or -1 when this is not a combined request. An origin that only implements version 1 should answer a higher version as it would answer an ordinary single request - the edge then degrades correctly (proposal section 9.1) instead of receiving an envelope it cannot read.
    • parseQueries

      public static List<String> parseQueries(jakarta.servlet.http.HttpServletRequest request)
      The members' query strings, decoded, in order. null when this is not a combined request, so a handler can branch on it directly. A missing fc-part-i is returned as an empty string rather than dropped: the response is positional, so silently shortening the list would misalign every later member.
    • parseParameters

      public static List<Map<String,String[]>> parseParameters(jakarta.servlet.http.HttpServletRequest request)
      The members' parameters, parsed, in order. null when this is not a combined request. The maps preserve parameter order and support repeated parameters, so a member query behaves the way request.getParameterMap() would have behaved for a single include.
    • parseQueryString

      public static Map<String,String[]> parseQueryString(String query)
      Splits one member's query string into parameters. Values are percent-decoded with UTF-8. Written out rather than delegated to the container because the member query arrived as a value: by the time it is in hand there is no request to ask.
    • param

      public static String param(Map<String,String[]> part, String name)
      First value of a parameter within one parsed member, or null. The per-member equivalent of request.getParameter.
    • queryOf

      public static String queryOf(Map<String,String[]> part)
      Re-renders a parsed member back into a query string, for the optional q echo (CombinePart.getQ()). Handlers that kept parseQueries(HttpServletRequest)' strings should echo those instead - this is for handlers that only kept the parsed form.
    • emptyPart

      public static Map<String,String[]> emptyPart()
      Unmodifiable empty member, for a handler that wants a non-null default.