WebSocket on Wildfly 10 not working on Windows 10 - windows

I have a problem with WebSocket to work on Wildfly 10, every time that I try send a message from Wildfly to the browser the connection is closed showing an 1006 code.
#ServerEndpoint("/debugger")
public class SocketDebugger {
#OnOpen
public void onConnect(Session session) {
session.setMaxIdleTimeout(0);
try {
session.getBasicRemote().sendText("Teste");
} catch (IOException e) {
e.printStackTrace();
}
}
}
This error does not occur if I open a WebSocket connection on a machine with Windows 7 or lower. Also on my machine with Windows 10, when I create a project using NodeJS Socket.IO communication works standard, this error happens with Java projects.

I found the solution, Kaspersky had a block to the WebSocket communication.

Related

Spring Boot + Sockjs client offline connecting issues

I'm trying to connect a Spring Boot Stomp Server with multiple sockjs clients offline but I get the warning
Websocket is closed before the connection is established
followed by
GET http://192.168.1.45:8080/socket/327/si5osugt/jsonp?c=jp.a3xdefl net::ERR_ABORTED 404 (Not Found)
I'm using Spring Boot Version 2.1.2 with the spring-boot-starter-websocket package on the backend side and on the frontend side I'm using Angular 6 with sockjs-client version 1.3.0. Frontend and backend are both running on port 8080
I'm getting some errors while turning the internet down. If the internet is turned off the iframe tries to reach to https://cdn.jsdelivr.net/npm/sockjs-client#1/dist/sockjs.js.
I managed by configuring stomp server on the backend to set the client library by adding .setClientLibraryUrl to a absolute path which is offline reachable.
registry.addEndpoint("/socket").setAllowedOrigins("*").withSockJS).setClientLibraryUrl("http://192.168.1.45/dist/sockjs.min.js");
and get a 200 OK on http://192.168.1.45/dist/sockjs.min.js
Spring Boot:
WebSocketConfiguration (extends AbstractWebSocketMessageBrokerConfigurer)
#Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/socket")
.setAllowedOrigins("*")
.withSockJS().setClientLibraryUrl("http://192.168.1.45/dist/sockjs.min.js");
}
#Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
MessageBrokerRegistry messageBrokerRegistry = registry.setApplicationDestinationPrefixes("/app");
messageBrokerRegistry.enableSimpleBroker( "/test", "/test2"
);
}
WebSocketController
private final SimpMessagingTemplate template;
#Autowired
WebSocketController(SimpMessagingTemplate template){
this.template=template;
}
#MessageMapping("/send/message")
public void onReceivedMessage( String destination , String message){
this.template.convertAndSend(destination , message);
}
public void convertAndSend(String url, Object o){
this.template.convertAndSend(url, o);
}
Angular 6:
TestComponet
ngAfterViewInit() {
let ws = new SockJS('http://192.168.1.45:8080/socket');
this.stompClient = Stomp.over(ws);
let that = this;
that.stompClient.subscribe("/test", (message) => {
if (message.body) {
console.log(message.body);
}
});
that.stompClient.subscribe("/test2", (message) => {
if (message.body) {
console.log(message.body);
}
});
}
I thought it would work by just adding the sockjs client lib to an offline reachable path but I get the warning
Websocket is closed before the connection is established
followed by
"GET http://192.168.1.45:8080/socket/327/si5osugt/jsonp?c=jp.a3xdefl net::ERR_ABORTED 404 (Not Found)"
The library works with an internet connection perfectly fine, but I need it to work with both situations online and offline.
I had the same issue, and I fixed it by removing SockJs.
So now I'm currently using only Stomp-Websockets.
Changes in SpringBoot-Service(WebsocketConfiguration):
registry.addEndpoint("/justStomp").setAllowedOrigins("*");
I removed the .withSockJS() and .setClientLibraryUrl(../sockjs.min.js)
Changes in my Javascript-Code to connect to the websocket:
const stompClient = Stomp.client(`ws://localhost:8080/justStomp`);
stompClient.heartbeat.outgoing = 0;
stompClient.heartbeat.incoming = 0;
stompClient.connect({ name: 'test' }, frame => this.stompSuccessCallBack(frame, stompClient), err => this.stompFailureCallBack(err));
Instead of using Stomp.over(sockjs) I use the Stomp.client Method to directly connect to the websocket-url.
I have a rabbitMQ in the background with stomp-plugin, and this only works properly with the 2 heartbeat-settings. see here RabbitMQ Web STOMP without SockJS

Spring AWS SQS Reconnect After Losing Connection

I am using Spring Cloud AWS (1.0.1.RELEASE) with Spring Boot to run a SQS consumer. The application runs fine, but when it looses network connection (for instance if I switch my WIFI off on my laptop when it runs on it), I see errors on the console and the application never recovers. It just hangs there and does not reconnect after the network becomes available. I have to kill it and bring it up. How do I force it to recover by itself?
// Spring Boot entry point:
public static void main(String[] args) {
SpringApplication.run(MyConsumerConfiguration.class, args);
}
// Message Listener (A different class)
#MessageMapping(value = "myLogicalQueueName" )
public void receive(MyPOJO object) {
}
The error I see at console:
Exception in thread "simpleMessageListenerContainer-1" com.amazonaws.AmazonClientException: Unable to execute HTTP request: sqs.us-east-1.amazonaws.com
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:473)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:297)
at com.amazonaws.services.sqs.AmazonSQSClient.invoke(AmazonSQSClient.java:2422)
at com.amazonaws.services.sqs.AmazonSQSClient.receiveMessage(AmazonSQSClient.java:1130)
at com.amazonaws.services.sqs.AmazonSQSAsyncClient$23.call(AmazonSQSAsyncClient.java:1678)
at com.amazonaws.services.sqs.AmazonSQSAsyncClient$23.call(AmazonSQSAsyncClient.java:1676)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745
I just figured out the problem why SQS is not able to reconnect after network connection lost.
Actually seems to be a problem in current Spring AWS implementation of org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer.java
private class AsynchronousMessageListener implements Runnable {
private final QueueAttributes queueAttributes;
private final String logicalQueueName;
private AsynchronousMessageListener(String logicalQueueName, QueueAttributes queueAttributes) {
this.logicalQueueName = logicalQueueName;
this.queueAttributes = queueAttributes;
}
#Override
public void run() {
while (isRunning()) {
ReceiveMessageResult receiveMessageResult = getAmazonSqs().receiveMessage(this.queueAttributes.getReceiveMessageRequest());
CountDownLatch messageBatchLatch = new CountDownLatch(receiveMessageResult.getMessages().size());
for (Message message : receiveMessageResult.getMessages()) {
if (isRunning()) {
MessageExecutor messageExecutor = new MessageExecutor(this.logicalQueueName, message, this.queueAttributes);
getTaskExecutor().execute(new SignalExecutingRunnable(messageBatchLatch, messageExecutor));
} else {
break;
}
}
try {
messageBatchLatch.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
}
Above code spins up a new thread which does the polling to SQS queue to grab messages. Once network connection is dropped getAmazonSqs().receiveMessage(this.queueAttributes.getReceiveMessageRequest()) throws UnknownHostException, which is not handled in the code and causes thread termination.
So when network connection is established later on, there is no thread polling the queue to retrieve the data.
I have already raised a issue with Spring for this. Following is the link: https://github.com/spring-cloud/spring-cloud-aws/issues/82
Hope this explains it all.

RMI very slow is client and server are not in the same machine

i have a strange problem. I developed client-server application with Java RMI, and in the localhost work very fine, also work very well if i put the client and server on two different MacBook Pro, but work very very slowly if i try to put the client and the server on two computer that are not macbook pro. I have this problem only if i try to send a reference of the client to the server with invocation of a remote method.
This is my code
SERVER:
public class Server{
public static void main(String [] args){
try
{
Server_Impl server=new Server_Impl();
Registry reg=LocateRegistry.createRegistry(1099);
reg.bind("Server",server);
if(new Scanner(System.in).nextInt()==-1){
System.exit(0);
}
}
catch (RemoteException e){e.printStackTrace( );}
catch (AlreadyBoundException e) {e.printStackTrace( );}
}
}
CLIENT
public class Client{
public static Interfaccia_Server Server;
public static void main(String [] args){
try{
Registry reg=LocateRegistry.getRegistry("10.0.1.5",1099);
Server = (Interfaccia_Server) reg.lookup("Server");
Client_Impl c= new Client_Impl(Server);
Server.connect_client(c);
c.check_action();
}
catch(Exception e){
}
}
}
All of the code work, but very very slow if client and server are not on the same machine, or on a apple mac computer.
If i remove this line of code from the client all work very well anywhere, but i need the reference of the client in the server
Server.connect_client(c);
I have no idea about, please help me

Bosh over https using smack

I am trying to have create Bosh connection to openfire over https. I have tried using the BoshConfiguration with hhtps argument as true. But connection times out at remote server.
Anyone has any working example of Bosh over https in smack ?
I´ve faced the same problem. I could make the connection and login by changing JBosh library, since the HttpClient usage there does not consider a SSL Context.
I followed the approach used in http://www.java-samples.com/showtutorial.php?tutorialid=211 for this, with some modification in subscribe() method, returning the SSLContext and using in XLightWebSender.java init() method, like this:
public void init(final BOSHClientConfig session) {
lock.lock();
try {
cfg = session;
SSLContext context = null;
try {
context = this.subscribe();
} catch (Exception e) {
e.printStackTrace();
}
client = new HttpClient(context);
} finally {
lock.unlock();
}
}
PS: I´m still testing and don´t guarantee that this work-around works fine for long living connections.

IBM.XMS ExceptionListener not firing

I am using IBM.XMS 2.0.0.5 and MQ Client 7.0.1.5 and have created a connection, set the exception listener, started the connection and started listening for messages using a message listener. This works fine, except that the ExceptionListener does not fire when I disable the network connection. Instead I get an unhandled socket exception.
I have gone back to the example given on the IBM site and recreated the error:
If I disable the network connetion I get the unhandled socket exception and the exceptionListener does not get fired.
using System;
using System.Threading;
using IBM.XMS;
public class Sample
{
public static void Main()
{
XMSFactoryFactory factoryFactory = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ);
IConnectionFactory connectionFactory = factoryFactory.CreateConnectionFactory();
connectionFactory.SetStringProperty(XMSC.WMQ_HOST_NAME, "**********");
connectionFactory.SetStringProperty(XMSC.WMQ_CHANNEL, "*****");
connectionFactory.SetIntProperty(XMSC.WMQ_PORT, 1414);
connectionFactory.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT);
connectionFactory.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, "*********");
//
// Create the connection and register an exception listener
//
IConnection connection = connectionFactory.CreateConnection();
connection.ExceptionListener = new ExceptionListener(OnException);
ISession session = connection.CreateSession(false, AcknowledgeMode.AutoAcknowledge);
IDestination queue = session.CreateQueue("queue://***********");
//
// Create the consumer and register an async message listener
//
IMessageConsumer consumer = session.CreateConsumer(queue);
consumer.MessageListener = new MessageListener(OnMessage);
connection.Start();
while (true)
{
Console.WriteLine("Waiting for messages....");
Thread.Sleep(1000);
}
}
static void OnMessage(IMessage msg)
{
Console.WriteLine(msg);
}
static void OnException(Exception ex)
{
Console.WriteLine(ex);
}
}
I'll put the answer up in the hope that it saves someone the time it wasted for me.
You need to use an unmanaged client connection in order to connect up an exception listener to your connection.
connectionFactory.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT_UNMANAGED);
If it's just worked in Unmanaged mode, then it's a bug at XMS .NET v2.0.0.5. It should work in Managed mode also (XMSC.WMQ_CM_CLIENT_MANAGED). Please move to the latest fix pack and test again.

Resources