|
From: <jbo...@li...> - 2005-09-20 08:00:19
|
Author: aron.gombas
Date: 2005-09-20 04:00:08 -0400 (Tue, 20 Sep 2005)
New Revision: 1154
Modified:
trunk/labs/kosmos/src/java/hu/midori/kosmos/server/AbstractKosmosService.java
trunk/labs/kosmos/web-server/WEB-INF/web.xml
Log:
Support for HTTPS, overrideable client URLs added
Modified: trunk/labs/kosmos/src/java/hu/midori/kosmos/server/AbstractKosmosService.java
===================================================================
--- trunk/labs/kosmos/src/java/hu/midori/kosmos/server/AbstractKosmosService.java 2005-09-20 06:52:07 UTC (rev 1153)
+++ trunk/labs/kosmos/src/java/hu/midori/kosmos/server/AbstractKosmosService.java 2005-09-20 08:00:08 UTC (rev 1154)
@@ -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;
@@ -100,27 +101,37 @@
* the absolute URL pointing to the resulted file.
*/
protected String saveCachedFile(String filename, InputStream in) throws URIException, IOException {
- // determine server-side cache path and cache URL
+ // grab parameters
String url = ctx.getServletContext().getInitParameter("webdav.url");
String user = ctx.getServletContext().getInitParameter("webdav.user");
String password = ctx.getServletContext().getInitParameter("webdav.password");
+ String clientUrl = ctx.getServletContext().getInitParameter("webdav.clientUrl");
+
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);
+ // determine server-side cache path and cache URL
+ boolean isHttps = url.startsWith("https://");
+ HttpURL webdavUrl = isHttps ? new HttpsURL(url) : new HttpURL(url);
+ if (!isHttps) {// 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((user != null) && (user.trim().length() != 0))
+ webdavUrl.setUser(user);
+ if((password != null) && (password.trim().length() != 0))
+ webdavUrl.setPassword(password);
+ }
+ // use "webdav.url" if "webdav.clientUrl" was not specified
+ if((clientUrl == null) || (clientUrl.trim().length() == 0))
+ clientUrl = webdavUrl.getURI();
+
String cacheDirPath = webdavUrl.getPath() + "/kosmos-cache/";
String cachedFilePath = cacheDirPath + filename;
- String cachedFileUrl = webdavUrl.getURI() + "/kosmos-cache/" + URLEncoder.encode(filename, "utf-8");
+ String cachedFileUrl = clientUrl + "/kosmos-cache/" + URLEncoder.encode(filename, "utf-8");
// create WebDAV dir if not existing
- WebdavResource webdavResource = new WebdavResource(webdavUrl);
- // TODO check if the dir was not existing yet
- webdavResource.mkcolMethod(cacheDirPath);
+ WebdavResource webdavResource = new WebdavResource(webdavUrl); // TODO check if the dir was not existing yet
+ if (!isHttps) // using this with https throws an exception
+ webdavResource.mkcolMethod(cacheDirPath);
// put resource to WebDAV
log.debug(String.format("Putting WebDAV resource \"%s\"...", cachedFilePath));
Modified: trunk/labs/kosmos/web-server/WEB-INF/web.xml
===================================================================
--- trunk/labs/kosmos/web-server/WEB-INF/web.xml 2005-09-20 06:52:07 UTC (rev 1153)
+++ trunk/labs/kosmos/web-server/WEB-INF/web.xml 2005-09-20 08:00:08 UTC (rev 1154)
@@ -4,10 +4,12 @@
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
+<!-- $Id$ -->
<web-app>
<display-name>Kosmos services servlet</display-name>
<description>Server component of Kosmos</description>
-
+
+ <!-- Both HTTP and HTTPS protocol can be used here. -->
<context-param>
<param-name>webdav.url</param-name>
<param-value>http://localhost:8080/slide/files</param-value>
@@ -20,7 +22,15 @@
<param-name>webdav.password</param-name>
<param-value></param-value>
</context-param>
-
+ <!-- This URL will be used as base URL for the generated images.
+ If you don't specify anything here, the value of "webdav.url"
+ will be used. Uncomment this, if you want to override that.
+ <context-param>
+ <param-name>webdav.clientUrl</param-name>
+ <param-value>http://myserver/my-webdav/kosmos/images</param-value>
+ </context-param>
+ -->
+
<servlet>
<servlet-name>kosmos-services</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
|