use of com.google.cloud.webrisk.v1.WebRiskServiceClient in project java-webrisk by googleapis.
the class SearchUriExample method searchUriExample.
// [START webrisk_search_uri]
public static SearchUrisResponse searchUriExample(String uri) throws IOException {
// create-webrisk-client
try (WebRiskServiceClient webRiskServiceClient = WebRiskServiceClient.create()) {
// Query the url for a specific threat type
SearchUrisRequest searchUrisRequest = SearchUrisRequest.newBuilder().addThreatTypes(ThreatType.MALWARE).setUri(uri).build();
SearchUrisResponse searchUrisResponse = webRiskServiceClient.searchUris(searchUrisRequest);
webRiskServiceClient.shutdownNow();
if (!searchUrisResponse.getThreat().getThreatTypesList().isEmpty()) {
System.out.println("The URL has the following threat : ");
System.out.println(searchUrisResponse);
} else {
System.out.println("The URL is safe!");
}
return searchUrisResponse;
}
}
use of com.google.cloud.webrisk.v1.WebRiskServiceClient in project java-webrisk by googleapis.
the class SubmitUriExample method submitUriExample.
// [START webrisk_submit_uri]
public static Submission submitUriExample(String uri) throws IOException {
// create-webrisk-client
try (WebRiskServiceClient webRiskServiceClient = WebRiskServiceClient.create()) {
Submission submission = Submission.newBuilder().setUri(uri).build();
CreateSubmissionRequest submissionRequest = CreateSubmissionRequest.newBuilder().setParent("projects/your-project-id").setSubmission(submission).build();
Submission submissionResponse = webRiskServiceClient.createSubmission(submissionRequest);
webRiskServiceClient.shutdownNow();
System.out.println("The submitted " + submissionResponse);
return submissionResponse;
}
}
Aggregations