Skip to content

Commit bc58db5

Browse files
committed
1 parent 6acb016 commit bc58db5

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

Diff for: src/docs/asciidoc/appendices/connectionproperties/connectionproperties.adoc

+6-1
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,16 @@ Attempts to create a database if it does not exist.
305305
See <<ref-create-database-if-not-exist>> for more information.
306306

307307
a|`reportSQLWarnings`
308-
a|Jaybird specific property ([.since]_Jaybird 6_)
308+
a|Jaybird specific property ([.since]_Jaybird 6_).
309309
Possible values (case-insensitive): `ALL` (default), `NONE`.
310310
Can be used to disable reporting of ``SQLWarning``s.
311311
See <<ref-report-sql-warnings>> for more information.
312312

313+
a|`socketFactory`
314+
a|Jaybird specific property ([.since]_Jaybird 6_).
315+
Sets a custom socket factory for pure Java connections.
316+
See <<ref-socket-factory>> for more information.
317+
313318
|===
314319

315320
In addition, Jaybird allows using arbitrary Database Parameters Block entries as connection properties (provided they are defined in Jaybird's `DpbItems` and `SpbItems` ([.since]_Jaybird 5_), or `ISCConstants` ([.until]_Jaybird 5_)).
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
[#ref-socket-factory]
2+
=== Custom socket factory
3+
4+
[.since]_Jaybird 6_
5+
6+
A custom socket factory can be specified to customize the creation of the `java.net.Socket` instance of a pure Java database or service connection.
7+
8+
The connection property `socketFactory` accepts the class name of an implementation of `javax.net.SocketFactory`.
9+
This socket factory is created anew for each connection.
10+
If `socketFactory` is not specified, Jaybird will use `SocketFactory.getDefault()` as its factory.
11+
12+
The `SocketFactory` implementation must adhere to the following rules:
13+
14+
- The class must have a public constructor accepting a `java.util.Properties` object, or a public no-arg constructor.
15+
- The implementation of `SocketFactory#createSocket()` must return an unconnected socket;
16+
the other `createSocket` methods are not called by Jaybird.
17+
+
18+
If you don't want to implement the other `createSocket` methods, we recommend throwing `java.lang.UnsupportedOperationException` with a clear message from those methods.
19+
20+
It is possible to pass custom connection properties to the socket factory if it has a public single-arg constructor accepting a `Properties` object.
21+
Jaybird will instantiate the socket factory with a `Properties` object containing _only_ the connection properties with the suffix `@socketFactory` and non-``null`` values;
22+
non-string values are converted to string.
23+
In the future, we may also -- selectively -- pass other connection properties, but for now we only expose those properties that are explicitly set for the socket factory.
24+
25+
For example, say we have some custom socket factory called `org.example.CustomProxySocketFactory` with a `CustomProxySocketFactory(Properties)` constructor:
26+
27+
[source,java]
28+
----
29+
var props = new Properties()
30+
props.setProperty("user", "sysdba");
31+
props.setProperty("password", "masterkey");
32+
props.setProperty("socketFactory", "org.example.CustomProxySocketFactory");
33+
props.setProperty("proxyHost@socketFactory", "localhost");
34+
props.setProperty("proxyPort@socketFactory", "1234");
35+
props.setProperty("proxyUser@socketFactory", "proxy-user");
36+
props.setProperty("proxyPassword@socketFactory", "proxy-password");
37+
38+
try (var connection = DriverManager.getConnection(
39+
"jdbc:firebird://remoteserver.example.org/db", props)) {
40+
// use connection
41+
}
42+
----
43+
44+
This will create the specified socket factory, passing a `Properties` object containing *only* the four custom properties ending in `@socketFactory`.
45+
The other properties -- here `user`, `password` and `socketFactory` -- are *not* passed to the socket factory.
46+
47+
See also https://github.com/FirebirdSQL/jaybird/blob/master/devdoc/jdp/jdp-2024-09-custom-socket-factory-for-pure-java-connections.adoc[jdp-2024-09: Custom socket factory for pure Java connections]

Diff for: src/docs/asciidoc/reference/reference.adoc

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ include::connection/clientinfoproperties.adoc[]
2828

2929
include::connection/createdatabaseifnotexist.adoc[]
3030

31+
include::connection/socketfactory.adoc[]
32+
3133
[[ref-statement]]
3234
== Statement reference
3335

0 commit comments

Comments
 (0)