Java integration

The following example demonstrates how to connect to the Oracle Empirica Topics web service using Jakarta as the JAX-RS implementation provider.

// Create new client

Client client = ClientBuilder.newClient();

// Set the endpoint address for the Topics web service

String target = https://<hostname>:<portnumber>/TopicsServiceR/empirica”

+ additional path parameters for the specific call

// Get the authorization string for the header

String authorizationTokenOrString =

  • For Basic Auth: "Basic " + Base64.encodeBytes(“<topics service username >:<topics service password >”.getBytes());
  • For oAuth: "Bearer " + oAuth token obtained from your provider (see example below)

// Invoke the Topics REST web service call. In this example a POST method, using JSON Input and Output.

String InputJSON = Input parameters in JSON format

Response response = client.target(target)

.request(MediaType.APPLICATION_JSON_TYPE)

.header("Authorization", authorizationTokenOrString)

.post(Entity.entity(inputJSON, MediaType.APPLICATION_JSON_TYPE));

String outputJSON = response.readEntity(String.class);

Substitute your environment's values for <hostname >, <port number >, <topics service username >, and <topics service password >.

Your application must handle serializing the input to JSON format, and deserialization from the response.

// Check the status of the response

response.getStatusInfo().getStatusCode()

// sample code to get an oAuth access token


String target = "your-token-provider-url";
String clientId = "your-client-id";
String clientSecret = "your-client-secret";
String scope = "your-scope"; 
String access_token = "";
String form = "grant_type=client_credentials" +
      "&client_id=" + URLEncoder.encode(clientId,
         StandardCharsets.UTF_8) +
      "&client_secret=" + URLEncoder.encode(clientSecret,
         StandardCharsets.UTF_8) +
      "&scope=" + URLEncoder.encode(scope, StandardCharsets.UTF_8);

 client = ClientBuilder.newClient();
 Response tokenResponse =
    client.target(target)
    .request(MediaType.APPLICATION_JSON)
    .post(Entity.entity(form, 
         MediaType.APPLICATION_FORM_URLENCODED_TYPE));
 String jsonString = tokenResponse.readEntity(String.class);
 // parse JSON to get the "access_token" attribute