Saturday, January 23, 2021

400 Bad Request / request header or cookie too large / nginx

 You see this error display on your web browser when you are navigating to some site.




To fix it, you need to delete the cookies specific to the website your trying to open.

In Chrome, click the three verticle dots on the top-right corner and select Settings.


Scroll down to the Privacy and security section and click on the Cookies and other site data.


In the new window, click on See all cookies and site data


Find your website, open it and remove all the cookies.

-----------------------------------------------------------------------------------------------------------------



If you have ever asked the questions below, you will benefit from reading this book.
What is the meaning of life?
Why do I have to suffer?
How can I have the life I like to have?
How can I be the person I want to be?
How can I have good and harmonious relations with others?

What is the true meaning of spiritual practice?  Check it out here. 

Friday, January 15, 2021

sftp in Java

 The code below shows how to transfer a file from one machine to another via sftp.

Session session = null;
ChannelSftp sftp = null;

try {
JSch jsch = new JSch();
session = jsch.getSession(username, remoteIPAddress);
session.setPassword(password);
session.setConfig("StrictHostKeyChecking", "no");
session.connect();

com.jcraft.jsch.Channel channel = session.openChannel("sftp");
channel.connect();
sftp = (ChannelSftp) channel;

//Get a file from a remote machine
String path = sftp.pwd(); //remote path

//If the file is located in a different directory, switch to that directory
sftp.cd("<the path>");
sftp.get("<the file>", "<local directory where you want the file to be>");

//Send a file to a remote machine
sftp.lcd("<local directory that has the file>"); 
sftp.put("<file name>", ".");
sftp.exit();
sftp.disconnect();
session.disconnect():

} catch (JSchException je) {
Log.instance().error(je);
System.out.println("Failed to restart rx30css for the store.");
}

-----------------------------------------------------------------------------------------------------------------



If you have ever asked the questions below, you will benefit from reading this book.
What is the meaning of life?
Why do I have to suffer?
How can I have the life I like to have?
How can I be the person I want to be?
How can I have good and harmonious relations with others?

What is the true meaning of spiritual practice?  Check it out here. 

Execute multiple commands one after another in Java


Let's say you want to execute the commands below on a remote Linux machine using a java program to restart program A.

cd /home/projectA
/home/projectA/stopProgramA
/home/projectA/startProgramA

You can use the code below to get them done.

JSch jsch = new JSch();
session = jsch.getSession(username, remoteIPAddress);
session.setPassword(password);
session.setConfig("StrictHostKeyChecking", "no");
session.connect();

ChannelExec channelExec = (ChannelExec) session.openChannel("exec");
channelExec.setCommand("cd /home/projectA && /home/projectA/stopProgramA && /home/projectA/startProgramA");

channelExec.setErrStream(System.err);
channelExec.connect();

TimeUnit.SECONDS.sleep(10);
channelExec.disconnect();
channelExec = null;

          session.disconnect();

-----------------------------------------------------------------------------------------------------------------



If you have ever asked the questions below, you will benefit from reading this book.
What is the meaning of life?
Why do I have to suffer?
How can I have the life I like to have?
How can I be the person I want to be?
How can I have good and harmonious relations with others?
What is the true meaning of spiritual practice?  Check it out here.