Using the ziti-sdk-jvm

success with a problem

this is how I got it to work

cd /home/opc/demo/ziti-sdk-jvm/samples/jdbc-postgres/build/libs/

wget https://repo1.maven.org/maven2/org/openziti/ziti/0.23.12/ziti-0.23.12-full.jar

run the app

java -classpath /home/opc/demo/ziti-sdk-jvm/samples/jdbc-postgres/build/libs/jdbc-sample-postgres.jar:/home/opc/demo/ziti-sdk-jvm/samples/jdbc-postgres/build/libs/ziti-0.23.12-full.jar jdbc.postgres.App

here are the problems

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".

SLF4J: Defaulting to no-operation (NOP) logger implementation

SLF4J: See SLF4J Error Codes for further details.

WARNING: An illegal reflective access operation has occurred

WARNING: Illegal reflective access by retrofit2.Platform (file:/home/opc/demo/ziti-sdk-jvm/samples/jdbc-postgres/build/libs/ziti-0.23.12-full.jar) to constructor java.lang.invoke.MethodHandles$Lookup(java.lang.Class,int)

WARNING: Please consider reporting this to the maintainers of retrofit2.Platform

WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations

WARNING: All illegal access operations will be denied in a future release

slf4j is used in the main ziti skd

I did a search for slf4j and it in the main gradle build file..

how can this be resolved? any tips

@TheLumberjack

ziti-sdk-jvm-main/build.gradle:
30 kotlin: '1.6.10',
31 coroutines: '1.6.0',
32: slf4j: '1.7.36',
33 jupiter: '5.8.2',
34 androidxCore: '1.7.0',
..
42 kotlinTest: "org.jetbrains.kotlin:kotlin-test-junit:${versions.kotlin}",
43 kotlinCoroutinesTest: "org.jetbrains.kotlinx:kotlinx-coroutines-test:${versions.coroutines}",
44: slf4jApi: "org.slf4j:slf4j-api:${versions.slf4j}",
45: slf4jSimple: "org.slf4j:slf4j-simple:${versions.slf4j}",
46 jupiterApi: "org.junit.jupiter:junit-jupiter-api:${versions.jupiter}",
47 jupiter: "org.junit.jupiter:junit-jupiter-engine:${versions.jupiter}"

Reading up on java and the various dependency/artifact systems would probably be interesting to you. Gradle and Maven are two such systems, the project I sent you to “should” have been really easy for you to try out. These systems do all this downloading and adding to your classpath for you! :). They make it easy.

You would:

  • clone the ziti-sdk-jvm repo
  • cd samples/jdbc-postgres
  • run the gradle wrapper: ./gradlew

You would then (hopefully) see:

./gradlew
Downloading https://services.gradle.org/distributions/gradle-7.1.1-bin.zip
..........10%...........20%...........30%..........40%...........50%...........60%..........70%...........80%...........90%...........100%

Welcome to Gradle 7.1.1!

Here are the highlights of this release:
 - Faster incremental Java compilation
 - Easier source set configuration in the Kotlin DSL

For more details see https://docs.gradle.org/7.1.1/release-notes.html

Starting a Gradle Daemon (subsequent builds will be faster)

> Task :help

Welcome to Gradle 7.1.1.

To run a build, run gradlew <task> ...

To see a list of available tasks, run gradlew tasks

To see a list of command-line options, run gradlew --help

To see more detail about a task, run gradlew help --task <task>

For troubleshooting, visit https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.1.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 8s
1 actionable task: 1 executed

Then you could choose to run the application using ./gradlew run which should “run”. You could bring this into your IDE and debug it, etc.

1 Like

Great feedback… I am working back from the start down… and re downloaded the repo.

One thing I noticed is that the ./gradlew is in the root of the repo… rather than in the samples/jdbc-postgres folder.

I thought to copy the gradlew file across and run… but get the following error.

Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain

Caused by: java.lang.ClassNotFoundException: org.gradle.wrapper.GradleWrapperMain

I must say, it reminds me of when I had a java team building java apps on the other side of the office… I had 0 idea of what they did… and are now starting to get a peak inside the window

PS… while I don’t have much idea of how this works… I want to learn how to get it to work so that if I do a demo… and someone says… how do you install it… I sort of know the basics

maybe I got it…

I entered gradle wrapper… which did something…

there are two gradlew files in that repo. The one at the root of the project - you don’t want that. It’s “too much” for you right now. It’s doing “a lot” that you don’t need to get into… That’s far deeper than I think you want to go. It’ll presume you have a lot of Java/Gradle expertise. Stick with the one I made in the sample project - it’s way simpler! :slight_smile:

Don’t copy/move that file either - it all goes together in that one project.

TBH - I really do encourage you to read up on the gradle build system, how gradle manages dependencies, and how to setup a basic gradle project. The gradle doc pages are reallygood and should get into nearly all these topics - far more than I can explain here!

If you run the project and you’ve setup the db and you’re not getting the 10 rows of results, let me know and I’ll try running through all of it again to make sure it still works.

1 Like

@TheLumberjack

Quick update.. still stuck.. this is all a bit too new to me.. this what I did

cd /home/opc/demo/
git clone GitHub - openziti/ziti-sdk-jvm: Ziti SDK for JVM

cd /home/opc/demo/ziti-sdk-jvm/samples/jdbc-postgres

vi gradle.build

add the following to the end of the file

def runnableJar = "${rootProject.name}_fat.jar";

task fatJar(type: Jar) {
clean
println("Creating fat jar")
manifest {
attributes 'Main-Class': 'jdbc.postgres.App'
}
archiveName "${runnableJar}"
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
} {
exclude 'META-INF/.RSA', 'META-INF/.SF', 'META-INF/*.DSA'
}

with jar

println("Fat jar is created")
}

gradle fatJar

cd /home/opc/demo/ziti-sdk-jvm/samples/jdbc-postgres/build/libs/

java -classpath jdbc-sample-postgres_fat.jar jdbc.postgres.App

this resolves all of the past problems.. but generates a new one

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".

SLF4J: Defaulting to no-operation (NOP) logger implementation

SLF4J: See SLF4J Error Codes for further details.

Exception in thread "main" java.lang.IllegalArgumentException: Failed to parse keystore. /home/opc/demo/ziti-sdk-jvm/samples/jdbc-postgres/build/libs/c:/temp/java-identity.json does not exist or can not be read

at org.openziti.identity.UtilKt.loadKeystore(util.kt:82)

at org.openziti.impl.ZitiImpl.loadContext$ziti(ZitiImpl.kt:75)

at org.openziti.impl.ZitiImpl.init(ZitiImpl.kt:94)

at org.openziti.Ziti.init(Ziti.kt:70)

at jdbc.postgres.App.main(App.java:28)

PS. there also appears to be some type of issue with SLF4J but don't have much idea if its a problem or not.

PS.. I tried this.. but there is no file located in that directory called gradlew to execute.

This is why I modified the build file to create a task

Hmm.. I forgot to update the property in the App.java file :slight_smile:

Will revert back shortly

I think that did it.. except that the results did not print out on the screen

also. I was expecting the app to stop after I run the command.. but I needed to cancel the command for it to stop.
not sure if that was expected or not

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".

SLF4J: Defaulting to no-operation (NOP) logger implementation

SLF4J: See SLF4J Error Codes for further details.

WARNING: An illegal reflective access operation has occurred

WARNING: Illegal reflective access by retrofit2.Platform (file:/home/opc/demo/ziti-sdk-jvm/samples/jdbc-postgres/build/libs/jdbc-sample-postgres_fat.jar) to constructor java.lang.invoke.MethodHandles$Lookup(java.lang.Class,int)

WARNING: Please consider reporting this to the maintainers of retrofit2.Platform

WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations

WARNING: All illegal access operations will be denied in a future release

The reason for the app not stopping appears to be a java thing..

still stuck on why the output is not being generated through..
could be related to the errors.. which seems like a class is not loading properly

Actually… I think its working… I am not letting it run long enough… as I am now getting a different error… as the terminator is not online

I will restart Docker and try again

After a restart of Docker.. I now get a different error

ziti-controller_1 | [2577.775] INFO : http: TLS handshake error from 172.18.0.1:42714: remote error: tls: unknown certificate

Exception in thread "main" org.postgresql.util.PSQLException: Something unusual has occurred to cause the driver to fail. Please report this exception.

at org.postgresql.Driver.connect(Driver.java:282)

at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:677)

at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:189)

at jdbc.postgres.App.main(App.java:37)

Caused by: java.nio.channels.UnresolvedAddressException

Any tips... must be due to self signed certificates.. is there a switch to turn off the ssl check?

I don’t think it’s the certificates. I see “UnresolvedAddressException” in there. I don’t think it worked quite right. I’ll revisit the video and test it myself and make sure it all still works. I’ll post back in a bit

1 Like

Hi @markamind - there appears to have been a regression in the SDK after 0.23.7. Version 0.23.7 works in my testing. I have put a PR up which includes gradlew in the project. That should make it MUCH easier for you to try the sample out. I didn’t realize the gradle wrapper wasn’t checked in.

Check out the latest/updated video at - YouTube

Get the code immediately by checking out the update-jdbc-postgres-example branch: GitHub - openziti/ziti-sdk-jvm at update-jdbc-postgres-example

The sample has the proper dependency checked in, it should “just work” for you if you follow the cheat sheet steps.

1 Like

Thanks for that… working through it now.

PS> the cheat sheet in the repo is still the old version

Just saw this.. so are doing this right now :slight_smile:

PS.. I am working through using the gradlew file.. but are not sure its in the right format for linux.. as I get errors due to the @ symbols..

when I replace all of the @ symbols with #.. this is the error I get
./gradlew.bat: line 33: syntax error near unexpected token (' ./gradlew.bat: line 33: for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi'

Not 100% how to fix. so I am reverting back to my old way to build the file

However.. when I build the file the old way.. and execute the file. I get the same error..

Exception in thread "main" org.postgresql.util.PSQLException: Something unusual has occurred to cause the driver to fail. Please report this exception.

at org.postgresql.Driver.connect(Driver.java:282)

at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:677)

at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:189)

at jdbc.postgres.App.main(App.java:37)

Caused by: java.nio.channels.UnresolvedAddressException

at java.base/sun.nio.ch.Net.checkAddress(Net.java:131)

now trying to debug it all to see where the problem is.

Is there a way to test the intercept without needing to load Java?... maybe it needs to be run through some type of test harness.. but not really sure how to even go in that direction

You shouldn’t need to edit these files. They are not meant to be edited. Run the bash variant, ./gradle. If you’re not running windows, you shouldn’t use gradle.bat, it’s the windows variant. The Gradle Wrapper

Let’s keep to using gradlew for this example. I can’t debug your example effectively.

If you run gradlew, please provide the entire output inside a code block and I’ll check it out.

1 Like

I am also a very novice git user… and eventually found out the commands to use.

git branch -a
git checkout remotes/origin/update-jdbc-postgres-example

git branch -r

So… now my directory looks like it should… will give it another go :slight_smile:

The gradle directory is missing the jar file

I will copy this from another directory and try again :slight_smile: