本文整理了Java中org.mortbay.jetty.Connector
类的一些代码示例,展示了Connector
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Connector
类的具体详情如下:
包路径:org.mortbay.jetty.Connector
类名称:Connector
[英]HTTP Connector. Implementations of this interface provide connectors for the HTTP protocol. A connector receives requests (normally from a socket) and calls the handle method of the Handler object. These operations are performed using threads from the ThreadPool set on the connector. When a connector is registered with an instance of Server, then the server will set itself as both the ThreadPool and the Handler. Note that a connector can be used without a Server if a thread pool and handler are directly provided.
[中]HTTP连接器。此接口的实现为HTTP协议提供连接器。连接器接收请求(通常来自套接字)并调用处理程序对象的handle方法。这些操作是使用连接器上ThreadPool集合中的线程执行的。当连接器注册到服务器实例时,服务器将自身设置为线程池和处理程序。请注意,如果直接提供线程池和处理程序,则可以在没有服务器的情况下使用连接器。
代码示例来源:origin: twitter/ambrose
connector.setPort(port);
server = new Server();
server.setConnectors(new Connector[]{connector});
});
server.setHandler(handler);
server.setStopAtShutdown(false);
代码示例来源:origin: Netflix/eureka
public void start() throws Exception {
server = new Server(port);
server.setHandler(new AppsResourceHandler());
server.start();
port = server.getConnectors()[0].getLocalPort();
}
代码示例来源:origin: pentaho/pentaho-kettle
public String getRedirectUri() throws IOException {
if ( this.port == -1 ) {
this.port = getUnusedPort();
}
this.server = new Server( this.port );
Connector[] arr$ = this.server.getConnectors();
int len$ = arr$.length;
for ( int i$ = 0; i$ < len$; ++i$ ) {
Connector c = arr$[i$];
c.setHost( this.host );
}
this.server.addHandler( new CustomLocalServerReceiver.CallbackHandler() );
try {
this.server.start();
} catch ( Exception var5 ) {
Throwables.propagateIfPossible( var5 );
throw new IOException( var5 );
}
return "http://" + this.host + ":" + this.port + "/Callback/success.html";
}
代码示例来源:origin: apache/hadoop-common
protected void start() throws Exception {
server = new Server(0);
context = new Context();
context.setContextPath("/foo");
server.setHandler(context);
context.addFilter(new FilterHolder(TestFilter.class), "/*", 0);
context.addServlet(new ServletHolder(TestServlet.class), "/bar");
host = "localhost";
ServerSocket ss = new ServerSocket(0);
port = ss.getLocalPort();
ss.close();
server.getConnectors()[0].setHost(host);
server.getConnectors()[0].setPort(port);
server.start();
System.out.println("Running embedded servlet container at: http://" + host + ":" + port);
}
代码示例来源:origin: com.facebook.hadoop/hadoop-core
try {
int port = 0;
int oriPort = listener.getPort(); // The original requested port
while (true) {
try {
port = webServer.getConnectors()[0].getLocalPort();
LOG.info("Port returned by webServer.getConnectors()[0]." +
"getLocalPort() before open() is "+ port +
". Opening the listener on " + oriPort);
listener.open();
port = listener.getLocalPort();
LOG.info("listener.getLocalPort() returned " + listener.getLocalPort() +
" webServer.getConnectors()[0].getLocalPort() returned " +
webServer.getConnectors()[0].getLocalPort());
port = listener.getLocalPort();
if (port > 0) {
break;
listener.close();
Thread.sleep(1000);
listener.setPort(oriPort == 0 ? 0 : (oriPort += 1));
listener.open();
Thread.sleep(100);
port = listener.getLocalPort();
port = listener.getLocalPort();
if (port < 0) {
LOG.warn("Bounds port is " + port + " after webserver start");
代码示例来源:origin: org.apache.slider/slider-core
private void openListeners() throws Exception {
// from HttpServer2.openListeners()
for (Connector listener : agentServer.getConnectors()) {
if (listener.getLocalPort() != -1) {
// This listener is either started externally or has been bound
continue;
}
int port = listener.getPort();
while (true) {
// jetty has a bug where you can't reopen a listener that previously
// failed to open w/o issuing a close first, even if the port is changed
try {
listener.close();
listener.open();
LOG.info("Jetty bound to port " + listener.getLocalPort());
break;
} catch (BindException ex) {
if (port == 0) {
BindException be = new BindException("Port in use: "
+ listener.getHost() + ":" + listener.getPort());
be.initCause(ex);
throw be;
}
}
// try the next port number
listener.setPort(++port);
Thread.sleep(100);
}
}
}
代码示例来源:origin: testcontainers/testcontainers-java
@Before
public void setupLocalServer() throws Exception {
// Set up a local Jetty HTTP server
Server server = new Server();
server.addConnector(new SocketConnector());
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setResourceBase("src/test/resources/server");
server.addHandler(resourceHandler);
server.start();
// The server will have a random port assigned, so capture that
localPort = server.getConnectors()[0].getLocalPort();
}
代码示例来源:origin: com.twitter.hraven/hraven-core
@Override
protected void startUp() throws Exception {
// setup the jetty config
ServletHolder sh = new ServletHolder(ServletContainer.class);
sh.setInitParameter("com.sun.jersey.config.property.packages", "com.twitter.hraven.rest");
sh.setInitParameter(JSONConfiguration.FEATURE_POJO_MAPPING, "true");
server = new Server();
Connector connector = new SelectChannelConnector();
connector.setPort(this.port);
connector.setHost(address);
server.addConnector(connector);
// TODO: in the future we may want to provide settings for the min and max threads
// Jetty sets the default max thread number to 250, if we don't set it.
//
QueuedThreadPool threadPool = new QueuedThreadPool();
server.setThreadPool(threadPool);
server.setSendServerVersion(false);
server.setSendDateHeader(false);
server.setStopAtShutdown(true);
// set up context
Context context = new Context(server, "/", Context.SESSIONS);
context.addServlet(sh, "/*");
// start server
server.start();
}
代码示例来源:origin: org.apache.reef/reef-webserver
private Server tryPort(final int portNumber) throws Exception {
Server srv = new Server();
final Connector connector = new SocketConnector();
connector.setHost(addressProvider.getLocalAddress());
connector.setPort(portNumber);
srv.addConnector(connector);
try {
srv.start();
LOG.log(Level.INFO, "Jetty Server started with port: {0}", portNumber);
} catch (final BindException ex) {
srv = null;
LOG.log(Level.FINEST, "Cannot use port: {0}. Will try another", portNumber);
}
return srv;
}
代码示例来源:origin: org.apache.hama/hama-core
/**
* stop the server
*/
public void stop() throws Exception {
listener.close();
webServer.stop();
}
代码示例来源:origin: com.github.jiayuhan-it/hadoop-common
protected Server createJettyServer() {
try {
InetAddress localhost = InetAddress.getLocalHost();
ServerSocket ss = new ServerSocket(0, 50, localhost);
int port = ss.getLocalPort();
ss.close();
jetty = new Server(0);
jetty.getConnectors()[0].setHost("localhost");
jetty.getConnectors()[0].setPort(port);
return jetty;
} catch (Exception ex) {
throw new RuntimeException("Could not setup Jetty: " + ex.getMessage(),
ex);
}
}
代码示例来源:origin: rhuss/jolokia
private Server getServer(MuleAgentConfig pConfig) {
Server newServer = new Server();
Connector connector = new SelectChannelConnector();
if (pConfig.getHost() != null) {
connector.setHost(pConfig.getHost());
}
connector.setPort(pConfig.getPort());
newServer.setConnectors(new Connector[]{connector});
return newServer;
}
代码示例来源:origin: tjake/Solandra
public JettySolandraRunner( String context, int port, String host)
{
this.context = context;
server = new Server( port );
server.getConnectors()[0].setHost(host);
server.setStopAtShutdown( true );
// Initialize the servlets
Context root = new Context( server, context, Context.SESSIONS );
// for some reason, there must be a servlet for this to get applied
root.addServlet( Servlet404.class, "/*" );
dispatchFilter = root.addFilter( SolandraDispatchFilter.class, "*", Handler.REQUEST );
}
代码示例来源:origin: Netflix/eureka
public void start() throws Exception {
server.start();
port = server.getConnectors()[0].getLocalPort();
}
代码示例来源:origin: info.aduna.commons/aduna-commons-net-http-server-embedded
public EmbeddedServer(String host, int port, String contextPath, String warPath) {
System.clearProperty("DEBUG");
jetty = new Server();
Connector conn = new BlockingChannelConnector();
conn.setHost(host);
conn.setPort(port);
jetty.addConnector(conn);
WebAppContext webapp = new WebAppContext();
webapp.setContextPath(contextPath);
webapp.setWar(warPath);
jetty.addHandler(webapp);
}
代码示例来源:origin: tjake/Solandra
/**
* Returns the Local Port of the first Connector found for the jetty Server.
* @exception RuntimeException if there is no Connector
*/
public int getLocalPort() {
Connector[] conns = server.getConnectors();
if (0 == conns.length) {
throw new RuntimeException("Jetty Server has no Connectors");
}
return conns[0].getLocalPort();
}
代码示例来源:origin: jetoile/hadoop-unit
/**
* Start the servlet container. The container starts on a free port.
*
* @throws Exception thrown if the container could not start.
*/
public void start() throws Exception {
if (StringUtils.isEmpty(host)) {
host = InetAddress.getLocalHost().getHostName();
}
ServerSocket ss = new ServerSocket(0);
if (this.port == 0) {
port = ss.getLocalPort();
}
ss.close();
server.getConnectors()[0].setHost(host);
server.getConnectors()[0].setPort(port);
server.start();
System.out.println("Running embedded servlet container at: http://" + host + ":" + port);
}
代码示例来源:origin: voldemort/voldemort
@Override
public void stopInner() {
try {
if(httpServer != null) {
httpServer.stop();
for(Connector c: httpServer.getConnectors()) {
c.close();
}
}
if(context != null)
context.destroy();
} catch(Exception e) {
throw new VoldemortException(e);
}
this.httpServer = null;
this.context = null;
}
代码示例来源:origin: net.disy.legato/legato-testing
public JettyWebServerEnvironment(final int port) {
this.server = new Server();
this.connector = new SelectChannelConnector();
connector.setPort(port);
this.server.setConnectors(new Connector[]{ connector });
// this.webAppContext = new WebAppContext();
// webAppContext.setContextPath(contextPath);
// webAppContext.setConfigurationClasses(DEFAULT_CONFIGURATION_CLASSES);
// webAppContext.setWar(location);
}
代码示例来源:origin: ch.cern.hadoop/hadoop-common
protected String getJettyURL() {
Connector c = jetty.getConnectors()[0];
return "http://" + c.getHost() + ":" + c.getPort();
}
内容来源于网络,如有侵权,请联系作者删除!