Author: adamw Date: 2005-09-09 11:33:45 -0400 (Fri, 09 Sep 2005) New Revision: 1067 Modified: trunk/forge/portal-extensions/forge-kosmos/kosmos-portlet/src/java/hu/midori/kosmos/server/AbstractKosmosService.java trunk/forge/portal-extensions/forge-kosmos/kosmos-server/src/java/hu/midori/kosmos/server/AbstractKosmosService.java trunk/forge/portal-extensions/forge-kosmos/kosmos-server/web-server/WEB-INF/web.xml Log: JBLAB-381: cache with file-access Modified: trunk/forge/portal-extensions/forge-kosmos/kosmos-portlet/src/java/hu/midori/kosmos/server/AbstractKosmosService.java =================================================================== --- trunk/forge/portal-extensions/forge-kosmos/kosmos-portlet/src/java/hu/midori/kosmos/server/AbstractKosmosService.java 2005-09-09 13:46:45 UTC (rev 1066) +++ trunk/forge/portal-extensions/forge-kosmos/kosmos-portlet/src/java/hu/midori/kosmos/server/AbstractKosmosService.java 2005-09-09 15:33:45 UTC (rev 1067) @@ -15,6 +15,7 @@ import java.util.Map; import org.apache.commons.httpclient.HttpURL; +import org.apache.commons.httpclient.HttpsURL; import org.apache.commons.httpclient.URIException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -104,23 +105,46 @@ String url = ctx.getServletContext().getInitParameter("webdav.url"); String user = ctx.getServletContext().getInitParameter("webdav.user"); String password = ctx.getServletContext().getInitParameter("webdav.password"); + String clientaccess = ctx.getServletContext().getInitParameter("webdav.clientaccess"); + log.debug(String.format("Connecting to \"%s\" as \"%s\" (\"%s\")...", url, user, password)); if((url == null) || (url.trim().length() == 0)) throw new IllegalStateException("'webdav.url' was not specified as servlet-context init-params"); - HttpURL webdavUrl = new HttpURL(url); - if((user != null) && (user.trim().length() != 0)) - webdavUrl.setUser(user); - if((password != null) && (password.trim().length() != 0)) - webdavUrl.setPassword(password); + if((clientaccess == null) || (clientaccess.trim().length() == 0)) + throw new IllegalStateException("'webdav.clientaccess' was not specified as servlet-context init-params"); + // Checking if the url uses http or https. + boolean isHttps = false; + if (url.startsWith("https")) + isHttps = true; + + HttpURL webdavUrl; + + if (isHttps) + webdavUrl = new HttpsURL(url); + else + webdavUrl = new HttpURL(url); + + // TODO: Check this + // If you use the setUser method with a HttpsUrl, a NPE is thrown, in the + // string's init, somewhere from HttpClient - maybe that's a bug there? + if (!isHttps) { + if((user != null) && (user.trim().length() != 0)) + webdavUrl.setUser(user); + if((password != null) && (password.trim().length() != 0)) + webdavUrl.setPassword(password); + } + String cacheDirPath = webdavUrl.getPath() + "/kosmos-cache/"; String cachedFilePath = cacheDirPath + filename; - String cachedFileUrl = webdavUrl.getURI() + "/kosmos-cache/" + URLEncoder.encode(filename, "utf-8"); + String cachedFileUrl = clientaccess + "/kosmos-cache/" + URLEncoder.encode(filename, "utf-8"); // create WebDAV dir if not existing WebdavResource webdavResource = new WebdavResource(webdavUrl); + // Using this with https throws an exception. // TODO check if the dir was not existing yet - webdavResource.mkcolMethod(cacheDirPath); + if (!isHttps) + webdavResource.mkcolMethod(cacheDirPath); // put resource to WebDAV log.debug(String.format("Putting WebDAV resource \"%s\"...", cachedFilePath)); Modified: trunk/forge/portal-extensions/forge-kosmos/kosmos-server/src/java/hu/midori/kosmos/server/AbstractKosmosService.java =================================================================== --- trunk/forge/portal-extensions/forge-kosmos/kosmos-server/src/java/hu/midori/kosmos/server/AbstractKosmosService.java 2005-09-09 13:46:45 UTC (rev 1066) +++ trunk/forge/portal-extensions/forge-kosmos/kosmos-server/src/java/hu/midori/kosmos/server/AbstractKosmosService.java 2005-09-09 15:33:45 UTC (rev 1067) @@ -14,6 +14,7 @@ import java.util.HashMap; import java.util.Map; +import org.apache.commons.httpclient.HttpURL; import org.apache.commons.httpclient.HttpsURL; import org.apache.commons.httpclient.URIException; import org.apache.commons.logging.Log; @@ -104,23 +105,46 @@ String url = ctx.getServletContext().getInitParameter("webdav.url"); String user = ctx.getServletContext().getInitParameter("webdav.user"); String password = ctx.getServletContext().getInitParameter("webdav.password"); + String clientaccess = ctx.getServletContext().getInitParameter("webdav.clientaccess"); + log.debug(String.format("Connecting to \"%s\" as \"%s\" (\"%s\")...", url, user, password)); if((url == null) || (url.trim().length() == 0)) throw new IllegalStateException("'webdav.url' was not specified as servlet-context init-params"); - HttpsURL webdavUrl = new HttpsURL(url); - if((user != null) && (user.trim().length() != 0)) - webdavUrl.setUser(user); - if((password != null) && (password.trim().length() != 0)) - webdavUrl.setPassword(password); + if((clientaccess == null) || (clientaccess.trim().length() == 0)) + throw new IllegalStateException("'webdav.clientaccess' was not specified as servlet-context init-params"); + // Checking if the url uses http or https. + boolean isHttps = false; + if (url.startsWith("https")) + isHttps = true; + + HttpURL webdavUrl; + + if (isHttps) + webdavUrl = new HttpsURL(url); + else + webdavUrl = new HttpURL(url); + + // TODO: Check this + // If you use the setUser method with a HttpsUrl, a NPE is thrown, in the + // string's init, somewhere from HttpClient - maybe that's a bug there? + if (!isHttps) { + if((user != null) && (user.trim().length() != 0)) + webdavUrl.setUser(user); + if((password != null) && (password.trim().length() != 0)) + webdavUrl.setPassword(password); + } + String cacheDirPath = webdavUrl.getPath() + "/kosmos-cache/"; String cachedFilePath = cacheDirPath + filename; - String cachedFileUrl = webdavUrl.getURI() + "/kosmos-cache/" + URLEncoder.encode(filename, "utf-8"); + String cachedFileUrl = clientaccess + "/kosmos-cache/" + URLEncoder.encode(filename, "utf-8"); // create WebDAV dir if not existing WebdavResource webdavResource = new WebdavResource(webdavUrl); + // Using this with https throws an exception. // TODO check if the dir was not existing yet - // webdavResource.mkcolMethod(cacheDirPath); + if (!isHttps) + webdavResource.mkcolMethod(cacheDirPath); // put resource to WebDAV log.debug(String.format("Putting WebDAV resource \"%s\"...", cachedFilePath)); Modified: trunk/forge/portal-extensions/forge-kosmos/kosmos-server/web-server/WEB-INF/web.xml =================================================================== --- trunk/forge/portal-extensions/forge-kosmos/kosmos-server/web-server/WEB-INF/web.xml 2005-09-09 13:46:45 UTC (rev 1066) +++ trunk/forge/portal-extensions/forge-kosmos/kosmos-server/web-server/WEB-INF/web.xml 2005-09-09 15:33:45 UTC (rev 1067) @@ -14,12 +14,16 @@ </context-param> <context-param> <param-name>webdav.user</param-name> - <param-value></param-value> + <param-value>labs-stats</param-value> </context-param> <context-param> <param-name>webdav.password</param-name> - <param-value></param-value> + <param-value>jbossforgeadmin</param-value> </context-param> + <context-param> + <param-name>webdav.clientaccess</param-name> + <param-value>http://labs.jboss.com/file-access/kosmos/images</param-value> + </context-param> <servlet> <servlet-name>kosmos-services</servlet-name> |