Shield Java Client SDK provides simple APIs to access risk control services.
This quickstart guide will show you how to install the client SDK and execute example Java programs.
Java 1.8 or higher:
<dependency>
<groupId>com.gentel.shield</groupId>
<artifactId>shield</artifactId>
<version>0.2.0</version>
</dependency>dependencies {
implementation 'com.gentel.shield:shield:0.2.0'
}This example demonstrates how to send a risk control request using Shield SDK and receive a response.
You need the following parameters to use the service:
| Parameter | Description |
|---|---|
| BaseURL | Service URL |
| API Key | API key for authentication |
import com.gentel.shield.ShieldClient;
import com.gentel.shield.core.ShieldRequest;
import com.gentel.shield.core.ShieldResponse;
public class ShieldExample {
public static void main(String[] args) {
try {
// Create Shield client instance
ShieldClient client = ShieldClient.builder()
.baseUrl("https://shield.gentel.com/api/shield/v1/")
.apikey("your-api-key")
.build();
// Build request
ShieldRequest request = ShieldRequest.builder()
.Modal(Modal.TEXT)
.format(Format.PLAIN)
.content("Test Content")
.role(Role.USER);
// Send request and get response
ShieldResponse response = client.Detect(request);
// Handle response
System.out.println("Sanitized Content: " + response.getSanitized());
System.out.println("Risk List: " + response.getRisks());
} catch(Exception e) {
System.out.println("Error occurred: " + e.getMessage());
}
}
}Here's an overview of the main API classes:
The main client class for sending risk control requests:
Detect- Risk DetectionTextDetect- Text Risk DetectionImageDectect- Image Risk Detection
ShieldRequest- Request objectShieldResponse- Response objectHttpRiskEvent- Risk event objectRisk- Risk details object
RiskLevel- Risk level enumerationFormat- Format enumerationRole- Role enumerationModal- Modal enumeration
The SDK provides the following example code:
The SDK defines the following exception types:
ShieldException- Base SDK exceptionBadRequestException- Request parameter errorServerException- Server-side errorConnectionException- Network connection error