use of org.parosproxy.paros.control.Control in project zaproxy by zaproxy.
the class GuiBootstrap method initControlAndPostViewInit.
/**
* Initialises the {@code Control} and does post {@code View} initialisations.
*
* @throws Exception if an error occurs during initialisation
* @see Control
* @see View
*/
private void initControlAndPostViewInit() throws Exception {
Control.initSingletonWithView(getControlOverrides());
final Control control = Control.getSingleton();
final View view = View.getSingleton();
EventQueue.invokeAndWait(new Runnable() {
@Override
public void run() {
view.postInit();
view.getMainFrame().setVisible(true);
boolean createNewSession = true;
if (getArgs().isEnabled(CommandLine.SESSION) && getArgs().isEnabled(CommandLine.NEW_SESSION)) {
view.showWarningDialog(Constant.messages.getString("start.gui.cmdline.invalid.session.options", CommandLine.SESSION, CommandLine.NEW_SESSION, Constant.getZapHome()));
} else if (getArgs().isEnabled(CommandLine.SESSION)) {
Path sessionPath = SessionUtils.getSessionPath(getArgs().getArgument(CommandLine.SESSION));
if (!Files.exists(sessionPath)) {
view.showWarningDialog(Constant.messages.getString("start.gui.cmdline.session.does.not.exist", Constant.getZapHome()));
} else {
createNewSession = !control.getMenuFileControl().openSession(sessionPath.toAbsolutePath().toString());
}
} else if (getArgs().isEnabled(CommandLine.NEW_SESSION)) {
Path sessionPath = SessionUtils.getSessionPath(getArgs().getArgument(CommandLine.NEW_SESSION));
if (Files.exists(sessionPath)) {
view.showWarningDialog(Constant.messages.getString("start.gui.cmdline.newsession.already.exist", Constant.getZapHome()));
} else {
createNewSession = !control.getMenuFileControl().newSession(sessionPath.toAbsolutePath().toString());
}
}
view.hideSplashScreen();
if (createNewSession) {
try {
control.getMenuFileControl().newSession(false);
} catch (Exception e) {
logger.error(e.getMessage(), e);
View.getSingleton().showWarningDialog(Constant.messages.getString("menu.file.newSession.error"));
}
}
}
});
try {
// Allow extensions to pick up command line args in GUI mode
control.getExtensionLoader().hookCommandLineListener(getArgs());
control.runCommandLine();
} catch (final Exception e) {
logger.error(e.getMessage(), e);
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
view.showWarningDialog(e.getMessage());
}
});
}
}
use of org.parosproxy.paros.control.Control in project zaproxy by zaproxy.
the class WithConfigsTest method setUp.
@Before
public void setUp() throws Exception {
/*
// Useful if you need to get some info when debugging
BasicConfigurator.configure();
ConsoleAppender ca = new ConsoleAppender();
ca.setWriter(new OutputStreamWriter(System.out));
ca.setLayout(new PatternLayout("%-5p [%t]: %m%n"));
Logger.getRootLogger().addAppender(ca);
Logger.getRootLogger().setLevel(Level.DEBUG);
/**/
Constant.setZapInstall(INSTALL_PATH);
HOME_DIR.mkdirs();
Constant.setZapHome(HOME_DIR.getAbsolutePath());
File langDir = new File(Constant.getZapInstall(), "lang");
ClassLoaderUtil.addFile(langDir.getAbsolutePath());
ExtensionLoader extLoader = Mockito.mock(ExtensionLoader.class);
Control control = Mockito.mock(Control.class);
Mockito.when(control.getExtensionLoader()).thenReturn(extLoader);
// Init all the things
Constant.getInstance();
I18N i18n = Mockito.mock(I18N.class);
given(i18n.getString(anyString())).willReturn("");
given(i18n.getString(anyString(), anyObject())).willReturn("");
given(i18n.getLocal()).willReturn(Locale.getDefault());
Constant.messages = i18n;
Control.initSingletonForTesting(Model.getSingleton());
Mockito.when(control.getExtensionLoader()).thenReturn(extLoader);
}
use of org.parosproxy.paros.control.Control in project zaproxy by zaproxy.
the class CommandLineBootstrap method start.
@Override
public int start() {
int rc = super.start();
if (rc != 0) {
return rc;
}
logger.info(getStartingMessage());
try {
initModel();
} catch (Exception e) {
if (e instanceof FileNotFoundException) {
System.out.println(Constant.messages.getString("start.db.error"));
System.out.println(e.getLocalizedMessage());
}
throw new RuntimeException(e);
}
Control control = initControl();
warnAddOnsAndExtensionsNoLongerRunnable();
try {
control.getExtensionLoader().hookCommandLineListener(getArgs());
if (getArgs().isEnabled(CommandLine.HELP) || getArgs().isEnabled(CommandLine.HELP2)) {
System.out.println(getArgs().getHelp());
} else if (getArgs().isReportVersion()) {
System.out.println(Constant.PROGRAM_VERSION);
} else {
if (handleCmdLineSessionArgsSynchronously(control)) {
control.runCommandLine();
try {
Thread.sleep(1000);
} catch (final InterruptedException e) {
}
} else {
rc = 1;
}
}
} catch (final Exception e) {
logger.error(e.getMessage(), e);
System.out.println(e.getMessage());
System.out.println();
// Help is kind of useful too ;)
System.out.println(getArgs().getHelp());
rc = 1;
} finally {
control.shutdown(Model.getSingleton().getOptionsParam().getDatabaseParam().isCompactDatabase());
logger.info(Constant.PROGRAM_TITLE + " terminated.");
}
return rc;
}
Aggregations