org.apache.catalina.startup.Tomcat.setHostname()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(12.2k)|赞(0)|评价(0)|浏览(87)

本文整理了Java中org.apache.catalina.startup.Tomcat.setHostname()方法的一些代码示例,展示了Tomcat.setHostname()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Tomcat.setHostname()方法的具体详情如下:
包路径:org.apache.catalina.startup.Tomcat
类名称:Tomcat
方法名:setHostname

Tomcat.setHostname介绍

[英]The the hostname of the default host, default is 'localhost'.
[中]默认主机的主机名,默认为“localhost”。

代码示例

代码示例来源:origin: spring-projects/spring-framework

@Override
protected void initServer() throws Exception {
  this.tomcatServer = new Tomcat();
  this.tomcatServer.setBaseDir(baseDir);
  this.tomcatServer.setHostname(getHost());
  this.tomcatServer.setPort(getPort());
  ServletHttpHandlerAdapter servlet = initServletAdapter();
  File base = new File(System.getProperty("java.io.tmpdir"));
  Context rootContext = tomcatServer.addContext(this.contextPath, base.getAbsolutePath());
  Tomcat.addServlet(rootContext, "httpHandlerServlet", servlet).setAsyncSupported(true);
  rootContext.addServletMappingDecoded(this.servletMapping, "httpHandlerServlet");
  if (wsListener != null) {
    rootContext.addApplicationListener(wsListener.getName());
  }
}

代码示例来源:origin: AsyncHttpClient/async-http-client

tomcat.setHostname("localhost");
tomcat.setPort(0);
tomcat.setBaseDir(path);

代码示例来源:origin: AsyncHttpClient/async-http-client

tomcat.setHostname("localhost");
tomcat.setPort(0);
tomcat.setBaseDir(path);

代码示例来源:origin: org.apache.airavata/airavata-embedded-tomcat

public void setDefaultHost(String defaultHostName) {
  tomcat.setHostname(defaultHostName);
  tomcat.getEngine().setDefaultHost(defaultHostName);
}

代码示例来源:origin: apache/eagle

public void start() {
  tomcat = new Tomcat();
  tomcat.setHostname("localhost");
  tomcat.setPort(port);
  try {
    tomcat.addWebapp("/eagle-service", new File(webappDirLocation).getAbsolutePath());
    tomcat.start();
  } catch (Exception ex) {
    LOG.error("Got an exception " + ex.getMessage());
  }
  Runtime.getRuntime().addShutdownHook(new Thread() {
    @Override
    public void run() {
      try {
        shutdown();
      } catch (Throwable t) {
        LOG.error("Got an exception why shutting down..." + t.getMessage());
      }
    }
  });
  try {
    Thread.sleep(10000000);
  } catch (Exception ex) {
    ex.printStackTrace();
  }
}

代码示例来源:origin: org.apache.eagle/eagle-embed-server

public void start() {
  tomcat = new Tomcat();
  tomcat.setHostname("localhost");
  tomcat.setPort(port);
  try {
    tomcat.addWebapp("/eagle-service", new File(webappDirLocation).getAbsolutePath());
    tomcat.start();
  } catch (Exception ex) {
    LOG.error("Got an exception " + ex.getMessage());
  }
  Runtime.getRuntime().addShutdownHook(new Thread() {
    @Override
    public void run() {
      try {            		
        shutdown();
      }
      catch (Throwable t) {
        LOG.error("Got an exception why shutting down..." + t.getMessage());
      }
    }
  });
  try {
    Thread.sleep(10000000);
  }catch(Exception ex){
    ex.printStackTrace();
  }
}

代码示例来源:origin: org.nuxeo.runtime/nuxeo-runtime-server

@Override
public int initialize(int port) {
  tomcat = new Tomcat();
  tomcat.setBaseDir("."); // for tmp dir
  tomcat.setHostname("localhost");
  tomcat.setPort(port);
  Connector connector = tomcat.getConnector();
  connector.setProperty("maxKeepAliveRequests", "1"); // vital for clean shutdown
  connector.setProperty("socket.soReuseAddress", "true");
  log.info("Configuring test Tomcat on port: {}", port);
  return port;
}

代码示例来源:origin: hantsy/spring-reactive-sample

@Bean
public Tomcat embededTomcatServer(ApplicationContext context) throws Exception {
  HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context).build(); 
  // Tomcat and Jetty (also see notes below)
  Servlet servlet = new TomcatHttpHandlerAdapter(handler);
  Tomcat tomcatServer = new Tomcat();
  tomcatServer.setHostname("localhost");
  tomcatServer.setPort(this.port);
  Context rootContext = tomcatServer.addContext("", System.getProperty("java.io.tmpdir"));
  Tomcat.addServlet(rootContext, "httpHandlerServlet", servlet);
  rootContext.addServletMappingDecoded("/", "httpHandlerServlet");
  return tomcatServer;
}

代码示例来源:origin: apache/ofbiz-framework

private Tomcat prepareTomcatServer(ContainerConfig.Configuration cc,
    ContainerConfig.Configuration.Property engineConfig) throws ContainerException {
  System.setProperty(Globals.CATALINA_HOME_PROP, System.getProperty("ofbiz.home") + "/" +
        ContainerConfig.getPropertyValue(cc, "catalina-runtime-home", "runtime/catalina"));
  System.setProperty(Globals.CATALINA_BASE_PROP, System.getProperty(Globals.CATALINA_HOME_PROP));
  Tomcat tomcat = new Tomcat();
  tomcat.setBaseDir(System.getProperty("ofbiz.home"));
  Property defaultHostProp = engineConfig.getProperty("default-host");
  if (defaultHostProp == null) {
    throw new ContainerException("default-host element of server property is required for catalina!");
  }
  tomcat.setHostname(defaultHostProp.value);
  if (ContainerConfig.getPropertyValue(cc, "use-naming", false)) {
    tomcat.enableNaming();
  }
  StandardServer server = (StandardServer) tomcat.getServer();
  try {
    server.setGlobalNamingContext(new InitialContext());
  } catch (NamingException e) {
    throw new ContainerException(e);
  }
  return tomcat;
}

代码示例来源:origin: com.github.skjolber.mockito-rest-spring/tomcat

tomcat.setHostname("localhost");

代码示例来源:origin: poutsma/web-function-sample

public void startTomcatServer() throws LifecycleException {
  RouterFunction<?> route = routingFunction();
  HttpHandler httpHandler = toHttpHandler(route);
  Tomcat tomcatServer = new Tomcat();
  tomcatServer.setHostname(HOST);
  tomcatServer.setPort(PORT);
  Context rootContext = tomcatServer.addContext("", System.getProperty("java.io.tmpdir"));
  ServletHttpHandlerAdapter servlet = new ServletHttpHandlerAdapter(httpHandler);
  Tomcat.addServlet(rootContext, "httpHandlerServlet", servlet);
  rootContext.addServletMapping("/", "httpHandlerServlet");
  tomcatServer.start();
}

代码示例来源:origin: apache/jackrabbit-oak

protected void setUp() throws Exception {
  File war = null;
  for (File f : new File("target").listFiles()) {
    if (f.isDirectory() && new File(f, "WEB-INF/web.xml").isFile()) {
      war = f;
      break;
    }
  }
  assertNotNull(war);
  rewriteWebXml(war);
  File bootstrap = new File("target", "bootstrap.properties");
  bootstrap.delete();
  File baseDir = new File("target", "tomcat");
  FileUtils.deleteQuietly(baseDir);
  File repoDir = new File("target", "repository");
  FileUtils.deleteQuietly(repoDir);
  url = new URL("http://localhost:"+getPort()+"/");
  tomcat = new Tomcat();
  tomcat.setSilent(true);
  tomcat.setBaseDir(baseDir.getPath());
  tomcat.setHostname(url.getHost());
  tomcat.setPort(url.getPort());
  tomcat.addWebapp("", war.getAbsolutePath());
  tomcat.start();
  client = new WebClient();
}

代码示例来源:origin: org.jmockring/jmockring-tomcat

tomcat.noDefaultWebXmlPath();
tomcat.setBaseDir(FilenameUtils.normalize(location + "/../tomcat-work"));
tomcat.setHostname(hostname);
tomcat.getEngine().setDefaultHost(hostname);
if ("https".equalsIgnoreCase(scheme)) {

代码示例来源:origin: hengyunabc/executable-embeded-tomcat-sample

public static void main(String[] args) throws ServletException, LifecycleException, IOException {

    String hostName = "localhost";
    int port = 8080;
    String contextPath = "";

    String tomcatBaseDir = TomcatUtil.createTempDir("tomcat", port).getAbsolutePath();
    String contextDocBase = TomcatUtil.createTempDir("tomcat-docBase", port).getAbsolutePath();

    Tomcat tomcat = new Tomcat();
    tomcat.setBaseDir(tomcatBaseDir);

    tomcat.setPort(port);
    tomcat.setHostname(hostName);

    Host host = tomcat.getHost();
    Context context = tomcat.addWebapp(host, contextPath, contextDocBase, new EmbededContextConfig());

    context.setJarScanner(new EmbededStandardJarScanner());

    ClassLoader classLoader = Main.class.getClassLoader();
    context.setParentClassLoader(classLoader);

    // context load WEB-INF/web.xml from classpath
    context.addLifecycleListener(new WebXmlMountListener());

    tomcat.start();
    tomcat.getServer().await();
  }
}

代码示例来源:origin: org.jboss.arquillian.container/arquillian-tomcat-embedded-7

tomcat.getService().setName(configuration.getServerName());
final String hostname = configuration.getBindAddress();
tomcat.setHostname(hostname);
tomcat.setPort(configuration.getBindHttpPort());
tomcat.setBaseDir(tempDir.getAbsolutePath());

代码示例来源:origin: org.apache.tomee.patch/commons-jcs-jcache-extras

@Test
public void testFilterNoOutput() throws Exception
{
  Empty.COUNTER.set(0);
  final Tomcat tomcat = new Tomcat();
  tomcat.setHostname("localhost");
  tomcat.setPort(0);
  try {
    tomcat.getEngine();
    tomcat.start();
    final Context ctx = tomcat.addWebapp("/sample", docBase.getAbsolutePath());
    Tomcat.addServlet(ctx, "empty", Empty.class.getName());
    ctx.addServletMapping("/", "empty");
    addJcsFilter(ctx);
    StandardContext.class.cast(ctx).filterStart();
    final URL url = new URL("http://localhost:" + tomcat.getConnector().getLocalPort() + "/sample/");
    assertEquals("", IOUtils.toString(url.openStream()));
    assertEquals(1, Empty.COUNTER.get());
    assertEquals("", IOUtils.toString(url.openStream()));
    assertEquals(1, Empty.COUNTER.get());
  } finally {
    stop(tomcat);
  }
}

代码示例来源:origin: nutzam/nutzboot

@Override
public void init() throws LifecycleException {
  this.tomcat = new Tomcat();
  File baseDir = createTempDir("tomcat");
  this.tomcat.setBaseDir(baseDir.getAbsolutePath());
  Connector connector = new Connector(PROP_PROTOCOL);
  connector.setPort(getPort());
  connector.setURIEncoding(DEFAULT_CHARSET.name());
  connector.setMaxPostSize(conf.getInt(PROP_MAX_POST_SIZE, 64 * 1024 * 1024));
  String connectorKey = PRE + "connector.";
  for (String key : conf.keys()) {
    if (key.startsWith(connectorKey)) {
      String k = key.substring(connectorKey.length());
      String v = conf.get(key);
      connector.setProperty(k, v);
    }
  }
  // 设置一下最大线程数
  this.tomcat.getService().addConnector(connector);
  StandardThreadExecutor executor = new StandardThreadExecutor();
  executor.setMaxThreads(getMaxThread());
  connector.getService().addExecutor(executor);
  this.tomcat.setConnector(connector);
  this.tomcat.setHostname(getHost());
  this.tomcat.getHost().setAutoDeploy(false);
  this.tomcat.getEngine().setBackgroundProcessorDelay(30);
  this.prepareContext();
}

代码示例来源:origin: hopshadoop/hops

protected void startTomcat() throws Exception {
 tomcat = new Tomcat();
 File base = new File(System.getProperty("java.io.tmpdir"));
 org.apache.catalina.Context ctx =
  tomcat.addContext("/foo",base.getAbsolutePath());
 FilterDef fd = new FilterDef();
 fd.setFilterClass(TestFilter.class.getName());
 fd.setFilterName("TestFilter");
 FilterMap fm = new FilterMap();
 fm.setFilterName("TestFilter");
 fm.addURLPattern("/*");
 fm.addServletName("/bar");
 ctx.addFilterDef(fd);
 ctx.addFilterMap(fm);
 tomcat.addServlet(ctx, "/bar", TestServlet.class.getName());
 ctx.addServletMapping("/bar", "/bar");
 host = "localhost";
 port = getLocalPort();
 tomcat.setHostname(host);
 tomcat.setPort(port);
 tomcat.start();
}

代码示例来源:origin: io.hops/hadoop-auth

protected void startTomcat() throws Exception {
 tomcat = new Tomcat();
 File base = new File(System.getProperty("java.io.tmpdir"));
 org.apache.catalina.Context ctx =
  tomcat.addContext("/foo",base.getAbsolutePath());
 FilterDef fd = new FilterDef();
 fd.setFilterClass(TestFilter.class.getName());
 fd.setFilterName("TestFilter");
 FilterMap fm = new FilterMap();
 fm.setFilterName("TestFilter");
 fm.addURLPattern("/*");
 fm.addServletName("/bar");
 ctx.addFilterDef(fd);
 ctx.addFilterMap(fm);
 tomcat.addServlet(ctx, "/bar", TestServlet.class.getName());
 ctx.addServletMapping("/bar", "/bar");
 host = "localhost";
 port = getLocalPort();
 tomcat.setHostname(host);
 tomcat.setPort(port);
 tomcat.start();
}

代码示例来源:origin: hortonworks/registry

protected void startTomcat() throws Exception {
  tomcat = new Tomcat();
  File base = new File(System.getProperty("java.io.tmpdir"));
  org.apache.catalina.Context ctx =
      tomcat.addContext("/foo", base.getAbsolutePath());
  FilterDef fd = new FilterDef();
  fd.setFilterClass(TestFilter.class.getName());
  fd.setFilterName("TestFilter");
  FilterMap fm = new FilterMap();
  fm.setFilterName("TestFilter");
  fm.addURLPattern("/*");
  fm.addServletName("/bar");
  ctx.addFilterDef(fd);
  ctx.addFilterMap(fm);
  tomcat.addServlet(ctx, "/bar", TestServlet.class.getName());
  ctx.addServletMapping("/bar", "/bar");
  host = "localhost";
  port = getLocalPort();
  tomcat.setHostname(host);
  tomcat.setPort(port);
  tomcat.start();
}

相关文章