Skip to content

Latest commit

 

History

History
52 lines (37 loc) · 1.87 KB

connect_from_java.md

File metadata and controls

52 lines (37 loc) · 1.87 KB

How to connect to a Conjure server from Java

Prerequisites

  • API already defined using gradle-conjure (see getting started)
  • Server implemented and working (e.g. using Dropwizard)

1. Depend on the Conjure-generated Jersey interfaces

 dependencies {
+    compile project('your-project-api:your-project-api-jersey')
 }

You should now be able to compile against generated interfaces and objects, e.g. RecipeBookService.

2. Depend on conjure-java-runtime

conjure-java just generates client/server interfaces, so to actually make network calls you need to provide a client. conjure-java-runtime uses reflection to read annotations from your generated interfaces and provides a client based on Java 8 dynamic proxies.

 dependencies {
     compile project('your-project-api:your-project-api-jersey')
+    compile 'com.palantir.conjure.java.runtime:conjure-java-jaxrs-client:latest.release'
 }

Check palantir/conjure-java-runtime for the latest release

3. Construct a client

Pass your interface as the first argument to have a client created:

RecipeBookService recipeBookService = JaxRsClient.create(
       RecipeBookService.class,
       UserAgent.of(Agent.of("your-server", "0.0.0")),
       NoOpHostEventsSink.INSTANCE,
       ClientConfigurations.of(ServiceConfiguration.builder()
               .addUris("http://localhost:8080/examples/api/")
               .security(SslConfiguration.of(Paths.get(TRUSTSTORE_PATH)))
               .build()));

The JVM contains a JKS truststore at $JAVA_HOME/lib/security/cacerts, but for production usage you should make sure your truststore is minimal.

4. Make a network call

Recipe recipe = recipeBookService.getRecipe("Recipe name");