Index: C:/workplaces/patch/jackrabbitpatch/src/main/java/org/apache/jackrabbit/spi2dav/IdURICache.java
===================================================================
--- C:/workplaces/patch/jackrabbitpatch/src/main/java/org/apache/jackrabbit/spi2dav/IdURICache.java (revision 981443)
+++ C:/workplaces/patch/jackrabbitpatch/src/main/java/org/apache/jackrabbit/spi2dav/IdURICache.java (working copy)
@@ -20,8 +20,15 @@
import org.slf4j.LoggerFactory;
import org.apache.jackrabbit.spi.ItemId;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.Map;
import java.util.HashMap;
+import java.util.Properties;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
/**
* IdURICache...
@@ -35,8 +42,36 @@
private Map idToUriCache = new HashMap();
private Map uriToIdCache = new HashMap();
+ /**
+ * Proxy settings.
+ */
+ private final Properties settings;
+
IdURICache(String workspaceUri) {
this.workspaceUri = workspaceUri;
+
+ // load proxy settings
+ this.settings = getStaticProperties();
+ }
+
+ private static Properties getStaticProperties() {
+ Properties properties = new Properties();
+ try {
+ InputStream stream =
+ getResource("proxy.properties");
+ try {
+ properties.load(stream);
+ } finally {
+ stream.close();
+ }
+ } catch (IOException e) {
+ // TODO: Log warning
+ }
+ return properties;
+ }
+
+ private static InputStream getResource(String name) {
+ return IdURICache.class.getResourceAsStream(name);
}
public ItemId getItemId(String uri) {
@@ -55,8 +90,32 @@
return idToUriCache.containsKey(itemId);
}
+ /**
+ If response URI contains IP address instead of the host name (because of proxy mappings),
+ the request URI will be converted back to the original URI according to the configurations
+ provided in proxy.properties file.
+ */
+ protected String getUriWithProxyConfig(String uri) {
+
+ try {
+ URL url = new URL(uri);
+ String hostIp = url.getHost();
+ if (settings.containsKey(hostIp)) {
+ //get proxy configuration
+ String hostName = (String) settings.get(hostIp);
+ //replace Ip with hostname
+ if (hostName != null && !hostName.isEmpty())
+ return uri.replace(hostIp, hostName);
+ }
+ } catch (MalformedURLException e) {
+ throw new IllegalArgumentException("Cannot parse request URI! " + e.getMessage());
+ }
+
+ return uri;
+ }
+
public void add(String uri, ItemId itemId) {
- if (!uri.startsWith(workspaceUri)) {
+ if (!uri.startsWith(workspaceUri) && !getUriWithProxyConfig(uri).startsWith(workspaceUri)) {
throw new IllegalArgumentException("Workspace missmatch.");
}
String cleanUri = getCleanUri(uri);
Index: C:/workplaces/patch/jackrabbitpatch/src/resources/org/apache/jackrabbit/core/proxy.properties.template
===================================================================
--- C:/workplaces/patch/jackrabbitpatch/src/resources/org/apache/jackrabbit/core/proxy.properties.template (revision 0)
+++ C:/workplaces/patch/jackrabbitpatch/src/resources/org/apache/jackrabbit/core/proxy.properties.template (revision 0)
@@ -0,0 +1,2 @@
+# proxy configuration (mapping between IP and host name)
+ip=hostname