Tuesday, December 31, 2019

Cannot Get Mail. The mail server imap.gmail.com is not responding in iPhone

I was trying to send an email to a friend and saw this message popped up on my iPhone screen.

Cannot Get Mail. The mail server imap.gmail.com is not responding. Verify that you have entered the correct account info in Mail settings.

The problem was due to that I had changed the password of my email account and the iPhone cannot connect to my email server with the old password.

To fix the problem, all you need to do is to open the Settings -> Passwords & Accounts -> Your email account, and it will ask you to enter your password.

If that does not work for you, simply remove the email account and re-add it to your iPhone.

-----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.

Thursday, December 12, 2019

NetBeans: java.nio.file.AccessDeniedException thrown when copying jars to your library

After you have your coding done, you do a Clean and Build, and you see the following error message in your Output pane.

Copy libraries to C:\MyProjects\lib.
Attempt to copy C:\dynamicreports-3.2.0\lib\xalan-2.7.1.jar to C:\MyProjects\lib\xalan-2.7.1.jar using NIO Channels failed due to 'C:\MyProjects\lib\xalan-2.7.1.jar'.  Falling back to streams.
C:\MyProjects\nbproject\build-impl.xml:1212: The following error occurred while executing this line:
C:\MyProjects\nbproject\build-impl.xml:1035:
java.nio.file.AccessDeniedException: C:\MyProjects\lib\xalan-2.7.1.jar
at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:83)
at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:102)
at sun.nio.fs.WindowsFileSystemProvider.newByteChannel(WindowsFileSystemProvider.java:230)
at java.nio.file.spi.FileSystemProvider.newOutputStream(FileSystemProvider.java:434)
at java.nio.file.Files.newOutputStream(Files.java:216)
at org.apache.tools.ant.util.FileUtils.newOutputStream(FileUtils.java:1721)
at org.apache.tools.ant.types.resources.FileResource.getOutputStream(FileResource.java:267)
at org.apache.tools.ant.types.resources.FileResource.getOutputStream(FileResource.java:241)
at org.apache.tools.ant.util.ResourceUtils.getOutputStream(ResourceUtils.java:791)
at org.apache.tools.ant.util.ResourceUtils.copyUsingStreams(ResourceUtils.java:765)
at org.apache.tools.ant.util.ResourceUtils.copyResource(ResourceUtils.java:435)
at org.apache.tools.ant.util.FileUtils.copyFile(FileUtils.java:565)
at org.apache.tools.ant.util.FileUtils.copyFile(FileUtils.java:525)
at org.apache.tools.ant.util.FileUtils.copyFile(FileUtils.java:486)
at org.apache.tools.ant.util.FileUtils.copyFile(FileUtils.java:449)
at org.apache.tools.ant.util.FileUtils.copyFile(FileUtils.java:415)
at org.apache.tools.ant.util.FileUtils.copyFile(FileUtils.java:390)
at org.apache.tools.ant.util.FileUtils.copyFile(FileUtils.java:328)
at org.netbeans.modules.java.j2seproject.copylibstask.CopyLibs.execute(CopyLibs.java:218)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor172.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
at org.apache.tools.ant.Task.perform(Task.java:350)
at java.util.Vector.forEach(Vector.java:1275)
at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:67)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor172.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
at org.apache.tools.ant.Task.perform(Task.java:350)
at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:391)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor172.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
at org.apache.tools.ant.Task.perform(Task.java:350)
at org.apache.tools.ant.Target.execute(Target.java:449)
at org.apache.tools.ant.Target.performTasks(Target.java:470)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1388)
at org.apache.tools.ant.Project.executeTarget(Project.java:1361)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:261)
at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:574)
at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:128)

To fix this problem, do one of the following.

1. Change the accessibility of your library folder.
     Right-click on the folder and select Properties. In the pop-up window, select the Security tab.               Select each group of users, click the Edit button to change their permission to access this folder.
2. Run your NetBeans as Administrator.
    Righ-click on your NetBeans icon and select Run as administrator.
3. Remove all the unused jar files from the lib directory.

-----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.

Tuesday, December 10, 2019

NetBeans: warning: [options] bootstrap class path not set in conjunction with -source 1.7

When you do a Clean and Build, you see this message in the Output window:

Compiling 1 source file to C:\MyProjects\MyJava\build\classes
warning: [options] bootstrap class path not set in conjunction with -source 1.7
1 warning

This means that you are using a Java version as sources in this project, which is different from the Java Platform of your NetBean.

To remove the warning:

1. Right-click on the project in the Porjects window and select Properties.

2. Select Libraries from the Categories in the popup window, look for what is set as your Java Platform on the top of the right-side panel.

3. Select Sources under the Categories.

4. In the right-side panel, set the Source/Binary Format to the Java version used by your Java Platform.

5. Click the OK button and recompile your project.



-----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.

Thursday, December 5, 2019

javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated

javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
        at sun.security.ssl.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:450)


This exception happens when the client cannot validate the certificate sent by the server during handshaking.


To fix this problem

1. If you are using a self-signed certificate, get the certificate from the server and click HERE to see the steps and sample code to make it work. If a certificate is not issued by any of the Certificate Authorities (CA), it is a self-signed certificate.

2. Check if your certificate is expired.

3. The client is using an old encryption protocol that is not supported by the server. You can force the client to use the TLSv1.2 protocol.

      SSLContext sc = SSLContext.getInstance("TLSv1.2");

-----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.



javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake

javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
        at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:994)
        at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1367)
        at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1395)
        at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1379)
     
Caused by: java.io.EOFException: SSL peer shut down incorrectly
        at sun.security.ssl.InputRecord.read(InputRecord.java:505)
        at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:975)


This exception happens when the client cannot validate the certificate sent by the server during handshaking.

To fix this problem, get the certificate from the server and click HERE to see the steps and sample code to make it work.

-----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.

java.net.ConnectException: Connection refused (Connection refused)

java.net.ConnectException: Connection refused (Connection refused)
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
        at java.net.Socket.connect(Socket.java:607)
        at java.net.Socket.connect(Socket.java:556)
        at java.net.Socket.<init>(Socket.java:452)
        at java.net.Socket.<init>(Socket.java:262)


This error occurs when the client cannot reach the server.

1. The server is down.
2. You are using a wrong IP address.
3. The server is not listening on the port.
4. Firewall or proxy blocks the connection.

-----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.



SSL/TLS handshake and Java



SSL (Secure Socket Layer) was first released in 1999. It was deprecated since Java 8u31 and renamed to TLS (Transaction Layer Security) due to its deficiency in handling padding attacks, it checks only the padding length but not the value.

TLS has two subprotocols: Handshake and Record Protocol.

The Handshake process establishes the common cryptographic parameters such as the encryption protocol and cipher to be used by both the server and the client.

The Record Protocol defines the rule for breaking down the data into blocks (packets), encrypt and decrypt them.

During  handshaking, thclient sends to the server the protocol and ciphers it supports. The server then chooses the protocol and the cipher to be used. The server has a list of supported ciphers and chooses the first one in priority supported by the client. If there is no cipher in common, the handshake fails. The protocol and cipher are suggested by client but chosen by the server.

An SSL/TLS connection succeeds only if the client trusts the server. After the protocol and cipher are chosen, the server sends the client its certificate. The client will trust the server only if it can trace the certificate to a root certificate, which is known as chain validation. 

Then, the server and the client exchange their public keys and generate the session key or master key. If the ending messages of the handshaking are successfully encrypted and decrypted by both sides, the handshaking is complete.

Since Java 8u151, the Java Cryptography extension, JCE, is bundled in the JDK. Java JCE is a framework for encryption, key generation, key agreement and message authentication code (MAC). 

From Java 8 onward, the default encryption protocol version is TLSv1.2 which is backward compatible. 

-----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.




Wednesday, December 4, 2019

SSL/TLS: Use a self-signed certificate in Java client for secure socket connection

A certificate not issued by any known Certificate Authorities (CA) but rather by the server hosting the certificate is a self-signed certificate. The root certificate for such a self-signed certificate is absent in the client's certificate store, which causes the chain validation failure.

After receiving your self-signed certificate mycert.crt, follow these steps to create your java client.

1. Import the self-signed certificate into your java truststore.

Your java truststore, cacerts, is located in $JAVA_HOME/jre/lib/security. Copy the cacerts to the location you want it to be. The password of the truststore is changeit

The cacerts bundled with the java JDK contains the root certificates for Certificate Authorities (CA) that issue certificates such as GoDaddy, Verisign, Network Solutions, and others. We will need these root certificates to establish the trust between the client and the server.

Open the Command Prompt and use the following command to import the mycert.crt into the cacerts truststore.

       keytool -import -v -trustcacerts -file mycert.crt -alias mycert -keystore cacerts
 
       Enter keystore password: changeit
     
       . . . . . .

       Trust this certificate? [no]: yes
       Certificate was added to keystore
       [Storing cacerts]

2. Create the java client using the truststore

public class TLSClient {

    public static void main(String[] args) throws IOException, KeyStoreException, NoSuchAlgorithmException, CertificateException, UnrecoverableKeyException, KeyManagementException {

        System.setProperty("javax.net.ssl.trustStore", "cacerts");
        System.setProperty("javax.net.ssl.keyStorePassword", "changeit");

        out.println("Load the keystore...");
        KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());

        try (FileInputStream readCert = new FileInputStream("./cacerts")) {
            ks.load(readCert, "changeit".toCharArray());
        }

        out.println("Initialize the KeyManagerFactory...");
        KeyManagerFactory kmf = KeyManagerFactory.getInstance(
                KeyManagerFactory.getDefaultAlgorithm());
        kmf.init(ks, "changeit".toCharArray());

        out.println("Create a trust manager...");
        TrustManagerFactory tmf = TrustManagerFactory.getInstance(
               TrustManagerFactory.getDefaultAlgorithm());
        tmf.init(ks);

        //Initialize the SSLContext
        out.println("Get the SSLContext...");
        SSLContext sc = SSLContext.getInstance("TLS");

        out.println("Initialize the SSLContext...");
        sc.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);

        out.println("create socket...");
        SSLSocketFactory factory = sc.getSocketFactory();
        try(SSLSocket clientSocket = (SSLSocket) factory.createSocket(getByName("<server IP address>"), <server port>)){

            //debug
            SSLSession session = clientSocket.getSession();
            Certificate[] cchain = session.getPeerCertificates();
            out.println("The Certificates used by peer");
            for (Certificate cchain1 : cchain) {
                out.println(((X509Certificate) cchain1).getSubjectDN());
            }
            out.println("Peer host is " + session.getPeerHost());
            out.println("Cipher is " + session.getCipherSuite());
            out.println("Protocol is " + session.getProtocol());
            out.println("ID is " + new BigInteger(session.getId()));
            out.println("Session created in " + session.getCreationTime());
            out.println("Session accessed in " + session.getLastAccessedTime());
            //finish debug

            out.println("Sucessfully connected!!!");
            //Use the clientSocket to communicate with the server now
        }
    }
}

If the code executes fine, it prints the output below:

Load the keystore...
Initialize the KeyManagerFactory...
Create a trust manager...
Get the SSLContext...
Initialize the SSLContext...
create socket...
The Certificates used by peer
O=Default Company Ltd, L=Default City, C=XX
Peer host is <server IP address>
Cipher is TLS_RSA_WITH_AES_256_CBC_SHA256
Protocol is TLSv1.2
ID is -20222101607659081628530787401436194355856927161855171792439103526019628250528
Session created in 1575480427055
Session accessed in 1575480427235
Sucessfully connected!!!
           
-----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.




Tuesday, November 26, 2019

javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake

When you are trying to connect your client to your server via SSL/TLS connection, you received the following exception.

javax.net.ssl.SSLException: Connection has been shutdown: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
at sun.security.ssl.SSLSocketImpl.checkEOF(Unknown Source)
at sun.security.ssl.SSLSocketImpl.checkWrite(Unknown Source)
at sun.security.ssl.AppOutputStream.write(Unknown Source)
at org.apache.http.impl.io.AbstractSessionOutputBuffer.flushBuffer(AbstractSessionOutputBuffer.java:131)
at org.apache.http.impl.io.AbstractSessionOutputBuffer.flush(AbstractSessionOutputBuffer.java:138)
at org.apache.http.impl.conn.LoggingSessionOutputBuffer.flush(LoggingSessionOutputBuffer.java:95)

. . . . . .

Caused by: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.writeRecord(Unknown Source)
at sun.security.ssl.AppOutputStream.write(Unknown Source)

. . . . . .

Caused by: java.io.EOFException: SSL peer shut down incorrectly
at sun.security.ssl.InputRecord.read(Unknown Source)


This exception occurs when the client and the server cannot agree on a version of the encryption protocol to use. At the beginning of the handshaking, the client sends the sever a message indicating what protocol it is ready to support, if by default the server does not support this protocol, the server will close the connection.

To fix this problem, add the following line to your code, which includes the protocol the client uses.

((SSLServerSocket) serverSocket).setEnabledProtocols(new String[]{"TLSv1", "TLSv1.1", "TLSv1.2", "SSLv3"});

or 
System.setProperty(“https.protocols”, “TLSv1,TLSv1.2,TLSv1.1,SSLv3”);

And make sure that your client code does not call the startShakeHand method after the client socket is created.
-----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.



Thursday, November 21, 2019

javax.net.ssl.SSLException: Unsupported record version Unknown-0.20

After you started your server and client are connected, you try to read data and you see the following exception.

javax.net.ssl.SSLException: Unsupported record version Unknown-0.20
        at sun.security.ssl.InputRecord.checkRecordVersion(InputRecord.java:552)
        at sun.security.ssl.InputRecord.readV3Record(InputRecord.java:565)
        at sun.security.ssl.InputRecord.read(InputRecord.java:529)
        at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:975)
        at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1367)
        at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:931)
        at sun.security.ssl.AppInputStream.read(AppInputStream.java:105)

To fix this exception:

1. Check if both the server and the client are connecting through SSL/TLS. If one end is using SSL/TLS and the other side is not, it will throw such an exception.

2. Make sure that both sides are using the same encryption protocol such as TLSv1, TLSv1.1, TLSv1.2,  or SSLv3. When you transmit using an SSL/TLS Socket, it calls a formatting and encryption routine to create the encrypted packet. It then calls the plain sockets layer to transfer the encrypted packet to the server. The server's sockets layer receives the packet and then calls the SSL/TLS package to decrypt the packet. If the packet doesn't fit the SSL/TLS format, you get the unsupported version exception.

3. The version of java you are using supports the encryption protocol.

-----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.

Tuesday, November 12, 2019

javax.net.ssl.SSLHandshakeException: no cipher suites in common

The exception:

javax.net.ssl.SSLHandshakeException: no cipher suites in common
        at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
        at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1946)
        at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:316)
        at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:306)
        at sun.security.ssl.ServerHandshaker.chooseCipherSuite(ServerHandshaker.java:1127)
        at sun.security.ssl.ServerHandshaker.clientHello(ServerHandshaker.java:814)
        at sun.security.ssl.ServerHandshaker.processMessage(ServerHandshaker.java:221)
        at sun.security.ssl.Handshaker.processLoop(Handshaker.java:1037)
        at sun.security.ssl.Handshaker.process_record(Handshaker.java:965)
        at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1064)
        at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1367)
        at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:931)
        at sun.security.ssl.AppInputStream.read(AppInputStream.java:105)

The solution:

Add these two lines of code before getting the SSLServerSocketFactory.

System.setProperty("javax.net.ssl.keyStore", <yourKeyStoreLocation>);
System.setProperty("javax.net.ssl.keyStorePassword", <yourKeyStorePasswork>);

-----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.

Wednesday, August 21, 2019

Microsoft Office Word 2016: Remove frame from a paragraph

You have a document looks like the one below, and you want to remove the frame from the paragraph,


1. Click anywhere in the frame, then click at the Design in the top menu.



2. select Page Borders from the toolbar.



3. Select the Borders tab in the popped-up Borders and Shading window. Then click on the None icon to select it and choose Paragraph in the Appy to drop-down list. finally, click the OK button.


-----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.

Thursday, August 15, 2019

Java 8: default methods, static methods, and their differences

Before Java 8, an interface can only have abstract methods. Starting Java 8, you can add default and static methods with executable method bodies. This change allows you to add new methods to an interface without affecting any of the many classes that have already implemented the interface.

Default Method

For example, you have a TestFace interface that are implemented by SportCenter1 and SportCenter2.

public interface TestFace {
      public boolean ableToRun(Person p);
}


public class SportCenter1 implement TestFace {
      private List<Person> memberList = <your member list>;

      public boolean ableToRun(Person p) {
            if (p.getForwardMoveSpeed() > 10) {
                  return true;
            }
            return false;
      }

      public List<Person> getRunnableMembers() {
            public List<Person> runnableMembers = memberList.stream()
                          .filter(p -> ableToRun(p))
                          .sort(Comparator.comparing(Person::getName))
                          .collect(Collectors.toList());

            return runnableMembers;
      }
}


public class SportCenter2 implement TestFace {
      private List<Member> memberList = <your member list>;

      public boolean ableToRun(Member p) {
            if (p.getMaxMoveDistance() > 5) {
                  return true;
            }
            return false;
      }

      public List<Member> getRunnableMembers() {
            public List<Member> runnableMembers = memberList.stream()
                          .filter(p -> ableToRun(p))
                          .sort(Comparator.comparingInt(Person::getAge))
                          .collect(Collectors.toList());

             return runnableMembers;
      }
}

Now, you have a new customer, SportCenter3, who wants to know if their members are able to swim. If you add an abstract method, ableToSwim, to the TestFace interface, you have to modify the code of SportCenter1 and SportCenter2 to make them compatible to the changed interface. Here, the default method came in handy. It provides you the backward compatibility to old code. Your modified interface can look like below, and it will not affect the SportCenter1 and SportCenter2 at all. It is especially convenient if there are a large number of classes using the interface.


public interface TestFace {
      public boolean ableToRun(Person p);

      public default boolean ableToSwim(Person p) {
            return true;
      }
}


public class SportCenter3 implement TestFace {
      private List<Person> memberList = <your member list>;

      public boolean ableToRun(Person p) {
            if (p.ableToRun() && p.ableToClimeMountain()) {
                  return true;
            }
            return false;
      }

     //optional to override the default method in the interface
      public boolean ableToSwim(Person p) {
            if (p.passedSwimmingTest()) {
                  retrun true;
            }
            return false;
      }
}

If your class implementing multiple interfaces and more than one interface have the same default method signature, your implementing class should explicitly specify which default method it is using or override this default method.

Static Method

A static method is another way to add a method to an interface without affecting its implementing children.

public interface TestFace {
      public boolean ableToRun(Person p);

      public default boolean ableToSwim(Person p) {
            return true;
      }

      public static void incrementAge(Person p) {
            p.setAge(p.getAge() + 1);
      }
}

Difference between Default Method and Static Method

1. While a default method can be override by implementing classes, static method cannot be overridden.

2. Static methods belong only to the interface and can only be called from the interface class, while default methods can be invoked from instances of both the interface and implementing classes.

-----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.

References:
1. Difference Between static and default methods in interface
2. Default Methods In Java 8
3. Java 8 Interface Changes – default method and static method

Wednesday, August 14, 2019

Java 8: Method Reference

Method Reference is a shorthand notation of Lambda Expression.

For example, you want to add an ActionListener to a JButton actButton.

Before Java 8:

actButton.addActionListener(new ActionListener () {
      public void actionPerformed(ActionEvent e) {
            searchButton.requestFocusInWindow();
      }
});


Use Lambda Expression:

actButton.addActionListener((ActionEvent e) -> {
      searchButton.requestFocusInWindow();
});


Use Method Reference:

actButton.addActionListener(searchButton::requestFocusInWindow());

If the method you are referencing is a member of the current class, it is also known as Memeber Reference.

For example, you are working in a class that is a subclass of the JFrame. After you have done some modification of the GUI, you want to call the pack() method.

javax.swing.SwingUtilities.invokeLater(new Runnable() {
      public void run() {
            this.pack();
      }
}


Use Memeber Reference:

javax.swing.SwingUtilities.invokeLater(this::pack());

The method called in Method Reference can be ordinary instance member of a class as shown in our above examples, a static method of a class, or even a constructor of a class, as long as the signature of the method exactly matches the method in the functional interface.

To reference a static method:

javax.swing.SwingUtilities.invokeLater(ResultCalss::print());

It requires the signature of the method print() matches the signature of the run() method in the Runnable interface.

-----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.

Reference:
Method References in Java 8


Friday, August 9, 2019

NetBeans: Migrate from an early JDK to Java 8 or a later version

After you have updated the Java platform from an earlier version to Java 8 or a later version, you want to convert the old java code to one with the new features of the newly added Java version.

Of course, you can check your code line by line to convert it manually. However, you can use the NetBeans built-in feature to perform this, which will save you a lot of time and effort.

1. Click the Refactor in the top menu of the NetBeans IDE, and choose Inspect and Transform/



2. In the Inspect and Transform window, select a project you want to refactor from the drop-down list next to the Inspect label.



3. While the Configuration is checked, select the target JDK you will convert to from the drop-down list next to the Configuration label. Then, click the Inspect button.



4. If the below window pops up, click the Inspect button again to continue.



5. In the Refactoring window, click the upward arrow with the notation "Previous Occurrence" on the left column of the window to view the suggestions of code changes.



6. Use the upward and downward arrows on the left column to view all the changes. If all look OK, click the Do Refactoring button.


-----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.

Wednesday, July 10, 2019

Solved - org.postgresql.util.PSQLException: ERROR: could not set permissions on directory

I had the following error when I was using my postgresql database.

org.postgresql.util.PSQLException: ERROR: could not set permissions on directory "/var/lib/pgsql/9.5/tablespace/postgresql": Operation not permitted
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2310)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2023)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:217)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:421)
at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:318)
at org.postgresql.jdbc.PgStatement.executeUpdate(PgStatement.java:294)

It turned out that no matter which user is logged in the posgresql database, the database server uses the posgres to set the permission on directories when creating table space.

User postgres should be the owner of the directory that you set for the table space.

----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.

Solved - ClassNotFoundException: org.postgresql.util.PSQLException

When I was launching my program, I got the following error.

Exception in thread "main" java.lang.NoClassDefFoundError: org/postgresql/util/PSQLException
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Class.java:2615)
        at java.lang.Class.getMethod0(Class.java:2856)
        at java.lang.Class.getMethod(Class.java:1668)
        at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
        at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
Caused by: java.lang.ClassNotFoundException: org.postgresql.util.PSQLException
        at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:358)

It was fixed by adding the database driver (postgresql-9.4.1209.jre7.jar) to the execution path.

-----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.

Thursday, May 23, 2019

403 Access Denied when opening the Manager App

After you installed the Apache Tomcat server and successfully launched the <host>:8080 web page, you click on the Manager App button, and you get a 403 Access Denied message.

To fix it

1. Open the $CATALINA_BASE/conf/tomcat-users.xml file and add the following to the <tomcat-users> section.

          <user username="admin" password="goanywhere" roles="admin-gui,manager-gui" />

2. If you are accessing the Tomcat server from a remote computer, open or create the file: $CATALINA_BASE/conf/Catalina/localhost/manager.xml, and add the below to the file.

          <Context privileged="true" antiResourceLocking="false"
                    docBase="${catalina.home}/webapps/manager">
                    <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="^.*$" />
         </Context>

3. Restart the tomcat server: sudo systemctl restart tomcat.service

-----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.