本文整理汇总了Java中org.mortbay.jetty.Server.addHandler方法的典型用法代码示例。如果您正苦于以下问题:Java Server.addHandler方法的具体用法?Java Server.addHandler怎么用?Java Server.addHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.mortbay.jetty.Server
的用法示例。
在下文中一共展示了Server.addHandler方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testJetty
import org.mortbay.jetty.Server; //导入方法依赖的package包/类
@Test
@TestJetty
public void testJetty() throws Exception {
Context context = new Context();
context.setContextPath("/");
context.addServlet(MyServlet.class, "/bar");
Server server = TestJettyHelper.getJettyServer();
server.addHandler(context);
server.start();
URL url = new URL(TestJettyHelper.getJettyURL(), "/bar");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_OK);
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
assertEquals(reader.readLine(), "foo");
reader.close();
}
示例2: setUp
import org.mortbay.jetty.Server; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
ContextHandler context = new ContextHandler();
context.setContextPath("/");
context.setResourceBase(RES_DIR);
ServletHandler sh = new ServletHandler();
sh.addServletWithMapping("org.apache.jasper.servlet.JspServlet", "*.jsp");
context.addHandler(sh);
context.addHandler(new SessionHandler());
server = new Server();
server.addHandler(context);
conf = new Configuration();
conf.addResource("nutch-default.xml");
conf.addResource("nutch-site-test.xml");
http = new Http();
http.setConf(conf);
}
示例3: JettyHttpServer
import org.mortbay.jetty.Server; //导入方法依赖的package包/类
public JettyHttpServer(URL url, final HttpHandler handler){
super(url, handler);
DispatcherServlet.addHttpHandler(url.getPort(), handler);
int threads = url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS);
QueuedThreadPool threadPool = new QueuedThreadPool();
threadPool.setDaemon(true);
threadPool.setMaxThreads(threads);
threadPool.setMinThreads(threads);
SelectChannelConnector connector = new SelectChannelConnector();
if (! url.isAnyHost() && NetUtils.isValidLocalHost(url.getHost())) {
connector.setHost(url.getHost());
}
connector.setPort(url.getPort());
server = new Server();
server.setThreadPool(threadPool);
server.addConnector(connector);
ServletHandler servletHandler = new ServletHandler();
ServletHolder servletHolder = servletHandler.addServletWithMapping(DispatcherServlet.class, "/*");
servletHolder.setInitOrder(2);
server.addHandler(servletHandler);
try {
server.start();
} catch (Exception e) {
throw new IllegalStateException("Failed to start jetty server on " + url.getAddress() + ", cause: "
+ e.getMessage(), e);
}
}
示例4: start
import org.mortbay.jetty.Server; //导入方法依赖的package包/类
public void start() {
String serverPort = ConfigUtils.getProperty(JETTY_PORT);
int port;
if (serverPort == null || serverPort.length() == 0) {
port = DEFAULT_JETTY_PORT;
} else {
port = Integer.parseInt(serverPort);
}
connector = new SelectChannelConnector();
connector.setPort(port);
ServletHandler handler = new ServletHandler();
String resources = ConfigUtils.getProperty(JETTY_DIRECTORY);
if (resources != null && resources.length() > 0) {
FilterHolder resourceHolder = handler.addFilterWithMapping(ResourceFilter.class, "/*", Handler.DEFAULT);
resourceHolder.setInitParameter("resources", resources);
}
ServletHolder pageHolder = handler.addServletWithMapping(PageServlet.class, "/*");
pageHolder.setInitParameter("pages", ConfigUtils.getProperty(JETTY_PAGES));
pageHolder.setInitOrder(2);
Server server = new Server();
server.addConnector(connector);
server.addHandler(handler);
try {
server.start();
} catch (Exception e) {
throw new IllegalStateException("Failed to start jetty server on " + NetUtils.getLocalHost() + ":" + port + ", cause: " + e.getMessage(), e);
}
}
示例5: getServer
import org.mortbay.jetty.Server; //导入方法依赖的package包/类
/**
* Creates a new JettyServer with one static root context
*
* @param port
* port to listen to
* @param staticContent
* folder where static content lives
* @throws UnknownHostException
*/
public static Server getServer(int port, String staticContent)
throws UnknownHostException {
Server webServer = new org.mortbay.jetty.Server();
SocketConnector listener = new SocketConnector();
listener.setPort(port);
listener.setHost("127.0.0.1");
webServer.addConnector(listener);
ContextHandler staticContext = new ContextHandler();
staticContext.setContextPath("/");
staticContext.setResourceBase(staticContent);
staticContext.addHandler(new ResourceHandler());
webServer.addHandler(staticContext);
return webServer;
}
示例6: main
import org.mortbay.jetty.Server; //导入方法依赖的package包/类
public static void main(String[] args) {
Server server = new Server();
SocketConnector connector = new SocketConnector();
// Set some timeout options to make debugging easier.
connector.setMaxIdleTime(1000 * 60 * 60);
connector.setSoLingerTime(-1);
connector.setPort(9080);
server.setConnectors(new Connector[]{connector});
WebAppContext context = new WebAppContext();
context.setServer(server);
context.setContextPath("/");
ProtectionDomain protectionDomain = Main.class.getProtectionDomain();
URL location = protectionDomain.getCodeSource().getLocation();
context.setWar(location.toExternalForm());
server.addHandler(context);
try {
server.start();
System.in.read();
server.stop();
server.join();
} catch (Exception e) {
e.printStackTrace();
System.exit(100);
}
}
示例7: start
import org.mortbay.jetty.Server; //导入方法依赖的package包/类
public void start() {
String serverPort = ConfigUtils.getProperty(JETTY_PORT);
int port;
if (serverPort == null || serverPort.length() == 0) {
port = DEFAULT_JETTY_PORT;
} else {
port = Integer.parseInt(serverPort);
}
connector = new SelectChannelConnector();
connector.setPort(port);
ServletHandler handler = new ServletHandler();
String resources = ConfigUtils.getProperty(JETTY_DIRECTORY);
if (resources != null && resources.length() > 0) {
FilterHolder resourceHolder = handler.addFilterWithMapping(ResourceFilter.class, "/*", Handler.DEFAULT);
resourceHolder.setInitParameter("resources", resources);
}
ServletHolder pageHolder = handler.addServletWithMapping(PageServlet.class, "/*");
pageHolder.setInitParameter("pages", ConfigUtils.getProperty(JETTY_PAGES));
pageHolder.setInitOrder(2);
Server server = new Server();
server.addConnector(connector);
server.addHandler(handler);
try {
server.start();
} catch (Exception e) {
throw new IllegalStateException("Failed to start jetty server on " + NetUtils.getLocalHost() + ":" + port + ", cause: " + e.getMessage(), e);
}
}
示例8: createHttpFSServer
import org.mortbay.jetty.Server; //导入方法依赖的package包/类
private void createHttpFSServer() throws Exception {
File homeDir = TestDirHelper.getTestDir();
Assert.assertTrue(new File(homeDir, "conf").mkdir());
Assert.assertTrue(new File(homeDir, "log").mkdir());
Assert.assertTrue(new File(homeDir, "temp").mkdir());
HttpFSServerWebApp.setHomeDirForCurrentThread(homeDir.getAbsolutePath());
File secretFile = new File(new File(homeDir, "conf"), "secret");
Writer w = new FileWriter(secretFile);
w.write("secret");
w.close();
//FileSystem being served by HttpFS
String fsDefaultName = getProxiedFSURI();
Configuration conf = new Configuration(false);
conf.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, fsDefaultName);
conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_ACLS_ENABLED_KEY, true);
conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_XATTRS_ENABLED_KEY, true);
File hdfsSite = new File(new File(homeDir, "conf"), "hdfs-site.xml");
OutputStream os = new FileOutputStream(hdfsSite);
conf.writeXml(os);
os.close();
//HTTPFS configuration
conf = new Configuration(false);
conf.set("httpfs.proxyuser." + HadoopUsersConfTestHelper.getHadoopProxyUser() + ".groups",
HadoopUsersConfTestHelper.getHadoopProxyUserGroups());
conf.set("httpfs.proxyuser." + HadoopUsersConfTestHelper.getHadoopProxyUser() + ".hosts",
HadoopUsersConfTestHelper.getHadoopProxyUserHosts());
conf.set("httpfs.authentication.signature.secret.file", secretFile.getAbsolutePath());
File httpfsSite = new File(new File(homeDir, "conf"), "httpfs-site.xml");
os = new FileOutputStream(httpfsSite);
conf.writeXml(os);
os.close();
ClassLoader cl = Thread.currentThread().getContextClassLoader();
URL url = cl.getResource("webapp");
WebAppContext context = new WebAppContext(url.getPath(), "/webhdfs");
Server server = TestJettyHelper.getJettyServer();
server.addHandler(context);
server.start();
}
示例9: createHttpFSServer
import org.mortbay.jetty.Server; //导入方法依赖的package包/类
private void createHttpFSServer(boolean addDelegationTokenAuthHandler)
throws Exception {
File homeDir = TestDirHelper.getTestDir();
Assert.assertTrue(new File(homeDir, "conf").mkdir());
Assert.assertTrue(new File(homeDir, "log").mkdir());
Assert.assertTrue(new File(homeDir, "temp").mkdir());
HttpFSServerWebApp.setHomeDirForCurrentThread(homeDir.getAbsolutePath());
File secretFile = new File(new File(homeDir, "conf"), "secret");
Writer w = new FileWriter(secretFile);
w.write("secret");
w.close();
//HDFS configuration
File hadoopConfDir = new File(new File(homeDir, "conf"), "hadoop-conf");
hadoopConfDir.mkdirs();
String fsDefaultName = TestHdfsHelper.getHdfsConf().get(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY);
Configuration conf = new Configuration(false);
conf.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, fsDefaultName);
conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_ACLS_ENABLED_KEY, true);
conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_XATTRS_ENABLED_KEY, true);
File hdfsSite = new File(hadoopConfDir, "hdfs-site.xml");
OutputStream os = new FileOutputStream(hdfsSite);
conf.writeXml(os);
os.close();
//HTTPFS configuration
conf = new Configuration(false);
if (addDelegationTokenAuthHandler) {
conf.set("httpfs.authentication.type",
HttpFSKerberosAuthenticationHandlerForTesting.class.getName());
}
conf.set("httpfs.services.ext", MockGroups.class.getName());
conf.set("httpfs.admin.group", HadoopUsersConfTestHelper.
getHadoopUserGroups(HadoopUsersConfTestHelper.getHadoopUsers()[0])[0]);
conf.set("httpfs.proxyuser." + HadoopUsersConfTestHelper.getHadoopProxyUser() + ".groups",
HadoopUsersConfTestHelper.getHadoopProxyUserGroups());
conf.set("httpfs.proxyuser." + HadoopUsersConfTestHelper.getHadoopProxyUser() + ".hosts",
HadoopUsersConfTestHelper.getHadoopProxyUserHosts());
conf.set("httpfs.authentication.signature.secret.file", secretFile.getAbsolutePath());
conf.set("httpfs.hadoop.config.dir", hadoopConfDir.toString());
File httpfsSite = new File(new File(homeDir, "conf"), "httpfs-site.xml");
os = new FileOutputStream(httpfsSite);
conf.writeXml(os);
os.close();
ClassLoader cl = Thread.currentThread().getContextClassLoader();
URL url = cl.getResource("webapp");
WebAppContext context = new WebAppContext(url.getPath(), "/webhdfs");
Server server = TestJettyHelper.getJettyServer();
server.addHandler(context);
server.start();
if (addDelegationTokenAuthHandler) {
HttpFSServerWebApp.get().setAuthority(TestJettyHelper.getAuthority());
}
}
示例10: createHttpFSServer
import org.mortbay.jetty.Server; //导入方法依赖的package包/类
/**
* Create an HttpFS Server to talk to the MiniDFSCluster we created.
* @throws Exception
*/
private void createHttpFSServer() throws Exception {
File homeDir = TestDirHelper.getTestDir();
Assert.assertTrue(new File(homeDir, "conf").mkdir());
Assert.assertTrue(new File(homeDir, "log").mkdir());
Assert.assertTrue(new File(homeDir, "temp").mkdir());
HttpFSServerWebApp.setHomeDirForCurrentThread(homeDir.getAbsolutePath());
File secretFile = new File(new File(homeDir, "conf"), "secret");
Writer w = new FileWriter(secretFile);
w.write("secret");
w.close();
// HDFS configuration
File hadoopConfDir = new File(new File(homeDir, "conf"), "hadoop-conf");
if ( !hadoopConfDir.mkdirs() ) {
throw new IOException();
}
String fsDefaultName =
nnConf.get(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY);
Configuration conf = new Configuration(false);
conf.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, fsDefaultName);
// Explicitly turn off XAttr support
conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_XATTRS_ENABLED_KEY, false);
File hdfsSite = new File(hadoopConfDir, "hdfs-site.xml");
OutputStream os = new FileOutputStream(hdfsSite);
conf.writeXml(os);
os.close();
// HTTPFS configuration
conf = new Configuration(false);
conf.set("httpfs.hadoop.config.dir", hadoopConfDir.toString());
conf.set("httpfs.proxyuser." +
HadoopUsersConfTestHelper.getHadoopProxyUser() + ".groups",
HadoopUsersConfTestHelper.getHadoopProxyUserGroups());
conf.set("httpfs.proxyuser." +
HadoopUsersConfTestHelper.getHadoopProxyUser() + ".hosts",
HadoopUsersConfTestHelper.getHadoopProxyUserHosts());
conf.set("httpfs.authentication.signature.secret.file",
secretFile.getAbsolutePath());
File httpfsSite = new File(new File(homeDir, "conf"), "httpfs-site.xml");
os = new FileOutputStream(httpfsSite);
conf.writeXml(os);
os.close();
ClassLoader cl = Thread.currentThread().getContextClassLoader();
URL url = cl.getResource("webapp");
if ( url == null ) {
throw new IOException();
}
WebAppContext context = new WebAppContext(url.getPath(), "/webhdfs");
Server server = TestJettyHelper.getJettyServer();
server.addHandler(context);
server.start();
}
示例11: deployWebApp
import org.mortbay.jetty.Server; //导入方法依赖的package包/类
private void deployWebApp() {
try {
Server server = new Server();
SelectChannelConnector connector = new SelectChannelConnector();
connector.setMaxIdleTime(MAX_IDLE_TIME_MILLIS);
connector.setHeaderBufferSize(HEADER_BUFFER_SIZE);
connector.setHost(getHost());
connector.setPort(getPort());
if (isHttpsEnabled()) {
connector.setConfidentialPort(getHttpsPort());
}
server.addConnector(connector);
if (isHttpsEnabled()) {
SslSocketConnector sslConnector = new SslSocketConnector();
sslConnector.setMaxIdleTime(MAX_IDLE_TIME_MILLIS);
sslConnector.setHeaderBufferSize(HEADER_BUFFER_SIZE);
sslConnector.setHost(getHost());
sslConnector.setPort(getHttpsPort());
sslConnector.setKeystore(System.getProperty("subsonic.ssl.keystore", getClass().getResource("/subsonic.keystore").toExternalForm()));
sslConnector.setPassword(System.getProperty("subsonic.ssl.password", "subsonic"));
server.addConnector(sslConnector);
}
WebAppContext context = new WebAppContext();
context.setTempDirectory(getJettyDirectory());
context.setContextPath(getContextPath());
context.setWar(getWar());
context.setOverrideDescriptor("/web-jetty.xml");
if (isHttpsEnabled()) {
// Allow non-https for streaming and cover art (for Chromecast, UPnP, Sonos etc)
context.getSecurityHandler().setConstraintMappings(new ConstraintMapping[]{
createConstraintMapping("/stream", Constraint.DC_NONE),
createConstraintMapping("/coverArt.view", Constraint.DC_NONE),
createConstraintMapping("/ws/*", Constraint.DC_NONE),
createConstraintMapping("/sonos/*", Constraint.DC_NONE),
createConstraintMapping("/", Constraint.DC_CONFIDENTIAL)
});
}
server.addHandler(context);
server.start();
System.err.println("Subsonic running on: " + getUrl());
if (isHttpsEnabled()) {
System.err.println(" and: " + getHttpsUrl());
}
} catch (Throwable x) {
x.printStackTrace();
exception = x;
}
}
示例12: createHttpFSServer
import org.mortbay.jetty.Server; //导入方法依赖的package包/类
/**
* Create an HttpFS Server to talk to the MiniDFSCluster we created.
* @throws Exception
*/
private void createHttpFSServer() throws Exception {
File homeDir = TestDirHelper.getTestDir();
Assert.assertTrue(new File(homeDir, "conf").mkdir());
Assert.assertTrue(new File(homeDir, "log").mkdir());
Assert.assertTrue(new File(homeDir, "temp").mkdir());
HttpFSServerWebApp.setHomeDirForCurrentThread(homeDir.getAbsolutePath());
File secretFile = new File(new File(homeDir, "conf"), "secret");
Writer w = new FileWriter(secretFile);
w.write("secret");
w.close();
// HDFS configuration
File hadoopConfDir = new File(new File(homeDir, "conf"), "hadoop-conf");
if ( !hadoopConfDir.mkdirs() ) {
throw new IOException();
}
String fsDefaultName =
nnConf.get(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY);
Configuration conf = new Configuration(false);
conf.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, fsDefaultName);
// Explicitly turn off ACLs, just in case the default becomes true later
conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_ACLS_ENABLED_KEY, false);
File hdfsSite = new File(hadoopConfDir, "hdfs-site.xml");
OutputStream os = new FileOutputStream(hdfsSite);
conf.writeXml(os);
os.close();
// HTTPFS configuration
conf = new Configuration(false);
conf.set("httpfs.hadoop.config.dir", hadoopConfDir.toString());
conf.set("httpfs.proxyuser." +
HadoopUsersConfTestHelper.getHadoopProxyUser() + ".groups",
HadoopUsersConfTestHelper.getHadoopProxyUserGroups());
conf.set("httpfs.proxyuser." +
HadoopUsersConfTestHelper.getHadoopProxyUser() + ".hosts",
HadoopUsersConfTestHelper.getHadoopProxyUserHosts());
conf.set("httpfs.authentication.signature.secret.file",
secretFile.getAbsolutePath());
File httpfsSite = new File(new File(homeDir, "conf"), "httpfs-site.xml");
os = new FileOutputStream(httpfsSite);
conf.writeXml(os);
os.close();
ClassLoader cl = Thread.currentThread().getContextClassLoader();
URL url = cl.getResource("webapp");
if ( url == null ) {
throw new IOException();
}
WebAppContext context = new WebAppContext(url.getPath(), "/webhdfs");
Server server = TestJettyHelper.getJettyServer();
server.addHandler(context);
server.start();
}
示例13: createHttpFSServer
import org.mortbay.jetty.Server; //导入方法依赖的package包/类
private void createHttpFSServer() throws Exception {
File homeDir = TestDirHelper.getTestDir();
Assert.assertTrue(new File(homeDir, "conf").mkdir());
Assert.assertTrue(new File(homeDir, "log").mkdir());
Assert.assertTrue(new File(homeDir, "temp").mkdir());
HttpFSServerWebApp.setHomeDirForCurrentThread(homeDir.getAbsolutePath());
File secretFile = new File(new File(homeDir, "conf"), "secret");
Writer w = new FileWriter(secretFile);
w.write("secret");
w.close();
//HDFS configuration
File hadoopConfDir = new File(new File(homeDir, "conf"), "hadoop-conf");
hadoopConfDir.mkdirs();
String fsDefaultName = TestHdfsHelper.getHdfsConf()
.get(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY);
Configuration conf = new Configuration(false);
conf.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, fsDefaultName);
File hdfsSite = new File(hadoopConfDir, "hdfs-site.xml");
OutputStream os = new FileOutputStream(hdfsSite);
conf.writeXml(os);
os.close();
conf = new Configuration(false);
conf.set("httpfs.proxyuser.client.hosts", "*");
conf.set("httpfs.proxyuser.client.groups", "*");
conf.set("httpfs.authentication.type", "kerberos");
conf.set("httpfs.authentication.signature.secret.file",
secretFile.getAbsolutePath());
File httpfsSite = new File(new File(homeDir, "conf"), "httpfs-site.xml");
os = new FileOutputStream(httpfsSite);
conf.writeXml(os);
os.close();
ClassLoader cl = Thread.currentThread().getContextClassLoader();
URL url = cl.getResource("webapp");
WebAppContext context = new WebAppContext(url.getPath(), "/webhdfs");
Server server = TestJettyHelper.getJettyServer();
server.addHandler(context);
server.start();
HttpFSServerWebApp.get().setAuthority(TestJettyHelper.getAuthority());
}