我不明白如何在springboot应用程序中正确编写websocket测试用例。我有一个实现的类,我在中添加了这个处理程序:WebSocketHandlerWebSocketConfigurer
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
registry.addHandler(logWebSocketHandler() , "/test")
.addInterceptors(new HttpSessionHandshakeInterceptor())
.setAllowedOrigins("*");
}
@Bean
public LogWebSocketHandler logWebSocketHandler(){
return new LogWebSocketHandler();
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我在下面编写测试用例时,我得到一个异常:
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration({App.class})
@WebAppConfiguration
public class LogsControllerTest {
private WebSocketContainer container;
@Before
public void setup() {
container = ContainerProvider.getWebSocketContainer();
}
@Test
public void testGetLog() throws Exception {
Session session = container.connectToServer(new TestEndpoint(),
URI.create("ws://127.0.0.1:8080/test"));
}
}
Run Code Online (Sandbox Code Playgroud)
异常::
javax.websocket.DeploymentException发起WebSocket连接的HTTP请求失败
我读到,如果我设置ws://127.0.0.1:8080/test/(末尾斜杠)它将起作用,但它不起作用。
我做错了什么?
我创建了.jar文件并将其移至dir,但是我不明白以后如何更改该文件的权限。
task fatJar(type: Jar) {
manifest {
attributes 'Implementation-Title': 'Gradle Jar File Example',
'Implementation-Version': version,
'Main-Class':'com.asd.App',
'Class-Path': 'com.asd'
}
baseName = project.name + '-all'
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
def file = file('/home/master/project/asd')
fileMode = 755
destinationDir = file
with jar
}
Run Code Online (Sandbox Code Playgroud)