- Addition of (optional) scheme, host & port configuration to web-client-config.xml

- Web Scripts are now sensitive to above configuration

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5783 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
David Caruana
2007-05-25 14:49:14 +00:00
parent 8553ab0d4a
commit 7255db6389
6 changed files with 137 additions and 9 deletions

View File

@@ -7,6 +7,7 @@
</evaluators> </evaluators>
<element-readers> <element-readers>
<element-reader element-name="client" class="org.alfresco.web.config.ClientElementReader"/> <element-reader element-name="client" class="org.alfresco.web.config.ClientElementReader"/>
<element-reader element-name="server" class="org.alfresco.web.config.ServerElementReader"/>
<element-reader element-name="property-sheet" class="org.alfresco.web.config.PropertySheetElementReader"/> <element-reader element-name="property-sheet" class="org.alfresco.web.config.PropertySheetElementReader"/>
<element-reader element-name="navigation" class="org.alfresco.web.config.NavigationElementReader" /> <element-reader element-name="navigation" class="org.alfresco.web.config.NavigationElementReader" />
<element-reader element-name="languages" class="org.alfresco.web.config.LanguagesElementReader" /> <element-reader element-name="languages" class="org.alfresco.web.config.LanguagesElementReader" />
@@ -83,6 +84,17 @@
</client> </client>
</config> </config>
<config evaluator="string-compare" condition="Server">
<!-- The public web server hosting this web client -->
<server>
<!-- Enable and adjust the following settings to allow for proxied use of Alfresco
<scheme>http</scheme>
<hostname>localhost</hostname>
<port>8080</port>
-->
</server>
</config>
<config evaluator="string-compare" condition="Languages"> <config evaluator="string-compare" condition="Languages">
<!-- the list of available language files --> <!-- the list of available language files -->
<languages> <languages>

View File

@@ -10,6 +10,7 @@
<bean id="webscripts.test" class="org.alfresco.web.scripts.TestWebScriptServer"> <bean id="webscripts.test" class="org.alfresco.web.scripts.TestWebScriptServer">
<property name="registry" ref="webscripts.registry" /> <property name="registry" ref="webscripts.registry" />
<property name="transactionService" ref="transactionComponent" /> <property name="transactionService" ref="transactionComponent" />
<property name="configService" ref="webClientConfigService" />
<property name="messages"> <property name="messages">
<bean class="org.springframework.context.support.ResourceBundleMessageSource"> <bean class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames"> <property name="basenames">

View File

@@ -33,9 +33,12 @@ import java.io.PrintStream;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.StringWriter; 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;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.service.transaction.TransactionService; import org.alfresco.service.transaction.TransactionService;
import org.alfresco.web.config.ServerConfigElement;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.MessageSource; import org.springframework.context.MessageSource;
import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -54,6 +57,10 @@ public class TestWebScriptServer
// dependencies // dependencies
protected TransactionService transactionService; protected TransactionService transactionService;
protected DeclarativeWebScriptRegistry registry; protected DeclarativeWebScriptRegistry registry;
protected ConfigService configService;
/** Server Configuration */
private ServerConfigElement serverConfig;
/** The reader for interaction. */ /** The reader for interaction. */
private BufferedReader fIn; private BufferedReader fIn;
@@ -87,6 +94,16 @@ public class TestWebScriptServer
{ {
this.registry = registry; 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() public void init()
{ {
registry.initWebScripts(); 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() 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); ApplicationContext context = new ClassPathXmlApplicationContext(CONFIG_LOCATIONS);
TestWebScriptServer testServer = (TestWebScriptServer)context.getBean("webscripts.test"); TestWebScriptServer testServer = (TestWebScriptServer)context.getBean("webscripts.test");
testServer.init(); testServer.init();
@@ -163,7 +188,7 @@ public class TestWebScriptServer
MockHttpServletRequest req = createRequest("get", uri); MockHttpServletRequest req = createRequest("get", uri);
MockHttpServletResponse res = new MockHttpServletResponse(); 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(); runtime.executeScript();
return res; return res;

View File

@@ -31,7 +31,10 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.alfresco.config.Config;
import org.alfresco.config.ConfigService;
import org.alfresco.service.transaction.TransactionService; import org.alfresco.service.transaction.TransactionService;
import org.alfresco.web.config.ServerConfigElement;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
@@ -54,8 +57,11 @@ public class WebScriptServlet extends HttpServlet
private DeclarativeWebScriptRegistry registry; private DeclarativeWebScriptRegistry registry;
private TransactionService transactionService; private TransactionService transactionService;
private WebScriptServletAuthenticator authenticator; private WebScriptServletAuthenticator authenticator;
protected ConfigService configService;
/** Host Server Configuration */
private static ServerConfigElement serverConfig;
@Override @Override
public void init() throws ServletException public void init() throws ServletException
@@ -64,6 +70,7 @@ public class WebScriptServlet extends HttpServlet
ApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext()); ApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
registry = (DeclarativeWebScriptRegistry)context.getBean("webscripts.registry"); registry = (DeclarativeWebScriptRegistry)context.getBean("webscripts.registry");
transactionService = (TransactionService)context.getBean("transactionComponent"); transactionService = (TransactionService)context.getBean("transactionComponent");
configService = (ConfigService)context.getBean("webClientConfigService");
// retrieve authenticator via servlet initialisation parameter // retrieve authenticator via servlet initialisation parameter
String authenticatorId = getInitParameter("authenticator"); 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 + ")"); throw new ServletException("Initialisation parameter 'authenticator' does not refer to a Web Script authenticator (" + authenticatorId + ")");
} }
authenticator = (WebScriptServletAuthenticator)bean; 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("Cache-Control", "no-cache");
res.setHeader("Pragma", "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(); runtime.executeScript();
} }

View File

@@ -28,6 +28,8 @@ import java.util.Set;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import org.alfresco.web.config.ServerConfigElement;
/** /**
* HTTP Servlet Web Script Request * HTTP Servlet Web Script Request
@@ -36,6 +38,9 @@ import javax.servlet.http.HttpServletRequest;
*/ */
public class WebScriptServletRequest implements WebScriptRequest public class WebScriptServletRequest implements WebScriptRequest
{ {
/** Server Config */
private ServerConfigElement serverConfig;
/** HTTP Request */ /** HTTP Request */
private HttpServletRequest req; private HttpServletRequest req;
@@ -51,10 +56,23 @@ public class WebScriptServletRequest implements WebScriptRequest
*/ */
WebScriptServletRequest(HttpServletRequest req, WebScriptMatch serviceMatch) 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.req = req;
this.serviceMatch = serviceMatch; this.serviceMatch = serviceMatch;
} }
/** /**
* Gets the HTTP Servlet Request * Gets the HTTP Servlet Request
* *
@@ -84,7 +102,7 @@ public class WebScriptServletRequest implements WebScriptRequest
*/ */
public String getServerPath() public String getServerPath()
{ {
return req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort(); return getServerScheme() + "://" + getServerName() + ":" + getServerPort();
} }
/* (non-Javadoc) /* (non-Javadoc)
@@ -221,4 +239,61 @@ public class WebScriptServletRequest implements WebScriptRequest
return null; 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;
}
} }

View File

@@ -28,6 +28,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.alfresco.service.transaction.TransactionService; import org.alfresco.service.transaction.TransactionService;
import org.alfresco.web.config.ServerConfigElement;
import org.alfresco.web.scripts.WebScriptDescription.RequiredAuthentication; import org.alfresco.web.scripts.WebScriptDescription.RequiredAuthentication;
@@ -41,6 +42,7 @@ public class WebScriptServletRuntime extends WebScriptRuntime
private HttpServletRequest req; private HttpServletRequest req;
private HttpServletResponse res; private HttpServletResponse res;
private WebScriptServletAuthenticator authenticator; private WebScriptServletAuthenticator authenticator;
private ServerConfigElement serverConfig;
/** /**
@@ -52,12 +54,14 @@ public class WebScriptServletRuntime extends WebScriptRuntime
* @param req * @param req
* @param res * @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); super(registry, transactionService);
this.req = req; this.req = req;
this.res = res; this.res = res;
this.authenticator = authenticator; this.authenticator = authenticator;
this.serverConfig = serverConfig;
} }
/* (non-Javadoc) /* (non-Javadoc)
@@ -84,7 +88,7 @@ public class WebScriptServletRuntime extends WebScriptRuntime
@Override @Override
protected WebScriptRequest createRequest(WebScriptMatch match) protected WebScriptRequest createRequest(WebScriptMatch match)
{ {
return new WebScriptServletRequest(req, match); return new WebScriptServletRequest(serverConfig, req, match);
} }
/* (non-Javadoc) /* (non-Javadoc)