use of org.mortbay.jetty.Server in project nutch by apache.
the class ProxyTestbed method main.
/**
* @param args
*/
public static void main(String[] args) throws Exception {
if (args.length == 0) {
System.err.println("TestbedProxy [-seg <segment_name> | -segdir <segments>] [-port <nnn>] [-forward] [-fake] [-delay nnn] [-debug]");
System.err.println("-seg <segment_name>\tpath to a single segment (can be specified multiple times)");
System.err.println("-segdir <segments>\tpath to a parent directory of multiple segments (as above)");
System.err.println("-port <nnn>\trun the proxy on port <nnn> (special permissions may be needed for ports < 1024)");
System.err.println("-forward\tif specified, requests to all unknown urls will be passed to");
System.err.println("\t\toriginal servers. If false (default) unknown urls generate 404 Not Found.");
System.err.println("-delay\tdelay every response by nnn seconds. If delay is negative use a random value up to nnn");
System.err.println("-fake\tif specified, requests to all unknown urls will succeed with fake content");
System.exit(-1);
}
Configuration conf = NutchConfiguration.create();
int port = conf.getInt("segment.proxy.port", 8181);
boolean forward = false;
boolean fake = false;
boolean delay = false;
boolean debug = false;
int delayVal = 0;
HashSet<Path> segs = new HashSet<Path>();
for (int i = 0; i < args.length; i++) {
if (args[i].equals("-segdir")) {
FileSystem fs = FileSystem.get(conf);
FileStatus[] fstats = fs.listStatus(new Path(args[++i]));
Path[] paths = HadoopFSUtil.getPaths(fstats);
segs.addAll(Arrays.asList(paths));
} else if (args[i].equals("-port")) {
port = Integer.parseInt(args[++i]);
} else if (args[i].equals("-forward")) {
forward = true;
} else if (args[i].equals("-delay")) {
delay = true;
delayVal = Integer.parseInt(args[++i]);
} else if (args[i].equals("-fake")) {
fake = true;
} else if (args[i].equals("-debug")) {
debug = true;
} else if (args[i].equals("-seg")) {
segs.add(new Path(args[++i]));
} else {
LOG.error("Unknown argument: " + args[i]);
System.exit(-1);
}
}
// Create the server
Server server = new Server();
SocketConnector connector = new SocketConnector();
connector.setPort(port);
connector.setResolveNames(false);
server.addConnector(connector);
// create a list of handlers
HandlerList list = new HandlerList();
server.addHandler(list);
if (debug) {
LOG.info("* Added debug handler.");
list.addHandler(new LogDebugHandler());
}
if (delay) {
LOG.info("* Added delay handler: " + (delayVal < 0 ? "random delay up to " + (-delayVal) : "constant delay of " + delayVal));
list.addHandler(new DelayHandler(delayVal));
}
// XXX alternatively, we can add the DispatchHandler as the first one,
// XXX to activate handler plugins and redirect requests to appropriate
// XXX handlers ... Here we always load these handlers
Iterator<Path> it = segs.iterator();
while (it.hasNext()) {
Path p = it.next();
try {
SegmentHandler segment = new SegmentHandler(conf, p);
list.addHandler(segment);
LOG.info("* Added segment handler for: " + p);
} catch (Exception e) {
LOG.warn("Skipping segment '" + p + "': " + StringUtils.stringifyException(e));
}
}
if (forward) {
LOG.info("* Adding forwarding proxy for all unknown urls ...");
ServletHandler servlets = new ServletHandler();
servlets.addServletWithMapping(AsyncProxyServlet.class, "/*");
servlets.addFilterWithMapping(LogDebugHandler.class, "/*", Handler.ALL);
list.addHandler(servlets);
}
if (fake) {
LOG.info("* Added fake handler for remaining URLs.");
list.addHandler(new FakeHandler());
}
list.addHandler(new NotFoundHandler());
// Start the http server
server.start();
server.join();
}
use of org.mortbay.jetty.Server in project wso2-axis2-transports by wso2.
the class JettyServer method setUp.
@Setup
@SuppressWarnings("unused")
private void setUp(HttpTestEnvironment env) throws Exception {
server = new Server();
SocketListener listener = new SocketListener();
listener.setPort(env.getServerPort());
server.addListener(listener);
context = new HttpContext(server, Channel.CONTEXT_PATH + "/*");
server.start();
}
Aggregations