本文整理匯總了Java中org.mortbay.jetty.Server類的典型用法代碼示例。如果您正苦於以下問題:Java Server類的具體用法?Java Server怎麽用?Java Server使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Server類屬於org.mortbay.jetty包,在下文中一共展示了Server類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: startServer
import org.mortbay.jetty.Server; //導入依賴的package包/類
private static void startServer() throws Exception, InterruptedException {
Server server = new Server(port);
Context context = new Context(server, "/", Context.SESSIONS);
context.addServlet(DefaultServlet.class, "/*");
context.addEventListener(new ContextLoaderListener(getContext()));
context.addEventListener(new RequestContextListener());
WicketFilter filter = new WicketFilter();
filter.setFilterPath("/");
FilterHolder holder = new FilterHolder(filter);
holder.setInitParameter("applicationFactoryClassName", APP_FACTORY_NAME);
context.addFilter(holder, "/*", Handler.DEFAULT);
server.setHandler(context);
server.start();
server.join();
}
示例2: start
import org.mortbay.jetty.Server; //導入依賴的package包/類
@Override
public void start() {
jettyServer = new Server();
//We can use Contexts etc if we have many urls to handle. For one url,
//specifying a handler directly is the most efficient.
SelectChannelConnector connector = new SelectChannelConnector();
connector.setReuseAddress(true);
connector.setPort(port);
jettyServer.setConnectors(new Connector[] {connector});
jettyServer.setHandler(new HTTPMetricsHandler());
try {
jettyServer.start();
while (!jettyServer.isStarted()) {
Thread.sleep(500);
}
} catch (Exception ex) {
LOG.error("Error starting Jetty. JSON Metrics may not be available.", ex);
}
}
示例3: start
import org.mortbay.jetty.Server; //導入依賴的package包/類
/**
* Simple http server. Server should send answer with status 200
*/
@BeforeClass
public static void start() throws Exception {
server = new Server(0);
Context context = new Context();
context.setContextPath("/foo");
server.setHandler(context);
context.addServlet(new ServletHolder(TestServlet.class), "/bar");
server.getConnectors()[0].setHost("localhost");
server.start();
originalPort = server.getConnectors()[0].getLocalPort();
LOG.info("Running embedded servlet container at: http://localhost:"
+ originalPort);
}
示例4: 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();
}
示例5: createJettyServer
import org.mortbay.jetty.Server; //導入依賴的package包/類
private Server createJettyServer() {
try {
InetAddress localhost = InetAddress.getByName("localhost");
String host = "localhost";
ServerSocket ss = new ServerSocket(0, 50, localhost);
int port = ss.getLocalPort();
ss.close();
Server server = new Server(0);
if (!ssl) {
server.getConnectors()[0].setHost(host);
server.getConnectors()[0].setPort(port);
} else {
SslSocketConnector c = new SslSocketConnectorSecure();
c.setHost(host);
c.setPort(port);
c.setNeedClientAuth(false);
c.setKeystore(keyStore);
c.setKeystoreType(keyStoreType);
c.setKeyPassword(keyStorePassword);
server.setConnectors(new Connector[] {c});
}
return server;
} catch (Exception ex) {
throw new RuntimeException("Could not stop embedded servlet container, " + ex.getMessage(), ex);
}
}
示例6: start
import org.mortbay.jetty.Server; //導入依賴的package包/類
/**
* Simple http server. Server should send answer with status 200
*/
@BeforeClass
public static void start() throws Exception {
server = new Server(0);
Context context = new Context();
context.setContextPath("/foo");
server.setHandler(context);
context.addServlet(new ServletHolder(TestServlet.class), "/bar");
server.getConnectors()[0].setHost("localhost");
server.start();
originalPort = server.getConnectors()[0].getLocalPort();
LOG.info("Running embedded servlet container at: http://localhost:"
+ originalPort);
// This property needs to be set otherwise CORS Headers will be dropped
// by HttpUrlConnection
System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
}
示例7: createJettyServer
import org.mortbay.jetty.Server; //導入依賴的package包/類
private Server createJettyServer() {
try {
InetAddress localhost = InetAddress.getByName("localhost");
String host = "localhost";
ServerSocket ss = new ServerSocket(0, 50, localhost);
int port = ss.getLocalPort();
ss.close();
Server server = new Server(0);
if (!ssl) {
server.getConnectors()[0].setHost(host);
server.getConnectors()[0].setPort(port);
} else {
SslSocketConnector c = new SslSocketConnectorSecure();
c.setHost(host);
c.setPort(port);
c.setNeedClientAuth(false);
c.setKeystore(keyStore);
c.setKeystoreType(keyStoreType);
c.setKeyPassword(keyStorePassword);
server.setConnectors(new Connector[] {c});
}
return server;
} catch (Exception ex) {
throw new RuntimeException("Could not start embedded servlet container, " + ex.getMessage(), ex);
}
}
示例8: createJettyServer
import org.mortbay.jetty.Server; //導入依賴的package包/類
private static Server createJettyServer(String keyStore, String password, int inPort) {
try {
boolean ssl = keyStore != null;
String host = "localhost";
Server server = new Server(inPort);
if (!ssl) {
server.getConnectors()[0].setHost(host);
} else {
SslSocketConnector c = new SslSocketConnectorSecure();
c.setHost(host);
c.setNeedClientAuth(false);
c.setKeystore(keyStore);
c.setKeystoreType("jks");
c.setKeyPassword(password);
server.setConnectors(new Connector[]{c});
}
return server;
} catch (Exception ex) {
throw new RuntimeException("Could not start embedded servlet container, "
+ ex.getMessage(), ex);
}
}
示例9: start
import org.mortbay.jetty.Server; //導入依賴的package包/類
/**
* Starts the server, which will listen to the given path going forward.
* @throws Exception
*/
public void start() throws Exception {
logger.info("Starting API server on {}:{}{}", HOST, port, contextPath);
server = new Server();
server.addListener(String.format("%s:%d", HOST, port));
ServletHttpContext context = (ServletHttpContext) server.getContext(contextPath);
context.addServlet(SERVLET_NAME, SERVLET_PATH, ServletContainer.class.getName());
context.getServletHandler().getServletHolder(SERVLET_NAME)
.setInitParameter(INIT_PARAM_PACKAGES, getClass().getPackage().getName());
if (!Strings.isNullOrEmpty(adsPropertiesPath)) {
context.getServletHandler().getServletHolder(SERVLET_NAME)
.setInitParameter(INIT_PARAM_ADS_PROPERTIES, adsPropertiesPath);
}
if (!Strings.isNullOrEmpty(propertiesPath)) {
context.getServletHandler().getServletHolder(SERVLET_NAME)
.setInitParameter(INIT_PARAM_PROPERTIES, propertiesPath);
}
server.start();
}
示例10: 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);
}
示例11: setupPspMithraService
import org.mortbay.jetty.Server; //導入依賴的package包/類
protected void setupPspMithraService()
{
server = new Server(this.getApplicationPort1());
Context context = new Context (server,"/",Context.SESSIONS);
ServletHolder holder = context.addServlet(PspServlet.class, "/PspServlet");
holder.setInitParameter("serviceInterface.MasterCacheService", "com.gs.fw.common.mithra.cache.offheap.MasterCacheService");
holder.setInitParameter("serviceClass.MasterCacheService", "com.gs.fw.common.mithra.cache.offheap.MasterCacheServiceImpl");
holder.setInitOrder(10);
// System.out.println(holder.getServlet().getClass().getName());
try
{
server.start();
}
catch (Exception e)
{
throw new RuntimeException("could not start server", e);
}
finally
{
}
}
示例12: setupServerWithHandler
import org.mortbay.jetty.Server; //導入依賴的package包/類
protected void setupServerWithHandler(
Handler handler) throws Exception
{
this.port = (int) (Math.random() * 10000.0 + 10000.0);
this.pspUrl = "http://localhost:" + this.port + "/PspServlet";
this.server = new Server(this.port);
Context context = new Context(server, "/", Context.SESSIONS);
if (handler != null)
{
context.addHandler(handler);
}
ServletHolder holder = context.addServlet(PspServlet.class, "/PspServlet");
holder.setInitParameter("serviceInterface.Echo", "com.gs.fw.common.mithra.test.tinyproxy.Echo");
holder.setInitParameter("serviceClass.Echo", "com.gs.fw.common.mithra.test.tinyproxy.EchoImpl");
holder.setInitOrder(10);
this.server.start();
this.servlet = (PspServlet) holder.getServlet();
}
示例13: setupPspMithraService
import org.mortbay.jetty.Server; //導入依賴的package包/類
protected void setupPspMithraService()
{
server = new Server(this.getApplicationPort1());
Context context = new Context (server,"/",Context.SESSIONS);
ServletHolder holder = context.addServlet(PspServlet.class, "/PspServlet");
holder.setInitParameter("serviceInterface.RemoteMithraService", "com.gs.fw.common.mithra.remote.RemoteMithraService");
holder.setInitParameter("serviceClass.RemoteMithraService", "com.gs.fw.common.mithra.remote.RemoteMithraServiceImpl");
holder.setInitOrder(10);
try
{
server.start();
}
catch (Exception e)
{
throw new RuntimeException("could not start server", e);
}
finally
{
}
}
示例14: setup
import org.mortbay.jetty.Server; //導入依賴的package包/類
@BeforeClass
public static void setup() throws Exception {
try {
JobCallbackRequestMaker.initialize(new Props());
jobCBMaker = JobCallbackRequestMaker.getInstance();
contextInfo = new HashMap<String, String>();
contextInfo.put(CONTEXT_SERVER_TOKEN, SERVER_NAME);
contextInfo.put(CONTEXT_PROJECT_TOKEN, PROJECT_NANE);
contextInfo.put(CONTEXT_FLOW_TOKEN, FLOW_NANE);
contextInfo.put(CONTEXT_EXECUTION_ID_TOKEN, EXECUTION_ID);
contextInfo.put(CONTEXT_JOB_TOKEN, JOB_NANE);
contextInfo.put(CONTEXT_JOB_STATUS_TOKEN, JobCallbackStatusEnum.STARTED.name());
embeddedJettyServer = new Server(PORT_NUMBER);
Context context = new Context(embeddedJettyServer, "/", Context.SESSIONS);
context.addServlet(new ServletHolder(new DelayServlet()), "/delay");
System.out.println("Start server");
embeddedJettyServer.start();
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
示例15: getRedirectUri
import org.mortbay.jetty.Server; //導入依賴的package包/類
@Override
public String getRedirectUri() throws IOException {
if (port == -1) {
port = getUnusedPort();
}
server = new Server(port);
for (Connector c : server.getConnectors()) {
c.setHost(host);
}
server.addHandler(new CallbackHandler());
try {
server.start();
} catch (Exception e) {
Throwables.propagateIfPossible(e);
throw new IOException(e);
}
return "http://" + host + ":" + port + CALLBACK_PATH;
}