use of org.springframework.extensions.webscripts.TestWebScriptServer in project records-management by Alfresco.
the class TestWebScriptRepoServer method main.
/**
* Main entry point.
*/
public static void main(String[] args) {
try {
TestWebScriptServer testServer = getTestServer();
AuthenticationUtil.setRunAsUserSystem();
testServer.rep();
} catch (Throwable e) {
StringWriter strWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(strWriter);
e.printStackTrace(printWriter);
System.out.println(strWriter.toString());
} finally {
System.exit(0);
}
}
use of org.springframework.extensions.webscripts.TestWebScriptServer in project records-management by Alfresco.
the class TestWebScriptRepoServer method getTestServer.
/**
* Start up a context and get the server bean.
* <p>
* This method will close and restart the application context only if the configuration has
* changed.
*
* @param appendTestConfigLocation additional context file to include in the application context
* @return Test Server
*/
public static synchronized TestWebScriptServer getTestServer(String appendTestConfigLocation) {
if (TestWebScriptRepoServer.ctx != null) {
boolean configChanged = !EqualsHelper.nullSafeEquals(appendTestConfigLocation, TestWebScriptRepoServer.appendedTestConfiguration);
if (configChanged) {
// The config changed, so close the context (it'll be restarted later)
try {
ctx.close();
ctx = null;
} catch (Throwable e) {
throw new RuntimeException("Failed to shut down existing application context", e);
}
} else {
// There is already a context with the required configuration
}
}
// Check if we need to start/restart the context
if (TestWebScriptRepoServer.ctx == null) {
// Restart it
final String[] configLocations;
if (appendTestConfigLocation == null) {
configLocations = CONFIG_LOCATIONS;
} else {
configLocations = new String[CONFIG_LOCATIONS.length + 1];
System.arraycopy(CONFIG_LOCATIONS, 0, configLocations, 0, CONFIG_LOCATIONS.length);
configLocations[CONFIG_LOCATIONS.length] = appendTestConfigLocation;
}
TestWebScriptRepoServer.ctx = new ClassPathXmlApplicationContext(configLocations);
TestWebScriptRepoServer.appendedTestConfiguration = appendTestConfigLocation;
}
// Get the bean
TestWebScriptServer testServer = (org.alfresco.repo.web.scripts.TestWebScriptRepoServer) TestWebScriptRepoServer.ctx.getBean("webscripts.test");
return testServer;
}
Aggregations