@@ -82,4 +82,46 @@ public void onResponse(Call call, final okhttp3.Response response) throws IOExce
8282 }
8383 });
8484 }
85+
86+ public JSONObject execSync (final String intent , final JSONObject intentData , final String userID ) throws AppsflyException {
87+ final JSONObject body = new JSONObject () {{
88+ put ("intent" , intent );
89+ put ("data" , intentData );
90+ }};
91+ String payload = body + "|" + microModuleId + "|" + config .appKey + "|" + userID ;
92+ String checksum = CtyptoUtil .getInstance ().getChecksum (payload .getBytes (), config .secretKey );
93+ OkHttpClient httpClient = new OkHttpClient ();
94+ Request request = new Request .Builder ()
95+ .url (this .config .repoUrl +"/executor/exec" )
96+ .addHeader ("X-Module-Handle" , microModuleId )
97+ .addHeader ("X-App-Key" , config .appKey )
98+ .addHeader ("X-Checksum" , checksum )
99+ .addHeader ("X-UUID" , userID )
100+ .post (RequestBody .create (JSON , body .toString ()))
101+ .build ();
102+ try {
103+ final Response response = httpClient .newCall (request ).execute ();
104+ String responseChecksum = response .headers ().get ("X-Checksum" );
105+ if (responseChecksum !=null ){
106+ boolean verified = CtyptoUtil .getInstance ().verifychecksum (response .body ().bytes (), responseChecksum , config .secretKey );
107+ if (verified ){
108+ return new JSONObject (response .body ().bytes ());
109+ }
110+ else {
111+ throw new AppsflyException ("Checksum Validation Failed" );
112+ }
113+ }
114+ else {
115+ final JSONObject responseBody = new JSONObject (response .body ().string ());
116+ if (responseBody .has ("error" )){
117+ throw new AppsflyException (responseBody .getJSONObject ("error" ).getString ("message" ));
118+ } else {
119+ return responseBody ;
120+ }
121+ }
122+ } catch (IOException e ) {
123+ e .printStackTrace ();
124+ return null ;
125+ }
126+ }
85127}
0 commit comments