WabURLConnection extends URLConnection { @Override public InputStream getInputStream() throws IOException { URL url = getURL(); Map<String, String[]> parameters = HttpUtil.getParameterMap( url.getQuery()); if (!parameters.containsKey("Web-ContextPath")) { throw new IllegalArgumentException( "The parameter map does not contain the required parameter " + "Web-ContextPath"); } String path = url.getPath(); String[] protocols = parameters.get("protocol"); if (ArrayUtil.isEmpty(protocols)) { if (path.startsWith("file:")) { path = path.substring(5); protocols = new String[] {"file"}; } else { throw new IllegalArgumentException( "The parameter map does not contain the required " + "parameter protocol"); } } String[] portalProfileNames = parameters.get( "liferay-portal-profile-names"); if (ArrayUtil.isNotEmpty(portalProfileNames)) { path = path.concat("?liferay-portal-profile-names="); path = path.concat(StringUtil.merge(portalProfileNames)); } final File file = transferToTempFile(new URL(protocols[0], null, path)); File processedFile = _wabGenerator.generate( _classLoader, file, parameters); return new FileInputStream(processedFile) { @Override public void close() throws IOException { try { super.close(); } finally { FileUtil.deltree(file.getParentFile()); } } }; } WabURLConnection(
		ClassLoader classLoader, WabGenerator wabGenerator, URL url); @Override void connect(); @Override InputStream getInputStream();  }
@Test(expected = UnknownServiceException.class) public void testWabURLConnectionRequiredParams() throws IOException { WabURLConnection wabURLConnection = new WabURLConnection( null, null, new URL( "webbundle:/path/to/foo?Web-ContextPath=foo&protocol=file")); wabURLConnection.getInputStream(); }
@Test(expected = UnknownServiceException.class) public void testWabURLConnectionRequiredParamsCompatibilityMode() throws Exception { String uriString = _getURIString("/classic-theme.autodeployed.war"); WabURLConnection wabURLConnection = new WabURLConnection( null, null, new URL("webbundle:" + uriString + "?Web-ContextPath=foo")); wabURLConnection.getInputStream(); }
@Test(expected = IllegalArgumentException.class) public void testWabURLConnectionRequiredParamsMissing() throws Exception { WabURLConnection wabURLConnection = new WabURLConnection( null, null, new URL("webbundle:/path/to/foo?Web-ContextPath=foo")); wabURLConnection.getInputStream(); }