Search in sources :

Example 1 with WebRiskServiceClient

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;
    }
}
Also used : SearchUrisRequest(com.google.webrisk.v1.SearchUrisRequest) WebRiskServiceClient(com.google.cloud.webrisk.v1.WebRiskServiceClient) SearchUrisResponse(com.google.webrisk.v1.SearchUrisResponse)

Example 2 with WebRiskServiceClient

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;
    }
}
Also used : Submission(com.google.webrisk.v1.Submission) WebRiskServiceClient(com.google.cloud.webrisk.v1.WebRiskServiceClient) CreateSubmissionRequest(com.google.webrisk.v1.CreateSubmissionRequest)

Aggregations

WebRiskServiceClient (com.google.cloud.webrisk.v1.WebRiskServiceClient)2 CreateSubmissionRequest (com.google.webrisk.v1.CreateSubmissionRequest)1 SearchUrisRequest (com.google.webrisk.v1.SearchUrisRequest)1 SearchUrisResponse (com.google.webrisk.v1.SearchUrisResponse)1 Submission (com.google.webrisk.v1.Submission)1