Skip to content

Commit 1217220

Browse files
committed
raw request for client
1 parent c54cc5e commit 1217220

File tree

2 files changed

+44
-0
lines changed
  • client/src/main/java/com/regula/documentreader/webclient/api
  • example/src/main/java/com/regula/documentreader/webclient/example

2 files changed

+44
-0
lines changed

client/src/main/java/com/regula/documentreader/webclient/api/DocumentReaderApi.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
package com.regula.documentreader.webclient.api;
22

3+
import com.google.gson.Gson;
4+
import com.google.gson.JsonElement;
5+
import com.google.gson.JsonObject;
6+
import com.google.gson.reflect.TypeToken;
37
import com.regula.documentreader.webclient.ApiClient;
48
import com.regula.documentreader.webclient.ApiException;
59
import com.regula.documentreader.webclient.Configuration;
10+
import com.regula.documentreader.webclient.Pair;
611
import com.regula.documentreader.webclient.model.DeviceInfo;
12+
import com.regula.documentreader.webclient.model.ProcessParams;
713
import com.regula.documentreader.webclient.model.ProcessRequest;
14+
import com.regula.documentreader.webclient.model.ProcessResponse;
815
import com.regula.documentreader.webclient.model.ext.RecognitionResponse;
16+
import java.lang.reflect.Type;
17+
import java.util.ArrayList;
18+
import java.util.HashMap;
919
import okio.ByteString;
1020

1121
public class DocumentReaderApi {
@@ -68,6 +78,38 @@ public RecognitionResponse process(ProcessRequest processRequest) {
6878
return new RecognitionResponse(processApi.apiProcess(processRequest));
6979
}
7080

81+
public RecognitionResponse process(byte[] processRequest, ProcessParams processParams) {
82+
if (processParams != null) {
83+
Gson converter = processApi.getApiClient().getJSON().getGson();
84+
JsonObject parsedProcessRequest =
85+
converter.fromJson(new String(processRequest), JsonObject.class);
86+
JsonElement params = converter.toJsonTree(processParams);
87+
parsedProcessRequest.add("processParam", params);
88+
processRequest = converter.toJson(parsedProcessRequest).getBytes();
89+
}
90+
91+
ApiClient client = processApi.getApiClient();
92+
okhttp3.Call apiCall = newProcessCall(processRequest);
93+
Type respType = new TypeToken<ProcessResponse>() {}.getType();
94+
return new RecognitionResponse((ProcessResponse) client.execute(apiCall, respType).getData());
95+
}
96+
97+
private okhttp3.Call newProcessCall(byte[] processRequest) {
98+
return processApi
99+
.getApiClient()
100+
.buildCall(
101+
"/api/process",
102+
"POST",
103+
new ArrayList<Pair>(),
104+
new ArrayList<Pair>(),
105+
processRequest,
106+
new HashMap<String, String>(),
107+
new HashMap<String, String>(),
108+
new HashMap<String, Object>(),
109+
new String[] {},
110+
null);
111+
}
112+
71113
public DocumentReaderApi withLicense(String license) {
72114
this.license = license;
73115
return this;

example/src/main/java/com/regula/documentreader/webclient/example/Main.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ public static void main(String[] args) throws IOException, ApiException {
7373
System.out.format("Web API version %s%n", info.getVersion());
7474

7575
RecognitionResponse response = api.process(request);
76+
// to send raw request(ex encrypted one) with overriding processing params here use next api
77+
// RecognitionResponse response = api.process(request, requestParams);
7678

7779
var status = response.status();
7880
var docOverallStatus = status.getOverallStatus() == CheckResult.OK ? "valid" : "not valid";

0 commit comments

Comments
 (0)