Ejemplo n.º 1
0
 private AlgoResponse pipeRequest(String input, ContentType content_type) throws APIException {
   try {
     return pipeRequestAsync(input, content_type).get();
   } catch (java.util.concurrent.ExecutionException e) {
     throw new APIException(e.getCause().getMessage());
   } catch (java.util.concurrent.CancellationException e) {
     throw new APIException(
         "API connection cancelled: " + algoRef.getUrl() + " (" + e.getMessage() + ")", e);
   } catch (java.lang.InterruptedException e) {
     throw new APIException(
         "API connection interrupted: " + algoRef.getUrl() + " (" + e.getMessage() + ")", e);
   }
 }
Ejemplo n.º 2
0
 private FutureAlgoResponse pipeBinaryRequestAsync(byte[] input) {
   Future<AlgoResponse> promise =
       client.post(
           algoRef.getUrl(),
           new ByteArrayEntity(input, org.apache.http.entity.ContentType.APPLICATION_OCTET_STREAM),
           new AlgoResponseHandler());
   return new FutureAlgoResponse(promise);
 }
Ejemplo n.º 3
0
 private FutureAlgoResponse pipeRequestAsync(String input, ContentType content_type) {
   StringEntity requestEntity = null;
   if (content_type == ContentType.Text) {
     requestEntity = new StringEntity(input, "UTF-8");
   } else if (content_type == ContentType.Json) {
     requestEntity = new StringEntity(input, org.apache.http.entity.ContentType.APPLICATION_JSON);
   }
   Future<AlgoResponse> promise =
       client.post(algoRef.getUrl(), requestEntity, new AlgoResponseHandler());
   return new FutureAlgoResponse(promise);
 }