You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: sdk/docs/manually-written/sdk/component-howtos/application-development/client-libraries/java-client-libraries.rst
+9-28Lines changed: 9 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,46 +10,27 @@ guidance on how to use them. Read below to learn about their code architecture,
10
10
Overview
11
11
--------
12
12
13
-
The Java client libraries are organized in two layers:
Copy file name to clipboardExpand all lines: sdk/docs/manually-written/sdk/sdlc-howtos/applications/develop/contracts-and-transactions-in-java.rst
+66-58Lines changed: 66 additions & 58 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -43,48 +43,38 @@ Find the available versions in the `Maven Central Repository <https://search.mav
43
43
Access the gRPC Ledger API using Java bindings
44
44
----------------------------------------------
45
45
46
-
The :ref:`Java bindings reactive library <component-howtos-application-development-java-client-libraries-bindings-rxjava>` provides a set of classes that allow you to access the gRPC Ledger API.
46
+
The ``bindings-java`` library comes pre-packaged with the generated gRPC stubs allowing you to access the Ledger API.
47
47
48
-
For each Ledger API service, there is a reactive counterpart with a matching name. For instance, the reactive
49
-
counterpart of ``UpdateServiceGrpc`` is ``UpdateClient``.
50
-
51
-
The library also exposes the main interface representing a client connecting via the gRPC Ledger API. This interface is
52
-
called ``LedgerClient`` and the main implementation working against a Daml ledger is the ``DamlLedgerClient``.
53
-
54
-
55
-
Set up dependencies in your project
56
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
57
-
58
-
To use the aforementioned classes, add the following dependencies to your project:
If your application is long-lived and your tokens are bound to expire, reload the necessary token when needed and pass
115
+
it explicitly for every call.
107
116
108
117
If you are communicating with a ledger that verifies authorization it is very important to secure the communication
109
118
channel to prevent your tokens to be exposed to man-in-the-middle attacks. The next chapter describes how to enable TLS.
@@ -113,39 +122,38 @@ channel to prevent your tokens to be exposed to man-in-the-middle attacks. The n
113
122
Connect securely
114
123
^^^^^^^^^^^^^^^^
115
124
116
-
The builders created by ``DamlLedgerClient.newBuilder`` default to a plaintext connection.
117
-
The Java bindings library lets you connect to a ledger via a secure connection. To do so, invoke ``withSslContext`` and
118
-
pass an ``SslContext``.
125
+
The builders created by ``NettyChannelBuilder.forAddress`` default to a tls connection, where the keys are taken from
126
+
the configured Java Keystore. You can override this behavior by providing your own cryptographic settings. To do so,
127
+
invoke ``sslContext`` and pass an ``SslContext``.
128
+
129
+
.. code-block:: java
130
+
131
+
NettyChannelBuilder.forAddress(host, port)
132
+
.useTransportSecurity()
133
+
.sslContext(sslContext)
134
+
.build();
119
135
120
136
.. warning::
121
137
122
-
Use the default plaintext connection only when connecting to a locally running ledger for development purposes.
138
+
You can also configure a plaintext connection invoking ``usePlaintext()``. Use it only when connecting to a locally
139
+
running ledger for development purposes.
123
140
124
141
Secure connections to a ledger must be configured to use client authentication certificates, which can be provided by a ledger operator.
125
142
126
143
For information on how to set up an ``SslContext`` with the provided certificates for client authentication, please consult the gRPC documentation on
127
144
`TLS with OpenSSL <https://github.com/grpc/grpc-java/blob/master/SECURITY.md#tls-with-openssl>`_ as well as the
128
145
`HelloWorldClientTls <https://github.com/grpc/grpc-java/blob/70b1b1696a258ffe042c7124217e3a7894821444/examples/src/main/java/io/grpc/examples/helloworldtls/HelloWorldClientTls.java#L46-L57>`_ example of the ``grpc-java`` project.
129
146
130
-
Advanced connection settings
131
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
132
-
133
-
Sometimes the default settings for gRPC connections or channels are not suitable. For such situations, create a custom
134
-
`NettyChannelBuilder <https://grpc.github.io/grpc-java/javadoc/io/grpc/netty/NettyChannelBuilder.html>`_ object and
135
-
pass the it to the ``newBuilder`` static method defined over `DamlLedgerClient </javadocs/3.3/com/daml/ledger/rxjava/DamlLedgerClient.html>`_.
136
-
137
-
Alternative ways to access the Ledger API
138
-
-----------------------------------------
139
-
140
-
The Java bindings client library is not the only way to access the Ledger API. You can also use the gRPC bindings or OpenAPI
141
-
bindings directly.
147
+
Use asynchronous stubs
148
+
----------------------
142
149
143
-
Use gRPC bindings
144
-
^^^^^^^^^^^^^^^^^
150
+
The classes generated for the Ledger API gRPC services come in several flavors: blocking, future-based and asynchronous.
151
+
The latter is the recommended way of interacting with the gRPC layer. In the example of the ``CommandService`` utilized
152
+
above they are called ``CommandServiceBlockingStub``, ``CommandServiceFutureStub`` and ``CommandServiceStub`` respectively.
145
153
146
154
For each gRPC endpoint that you want to call from your Java application, create a gRPC `StreamObserver <https://grpc.github.io/grpc-java/javadoc/io/grpc/stub/StreamObserver.html>`_ providing
147
-
implementations of the onNext, onError and onComplete observer methods.
148
-
To decode and encode the gRPC messages, use the fromProto and toProto methods of the generated classes of the :ref:`Java
155
+
implementations of the ``onNext``, ``onError`` and ``onComplete`` observer methods.
156
+
To decode and encode the gRPC messages, use the ``fromProto`` and ``toProto`` methods of the generated classes of the :ref:`Java
0 commit comments