/** * @see io.apiman.gateway.engine.io.IWriteStream#end() */ @Override public void end() { // Called when the upload to the 'API' is complete. This is when we // need to response with the connection response. handler.handle(AsyncResultImpl.<IApiConnectionResponse>create(this)); }
/** * Creates the handler to use when an error is detected during the processing * of a chain. */ private IAsyncHandler<Throwable> createPolicyErrorHandler() { return error -> resultHandler.handle(AsyncResultImpl.<IEngineResult> create(error)); } }
private <T> Handler<AsyncResult<T>> handleSuccessfulResult(IAsyncResultHandler<Void> failureHandler, Handler<T> successHandler) { return result -> { if (result.succeeded()) { successHandler.handle(result.result()); } else { failureHandler.handle(AsyncResultImpl.create(result.cause())); } }; }
private void checkSuccess(URILoadingRegistry reg) { if (!failed) { handlers.get(reg).handle(AsyncResultImpl.create((Void) null)); } } }
@SuppressWarnings("unchecked") private <T> Handler<AsyncResult<CompositeFuture>> handleCompositeResult(IAsyncResultHandler<T> apimanResultHandler) { return result -> { if (result.succeeded()) { apimanResultHandler.handle(AsyncResultImpl.create((T) result.result())); } else { apimanResultHandler.handle(AsyncResultImpl.create(result.cause())); } }; }
@SuppressWarnings("unchecked") private <T, Q> Handler<AsyncResult<Q>> handleResult(IAsyncResultHandler<T> apimanResultHandler) { return result -> { if (result.succeeded()) { apimanResultHandler.handle(AsyncResultImpl.create((T) result.result())); } else { apimanResultHandler.handle(AsyncResultImpl.create(result.cause())); } }; }
private Handler<AsyncResult<Void>> handleResultVoid(IAsyncResultHandler<Void> apimanResultHandler) { return result -> { if (result.succeeded()) { apimanResultHandler.handle(AsyncResultImpl.create(result.result())); } else { apimanResultHandler.handle(AsyncResultImpl.create(result.cause())); } }; } }
@Override public void getClient(String organizationId, String clientId, String clientVersion, IAsyncResultHandler<Client> handler) { try { Client client = lookupClient(organizationId, clientId, clientVersion); handler.handle(AsyncResultImpl.create(client)); } catch (ClientNotFoundException e) { handler.handle(AsyncResultImpl.create(e, Client.class)); } }
/** * @see io.apiman.gateway.engine.IRegistry#getClient(java.lang.String, io.apiman.gateway.engine.async.IAsyncResultHandler) */ @Override public void getClient(String apiKey, IAsyncResultHandler<Client> handler) { try { Client client = getClientInternal(apiKey); handler.handle(AsyncResultImpl.create(client)); } catch (SQLException e) { handler.handle(AsyncResultImpl.create(e, Client.class)); } }
/** * @see io.apiman.gateway.engine.jdbc.JdbcRegistry#getClient(java.lang.String, io.apiman.gateway.engine.async.IAsyncResultHandler) */ @Override public void getClient(String apiKey, IAsyncResultHandler<Client> handler) { try { Client client = getClient(apiKey); handler.handle(AsyncResultImpl.create(client)); } catch (IOException e) { handler.handle(AsyncResultImpl.create(e, Client.class)); } }
@Override public void close(IAsyncResultHandler<Void> closeResultHandler) { close(); closeResultHandler.handle(AsyncResultImpl.create((Void) null)); }
@Override public void listClients(String organizationId, int page, int pageSize, IAsyncResultHandler<List<String>> handler) { QueryRunner run = new QueryRunner(ds); try { List<String> clientList = run.query("SELECT DISTINCT id FROM gw_clients WHERE org_id = ?", Handlers.STRING_LIST_COL1_HANDLER, organizationId); handler.handle(AsyncResultImpl.create(clientList)); } catch (SQLException e) { handler.handle(AsyncResultImpl.create(e)); } }
@Override public void listClientVersions(String organizationId, String clientId, int page, int pageSize, IAsyncResultHandler<List<String>> handler) { QueryRunner run = new QueryRunner(ds); try { List<String> clientVersions = run.query("SELECT DISTINCT version FROM gw_clients WHERE org_id = ? AND id = ?", Handlers.STRING_LIST_COL1_HANDLER, organizationId, clientId); handler.handle(AsyncResultImpl.create(clientVersions)); } catch (SQLException e) { handler.handle(AsyncResultImpl.create(e)); } }
@Override public void write(IApimanBuffer chunk) { if (done) { return; } if (buffer.length() > api.getMaxPayloadBufferSize()) { payloadResultHandler.handle(AsyncResultImpl.create(new Exception("Max request payload size exceeded."))); //$NON-NLS-1$ done = true; return; } buffer.append(chunk); }
private void getResults(String searchDn, String filter, LdapSearchScope scope, final IAsyncResultHandler<List<SearchResultEntry>> result) { try { SearchScope searchScope = (scope == LdapSearchScope.ONE) ? SearchScope.ONE : SearchScope.SUB; List<SearchResultEntry> searchResults = connection.search(searchDn, searchScope, filter).getSearchEntries(); result.handle(AsyncResultImpl.create(searchResults)); } catch (LDAPException e) { ldapErrorHandler.handle(DefaultExceptionFactory.create(e)); } catch (Exception e) { result.handle(AsyncResultImpl.<List<SearchResultEntry>>create(e)); } }
@Override public void retireApi(Api api, IAsyncResultHandler<Void> handler) { objectMap.remove(getApiIndex(api), handleSuccessfulResult(handler, deletedApi -> { if (deletedApi == null) { Exception ex = new ApiNotFoundException(Messages.i18n.format("InMemoryRegistry.ApiNotFound")); handler.handle(AsyncResultImpl.create(ex)); } else { handler.handle(AsyncResultImpl.create((Void) null)); } })); }
@Override public void handle(IAsyncResult<IJdbcConnection> result) { if (result.isError()) { handler.handle(AsyncResultImpl.create(result.getError(), Boolean.class)); } else { validate(result.getResult(), query, queryUsername, queryPassword, context, config, handler); } } });
@Override public void handle(IAsyncResult<T> result) { if (result.isError()) { errorHandler.handle(AsyncResultImpl.<Q>create(result.getError())); } else { successHandler.handle(result.getResult()); } } };
protected <T> void handleError(IAsyncResult<IHttpClientResponse> result, IAsyncResultHandler<T> handler) { if (result.isError()) { handler.handle(AsyncResultImpl.<T> create(result.getError())); } else if (result.getResult().getResponseCode() != 200) { handler.handle(AsyncResultImpl.<T> create(new InfluxException("Influx: " //$NON-NLS-1$ + result.getResult().getResponseCode() + " " + result.getResult().getResponseMessage()))); //$NON-NLS-1$ } }