use of com.servoy.j2db.scripting.StartupArguments in project servoy-client by Servoy.
the class NGClientWebsocketSession method onOpen.
@SuppressWarnings("nls")
@Override
public void onOpen(final Map<String, List<String>> requestParams) {
super.onOpen(requestParams);
if (requestParams == null) {
CurrentWindow.get().cancelSession("Solution name is required");
return;
}
if (requestParams.containsKey("clienttype")) {
clientType = Utils.getAsInteger(requestParams.get("clienttype").get(0), 1);
if (clientType == 2)
client.getRuntimeProperties().put("NG2", Boolean.TRUE);
else
client.getRuntimeProperties().remove("NG2");
} else {
clientType = 1;
client.getRuntimeProperties().remove("NG2");
}
lastSentStyleSheets = null;
final StartupArguments args = new StartupArguments(requestParams);
final String solutionName = args.getSolutionName();
if (Utils.stringIsEmpty(solutionName)) {
CurrentWindow.get().cancelSession("Invalid solution name");
return;
}
if (!client.isEventDispatchThread())
J2DBGlobals.setServiceProvider(client);
try {
FlattenedSolution solution = client.getFlattenedSolution();
if (solution != null) {
// test for the main solution meta data else a login solution will constantly be closed even if it is for the right main solution.
if (solution.getSolution() != null && !solutionName.equals(solution.getMainSolutionMetaData().getName())) {
client.closeSolution(true, null);
} else {
if (solution.isMainSolutionLoaded() || solution.getSolution() != null && solution.getSolution().getSolutionType() == SolutionMetaData.LOGIN_SOLUTION) {
// this is needed for the situation when the solution is already loaded and the deeplink url was changed (different arg values for instance)
String method = args.getMethodName();
String firstArgument = args.getFirstArgument();
if (method != null) {
try {
client.getScriptEngine().getScopesScope().executeGlobalFunction(null, method, (args.toJSMap().isEmpty() ? null : new Object[] { firstArgument, args.toJSMap() }), false, false);
} catch (Exception e1) {
// $NON-NLS-1$
client.reportError(Messages.getString("servoy.formManager.error.ExecutingOpenSolutionMethod", new Object[] { method }), e1);
}
}
}
client.getRuntimeWindowManager().setCurrentWindowName(String.valueOf(CurrentWindow.get().getNr()));
IWebFormController currentForm = client.getFormManager().getCurrentForm();
if (currentForm != null) {
// we have to call setcontroller again so that switchForm is called and the form is loaded into the reloaded/new window.
startHandlingEvent();
try {
client.getClientFunctions().clear();
sendUIProperties();
client.getRuntimeWindowManager().getCurrentWindow().setController(currentForm);
sendSolutionCSSURL(solution.getSolution());
} finally {
stopHandlingEvent();
}
return;
}
}
}
getEventDispatcher().addEvent(new Runnable() {
@Override
public void run() {
try {
sendUIProperties();
// the solution was not loaded or another was loaded, now create a main window and load the solution.
client.getRuntimeWindowManager().createMainWindow(CurrentWindow.get().getNr());
client.handleArguments(args.getFirstArgument() != null ? new String[] { args.getSolutionName(), args.getMethodName(), args.getFirstArgument() } : new String[] { args.getSolutionName(), args.getMethodName() }, args);
client.loadSolution(solutionName);
client.showInfoPanel();
} catch (RepositoryException e) {
Debug.error("Failed to load the solution: " + solutionName, e);
sendInternalError(e);
}
}
});
} catch (Exception e) {
Debug.error(e);
sendInternalError(e);
} finally {
if (!client.isEventDispatchThread())
J2DBGlobals.setServiceProvider(null);
}
}
use of com.servoy.j2db.scripting.StartupArguments in project servoy-client by Servoy.
the class ClientState method handleArguments.
public void handleArguments(String[] args) {
String[] filteredArgs = null;
// filter out all system.properties
if (args != null) {
ArrayList<String> filteredArgsList = new ArrayList<String>();
for (String arg : args) {
// $NON-NLS-1$
if (arg != null && arg.startsWith("system.property."))
continue;
filteredArgsList.add(arg);
}
filteredArgs = new String[filteredArgsList.size()];
filteredArgs = filteredArgsList.toArray(filteredArgs);
}
clientInfo.setSpecialClientIndentifier(null);
if (filteredArgs == null || filteredArgs.length == 0) {
// clear, do not clear method and arguments (clear method when it is called, we want to access the arguments during the app livespan)
preferredSolutionNameToLoadOnInit = null;
} else {
argumentsScope = new StartupArguments(filteredArgs);
if (argumentsScope.getSolutionName() == null && argumentsScope.getMethodName() == null && argumentsScope.getFirstArgument() == null && argumentsScope.getClientIdentifier() == null) {
preferredSolutionNameToLoadOnInit = filteredArgs[0];
if (filteredArgs.length >= 2) {
if (// $NON-NLS-1$
filteredArgs[1] != null && filteredArgs[1].startsWith("CI:")) {
clientInfo.setSpecialClientIndentifier(filteredArgs[1].substring(3));
} else {
preferredSolutionMethodNameToCall = filteredArgs[1];
}
preferredSolutionMethodArguments = null;
if (filteredArgs.length >= 3) {
if (// $NON-NLS-1$
filteredArgs[2] != null && filteredArgs[2].startsWith("CI:")) {
clientInfo.setSpecialClientIndentifier(filteredArgs[2].substring(3));
} else {
preferredSolutionMethodArguments = new Object[] { filteredArgs[2] };
}
if (// $NON-NLS-1$
filteredArgs.length >= 4 && filteredArgs[3] != null && filteredArgs[3].startsWith("CI:")) {
clientInfo.setSpecialClientIndentifier(filteredArgs[3].substring(3));
}
}
}
} else {
preferredSolutionNameToLoadOnInit = argumentsScope.getSolutionName();
preferredSolutionMethodNameToCall = argumentsScope.getMethodName();
preferredSolutionMethodArguments = argumentsScope.getFirstArgument() != null ? new Object[] { argumentsScope.getFirstArgument() } : null;
if (argumentsScope.getClientIdentifier() != null)
clientInfo.setSpecialClientIndentifier(argumentsScope.getClientIdentifier());
appendArgumentsScopeToPreferedSolutionMethodArguments(argumentsScope);
}
}
}
use of com.servoy.j2db.scripting.StartupArguments in project servoy-client by Servoy.
the class J2DBClient method main.
/**
* Starting point
*/
@SuppressWarnings("nls")
public static void main(final String[] args) {
String userTimeZone = System.getProperty("user.timezone");
// Bug around java when downloading the first time (pack or gzip seems to alter the timezone and don't set it back)
if (userTimeZone != null && !userTimeZone.equals(TimeZone.getDefault().getID())) {
TimeZone timeZone = TimeZone.getTimeZone(userTimeZone);
if (userTimeZone.equals(timeZone.getID())) {
TimeZone.setDefault(timeZone);
}
}
String remoteRunnerClassName = System.getProperty("com.servoy.remote.checker");
if (remoteRunnerClassName != null) {
try {
Class<?> clazz = Class.forName(remoteRunnerClassName);
RemoteRunnerChecker.setInstance((IRemoteRunner) clazz.newInstance());
} catch (Throwable t) {
System.err.println("Error setting the remote runner check for " + remoteRunnerClassName);
}
}
boolean toggleTracing = false;
StartupArguments arguments = new StartupArguments(args);
Iterator<Entry<String, Object>> iterator = arguments.entrySet().iterator();
while (iterator.hasNext()) {
Entry<String, Object> arg = iterator.next();
if (arg.getKey().startsWith("system.property.")) {
System.setProperty(arg.getKey().substring(16), (String) arg.getValue());
}
if (arg.getKey().equals("tracing") && arg.getValue().equals("true")) {
toggleTracing = true;
}
}
if (toggleTracing)
Debug.toggleTracing();
if (Boolean.getBoolean("servoy.usejaas")) {
final boolean[] loginShown = new boolean[1];
System.setProperty("javax.security.auth.useSubjectCredsOnly", "true");
try {
Debug.log("creating context");
LoginContext lc = new LoginContext("ServoyClient", new CallbackHandler() {
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
Debug.log("handle call back");
String loginName = null;
String passwordString = null;
for (Callback callback : callbacks) {
if (callback instanceof TextOutputCallback) {
final TextOutputCallback textOutputCallback = (TextOutputCallback) callback;
switch(textOutputCallback.getMessageType()) {
case TextOutputCallback.INFORMATION:
Debug.log(textOutputCallback.getMessage());
break;
case TextOutputCallback.WARNING:
Debug.warn(textOutputCallback.getMessage());
break;
case TextOutputCallback.ERROR:
Debug.error(textOutputCallback.getMessage());
break;
default:
throw new IOException("Unsupported message type: " + textOutputCallback.getMessageType());
}
} else if (callback instanceof NameCallback) {
final NameCallback nameCallback = (NameCallback) callback;
if (loginName == null) {
LoginDialog ld = new LoginDialog((Frame) null, null, "Sign on", false, true);
Object[] credentials = ld.showDialog(null);
if (credentials != null && credentials.length == 2) {
loginName = (String) credentials[0];
passwordString = (String) credentials[1];
}
if (loginName == null) {
loginName = "";
passwordString = "";
}
loginShown[0] = true;
}
nameCallback.setName(loginName);
} else if (callback instanceof PasswordCallback) {
final PasswordCallback passwordCallback = (PasswordCallback) callback;
if (passwordString == null) {
LoginDialog ld = new LoginDialog((Frame) null, null, "Sign on", false, true);
Object[] credentials = ld.showDialog(null);
if (credentials != null && credentials.length == 2) {
loginName = (String) credentials[0];
passwordString = (String) credentials[1];
}
if (passwordString == null) {
loginName = "";
passwordString = "";
}
loginShown[0] = true;
}
passwordCallback.setPassword(passwordString.toCharArray());
} else {
throw new UnsupportedCallbackException(callback, "Unrecognized Callback");
}
}
}
});
Debug.log("context created");
boolean loggedIn = true;
try {
lc.login();
} catch (LoginException e) {
Debug.log("login failed", e);
loggedIn = false;
}
if (loggedIn) {
Subject.doAsPrivileged(lc.getSubject(), new PrivilegedExceptionAction<Void>() {
public Void run() throws Exception {
mainImpl(args);
return null;
}
}, null);
} else {
mainImpl(args);
}
} catch (Exception e) {
Debug.log("context creation failed", e);
if (loginShown[0]) {
JOptionPane.showMessageDialog(null, "Couldnt login", "Login failed", JOptionPane.ERROR_MESSAGE);
}
mainImpl(args);
}
} else {
mainImpl(args);
}
}
Aggregations