File keyStoreFile = null;
char[] keyStorePassword = null;
String keyStoreType = null;
boolean isHTTPProxy = true;
boolean console = false;
EndPoint chainedHTTPProxy = null;
EndPoint chainedHTTPSProxy = null;
int timeout = 0;
boolean useColour = false;
final FilterChain requestFilterChain = new FilterChain("request");
final FilterChain responseFilterChain = new FilterChain("response");
try {
// Parse 1.
for (int i = 0; i < args.length; i++) {
if ("-properties".equalsIgnoreCase(args[i])) {
final Properties properties = new Properties();
final FileInputStream in = new FileInputStream(
new File(args[++i]));
try {
properties.load(in);
} finally {
in.close();
}
System.getProperties().putAll(properties);
}
}
// Parse 2.
for (int i = 0; i < args.length; i++) {
if ("-requestfilter".equalsIgnoreCase(args[i])) {
requestFilterChain.add(args[++i]);
} else if ("-responsefilter".equalsIgnoreCase(args[i])) {
responseFilterChain.add(args[++i]);
} else if ("-component".equalsIgnoreCase(args[i])) {
final Class<?> componentClass;
try {
componentClass = Class.forName(args[++i]);
} catch (ClassNotFoundException e) {
throw barfError("Class '" + args[i]
+ "' not found.");
}
m_filterContainer.addComponent(componentClass);
} else if ("-http".equalsIgnoreCase(args[i])) {
requestFilterChain.add(HTTPRequestFilter.class);
responseFilterChain.add(HTTPResponseFilter.class);
m_filterContainer
.addComponent(AttributeStringParserImplementation.class);
m_filterContainer.addComponent(ConnectionCache.class);
m_filterContainer
.addComponent(ConnectionHandlerFactoryImplementation.class);
m_filterContainer
.addComponent(HTTPRecordingImplementation.class);
m_filterContainer
.addComponent(ProcessHTTPRecordingWithXSLT.class);
m_filterContainer
.addComponent(RegularExpressionsImplementation.class);
m_filterContainer
.addComponent(URIParserImplementation.class);
m_filterContainer
.addComponent(SimpleStringEscaper.class);
if (i + 1 < args.length && !args[i + 1].startsWith("-")) {
final String s = args[++i];
if ("oldjython".equals(s)) {
// Default.
} else if ("jython".equals(s)) {
m_filterContainer
.addComponent(BuiltInStyleSheet.Jython);
} else if ("clojure".equals(s)) {
m_filterContainer
.addComponent(BuiltInStyleSheet.Clojure);
} else {
m_filterContainer
.addComponent(new StyleSheetFile(
new File(s)));
}
}
} else if ("-localhost".equalsIgnoreCase(args[i])) {
localHost = args[++i];
} else if ("-localport".equalsIgnoreCase(args[i])) {
localPort = Integer.parseInt(args[++i]);
} else if ("-remotehost".equalsIgnoreCase(args[i])) {
remoteHost = args[++i];
isHTTPProxy = false;
} else if ("-remoteport".equalsIgnoreCase(args[i])) {
remotePort = Integer.parseInt(args[++i]);
isHTTPProxy = false;
} else if ("-ssl".equalsIgnoreCase(args[i])) {
useSSLPortForwarding = true;
} else if ("-keystore".equalsIgnoreCase(args[i])) {
keyStoreFile = new File(args[++i]);
} else if ("-keystorepassword".equalsIgnoreCase(args[i])
|| "-storepass".equalsIgnoreCase(args[i])) {
keyStorePassword = args[++i].toCharArray();
} else if ("-keystoretype".equalsIgnoreCase(args[i])
|| "-storetype".equalsIgnoreCase(args[i])) {
keyStoreType = args[++i];
} else if ("-timeout".equalsIgnoreCase(args[i])) {
timeout = Integer.parseInt(args[++i]) * 1000;
} else if ("-console".equalsIgnoreCase(args[i])) {
console = true;
} else if ("-colour".equalsIgnoreCase(args[i])
|| "-color".equalsIgnoreCase(args[i])) {
useColour = true;
} else if ("-properties".equalsIgnoreCase(args[i])) {
/* Already handled */
++i;
} else if ("-httpproxy".equalsIgnoreCase(args[i])) {
chainedHTTPProxy = new EndPoint(args[++i],
Integer.parseInt(args[++i]));
} else if ("-httpsproxy".equalsIgnoreCase(args[i])) {
chainedHTTPSProxy = new EndPoint(args[++i],
Integer.parseInt(args[++i]));
} else if ("-debug".equalsIgnoreCase(args[i])) {
m_filterContainer
.changeMonitor(new ConsoleComponentMonitor(
System.err));
} else if ("-initialtest".equalsIgnoreCase(args[i])) {
final String argument = i + 1 < args.length ? args[++i]
: "123";
throw barfError("-initialTest is no longer supported. "
+ "Use -DHTTPPlugin.initialTest=" + argument
+ " or the -properties option instead.");
} else {
throw barfUsage();
}
}
} catch (FileNotFoundException fnfe) {
throw barfError(fnfe.getMessage());
} catch (IndexOutOfBoundsException e) {
throw barfUsage();
} catch (NumberFormatException e) {
throw barfUsage();
}
if (timeout < 0) {
throw barfError("Timeout must be non-negative.");
}
final EndPoint localEndPoint = new EndPoint(localHost, localPort);
final EndPoint remoteEndPoint = new EndPoint(remoteHost, remotePort);
if (chainedHTTPSProxy == null && chainedHTTPProxy != null) {
chainedHTTPSProxy = chainedHTTPProxy;
}