20 Kasım 2016 Pazar

java.sql.SQLException: Your password has expired. To log in you must change it using a client that supports expired passwords.

*** To clarify the issue, I can give the reason that causes this exception of MySQL (https://dev.mysql.com/doc/refman/5.7/en/password-expiration-policy.html);

"From MySQL 5.7.4 to 5.7.10, the default default_password_lifetime value is 360 (passwords must be changed approximately once per year). For those versions, be aware that, if you make no changes to the default_password_lifetime variable or to individual user accounts, all user passwords will expire after 360 days, and all user accounts will start running in restricted mode when this happens. Clients (which are effectively users) connecting to the server will then get an error indicating that the password must be changed: ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement."
*** How can we handle it;
Open the terminal, reach the directory that has mysql.exe (usually at C:\Program Files\MySQL\MySQL Server 5.7\bin) and typed:
mysql -u root -p
After this, you will realise that you cannot use "ALTER" command to change password. Because your password is expired and actions allowed are limited on this process. Here is the solution to reset the password on this screen;
SET PASSWORD = PASSWORD('xxxxxxxx');
*** Further upgrade after reseting the password (https://dev.mysql.com/doc/refman/5.7/en/password-expiration-policy.html); 
"To avoid having such clients suddenly stop working due to a password expiring, make sure to change the password expiration settings for those clients, like this:
ALTER USER 'script'@'localhost' PASSWORD EXPIRE NEVER
Alternatively, set the default_password_lifetime variable to 0, thus disabling automatic password expiration for all users."

18 Temmuz 2016 Pazartesi

How can it be possible that HTTP is stateless, although HTTP uses TCP protocol?

- TCP is connection-oriented, stateful and reliable.
- UDP is connectionless, stateless and unreliable.
- HTTP uses most commonly TCP protocol.

By taking information above into consideration, how can it be possible that HTTP is stateless?

* HTTP does not inherit from TCP or any other lower-level protocols used to transport itself. Using one of these protocols in transport layer doesn’t mean that HTTP becomes stateful automatically or is required to be stateful [1].

HTTP will work the same without considering a transport technology such TCP, SCTP or another protocol over HTTP;

- HTTP provides a stateful connection by using TCP, but then it makes this connection disconnect. Later on, it can connect again, if it is needed. Many different connections are created while a user browses a web-site. These connections are surely stateful, but the whole, I mean the conversation, is not, because each connection in the conversation is started and ended in a way of being independent of any other connection [2].

There is good example here about what I tell above;

" Consider the phone service to be TCP and consider your relationship with distant family members to be HTTP. You will contact them with the phone service. Each call to them would be a stateful TCP connection. However, you don't constantly stay on the phone with them, as you will disconnect and call them back again at a later time. You would certainly expect them to remember what you talked about on the last call. HTTP in itself does not do that, but it is rather a function of the web server that maintains the state of the overall conversation." [3]

If you have a popular server that has a million hits per day, management of these hits is very important in this sense. Each hit consists of a quick connect and disconnect. However, if each user open a connection in your web-site, then it could potentially overwhelm your server.

As a result, HTTP itself is stateless without considering its transport technology. It means that applications have to implement another layer on top of HTTP to establish state. Session cookies are typically used for this reason [1].

References:
  1. http://superuser.com/a/825372
  2. http://whatis.techtarget.com/definition/stateless
  3. http://fixunix.com/tcp-ip/66544-tcp-stateful-protocol-then-why-not-http.html#post214883

18 Mayıs 2016 Çarşamba

Caused by: java.io.NotSerializableException: bean.Example

NotSerializableException is common exception type on run-time of Java web applications when Tomcat server restarts. This is due to Tomcat's default behavior of serializing all the sessions and after restart trying to deserialize them. This is the persistance feature of Tomcat server.

Caused by: java.io.NotSerializableException: bean.Example

1) In the exception above, "bean.example" is fully qualified name of class that does not implement the Serializableinterface while it is been expected by the code behind. To fix it:

package bean;

import java.io.Serializable;

public class Example implements Serializable {
   private static final long serialVersionUID = 1L;
  private DeviceManager deviceManager = new DeviceManager();
// ... }
There is another important thing that Tomcat persists sessions and all objects in each session. Hence, if there is a variable that is used to keep instance of another classses, they also should be implemented with the Serializableinterface.

2) Sometimes, finding the class that throws the exception and making it implement theSerializableinterface may not be feasible when the class belongs to a third-party library. Objects that are created from this kind of class should not be serialized, but these objects can be declared as transient. Once a field of a class is declared as transient, then, it is ignored by the serializable runtime.


package bean;

import java.io.Serializable;
import com.google.gson.*;
public class Example implements Serializable { private static final long serialVersionUID = 1L;
  private transient Object deviceInformation = null;
// ... }
3) Another solution to get rid of NotSerializableException may be disabling session persistence in Tomcat server. To disable it, find tomcat_dir/conf/context.xml and find a place where it says:

<!-- Uncomment this to disable session persistence across Tomcat restarts -->

* This solution is valid for both Tomcat 6 and Tomcat 7.
References:
  1. http://stackoverflow.com/a/11692208/1194553
  2. https://mihail.stoynov.com/2011/04/11/disable-session-persistence-in-tomcat/
  3. https://examples.javacodegeeks.com/java-basics/exceptions/java-io-notserializableexception-how-to-solve-not-serializable-exception/
  4. http://stackoverflow.com/a/1904705/1194553

22 Mart 2016 Salı

How to run Java console application as a Windows service?

I needed to run Java console application as a Windows service. When I googling, I found out two solution such as;

1) Java service wrapper such as Tanuki and YAJSW. It provides reaching the solution in a direct way. However, configuration in wrapping process is more difficult than the second solution.

2) It is a little long, but easy way. Instruction of second solution is indicated below;

  • Export Java console application project as a jar file. I used Eclipse as Java code editor that's why I made it easily.
  • Download Launch4j and convert the jar file to exe file. This program has user-friendly UI. Also, the tutorial video can be reached through this link.
  • Download NSSM - the Non-Sucking Service Manager and install the exe file as a Windows service. This link shows how to do it. Configuration is very easy, because of its GUI (Figure-1).

I use the second solution and the console application works properly as a Windows service in my computer.

11 Şubat 2016 Perşembe

Rebuild .apk file of Android project on Eclipse without run

For Mac: Eclipse -> Preferences
For Windows: Windows -> Preferences
then, Preferences -> Android -> Build.
Uncheck "Skip packaging and dexing until export or launch. (Speeds up automatic builds on file save.)"
Lastly, restart Eclipse. You will realize that when you change something on your code and save it, .apk file of your project will be updated corresponding your changes on your code.