本文整理汇总了Java中io.apiman.gateway.engine.async.IAsyncResult.isError方法的典型用法代码示例。如果您正苦于以下问题:Java IAsyncResult.isError方法的具体用法?Java IAsyncResult.isError怎么用?Java IAsyncResult.isError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.apiman.gateway.engine.async.IAsyncResult
的用法示例。
在下文中一共展示了IAsyncResult.isError方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: wrapResultHandler
import io.apiman.gateway.engine.async.IAsyncResult; //导入方法依赖的package包/类
/**
* Wraps the result handler so that metrics can be properly recorded.
*/
private IAsyncResultHandler<IEngineResult> wrapResultHandler(final IAsyncResultHandler<IEngineResult> handler) {
return (IAsyncResult<IEngineResult> result) -> {
boolean doRecord = true;
if (result.isError()) {
recordErrorMetrics(result.getError());
} else {
IEngineResult engineResult = result.getResult();
if (engineResult.isFailure()) {
recordFailureMetrics(engineResult.getPolicyFailure());
} else {
recordSuccessMetrics(engineResult.getApiResponse());
doRecord = false; // don't record the metric now because we need to record # of bytes downloaded, which hasn't happened yet
}
}
requestMetric.setRequestEnd(new Date());
if (doRecord) {
metrics.record(requestMetric);
}
handler.handle(result);
};
}
示例2: doCreate
import io.apiman.gateway.engine.async.IAsyncResult; //导入方法依赖的package包/类
/**
* @param connection
*/
protected void doCreate(final IJdbcConnection connection) {
String createSql = "CREATE TABLE users ("
+ "userId VARCHAR(255) NOT NULL, "
+ "name VARCHAR(255) NOT NULL, "
+ "age INTEGER, "
+ "isAdmin BIT, "
+ "PRIMARY KEY (userId))";
IAsyncResultHandler<Void> afterCreateTable = new IAsyncResultHandler<Void>() {
@Override
public void handle(IAsyncResult<Void> result) {
if (result.isError()) {
errors.add(result.getError());
} else {
System.out.println("Create worked, inserting.");
doInserts(connection);
}
}
};
connection.execute(afterCreateTable, createSql);
}
示例3: doInserts
import io.apiman.gateway.engine.async.IAsyncResult; //导入方法依赖的package包/类
/**
* @param connection
*/
protected void doInserts(IJdbcConnection connection) {
String insertSql = "INSERT INTO users (userId, name, age, isAdmin) VALUES (?, ?, ?, ?)";
IAsyncResultHandler<Void> dfltHandler = new IAsyncResultHandler<Void>() {
@Override
public void handle(IAsyncResult<Void> result) {
if (result.isError()) {
errors.add(result.getError());
} else {
System.out.println("Insert successful.");
}
}
};
connection.execute(dfltHandler, insertSql, "ewittman", "Eric Wittmann", 17, Boolean.TRUE);
connection.execute(dfltHandler, insertSql, "msavy", "Marc Savy", 50, Boolean.FALSE);
connection.execute(dfltHandler, insertSql, "ryordan", "Rachel Yordan", 92, Boolean.FALSE);
doQueries(connection);
}
示例4: doQueries
import io.apiman.gateway.engine.async.IAsyncResult; //导入方法依赖的package包/类
/**
* @param connection
*/
private void doQueries(IJdbcConnection connection) {
IAsyncResultHandler<IJdbcResultSet> queryHandler = new IAsyncResultHandler<IJdbcResultSet>() {
@Override
public void handle(IAsyncResult<IJdbcResultSet> result) {
if (result.isError()) {
errors.add(result.getError());
} else {
try {
doQueryAssertions(result.getResult());
} catch (Throwable t) {
errors.add(t);
}
}
}
};
String querySql = "SELECT u.userId, u.name, u.age, u.isAdmin FROM users u WHERE userId = ?";
connection.query(queryHandler, querySql , "ewittman");
}
示例5: handleError
import io.apiman.gateway.engine.async.IAsyncResult; //导入方法依赖的package包/类
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$
}
}
示例6: handle
import io.apiman.gateway.engine.async.IAsyncResult; //导入方法依赖的package包/类
@Override
public void handle(IAsyncResult<Void> result) {
if (result.isError()) {
log.error("Error {0}", result.getError());
throw new RuntimeException(result.getError());
}
}
示例7: validate
import io.apiman.gateway.engine.async.IAsyncResult; //导入方法依赖的package包/类
/**
* @param connection
* @param query
* @param username
* @param context
* @param password
* @param config
* @param handler
*/
protected void validate(final IJdbcConnection connection, final String query, final String username,
final String password, final IPolicyContext context, final JDBCIdentitySource config,
final IAsyncResultHandler<Boolean> handler) {
IAsyncResultHandler<IJdbcResultSet> queryHandler = new IAsyncResultHandler<IJdbcResultSet>() {
@Override
public void handle(IAsyncResult<IJdbcResultSet> result) {
if (result.isError()) {
closeQuietly(connection);
handler.handle(AsyncResultImpl.create(result.getError(), Boolean.class));
} else {
boolean validated = false;
IJdbcResultSet resultSet = result.getResult();
if (resultSet.next()) {
validated = true;
}
resultSet.close();
if (validated && config.isExtractRoles()) {
extractRoles(connection, username, context, config, handler);
} else {
closeQuietly(connection);
handler.handle(AsyncResultImpl.create(validated));
}
}
}
};
connection.query(queryHandler, query, username, password);
}
示例8: extractRoles
import io.apiman.gateway.engine.async.IAsyncResult; //导入方法依赖的package包/类
/**
* @param connection
* @param username
* @param context
* @param config
* @param handler
*/
protected void extractRoles(final IJdbcConnection connection, final String username,
final IPolicyContext context, final JDBCIdentitySource config,
final IAsyncResultHandler<Boolean> handler) {
String roleQuery = config.getRoleQuery();
IAsyncResultHandler<IJdbcResultSet> roleHandler = new IAsyncResultHandler<IJdbcResultSet>() {
@Override
public void handle(IAsyncResult<IJdbcResultSet> result) {
if (result.isError()) {
closeQuietly(connection);
handler.handle(AsyncResultImpl.create(result.getError(), Boolean.class));
} else {
Set<String> extractedRoles = new HashSet<>();
IJdbcResultSet resultSet = result.getResult();
while (resultSet.next()) {
String roleName = resultSet.getString(1);
extractedRoles.add(roleName);
}
context.setAttribute(AuthorizationPolicy.AUTHENTICATED_USER_ROLES, extractedRoles);
closeQuietly(connection);
handler.handle(AsyncResultImpl.create(true));
}
}
};
connection.query(roleHandler, roleQuery, username);
}