|
|
|
@ -7,6 +7,13 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties |
|
|
|
import org.springframework.context.annotation.Bean; |
|
|
|
import org.springframework.context.annotation.Bean; |
|
|
|
import org.springframework.context.annotation.Configuration; |
|
|
|
import org.springframework.context.annotation.Configuration; |
|
|
|
import org.springframework.context.annotation.DependsOn; |
|
|
|
import org.springframework.context.annotation.DependsOn; |
|
|
|
|
|
|
|
import org.springframework.core.io.ClassPathResource; |
|
|
|
|
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
|
|
|
|
import java.io.FileInputStream; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
import java.io.InputStream; |
|
|
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
@Configuration |
|
|
|
@EnableConfigurationProperties(SocketProperty.class) |
|
|
|
@EnableConfigurationProperties(SocketProperty.class) |
|
|
|
@ -15,9 +22,10 @@ public class SocketConfig { |
|
|
|
private SocketProperty property; |
|
|
|
private SocketProperty property; |
|
|
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
@Bean |
|
|
|
public SocketIOServer socketIOServer() { |
|
|
|
public SocketIOServer socketIOServer() throws IOException { |
|
|
|
com.corundumstudio.socketio.Configuration config = new com.corundumstudio.socketio.Configuration(); |
|
|
|
com.corundumstudio.socketio.Configuration config = new com.corundumstudio.socketio.Configuration(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setSSL(config); |
|
|
|
config.setHostname(property.getHostname()); |
|
|
|
config.setHostname(property.getHostname()); |
|
|
|
config.setPort(property.getPort()); |
|
|
|
config.setPort(property.getPort()); |
|
|
|
config.setMaxFramePayloadLength(property.getMaxFramePayloadLength()); |
|
|
|
config.setMaxFramePayloadLength(property.getMaxFramePayloadLength()); |
|
|
|
@ -36,4 +44,28 @@ public class SocketConfig { |
|
|
|
public void setSocketProperty(SocketProperty socketProperty) { |
|
|
|
public void setSocketProperty(SocketProperty socketProperty) { |
|
|
|
this.property = socketProperty; |
|
|
|
this.property = socketProperty; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void setSSL(com.corundumstudio.socketio.Configuration config) throws IOException { |
|
|
|
|
|
|
|
String keyStore = property.getKeyStore(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(keyStore)) return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InputStream inputStream; |
|
|
|
|
|
|
|
String classpathPrefix = "classpath:"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (keyStore.startsWith(classpathPrefix)) { |
|
|
|
|
|
|
|
inputStream = new ClassPathResource(keyStore.substring(classpathPrefix.length())).getInputStream(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
inputStream = new FileInputStream(new File(keyStore)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
config.setKeyStore(inputStream); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String password = property.getKeyStorePassword(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!StringUtils.isEmpty(password)) { |
|
|
|
|
|
|
|
config.setKeyStorePassword(password); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|