-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Created cloudant-with-open-liberty.adoc #4153
Conversation
@@ -0,0 +1,170 @@ | |||
--- | |||
layout: post | |||
title: "Access Cloudant client with Open Liberty using CDI" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Access Cloudant with Open Liberty using CDI"
categories: blog | ||
author_picture: https://avatars3.githubusercontent.com/revijay | ||
author_github: https://github.com/revijay | ||
seo-title: Access Cloudant client with Open Liberty using CDI - OpenLiberty.io |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Access Cloudant with Open Liberty using CDI"
author_picture: https://avatars3.githubusercontent.com/revijay | ||
author_github: https://github.com/revijay | ||
seo-title: Access Cloudant client with Open Liberty using CDI - OpenLiberty.io | ||
seo-description: Using Cloudant with Open Liberty previously meant enabling the cloudant-1.0 feature and configuring several elements in server.xml. Now, with improvements in CDI and the introduction of MicroProfile Config, you can easily configure access to Cloudant with a CDI producer. Earlier cloudant-1.0 feature was implemented using Java Cloudant Client library which is not under active development now, so in this demonstration we are using Cloudant Java SDK library. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seo-description: Using Cloudant with Open Liberty previously meant enabling the cloudant-1.0 feature and configuring several elements in server.xml. With CDI and MicroProfile Config, you can easily configure access to Cloudant with a CDI producer. The cloudant-1.0 feature was implemented using the Java Cloudant Client library which is no longer supported, so in this demonstration we are using the new Cloudant SDK for Java.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same recommendation for blog_description
:url-prefix: | ||
:url-about: / | ||
|
||
Using Cloudant with Open Liberty previously meant enabling the `cloudant-1.0` feature and configuring several elements in ``server.xml``. Now, with improvements in CDI and the introduction of MicroProfile Config, you can easily configure access to Cloudant with a CDI producer (for an introduction to using CDI producers, see the https://openliberty.io/guides/cdi-intro.html[Injecting Dependencies into Microservices guide]). Earlier cloudant-1.0 feature was implemented using Java Cloudant Client library which is not under active development now, so in this demonstration we are using Cloudant Java SDK library. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using Cloudant with Open Liberty previously meant enabling the cloudant-1.0
feature and configuring several elements in server.xml
. With CDI and MicroProfile Config, you can easily configure access to Cloudant with a CDI producer (for an introduction to using CDI producers, see the https://openliberty.io/guides/cdi-intro.html[Injecting Dependencies into Microservices guide]). The cloudant-1.0
feature was implemented using the Java Cloudant Client library which is no longer supported, so in this demonstration we are using the new Cloudant SDK for Java.
<feature>passwordUtilities-1.0</feature> | ||
---- | ||
|
||
By default, Cloudant communication occurs over HTTPS (SSL). However, if you're working with a custom Cloudant instance or self-signed certificates, you may need to configure your Open Liberty application to trust the custom certificate. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar with using Cloudant with SSL, is this something that will always be necessary? If it's just for cases where self-signed certificates are used it may not be worth mentioning here, since I think that would apply to any use of self-signed certificates?
|
||
@Produces | ||
public Cloudant createCloudant() { | ||
return new Cloudant(“cloudant”, new BasicAuthenticator.Builder().build()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't valid since BasicAuthenticator needs a user and password. I think for this blog we should just go straight to the full example vs starting with a minimal example like this. I think more people are familiar with CDI/MP Config than when the MongoDb post was written.
[source, java] | ||
---- | ||
@Inject | ||
Cloudant client; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a new line under here
In the above code: | ||
|
||
* `@Inject` is used to inject the Cloudant client instance provided by the CDI producer. | ||
* The `postDocument` method demonstrates how to create and post a document in the cloudant database using the injected CloudantClient. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would go into more detail here, postDocument
isn't really what's creating the the document. Maybe describe how the PostDocumentOptions is created with the database name and the new document, and then the postDocument method is used on the injected client to put the document in the database.
* `@Inject` is used to inject the Cloudant client instance provided by the CDI producer. | ||
* The `postDocument` method demonstrates how to create and post a document in the cloudant database using the injected CloudantClient. | ||
|
||
== Enhancing the CDI producer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mentioned above, but use this as the first example
<dependency> | ||
<groupId>io.openliberty.features</groupId> | ||
<artifactId>passwordUtilities-1.0</artifactId> | ||
<version>18.0.0.4</version> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This uses password util now instead:
com.ibm.websphere.appserver.api
com.ibm.websphere.appserver.api.passwordUtil
1.0.95
Now that you have a more advanced CDI producer, it would be nice to add configurability to some of the variables, like the user and password. Using link:{url-prefix}/guides/microprofile-config-intro.html[MicroProfile Config] makes configuring the Cloudant driver simple. You can add the following to your CDI producer to add configuration: | ||
[source, java] | ||
---- | ||
@Inject |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above, let's just start with this in the CDI producer
cloudant.password={aes}AEEjCqvh7XAwDxrdYC6BUbqYlwqI8NAxRkWWWq7muxZu | ||
---- | ||
== No need for a Cloudant feature | ||
Previously, using Cloudant required enabling the `cloudant-1.0` feature. Even if the Cloudant Java Driver API changes, simple updates to your CDI producer will allow it to continue to work. You should remove the `cloudant-1.0` feature from your `server.xml` when using newer versions of Cloudant with a CDI producer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously, using Cloudant required enabling the cloudant-1.0
feature. You should remove the cloudant-1.0
feature from your server.xml
when using the new Cloudant SDK for Java.
== No need for a Cloudant feature | ||
Previously, using Cloudant required enabling the `cloudant-1.0` feature. Even if the Cloudant Java Driver API changes, simple updates to your CDI producer will allow it to continue to work. You should remove the `cloudant-1.0` feature from your `server.xml` when using newer versions of Cloudant with a CDI producer. | ||
|
||
The Cloudant client should be bundled in your application. To do this with Maven you can use a dependency: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Cloudant SDK for Java should be bundled in your application. To do this with Maven you can use a dependency:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments
Created blog file cloudant-with-open-liberty.adoc
Issue #4152