本文整理汇总了Java中org.mortbay.jetty.nio.SelectChannelConnector.setHost方法的典型用法代码示例。如果您正苦于以下问题:Java SelectChannelConnector.setHost方法的具体用法?Java SelectChannelConnector.setHost怎么用?Java SelectChannelConnector.setHost使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.mortbay.jetty.nio.SelectChannelConnector
的用法示例。
在下文中一共展示了SelectChannelConnector.setHost方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: JettyHttpServer
import org.mortbay.jetty.nio.SelectChannelConnector; //导入方法依赖的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);
}
}
示例2: startServer
import org.mortbay.jetty.nio.SelectChannelConnector; //导入方法依赖的package包/类
/**
* Starts the Jetty server at a specified port and redirection parameter.
*
* @param portno
* Port number.
* @param redirection
* whether redirection
*/
private void startServer(int portno, boolean redirection) throws Exception {
port = portno;
setUp(redirection);
SelectChannelConnector connector = new SelectChannelConnector();
connector.setHost("127.0.0.1");
connector.setPort(port);
server.addConnector(connector);
server.start();
}
示例3: bind
import org.mortbay.jetty.nio.SelectChannelConnector; //导入方法依赖的package包/类
@Override
public void bind(InetSocketAddress addr, int backlog) throws IOException
{
this._addr = addr;
// check if there is already a connector listening
Connector[] connectors = _server.getConnectors();
if (connectors != null)
{
for (int i = 0; i < connectors.length; i++)
{
if (connectors[i].getPort() == addr.getPort())
{
if (Log.isDebugEnabled()) Log.debug("server already bound to port " + addr.getPort() + ", no need to rebind");
return;
}
}
}
if (_executor != null && _server.getThreadPool() == null)
{
if (Log.isDebugEnabled()) Log.debug("using given Executor for server thread pool");
_server.setThreadPool(new ThreadPoolExecutorAdapter(_executor));
}
SelectChannelConnector connector = new SelectChannelConnector();
connector.setAcceptors(1);
connector.setPort(addr.getPort());
connector.setHost(addr.getHostName());
_server.addConnector(connector);
_connectors.put(addr.getHostName() + addr.getPort(), connector);
}
示例4: JettyAdminServer
import org.mortbay.jetty.nio.SelectChannelConnector; //导入方法依赖的package包/类
public JettyAdminServer(String address, int port, String commandUrl) {
this.port = port;
this.commandUrl = commandUrl;
this.address = address;
server = new Server();
SelectChannelConnector connector = new SelectChannelConnector();
connector.setHost(address);
connector.setPort(port);
server.addConnector(connector);
Context context = new Context(server, "/");
server.setHandler(context);
context.addServlet(new ServletHolder(new CommandServlet()), commandUrl
+ "/*");
}
示例5: createBaseListener
import org.mortbay.jetty.nio.SelectChannelConnector; //导入方法依赖的package包/类
/** {@inheritDoc} */
protected Connector createBaseListener(Configuration conf)
throws IOException {
final String sAddr;
if (null == (sAddr = conf.get("proxy.http.test.listener.addr"))) {
SslSocketConnector sslListener = new SslSocketConnector();
sslListener.setKeystore(conf.get("ssl.server.keystore.location"));
sslListener.setPassword(conf.get("ssl.server.keystore.password", ""));
sslListener.setKeyPassword(conf.get("ssl.server.keystore.keypassword", ""));
sslListener.setKeystoreType(conf.get("ssl.server.keystore.type", "jks"));
sslListener.setNeedClientAuth(true);
System.setProperty("javax.net.ssl.trustStore",
conf.get("ssl.server.truststore.location", ""));
System.setProperty("javax.net.ssl.trustStorePassword",
conf.get("ssl.server.truststore.password", ""));
System.setProperty("javax.net.ssl.trustStoreType",
conf.get("ssl.server.truststore.type", "jks"));
return sslListener;
}
// unit test
InetSocketAddress proxyAddr = NetUtils.createSocketAddr(sAddr);
SelectChannelConnector testlistener = new SelectChannelConnector();
testlistener.setUseDirectBuffers(false);
testlistener.setHost(proxyAddr.getHostName());
testlistener.setPort(proxyAddr.getPort());
return testlistener;
}
示例6: get
import org.mortbay.jetty.nio.SelectChannelConnector; //导入方法依赖的package包/类
@Override
public Connector get() {
SelectChannelConnector ret = new SelectChannelConnector();
ret.setName("Myriad");
ret.setHost("0.0.0.0");
ret.setPort(myriadConf.getRestApiPort());
return ret;
}
示例7: createConnector
import org.mortbay.jetty.nio.SelectChannelConnector; //导入方法依赖的package包/类
private SelectChannelConnector createConnector() throws IOException {
SelectChannelConnector connector = new SelectChannelConnector();
connector.setHost(mojo.getAddress());
connector.setPort(mojo.getPort());
connector.setSoLingerTime(0);
connector.open();
return connector;
}
示例8: createBaseListener
import org.mortbay.jetty.nio.SelectChannelConnector; //导入方法依赖的package包/类
/** {@inheritDoc} */
public Connector createBaseListener(Configuration conf)
throws IOException {
final String sAddr;
if (null == (sAddr = conf.get("proxy.http.test.listener.addr"))) {
SslSocketConnector sslListener = new SslSocketConnector();
sslListener.setKeystore(conf.get("ssl.server.keystore.location"));
sslListener.setPassword(conf.get("ssl.server.keystore.password", ""));
sslListener.setKeyPassword(conf.get("ssl.server.keystore.keypassword", ""));
sslListener.setKeystoreType(conf.get("ssl.server.keystore.type", "jks"));
sslListener.setNeedClientAuth(true);
System.setProperty("javax.net.ssl.trustStore",
conf.get("ssl.server.truststore.location", ""));
System.setProperty("javax.net.ssl.trustStorePassword",
conf.get("ssl.server.truststore.password", ""));
System.setProperty("javax.net.ssl.trustStoreType",
conf.get("ssl.server.truststore.type", "jks"));
return sslListener;
}
// unit test
InetSocketAddress proxyAddr = NetUtils.createSocketAddr(sAddr);
SelectChannelConnector testlistener = new SelectChannelConnector();
testlistener.setUseDirectBuffers(false);
testlistener.setHost(proxyAddr.getHostName());
testlistener.setPort(proxyAddr.getPort());
return testlistener;
}
示例9: JettyHttpServer
import org.mortbay.jetty.nio.SelectChannelConnector; //导入方法依赖的package包/类
public JettyHttpServer(URL url, final HttpHandler handler) {
super(url, handler);
DispatcherServlet.addHttpHandler(url.getParameter(Constants.BIND_PORT_KEY, 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();
String bindIp = url.getParameter(Constants.BIND_IP_KEY, url.getHost());
if (!url.isAnyHost() && NetUtils.isValidLocalHost(bindIp)) {
connector.setHost(bindIp);
}
connector.setPort(url.getParameter(Constants.BIND_PORT_KEY, 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.getParameter(Constants.BIND_IP_KEY) + ":" + url.getParameter(Constants.BIND_PORT_KEY) + ", cause: "
+ e.getMessage(), e);
}
}
示例10: JettyServer
import org.mortbay.jetty.nio.SelectChannelConnector; //导入方法依赖的package包/类
/**
* Constructor.
* @param mgmtIfPort
* @param guiPort
* @param handler
* @param ipv6
*/
public JettyServer(int mgmtIfPort, int guiPort, AbstractHandler handler, boolean ipv6) {
// create the server
server = new Server();
// add the Management Interface connector
SelectChannelConnector conn1 = new SelectChannelConnector();
if (ipv6) {
conn1.setHost("::0");
} else {
conn1.setHost("0.0.0.0");
} // if else
conn1.setPort(mgmtIfPort);
server.addConnector(conn1);
if (guiPort != 0) {
// add the GUI connector
SelectChannelConnector conn2 = new SelectChannelConnector();
if (ipv6) {
conn2.setHost("::0");
} else {
conn2.setHost("0.0.0.0");
} // if else
conn2.setPort(guiPort);
server.addConnector(conn2);
} // if
// set the handler
server.setHandler(handler);
}
示例11: JettyHttpServer
import org.mortbay.jetty.nio.SelectChannelConnector; //导入方法依赖的package包/类
public JettyHttpServer(URL url, final HttpHandler handler){
super(url, handler);
// modified by lishen
this.url = url;
// TODO we should leave this setting to slf4j
Log.setLog(new StdErrLog());
Log.getLog().setDebugEnabled(false);
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);
// modified by lishen
// dubbo's original impl can't support the use of ServletContext
// server.addHandler(servletHandler);
// TODO Context.SESSIONS is the best option here?
Context context = new Context(server, "/", Context.SESSIONS);
context.setServletHandler(servletHandler);
ServletManager.getInstance().addServletContext(url.getPort(), context.getServletContext());
try {
server.start();
} catch (Exception e) {
throw new IllegalStateException("Failed to start jetty server on " + url.getAddress() + ", cause: "
+ e.getMessage(), e);
}
}
示例12: deployWebApp
import org.mortbay.jetty.nio.SelectChannelConnector; //导入方法依赖的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;
}
}
示例13: JettyHttpServer
import org.mortbay.jetty.nio.SelectChannelConnector; //导入方法依赖的package包/类
public JettyHttpServer(URL url, final HttpHandler handler){
super(url, handler);
// modified by lishen
this.url = url;
// TODO we should leave this setting to slf4j
Log.setLog(new StdErrLog());
Log.getLog().setDebugEnabled(false);
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);
// modified by lishen
// dubbo's original impl can't support the use of ServletContext
// server.addHandler(servletHandler);
// TODO Context.SESSIONS is the best option here?
Context context = new Context(server, "/", Context.SESSIONS);
context.setServletHandler(servletHandler);
BaseContext.CTX.addServletContext(url.getPort(), context.getServletContext());
try {
server.start();
} catch (Exception e) {
throw new IllegalStateException("Failed to start jetty server on " + url.getAddress() + ", cause: "
+ e.getMessage(), e);
}
}
示例14: init
import org.mortbay.jetty.nio.SelectChannelConnector; //导入方法依赖的package包/类
@Override
public void init(DaemonContext context) throws Exception {
System.err.println("Initializing secure datanode resources");
// We should only start up a secure datanode in a Kerberos-secured cluster
Configuration conf = new Configuration(); // Skip UGI method to not log in
if(!conf.get(HADOOP_SECURITY_AUTHENTICATION).equals("kerberos"))
throw new RuntimeException("Cannot start secure datanode in unsecure cluster");
// Stash command-line arguments for regular datanode
args = context.getArguments();
// Obtain secure port for data streaming to datanode
InetSocketAddress socAddr = DataNode.getStreamingAddr(conf);
int socketWriteTimeout = conf.getInt("dfs.datanode.socket.write.timeout",
HdfsConstants.WRITE_TIMEOUT);
ServerSocket ss = (socketWriteTimeout > 0) ?
ServerSocketChannel.open().socket() : new ServerSocket();
ss.bind(socAddr, 0);
// Check that we got the port we need
if(ss.getLocalPort() != socAddr.getPort())
throw new RuntimeException("Unable to bind on specified streaming port in secure " +
"context. Needed " + socAddr.getPort() + ", got " + ss.getLocalPort());
// Obtain secure listener for web server
SelectChannelConnector listener =
(SelectChannelConnector)HttpServer.createDefaultChannelConnector();
InetSocketAddress infoSocAddr = DataNode.getInfoAddr(conf);
listener.setHost(infoSocAddr.getHostName());
listener.setPort(infoSocAddr.getPort());
// Open listener here in order to bind to port as root
listener.open();
if(listener.getPort() != infoSocAddr.getPort())
throw new RuntimeException("Unable to bind on specified info port in secure " +
"context. Needed " + socAddr.getPort() + ", got " + ss.getLocalPort());
if(ss.getLocalPort() >= 1023 || listener.getPort() >= 1023)
throw new RuntimeException("Cannot start secure datanode on non-privileged "
+" ports. (streaming port = " + ss + " ) (http listener port = " +
listener.getConnection() + "). Exiting.");
System.err.println("Successfully obtained privileged resources (streaming port = "
+ ss + " ) (http listener port = " + listener.getConnection() +")");
resources = new SecureResources(ss, listener);
}
示例15: init
import org.mortbay.jetty.nio.SelectChannelConnector; //导入方法依赖的package包/类
@Override
public void init(DaemonContext context) throws Exception {
System.err.println("Initializing secure datanode resources");
// We should only start up a secure datanode in a Kerberos-secured cluster
Configuration conf = new Configuration(); // Skip UGI method to not log in
if(!conf.get(HADOOP_SECURITY_AUTHENTICATION).equals("kerberos"))
throw new RuntimeException("Cannot start secure datanode in unsecure cluster");
// Stash command-line arguments for regular datanode
args = context.getArguments();
// Obtain secure port for data streaming to datanode
InetSocketAddress socAddr = DataNode.getStreamingAddr(conf);
int socketWriteTimeout = conf.getInt("dfs.datanode.socket.write.timeout",
HdfsConstants.WRITE_TIMEOUT);
ServerSocket ss = (socketWriteTimeout > 0) ?
ServerSocketChannel.open().socket() : new ServerSocket();
ss.bind(socAddr, 0);
// Check that we got the port we need
if(ss.getLocalPort() != socAddr.getPort())
throw new RuntimeException("Unable to bind on specified streaming port in secure " +
"context. Needed " + socAddr.getPort() + ", got " + ss.getLocalPort());
// Obtain secure listener for web server
SelectChannelConnector listener =
(SelectChannelConnector)HttpServer.createDefaultChannelConnector();
InetSocketAddress infoSocAddr = DataNode.getInfoAddr(conf);
listener.setHost(infoSocAddr.getHostName());
listener.setPort(infoSocAddr.getPort());
// Open listener here in order to bind to port as root
listener.open();
if(listener.getPort() != infoSocAddr.getPort())
throw new RuntimeException("Unable to bind on specified info port in secure " +
"context. Needed " + socAddr.getPort() + ", got " + ss.getLocalPort());
System.err.println("Successfully obtained privileged resources (streaming port = "
+ ss + " ) (http listener port = " + listener.getConnection() +")");
if(ss.getLocalPort() >= 1023 || listener.getPort() >= 1023)
throw new RuntimeException("Cannot start secure datanode with unprivileged ports");
resources = new SecureResources(ss, listener);
}