Anura Docs

Anura SDK for Java

The Anura SDK for Java makes it easy for developers to access Anura Direct within their Java code and begin analyzing their traffic. You can get started in minutes by installing the SDK with Maven, Gradle, or building and installing a JAR file from our source code.

Getting Started

  1. Have an open active account with Anura - You can see more about Anura's offerings here.
  2. Minimum Requirements - To use the SDK, you will need Java >=8.
  3. Install the SDK
  4. View our Quick Examples to immediately begin using the SDK!

Installing the SDK

With Maven

The recommended way to use the SDK in your project is by consuming it from Maven Central. You can add it to your project by adding the following:

pom.xml
<dependency>
  <groupId>io.anura</groupId>
  <artifactId>anura-sdk-java</artifactId>
  <version>1.0.0</version>
</dependency>

Building From Source

Once you clone the repository, navigate to /anura-sdk-java and build using the appropriate command according to your operating system:

Linux/Mac:

Terminal
./mvnw clean install

Windows:

Terminal
./mvnw.cmd clean install

Once installed, you are now able to use it within any of your Java projects by adding the installed JAR to your project.

Quick Examples

Create the Anura Direct client

// Import all SDK classes, exceptions, and the HashMap class
import io.anura.sdk.*;
import io.anura.sdk.exceptions.*;
import java.util.HashMap;

// AnuraDirect constructor takes on parameter (a boolean) - whether to use HTTPS or not for API calls to Anura Direct.
// If false is given to the constructor, the API client will use HTTP instead of HTTPS.
AnuraDirect direct = new AnuraDirect(true);

Create a DirectRequest object for AnuraDirect client

DirectRequestBuilder builder = new DirectRequestBuilder();
DirectRequest request = request
    .setInstanceId("your-instance-id")                // required
    .setIpAddress("visitors-ip-address")              // required
    .setSource("your-source-value")                   // optional
    .setCampaign("your-campaign-value")               // optional
    .setUserAgent("visitors-user-agent")              // optional
    .setAppId("visitors-app-id")                      // optional
    .setDeviceId("visitors-device-id")                // optional
    .addAdditionalData(new HashMap<String, String>()) // optional
    .build();

Add Additional Data to a DirectRequest object

Any time you need to add/update your additional data, pass a new HashMap to the request's setAdditionalData() method:

HashMap<String, String> additionalData = new HashMap<String, String>();
additionalData.put("1", "your-value-here");

request.setAdditionalData(additionalData);

Remove Additional Data

To remove all additional data that you have added, pass an empty HashMap to the request's setAdditionalData() method:

request.setAdditionalData(new HashMap<String, String>());

Get a result from Anura Direct

DirectResult result;
try {
    result = direct.getResult(request);
} catch (IOException e) {
    // Handle IOException
} catch (InterruptedException e) {
    // Handle InterruptedException
} catch (AnuraClientException e) {
    // Handle any 4XX responses
} catch (AnuraServerException e) {
    // Handle any 5XX responses
} catch (AnuraException e) {
   /**
    * Handle any other exceptions that may have occurred.
    * Since AnuraClientException & AnuraServerException are children of AnuraException, 
    * feel free to remove those handling blocks if your handling logic is the same for both.
    */
}

API Reference

AnuraDirect

Can get results from Anura Direct. These results are fetched using Direct's /direct.json API endpoint.

Methods

DirectResult getResult(DirectRequest request) boolean isUseHttps() void setUseHttps(boolean useHttps)

DirectResult

The result upon a successful call to getResult() from the AnuraDirect client. It contains not only the result from Anura Direct, but some other methods to help you use the result.

Methods

boolean isSuspect() boolean isNonSuspect() Boolean isMobile() String getResult() String getRuleSets() String getInvalidTrafficType()

DirectRequest

A plain old java object (POJO) that represents an API request to be sent to the Anura Direct API.

Methods

String getInstanceId() String getSource() String getCampaign() String getIpAddress() String getUserAgent() String getAppId() String getDeviceId() HashMap<String, String> getAdditionalData() void setInstanceId(String instanceId) void setSource(String source) void setCampaign(String source) void setIpAddress(String ipAddress) void setUserAgent(String userAgent) void setAppId(String appId) void setDeviceId(String deviceId) void setAdditionalData(HashMap<String, String> additionalData)

DirectRequestBuilder

A builder class for creating a DirectRequest.

DirectRequest build() DirectRequestBuilder setInstanceId(String instanceId) DirectRequestBuilder setSource(String source) DirectRequestBuilder setCampaign(String campaign) DirectRequestBuilder setIpAddress(String ipAddress) DirectRequestBuilder setUserAgent(String userAgent) DirectRequestBuilder setAppId(String appId) DirectRequestBuilder setDeviceId(String deviceId) DirectRequestBuilder setAdditionalData(HashMap<String, String> additionalData)