diff --git a/config/alfresco/web-client-config.xml b/config/alfresco/web-client-config.xml index a1a1d59527..116693c253 100644 --- a/config/alfresco/web-client-config.xml +++ b/config/alfresco/web-client-config.xml @@ -7,6 +7,7 @@ + @@ -83,6 +84,17 @@ + + + + + + + diff --git a/config/alfresco/web-scripts-application-context-test.xml b/config/alfresco/web-scripts-application-context-test.xml index 7cf91a882e..fa83bca578 100644 --- a/config/alfresco/web-scripts-application-context-test.xml +++ b/config/alfresco/web-scripts-application-context-test.xml @@ -10,6 +10,7 @@ + diff --git a/source/java/org/alfresco/web/scripts/TestWebScriptServer.java b/source/java/org/alfresco/web/scripts/TestWebScriptServer.java index fbe320babc..70262eaf76 100644 --- a/source/java/org/alfresco/web/scripts/TestWebScriptServer.java +++ b/source/java/org/alfresco/web/scripts/TestWebScriptServer.java @@ -33,9 +33,12 @@ import java.io.PrintStream; import java.io.PrintWriter; import java.io.StringWriter; +import org.alfresco.config.Config; +import org.alfresco.config.ConfigService; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; import org.alfresco.service.transaction.TransactionService; +import org.alfresco.web.config.ServerConfigElement; import org.springframework.context.ApplicationContext; import org.springframework.context.MessageSource; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -54,6 +57,10 @@ public class TestWebScriptServer // dependencies protected TransactionService transactionService; protected DeclarativeWebScriptRegistry registry; + protected ConfigService configService; + + /** Server Configuration */ + private ServerConfigElement serverConfig; /** The reader for interaction. */ private BufferedReader fIn; @@ -87,6 +94,16 @@ public class TestWebScriptServer { this.registry = registry; } + + /** + * Sets the Config Service + * + * @param configService + */ + public void setConfigService(ConfigService configService) + { + this.configService = configService; + } /** @@ -110,6 +127,8 @@ public class TestWebScriptServer public void init() { registry.initWebScripts(); + Config config = configService.getConfig("Server"); + serverConfig = (ServerConfigElement)config.getConfigElement(ServerConfigElement.CONFIG_ELEMENT_ID); } /** @@ -142,7 +161,13 @@ public class TestWebScriptServer */ public static TestWebScriptServer getTestServer() { - String[] CONFIG_LOCATIONS = new String[] { "classpath:alfresco/application-context.xml", "classpath:alfresco/web-scripts-application-context.xml", "classpath:alfresco/web-scripts-application-context-test.xml" }; + String[] CONFIG_LOCATIONS = new String[] + { + "classpath:alfresco/application-context.xml", + "classpath:alfresco/web-scripts-application-context.xml", + "classpath:alfresco/web-client-application-context.xml", + "classpath:alfresco/web-scripts-application-context-test.xml" + }; ApplicationContext context = new ClassPathXmlApplicationContext(CONFIG_LOCATIONS); TestWebScriptServer testServer = (TestWebScriptServer)context.getBean("webscripts.test"); testServer.init(); @@ -163,7 +188,7 @@ public class TestWebScriptServer MockHttpServletRequest req = createRequest("get", uri); MockHttpServletResponse res = new MockHttpServletResponse(); - WebScriptRuntime runtime = new WebScriptServletRuntime(registry, transactionService, null, req, res); + WebScriptRuntime runtime = new WebScriptServletRuntime(registry, transactionService, null, req, res, serverConfig); runtime.executeScript(); return res; diff --git a/source/java/org/alfresco/web/scripts/WebScriptServlet.java b/source/java/org/alfresco/web/scripts/WebScriptServlet.java index b6d0b2fc4b..afd64dc835 100644 --- a/source/java/org/alfresco/web/scripts/WebScriptServlet.java +++ b/source/java/org/alfresco/web/scripts/WebScriptServlet.java @@ -31,7 +31,10 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.alfresco.config.Config; +import org.alfresco.config.ConfigService; import org.alfresco.service.transaction.TransactionService; +import org.alfresco.web.config.ServerConfigElement; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.context.ApplicationContext; @@ -54,8 +57,11 @@ public class WebScriptServlet extends HttpServlet private DeclarativeWebScriptRegistry registry; private TransactionService transactionService; private WebScriptServletAuthenticator authenticator; - - + protected ConfigService configService; + + /** Host Server Configuration */ + private static ServerConfigElement serverConfig; + @Override public void init() throws ServletException @@ -64,6 +70,7 @@ public class WebScriptServlet extends HttpServlet ApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext()); registry = (DeclarativeWebScriptRegistry)context.getBean("webscripts.registry"); transactionService = (TransactionService)context.getBean("transactionComponent"); + configService = (ConfigService)context.getBean("webClientConfigService"); // retrieve authenticator via servlet initialisation parameter String authenticatorId = getInitParameter("authenticator"); @@ -77,6 +84,10 @@ public class WebScriptServlet extends HttpServlet throw new ServletException("Initialisation parameter 'authenticator' does not refer to a Web Script authenticator (" + authenticatorId + ")"); } authenticator = (WebScriptServletAuthenticator)bean; + + // retrieve host server configuration + Config config = configService.getConfig("Server"); + serverConfig = (ServerConfigElement)config.getConfigElement(ServerConfigElement.CONFIG_ELEMENT_ID); } @@ -94,7 +105,7 @@ public class WebScriptServlet extends HttpServlet res.setHeader("Cache-Control", "no-cache"); res.setHeader("Pragma", "no-cache"); - WebScriptRuntime runtime = new WebScriptServletRuntime(registry, transactionService, authenticator, req, res); + WebScriptRuntime runtime = new WebScriptServletRuntime(registry, transactionService, authenticator, req, res, serverConfig); runtime.executeScript(); } diff --git a/source/java/org/alfresco/web/scripts/WebScriptServletRequest.java b/source/java/org/alfresco/web/scripts/WebScriptServletRequest.java index c702a5bb53..96deb60b2d 100644 --- a/source/java/org/alfresco/web/scripts/WebScriptServletRequest.java +++ b/source/java/org/alfresco/web/scripts/WebScriptServletRequest.java @@ -28,6 +28,8 @@ import java.util.Set; import javax.servlet.http.HttpServletRequest; +import org.alfresco.web.config.ServerConfigElement; + /** * HTTP Servlet Web Script Request @@ -36,6 +38,9 @@ import javax.servlet.http.HttpServletRequest; */ public class WebScriptServletRequest implements WebScriptRequest { + /** Server Config */ + private ServerConfigElement serverConfig; + /** HTTP Request */ private HttpServletRequest req; @@ -51,10 +56,23 @@ public class WebScriptServletRequest implements WebScriptRequest */ WebScriptServletRequest(HttpServletRequest req, WebScriptMatch serviceMatch) { + this(null, req, serviceMatch); + } + + /** + * Construct + * + * @param serverConfig + * @param req + * @param serviceMatch + */ + WebScriptServletRequest(ServerConfigElement serverConfig, HttpServletRequest req, WebScriptMatch serviceMatch) + { + this.serverConfig = serverConfig; this.req = req; this.serviceMatch = serviceMatch; } - + /** * Gets the HTTP Servlet Request * @@ -84,7 +102,7 @@ public class WebScriptServletRequest implements WebScriptRequest */ public String getServerPath() { - return req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort(); + return getServerScheme() + "://" + getServerName() + ":" + getServerPort(); } /* (non-Javadoc) @@ -221,4 +239,61 @@ public class WebScriptServletRequest implements WebScriptRequest return null; } + /** + * Get Server Scheme + * + * @return server scheme + */ + private String getServerScheme() + { + String scheme = null; + if (serverConfig != null) + { + scheme = serverConfig.getScheme(); + } + if (scheme == null) + { + scheme = req.getScheme(); + } + return scheme; + } + + /** + * Get Server Name + * + * @return server name + */ + private String getServerName() + { + String name = null; + if (serverConfig != null) + { + name = serverConfig.getHostName(); + } + if (name == null) + { + name = req.getServerName(); + } + return name; + } + + /** + * Get Server Port + * + * @return server name + */ + private int getServerPort() + { + Integer port = null; + if (serverConfig != null) + { + port = serverConfig.getPort(); + } + if (port == null) + { + port = req.getServerPort(); + } + return port; + } + } diff --git a/source/java/org/alfresco/web/scripts/WebScriptServletRuntime.java b/source/java/org/alfresco/web/scripts/WebScriptServletRuntime.java index 7c551e3c59..5f9875c0c5 100644 --- a/source/java/org/alfresco/web/scripts/WebScriptServletRuntime.java +++ b/source/java/org/alfresco/web/scripts/WebScriptServletRuntime.java @@ -28,6 +28,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.alfresco.service.transaction.TransactionService; +import org.alfresco.web.config.ServerConfigElement; import org.alfresco.web.scripts.WebScriptDescription.RequiredAuthentication; @@ -41,6 +42,7 @@ public class WebScriptServletRuntime extends WebScriptRuntime private HttpServletRequest req; private HttpServletResponse res; private WebScriptServletAuthenticator authenticator; + private ServerConfigElement serverConfig; /** @@ -52,12 +54,14 @@ public class WebScriptServletRuntime extends WebScriptRuntime * @param req * @param res */ - public WebScriptServletRuntime(WebScriptRegistry registry, TransactionService transactionService, WebScriptServletAuthenticator authenticator, HttpServletRequest req, HttpServletResponse res) + public WebScriptServletRuntime(WebScriptRegistry registry, TransactionService transactionService, WebScriptServletAuthenticator authenticator, + HttpServletRequest req, HttpServletResponse res, ServerConfigElement serverConfig) { super(registry, transactionService); this.req = req; this.res = res; this.authenticator = authenticator; + this.serverConfig = serverConfig; } /* (non-Javadoc) @@ -84,7 +88,7 @@ public class WebScriptServletRuntime extends WebScriptRuntime @Override protected WebScriptRequest createRequest(WebScriptMatch match) { - return new WebScriptServletRequest(req, match); + return new WebScriptServletRequest(serverConfig, req, match); } /* (non-Javadoc)