當前位置: 首頁>>代碼示例>>Java>>正文


Java SocketUtils類代碼示例

本文整理匯總了Java中org.springframework.util.SocketUtils的典型用法代碼示例。如果您正苦於以下問題:Java SocketUtils類的具體用法?Java SocketUtils怎麽用?Java SocketUtils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SocketUtils類屬於org.springframework.util包,在下文中一共展示了SocketUtils類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testHealthCommand

import org.springframework.util.SocketUtils; //導入依賴的package包/類
@Test
public void testHealthCommand() {
    int smtpPort = SocketUtils.findAvailableTcpPort();
    ServerSetup setup = new ServerSetup(smtpPort, null, ServerSetup.PROTOCOL_SMTP);
    setup.setServerStartupTimeout(5000);
    GreenMail mailServer = new GreenMail(setup);
    mailServer.start();
    ((JavaMailSenderImpl) mailSender).setPort(smtpPort);
    sshCallShell((is, os) -> {
        write(os, "health");
        verifyResponse(is, "{\r\n  \"status\" : \"UP\"");
        mailServer.stop();
    });
}
 
開發者ID:anand1st,項目名稱:sshd-shell-spring-boot,代碼行數:15,代碼來源:SshdShellAutoConfigurationTest.java

示例2: databaseServer

import org.springframework.util.SocketUtils; //導入依賴的package包/類
@Bean(destroyMethod = "stop")
public Server databaseServer() throws SQLException, IOException {
	DriverManager.registerDriver(new org.hsqldb.jdbcDriver());
	int hsqldbPort = SocketUtils.findAvailableTcpPort(10000);
	System.setProperty("db.server.port", Integer.toString(hsqldbPort));
	logger.info("Database is using port: " + Integer.toString(hsqldbPort));
	HsqlProperties configProps = new HsqlProperties();
	configProps.setProperty("server.port", hsqldbPort);
	configProps.setProperty("server.database.0", "file:target/db/test");
	configProps.setProperty("server.dbname.0", "test");
	Server server = new org.hsqldb.Server();
	server.setLogWriter(null);
	server.setErrWriter(null);
	server.setRestartOnShutdown(false);
	server.setNoSystemExit(true);
	server.setProperties(configProps);
	server.start();
	return server;
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-task-modules,代碼行數:20,代碼來源:SqoopToolDatabaseConfiguration.java

示例3: configureHttp

import org.springframework.util.SocketUtils; //導入依賴的package包/類
private void configureHttp(final TomcatEmbeddedServletContainerFactory tomcat) {
    final CasServerProperties.Http http = casProperties.getServer().getHttp();
    if (http.isEnabled()) {
        LOGGER.debug("Creating HTTP configuration for the embedded tomcat container...");
        final Connector connector = new Connector(http.getProtocol());
        int port = http.getPort();
        if (port <= 0) {
            LOGGER.warn("No explicit port configuration is provided to CAS. Scanning for available ports...");
            port = SocketUtils.findAvailableTcpPort();
        }
        LOGGER.info("Activated embedded tomcat container HTTP port to [{}]", port);
        connector.setPort(port);

        LOGGER.debug("Configuring embedded tomcat container for HTTP2 protocol support");
        connector.addUpgradeProtocol(new Http2Protocol());

        http.getAttributes().forEach(connector::setAttribute);
        tomcat.addAdditionalTomcatConnectors(connector);
    }
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:21,代碼來源:CasEmbeddedContainerTomcatConfiguration.java

示例4: App

import org.springframework.util.SocketUtils; //導入依賴的package包/類
public App(String appName, Map<String, String> env) {
    ProcessBuilder processBuilder = new ProcessBuilder("java", "-jar", appName + "-trace-example-0.0.1-SNAPSHOT.jar");
    Map<String, String> environment = processBuilder.environment();

    int port = SocketUtils.findAvailableTcpPort();
    environment.put("SERVER_PORT", Integer.toString(port));
    environment.putAll(env);
    processBuilder.directory(new File("../applications/" + appName + "/build/libs/"));

    File logFile = new File("tmp/" + appName + ".log");
    processBuilder.redirectOutput(logFile);

    this.port = port;
    try {
        this.process = processBuilder.start();
    } catch (IOException e) {
        throw new RuntimeException("app " + appName + " failed to start", e);
    }
    this.logFile = logFile;
}
 
開發者ID:pivotal-cf,項目名稱:pcf-metrics-trace-example-spring,代碼行數:21,代碼來源:App.java

示例5: testStatusCommand

import org.springframework.util.SocketUtils; //導入依賴的package包/類
@Test
public void testStatusCommand() {
    int smtpPort = SocketUtils.findAvailableTcpPort();
    ServerSetup setup = new ServerSetup(smtpPort, null, ServerSetup.PROTOCOL_SMTP);
    setup.setServerStartupTimeout(5000);
    GreenMail mailServer = new GreenMail(setup);
    mailServer.start();
    ((JavaMailSenderImpl) mailSender).setPort(smtpPort);
    sshCallShell((is, os) -> {
        write(os, "status");
        verifyResponse(is, "{\r\n  \"status\" : \"UP\"\r\n}");
        mailServer.stop();
    });
}
 
開發者ID:anand1st,項目名稱:sshd-shell-spring-boot,代碼行數:15,代碼來源:SshdShellAutoConfigurationTest.java

示例6: setup

import org.springframework.util.SocketUtils; //導入依賴的package包/類
@Override
public void setup() {
	this.port = SocketUtils.findAvailableTcpPort();

	Connector connector = new Connector(Http11NioProtocol.class.getName());
	connector.setPort(this.port);

	File baseDir = createTempDir("tomcat");
	String baseDirPath = baseDir.getAbsolutePath();

	this.tomcatServer = new Tomcat();
	this.tomcatServer.setBaseDir(baseDirPath);
	this.tomcatServer.setPort(this.port);
	this.tomcatServer.getService().addConnector(connector);
	this.tomcatServer.setConnector(connector);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:17,代碼來源:TomcatWebSocketTestServer.java

示例7: portClashOfSecondaryConnectorResultsInPortInUseException

import org.springframework.util.SocketUtils; //導入依賴的package包/類
@Test
public void portClashOfSecondaryConnectorResultsInPortInUseException()
		throws IOException {
	doWithBlockedPort(new BlockedPortAction() {

		@Override
		public void run(int port) {
			try {
				AbstractEmbeddedServletContainerFactory factory = getFactory();
				factory.setPort(SocketUtils.findAvailableTcpPort(40000));
				addConnector(port, factory);
				AbstractEmbeddedServletContainerFactoryTests.this.container = factory
						.getEmbeddedServletContainer();
				AbstractEmbeddedServletContainerFactoryTests.this.container.start();
				fail();
			}
			catch (PortInUseException ex) {
				assertThat(ex.getPort()).isEqualTo(port);
			}
		}

	});
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:24,代碼來源:AbstractEmbeddedServletContainerFactoryTests.java

示例8: doWithBlockedPort

import org.springframework.util.SocketUtils; //導入依賴的package包/類
protected final void doWithBlockedPort(BlockedPortAction action) throws IOException {
	int port = SocketUtils.findAvailableTcpPort(40000);
	ServerSocket serverSocket = new ServerSocket();
	for (int i = 0; i < 10; i++) {
		try {
			serverSocket.bind(new InetSocketAddress(port));
			break;
		}
		catch (Exception ex) {
		}
	}
	try {
		action.run(port);
	}
	finally {
		serverSocket.close();
	}
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:19,代碼來源:AbstractEmbeddedServletContainerFactoryTests.java

示例9: tomcatEngineNames

import org.springframework.util.SocketUtils; //導入依賴的package包/類
@Test
public void tomcatEngineNames() throws Exception {
	TomcatEmbeddedServletContainerFactory factory = getFactory();
	this.container = factory.getEmbeddedServletContainer();
	factory.setPort(SocketUtils.findAvailableTcpPort(40000));
	TomcatEmbeddedServletContainer container2 = (TomcatEmbeddedServletContainer) factory
			.getEmbeddedServletContainer();

	// Make sure that the names are different
	String firstContainerName = ((TomcatEmbeddedServletContainer) this.container)
			.getTomcat().getEngine().getName();
	String secondContainerName = container2.getTomcat().getEngine().getName();
	assertThat(firstContainerName).as("Tomcat engines must have different names")
			.isNotEqualTo(secondContainerName);
	container2.stop();
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:17,代碼來源:TomcatEmbeddedServletContainerFactoryTests.java

示例10: assertVersionConfiguration

import org.springframework.util.SocketUtils; //導入依賴的package包/類
private void assertVersionConfiguration(String configuredVersion,
		String expectedVersion) {
	this.context = new AnnotationConfigApplicationContext();
	int mongoPort = SocketUtils.findAvailableTcpPort();
	EnvironmentTestUtils.addEnvironment(this.context,
			"spring.data.mongodb.port=" + mongoPort);
	if (configuredVersion != null) {
		EnvironmentTestUtils.addEnvironment(this.context,
				"spring.mongodb.embedded.version=" + configuredVersion);
	}
	this.context.register(MongoAutoConfiguration.class,
			MongoDataAutoConfiguration.class, EmbeddedMongoAutoConfiguration.class);
	this.context.refresh();
	MongoTemplate mongo = this.context.getBean(MongoTemplate.class);
	CommandResult buildInfo = mongo.executeCommand("{ buildInfo: 1 }");

	assertThat(buildInfo.getString("version")).isEqualTo(expectedVersion);
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:19,代碼來源:EmbeddedMongoAutoConfigurationTests.java

示例11: tomcatEngineNames

import org.springframework.util.SocketUtils; //導入依賴的package包/類
@Test
public void tomcatEngineNames() throws Exception {
	TomcatEmbeddedServletContainerFactory factory = getFactory();
	this.container = factory.getEmbeddedServletContainer();
	factory.setPort(SocketUtils.findAvailableTcpPort(40000));
	TomcatEmbeddedServletContainer container2 = (TomcatEmbeddedServletContainer) factory
			.getEmbeddedServletContainer();

	// Make sure that the names are different
	String firstContainerName = ((TomcatEmbeddedServletContainer) this.container)
			.getTomcat().getEngine().getName();
	String secondContainerName = container2.getTomcat().getEngine().getName();
	assertFalse("Tomcat engines must have different names",
			firstContainerName.equals(secondContainerName));
	container2.stop();
}
 
開發者ID:Nephilim84,項目名稱:contestparser,代碼行數:17,代碼來源:TomcatEmbeddedServletContainerFactoryTests.java

示例12: primaryConnectorPortClashThrowsIllegalStateException

import org.springframework.util.SocketUtils; //導入依賴的package包/類
@Test
public void primaryConnectorPortClashThrowsIllegalStateException()
		throws InterruptedException, IOException {
	final int port = SocketUtils.findAvailableTcpPort(40000);

	doWithBlockedPort(port, new Runnable() {

		@Override
		public void run() {
			TomcatEmbeddedServletContainerFactory factory = getFactory();
			factory.setPort(port);

			try {
				TomcatEmbeddedServletContainerFactoryTests.this.container = factory
						.getEmbeddedServletContainer();
				TomcatEmbeddedServletContainerFactoryTests.this.container.start();
				fail();
			}
			catch (EmbeddedServletContainerException ex) {
				// Ignore
			}
		}

	});

}
 
開發者ID:Nephilim84,項目名稱:contestparser,代碼行數:27,代碼來源:TomcatEmbeddedServletContainerFactoryTests.java

示例13: assertVersionConfiguration

import org.springframework.util.SocketUtils; //導入依賴的package包/類
private void assertVersionConfiguration(String configuredVersion,
		String expectedVersion) {
	this.context = new AnnotationConfigApplicationContext();
	int mongoPort = SocketUtils.findAvailableTcpPort();
	EnvironmentTestUtils.addEnvironment(this.context,
			"spring.data.mongodb.port=" + mongoPort);
	if (configuredVersion != null) {
		EnvironmentTestUtils.addEnvironment(this.context,
				"spring.mongodb.embedded.version=" + configuredVersion);
	}
	this.context.register(MongoAutoConfiguration.class,
			MongoDataAutoConfiguration.class, EmbeddedMongoAutoConfiguration.class);
	this.context.refresh();
	MongoTemplate mongo = this.context.getBean(MongoTemplate.class);
	CommandResult buildInfo = mongo.executeCommand("{ buildInfo: 1 }");

	assertThat(buildInfo.getString("version"), equalTo(expectedVersion));
}
 
開發者ID:Nephilim84,項目名稱:contestparser,代碼行數:19,代碼來源:EmbeddedMongoAutoConfigurationTests.java

示例14: contextLoads

import org.springframework.util.SocketUtils; //導入依賴的package包/類
@Test public void contextLoads() throws Exception {
	int zkPort = SocketUtils.findAvailableTcpPort();
	TestingServer server = new TestingServer(zkPort);

	int port = SocketUtils.findAvailableTcpPort(zkPort+1);

	ConfigurableApplicationContext context = new SpringApplicationBuilder(SampleZookeeperApplication.class).run(
			"--server.port="+port,
			"--management.endpoints.web.expose=*",
			"--spring.cloud.zookeeper.connect-string=localhost:" + zkPort);

	ResponseEntity<String> response = new TestRestTemplate().getForEntity("http://localhost:"+port+"/hi", String.class);
	assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);

	context.close();
	server.close();
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-zookeeper,代碼行數:18,代碼來源:SampleApplicationTests.java

示例15: beforeClass

import org.springframework.util.SocketUtils; //導入依賴的package包/類
@Before
public void beforeClass() throws Exception {
    zookeeper = new TestingServer(SocketUtils.findAvailableTcpPort());
    curatorFramework = CuratorFrameworkFactory.newClient(zookeeper.getConnectString(), new RetryOneTime(1000));
    curatorFramework.start();

    curatorFramework.create().forPath(CONFIG_BASE_PATH);

    Map<String, Object> defaults = new HashMap<>();
    defaults.put(DEF_KEY1, DEF_VAL1);
    defaults.put(DEF_KEY2, DEF_VAL2);

    defaultConfiguration = new MapConfiguration(defaults);

    node = UUID.randomUUID().toString();
    config = new ConcurrentCompositeConfiguration();
}
 
開發者ID:Kixeye,項目名稱:chassis,代碼行數:18,代碼來源:DynamicZookeeperConfigurationSourceTest.java


注:本文中的org.springframework.util.SocketUtils類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。