AbstractHttpTransport implements IHttpTransport, IConfigModifier, IShutdownListener, IDependenciesListener { protected Features getFeaturesFromRequestEncoded(HttpServletRequest request, Features defaultFeatures) throws IOException { final String methodName = "getFeaturesFromRequestEncoded"; boolean traceLogging = log.isLoggable(Level.FINER); if (traceLogging) { log.entering(sourceClass, methodName, new Object[]{request}); } if (depsInitialized == null) { if (traceLogging) { log.finer("No initialization semphore"); log.exiting(sourceClass, methodName); } return null; } String encoded = request.getParameter(ENCODED_FEATURE_MAP_REQPARAM); if (encoded == null) { if (traceLogging) { log.finer(ENCODED_FEATURE_MAP_REQPARAM + " param not specified in request"); log.exiting(sourceClass, methodName); } return null; } if (traceLogging) { log.finer(ENCODED_FEATURE_MAP_REQPARAM + " param = " + encoded); } byte[] decoded = Base64.decodeBase64(encoded); int len = dependentFeatures.size(); ByteArrayOutputStream bos = new ByteArrayOutputStream(len); if (len != (decoded[0]&0xFF)+((decoded[1]&0xFF)<< 8) || decoded.length != len/5 + (len%5==0?0:1) + 2) { if (log.isLoggable(Level.FINER)) { log.finer("Invalid encoded feature list. Expected feature list length = " + len); } throw new BadRequestException("Invalid encoded feature list"); } for (int i = 2; i < decoded.length; i++) { int q = decoded[i] & 0xFF; for (int j = 0; j < 5 && (i-2)*5+j < len; j++) { bos.write(q % 3); q = q / 3; } } Features result = new Features(defaultFeatures); int i = 0; for (byte b : bos.toByteArray()) { if (b < 2) { result.put(dependentFeatures.get(i), b == 1); } i++; } if (traceLogging) { log.exiting(sourceClass, methodName, result); } return result; } AbstractHttpTransport();   AbstractHttpTransport(CountDownLatch depsInitialized, List<String> dependentFeatures, long depsLastMod); @SuppressWarnings("deprecation") @Override void decorateRequest(HttpServletRequest request); @Override Map<String, Integer> getModuleIdMap(); @Override String getModuleIdRegFunctionName(); @Override void modifyConfig(IAggregator aggregator, Object configObj); @Override void initialize(IAggregator aggregator, IAggregatorExtension extension, IExtensionRegistrar reg); @Override void shutdown(IAggregator aggregator); @Override void contributeLoaderExtensionJavaScript(String contribution); @Override String getLayerContribution(HttpServletRequest request,
			LayerContributionType type, Object arg); abstract boolean isServerExpandable(HttpServletRequest request, String mid); @Override abstract List<ICacheKeyGenerator> getCacheKeyGenerators(); @Override void dependenciesLoaded(IDependencies deps, long sequence); static final String PATHS_PROPNAME; static final String REQUESTEDMODULES_REQPARAM; static final String REQUESTEDMODULEIDS_REQPARAM; static final String REQUESTEDMODULESCOUNT_REQPARAM; static final String EXCLUDEENC_REQPARAM; static final String EXCLUDEIDS_REQPARAM; static final String CONSOLE_WARNING_MSG_FMT; static final String SCRIPTS_REQPARAM; static final String DEPS_REQPARAM; static final String REQUIRED_REQPARAM; static final String PRELOADS_REQPARAM; static final String EXCLUDES_REQPARAM; static final String FEATUREMAP_REQPARAM; static final String FEATUREMAPHASH_REQPARAM; static final String FAILONVERSIONERR_REQPARAM; static final String[] INCLUDEREQUIREDEPS_REQPARAM; static final String[] INCLUDEUNDEFINEDFEATUREDEPS_REQPARAM; static final String[] ASSERTNONLS_REQPARAM; static final String[] OPTIMIZATIONLEVEL_REQPARAMS; static final String[] EXPANDREQUIRELISTS_REQPARAMS; static final String[] EXPORTMODULENAMES_REQPARAMS; static final String[] SHOWFILENAMES_REQPARAMS; static final String[] NOCACHE_REQPARAMS; static final String[] REQUESTEDLOCALES_REQPARAMS; static final String[] CACHEBUST_REQPARAMS; static final String[] SERVEREXPANDLAYERS_REQPARAMS; static final String[] DEPENDENCYEXPANSIONLOGGING_REQPARAMS; static final String[] GENERATESOURCEMAPS_REQPARAMS; static final String CONFIGVARNAME_REQPARAM; static final String LAYERCONTRIBUTIONSTATE_REQATTRNAME; static final String ENCODED_FEATURE_MAP_REQPARAM; static final String FEATURE_LIST_PRELUDE; static final String FEATURE_LIST_PROLOGUE; }
@Test public void testGetHasConditionsEncodedFromRequest() throws Exception{ CountDownLatch latch = new CountDownLatch(0); AbstractHttpTransport transport = new TestHttpTransport(latch, featureList, 0L); Map<String, String[]> requestParams = new HashMap<String, String[]>(); HttpServletRequest mockRequest = TestUtils.createMockRequest(null, new HashMap<String, Object>(), requestParams, new Cookie[0], new HashMap<String, String>()); EasyMock.replay(mockRequest); Features features = new Features(); features.put("0", true); features.put("2", true); features.put("10", false); features.put("17", false); features.put("21", true); features.put("50", true); features.put("99", true); requestParams.put(AbstractHttpTransport.ENCODED_FEATURE_MAP_REQPARAM, new String[]{encode(features)}); Features result = transport.getFeaturesFromRequestEncoded(mockRequest, new Features()); System.out.println(result); Assert.assertEquals(features, result); features = new Features(); requestParams.put(AbstractHttpTransport.ENCODED_FEATURE_MAP_REQPARAM, new String[]{encode(features)}); result = transport.getFeaturesFromRequestEncoded(mockRequest, new Features()); Assert.assertEquals(features, result); features = new Features(); for (String name : featureList) {features.put(name, true); } requestParams.put(AbstractHttpTransport.ENCODED_FEATURE_MAP_REQPARAM, new String[]{encode(features)}); result = transport.getFeaturesFromRequestEncoded(mockRequest, new Features()); System.out.println(result); Assert.assertEquals(features, result); }