Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Too many sockets with custom socket factory implementation with JSSE

User_I9M6GAug 26 2021 — edited Aug 26 2021

Hello,
I've implemented custom socket factory as defined in the JSSE example here: https://docs.oracle.com/javase/10/security/sample-code-illustrating-secure-rmi-connection.htm#JSSEC-GUID-2F82CCFD-22E6-4E6E-A2E1-88CF2BB19E87

When I run my applications, rmi works fine along with ssl. But, what I noticed is that too many threads/ sockets are created. Socket reuse is not happening. When looking for this problem, found out this page: https://docs.oracle.com/javase/7/docs/technotes/guides/rmi/faq.html#customsocketreuse (look for A.5), which expresses the problem with too many socket creation when using custom socket factories. When tried to override the equal and hashcode of custom socket factories, the looking up of remote object in the registry fails during unmarshalling phase. It throws an exception about the serialVersionUID of the custom client socket factory being different from the local class as below.
java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.io.InvalidClassException: ...SslClientSocketFactory; local class incompatible: stream classdesc serialVersionUID = -2466850771396148787, local class serialVersionUID = -8809708706764478887
Defining a static serialVersionUID for SslClientSocketFactory also doesn't work. Throws the same exception. The problem can be that RMI runtime internally uses RMIClientSocketFactory for getting the rmi clients for RMI calls and has a different serialVersionUID for the client socket factory.
Has anyone faced a similar problem and have a solution for this?

Comments
Post Details
Added on Aug 26 2021
0 comments
109 views