Spring boot + Websockets : Connection getting closed by itself.

Problem : Getting the message “Websocket already in CLOSED or CLOSING state” from browser console after sending the first message.

Reason: The packet size is larger than the one set for Text/Binary message on Spring WebSocket handler.

Fix: Increase size limit for individual packages/frames in the Spring handler –

 

 @Override
    public void afterConnectionEstablished(WebSocketSession session) throws Exception {
        session.setTextMessageSizeLimit(Integer.MAX_VALUE);
        session.setBinaryMessageSizeLimit(Integer.MAX_VALUE);
        log.info("Connection established");
    }

Fixed : “Json Array should begin with [” error on UTF-8 or UTF-16 files

Problem : JSON file which store top level JSON arrays just wouldn’t parse (using org.json library), and gives out an error message like – “Json Array should begin with [ …..”. Editors like Vim or Gedit or IntelliJ show no errors (or any character before “[” )in these files.

Reason :  Byte order marker character is prefixed to the file content (this was probably added when I converted the files from UTF-16 to UTF-8).

Fix:

  1. Open the file in Vim.
  2. Run command-   :set nobomb
  3. save and exit. (:wq)

Bash on VNC session – Tabs do not auto complete

Problem : Pressing Tab keys not auto-completing when using Bash within a VNC session (to guest VM running on Ubuntu and XFCE.)

Reason : Unknown, possibly tabs are caught and consumed by the window switch handler.

Fix:

  1. vi ~/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-keyboard-shortcuts.xml
  2. search for
    • <property name=”&lt;Super&gt;Tab” type=”string” value=”switch_window_key”/>
  3. Change the above line to –
    • <property name=”&lt;Super&gt;Tab” type=”empty”/>
  4. Reboot the machine.

Reference : https://ubuntuforums.org/archive/index.php/t-1771058.html

Fix: Unable to connect to RabbitMQ server from remote clients

Problem : When connected from a remote client, this error is thrown (at client) – An unexpected connection driver error occured (Exception message: Socket closed)

Reason : As per default settings, the default user (“guest”) can access only from localhost (or Loop back IP).

Fix: Remove “guest” user from “loopback_users”. This is how –

sudo vi /etc/rabbitmq/rabbitmq.config # create new file if in Ubuntu
[{rabbit, [{loopback_users, []}]}].   # Add this line, save and quit vim.

sudo rabbit-server restart # this mostly fails. So we grep & kill in next steps.

ps auxx|grep rabbitmq # gives multiple processes

kill -9 3099 3288 3289 10263 # process-Ids are place holders

sudo rabbitmq-server start

Should be able to connect from remote clients now.

Increase Zuul timeouts for backend BOSH or Comet servers

This is how I could make Spring Zuul work with my backend XMPP (over BOSH) server which had a hanging post of 5 mins.
Please find the relevant settings in application.yml here –

 

zuul:
  add-host-header: true
  host:
   connect-timeout-millis: 5000
   socket-timeout-millis: 601000

hystrix:
 command:
   default:
     execution:
       isolation:
         thread:
           timeoutInMilliseconds: 601000
   xmppServer:
     execution:
       timeout:
         enabled: false;

ribbon:
 eureka:
   enabled: false
xmppServer:
 ribbon:
   ReadTimeout: 601000
   ConnectTimeout: 601000

MySQL Data migration from one server box to another

 

Here’s a quick way to move data from one MySQL server to another

Let source box be ServerOne, and the target box be ServerTwo. (user-names and schema names are indicative) –

  1. On ServerOne,
    1. mysqldump -u username -p db_name > data-dump.sql  (provide password when asked)
    2. scp data-dump.sql serverTwoUsername@ServerTwo:~/
  2. On ServerTwo
    1. mysql -u username -p
    2. create schema schema-name;
    3. exit
    4. mysql -u username -p -h localhost schema-name < data-dump.sql
    5. verify
      1. mysql -u username -p
      2. use schema-name;
      3. show tables;

Should be done.

Fix : Cassandra not accessible from outside the local machine.

Problem: In Single node setup of cassandra, after installation and starting Cassandra, the native port (9042) is not accessible from outside the local box.

Reason : By default Cassandra binds to the loopback IP or localhost.

Fix:


sudo vi /etc/cassandra/cassandra.yaml

# Comment out below line
#listen_address: localhost

# Uncomment below lines
listen_interface: eth0
listen_interface_prefer_ipv6: false

#Comment out below line
# rpc_address: localhost

#Uncomment below lines
rpc_interface: eth0
rpc_interface_prefer_ipv6: false

seeds: "127.0.0.1,192.168.14.49" #Added the LAN address after a comma


Install Artefactory Maven repository on Ubuntu 16.04

 

Follow these steps to install Artifactory Maven repository on Ubuntu 16.04 ( terminal commands, mostly )-

  1. wget -c -O- “https://bintray.com/user/downloadSubjectPublicKey?username=jfrog” | sudo apt-key add –
  2. echo “deb https://bintray.com/artifact/download/jfrog/artifactory-debs xenial main” | sudo tee -a /etc/apt/sources.list.d/artifactory-oss.list
  3. sudo apt-get update
  4. sudo apt-get -y install jfrog-artifactory-oss
  5. Set credentials of DB accounts after running –
    1. sudo /opt/jfrog/artifactory/bin/configure.mysql.sh

Refer : https://hostpresto.com/community/tutorials/how-to-install-jfrog-artifactory-on-ubuntu-14-04/

After installation, launch the Artefactory portal. Then –

  1. From Security Configuration page, remove Anonymous access (untick the checkbox).
  2. Also scroll down and activate password Encryption.
  3. Create a new user (Eg, “developer”), as the existing user is Admin, and granular permissions cannot be added to it. Also for some reason, unless we add permissions for Manage, Overwrite, Read etc individually, the Artefactory would continue to respond with 401 for any request.
  4. Logout Admin, and login as the user created in above step.
  5. Go to user profile by click on users name on top right corner, and unlock the page by entering the user’s password again.
  6. Scroll down and view the encrypted password by click on the “eye” icon adjacent to it. Note this down.
  7. From Home page, click on repository “libs release”. Unlock credentials in this panel by entering the user’s  password again.
  8. Click and “Generate Maven Settings”, and download the maven settings file.
  9. Edit Maven Settings file –
    1. Change parameterized username to username of the user (eg, developer)
    2. Change parameterized password to just the encrypted password (obtained at step 6)
    3. Save the file, and move it to /[user-home]/.m2/settings.xml
  10. Test the above setup by running “mvn deploy” on any of the maven project you have.