本文整理汇总了Java中io.apiman.gateway.engine.async.IAsyncResultHandler类的典型用法代码示例。如果您正苦于以下问题:Java IAsyncResultHandler类的具体用法?Java IAsyncResultHandler怎么用?Java IAsyncResultHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IAsyncResultHandler类属于io.apiman.gateway.engine.async包,在下文中一共展示了IAsyncResultHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getProperty
import io.apiman.gateway.engine.async.IAsyncResultHandler; //导入依赖的package包/类
/**
* @see io.apiman.gateway.engine.components.ISharedStateComponent#getProperty(java.lang.String, java.lang.String, java.lang.Object, io.apiman.gateway.engine.async.IAsyncResultHandler)
*/
@SuppressWarnings("unchecked")
@Override
public <T> void getProperty(String namespace, String propertyName, T defaultValue, IAsyncResultHandler<T> handler) {
final String namespacedKey = buildNamespacedKey(namespace, propertyName);
if (getSharedState().containsKey(namespacedKey)) {
try {
T rval = (T) getSharedState().get(namespacedKey);
handler.handle(AsyncResultImpl.create(rval));
} catch (Exception e) {
handler.handle(AsyncResultImpl.create(e));
}
} else {
handler.handle(AsyncResultImpl.create(defaultValue));
}
}
示例2: fetchSession
import io.apiman.gateway.engine.async.IAsyncResultHandler; //导入依赖的package包/类
/**
* Retrieve the Session with the given ID.
*
* @param sessionId the ID of the Session.
* @return the Session
*/
public static Session fetchSession(String sessionId) {
final AtomicReference<IAsyncResult<Session>> propertyResult = new AtomicReference<>();
// fetch the session
final ISessionStore sessionStore = getSessionStore();
sessionStore.fetchSession(sessionId, new IAsyncResultHandler<Session>() {
@Override
public void handle(IAsyncResult<Session> result) {
propertyResult.set(result);
}
});
// wait for the result
while (null == propertyResult.get()) {
Thread.yield();
}
return propertyResult.get().getResult();
}
示例3: storeSession
import io.apiman.gateway.engine.async.IAsyncResultHandler; //导入依赖的package包/类
/**
* Store the Session.
*
* @param session the Session to store
*/
private static void storeSession(Session session) {
final AtomicBoolean stored = new AtomicBoolean(false);
// store the session
final ISessionStore sessionStore = getSessionStore();
sessionStore.storeSession(session.getSessionId(), session, new IAsyncResultHandler<Void>() {
@Override
public void handle(IAsyncResult<Void> result) {
stored.set(true);
}
});
// wait for storage
while (!stored.get()) {
Thread.yield();
}
}
示例4: auth
import io.apiman.gateway.engine.async.IAsyncResultHandler; //导入依赖的package包/类
@Override
public StandardAuth auth(IAsyncResultHandler<Void> resultHandler) {
// If we have no cache entry, then block. Otherwise, the request can immediately go
// through and we will resolve the rate limiting status post hoc (various strategies
// depending on settings).
if (authCache.isAuthCached(config, request, keyElems)) {
logger.debug("[ServiceId: {0}] Cached auth on request: {1}", serviceId, request);
resultHandler.handle(OK_CACHED);
} else {
logger.debug("[ServiceId: {0}] Uncached auth on request: {1}", serviceId, request);
context.setAttribute(BLOCKING_FLAG, true);
doBlockingAuthRep(result -> {
logger.debug("Blocking auth success?: {0}", result.isSuccess());
// Only cache if successful
if (result.isSuccess()) {
authCache.cache(config, request, keyElems);
}
// Pass result up.
resultHandler.handle(result);
});
}
return this;
}
示例5: doBlockingAuthRep
import io.apiman.gateway.engine.async.IAsyncResultHandler; //导入依赖的package包/类
protected void doBlockingAuthRep(IAsyncResultHandler<Void> resultHandler) {
IHttpClientRequest get = httpClient.request(backendUri + AUTHREP_PATH + report.encode(),
HttpMethod.GET,
new AuthResponseHandler(failureFactory)
.failureHandler(failure -> {
logger.debug("[ServiceId: {0}] Blocking AuthRep failure: {1}", serviceId, failure.getResponseCode());
policyFailureHandler.handle(failure);
})
.exceptionHandler(exception -> resultHandler.handle(AsyncResultImpl.create(exception)))
.statusHandler(status -> {
logger.debug("[ServiceId: {0}] Backend status: {1}", serviceId, status);
if (!status.isAuthorized()) {
flushCache();
} else {
resultHandler.handle(OK_CACHED);
}
}));
get.addHeader("Accept-Charset", "UTF-8");
get.addHeader("X-3scale-User-Client", "apiman");
get.end();
}
示例6: auth
import io.apiman.gateway.engine.async.IAsyncResultHandler; //导入依赖的package包/类
@Override
public BatchedAuth auth(IAsyncResultHandler<Void> resultHandler) {
// If we have no cache entry, then block. Otherwise, the request can immediately go
// through and we will resolve the rate limiting status post hoc (various strategies
// depending on settings).
if (authCache.isAuthCached(config, request, keyElems)) {
logger.debug("[ServiceId: {0}] Cached auth on request: {1}", serviceId, request);
resultHandler.handle(OK_CACHED);
} else {
logger.debug("[ServiceId: {0}] Uncached auth on request: {1}", serviceId, request);
context.setAttribute(BLOCKING_FLAG, true);
doBlockingAuthRep(result -> {
logger.debug("Blocking auth success?: {0}", result.isSuccess());
// Only cache if successful
if (result.isSuccess()) {
authCache.cache(config, request, keyElems);
}
// Pass result up.
resultHandler.handle(result);
});
}
return this;
}
示例7: apply
import io.apiman.gateway.engine.async.IAsyncResultHandler; //导入依赖的package包/类
/**
* @see io.apiman.gateway.engine.policy.IPolicy#apply(io.apiman.gateway.engine.beans.ApiResponse, io.apiman.gateway.engine.policy.IPolicyContext, java.lang.Object, io.apiman.gateway.engine.policy.IPolicyChain)
*/
@Override
public void apply(final ApiResponse response, IPolicyContext context, Object config,
final IPolicyChain<ApiResponse> chain) {
final ISharedStateComponent sharedState = context.getComponent(ISharedStateComponent.class);
final String namespace = "urn:" + getClass().getName();
final String propName = "test-property";
sharedState.getProperty(namespace, propName, "NOT_FOUND", new IAsyncResultHandler<String>() {
@Override
public void handle(IAsyncResult<String> result) {
String propVal = result.getResult();
response.getHeaders().put("X-Shared-State-Value", propVal);
chain.doApply(response);
}
});
}
示例8: reloadData
import io.apiman.gateway.engine.async.IAsyncResultHandler; //导入依赖的package包/类
public static void reloadData(IAsyncHandler<Void> doneHandler) {
synchronized(URILoadingRegistry.class) {
if (instance == null) {
doneHandler.handle((Void) null);
return;
}
Map<URILoadingRegistry, IAsyncResultHandler<Void>> regs = instance.handlers;
Vertx vertx = instance.vertx;
URI uri = instance.uri;
Map<String, String> config = instance.config;
AtomicInteger ctr = new AtomicInteger(regs.size());
OneShotURILoader newLoader = new OneShotURILoader(vertx, uri, config);
regs.entrySet().stream().forEach(pair -> {
// Clear the registrys' internal maps to prepare for reload.
// NB: If we add production hot reloading, we'll need to work around this (e.g. clone?).
pair.getKey().getMap().clear();
// Re-subscribe the registry.
newLoader.subscribe(pair.getKey(), result -> {
checkAndFlip(ctr.decrementAndGet(), newLoader, doneHandler);
});
});
checkAndFlip(ctr.get(), newLoader, doneHandler);
}
}
示例9: shouldFailWithDevModeAndNoClientKeys
import io.apiman.gateway.engine.async.IAsyncResultHandler; //导入依赖的package包/类
/**
* Scenario:
* - Development mode TLS pass-through. Gateway accepts anything.
* - Server should still refuse on basis of requiring client auth.
*/
@Test
public void shouldFailWithDevModeAndNoClientKeys() {
config.put(TLSOptions.TLS_DEVMODE, "true");
HttpConnectorFactory factory = new HttpConnectorFactory(config);
IApiConnector connector = factory.createConnector(request, api, RequiredAuthType.DEFAULT, false);
IApiConnection connection = connector.connect(request,
new IAsyncResultHandler<IApiConnectionResponse>() {
@Override
public void handle(IAsyncResult<IApiConnectionResponse> result) {
Assert.assertTrue(result.isError());
System.out.println(result.getError());
}
});
connection.end();
}
示例10: shouldAllowAllWhenDevMode
import io.apiman.gateway.engine.async.IAsyncResultHandler; //导入依赖的package包/类
/**
* Scenario:
* - Development mode TLS pass-through. Accepts anything.
*/
@Test
public void shouldAllowAllWhenDevMode() {
config.put(TLSOptions.TLS_DEVMODE, "true");
HttpConnectorFactory factory = new HttpConnectorFactory(config);
IApiConnector connector = factory.createConnector(request, api, RequiredAuthType.DEFAULT, false);
IApiConnection connection = connector.connect(request,
new IAsyncResultHandler<IApiConnectionResponse>() {
@Override
public void handle(IAsyncResult<IApiConnectionResponse> result) {
Assert.assertTrue(result.isSuccess());
}
});
connection.end();
}
示例11: shouldSucceedWithBasicAuth
import io.apiman.gateway.engine.async.IAsyncResultHandler; //导入依赖的package包/类
/**
* Scenario successful connection to the back end API via basic auth.
*/
@Test
public void shouldSucceedWithBasicAuth() {
endpointProperties.put(BasicAuthOptions.BASIC_USERNAME, "user");
endpointProperties.put(BasicAuthOptions.BASIC_PASSWORD, "user123!");
endpointProperties.put(BasicAuthOptions.BASIC_REQUIRE_SSL, "false");
api.setEndpointProperties(endpointProperties);
api.setEndpoint("http://localhost:8008/echo");
HttpConnectorFactory factory = new HttpConnectorFactory(globalConfig);
IApiConnector connector = factory.createConnector(request, api, RequiredAuthType.BASIC, false);
IApiConnection connection = connector.connect(request,
new IAsyncResultHandler<IApiConnectionResponse>() {
@Override
public void handle(IAsyncResult<IApiConnectionResponse> result) {
Assert.assertTrue("Expected a successful connection response.", result.isSuccess());
IApiConnectionResponse scr = result.getResult();
Assert.assertEquals("Expected a 200 response from the echo server (valid creds).", 200, scr.getHead().getCode());
}
});
if (connection.isConnected()) {
connection.end();
}
}
示例12: shouldSucceedWithBasicAuthAndSSL
import io.apiman.gateway.engine.async.IAsyncResultHandler; //导入依赖的package包/类
/**
* Scenario successful connection to the back end API via basic auth.
*/
@Test
public void shouldSucceedWithBasicAuthAndSSL() {
endpointProperties.put(BasicAuthOptions.BASIC_USERNAME, "user");
endpointProperties.put(BasicAuthOptions.BASIC_PASSWORD, "user123!");
endpointProperties.put(BasicAuthOptions.BASIC_REQUIRE_SSL, "true");
api.setEndpointProperties(endpointProperties);
api.setEndpoint("https://localhost:8009/echo");
HttpConnectorFactory factory = new HttpConnectorFactory(globalConfig);
IApiConnector connector = factory.createConnector(request, api, RequiredAuthType.BASIC, false);
IApiConnection connection = connector.connect(request,
new IAsyncResultHandler<IApiConnectionResponse>() {
@Override
public void handle(IAsyncResult<IApiConnectionResponse> result) {
Assert.assertTrue("Expected a successful connection response.", result.isSuccess());
IApiConnectionResponse scr = result.getResult();
Assert.assertEquals("Expected a 200 response from the echo server (valid creds).", 200, scr.getHead().getCode());
}
});
if (connection.isConnected()) {
connection.end();
}
}
示例13: shouldFailWithBadCredentials
import io.apiman.gateway.engine.async.IAsyncResultHandler; //导入依赖的package包/类
/**
* Should fail because the credentials provided are not valid/
*/
@Test
public void shouldFailWithBadCredentials() {
endpointProperties.put(BasicAuthOptions.BASIC_USERNAME, "user");
endpointProperties.put(BasicAuthOptions.BASIC_PASSWORD, "bad-password");
endpointProperties.put(BasicAuthOptions.BASIC_REQUIRE_SSL, "false");
api.setEndpointProperties(endpointProperties);
api.setEndpoint("http://localhost:8008/echo");
HttpConnectorFactory factory = new HttpConnectorFactory(globalConfig);
IApiConnector connector = factory.createConnector(request, api, RequiredAuthType.BASIC, false);
IApiConnection connection = connector.connect(request,
new IAsyncResultHandler<IApiConnectionResponse>() {
@Override
public void handle(IAsyncResult<IApiConnectionResponse> result) {
Assert.assertTrue("Expected a successful connection response.", result.isSuccess());
IApiConnectionResponse scr = result.getResult();
Assert.assertEquals("Expected a 401 response from the echo server (invalid creds).", 401, scr.getHead().getCode());
}
});
if (connection.isConnected()) {
connection.end();
}
}
示例14: publishApi
import io.apiman.gateway.engine.async.IAsyncResultHandler; //导入依赖的package包/类
/**
* @see io.apiman.gateway.engine.IRegistry#publishApi(io.apiman.gateway.engine.beans.Api, io.apiman.gateway.engine.async.IAsyncResultHandler)
*/
@Override
public void publishApi(final Api api, final IAsyncResultHandler<Void> handler) {
try {
String id = getApiId(api);
Index index = new Index.Builder(api).refresh(false)
.index(getIndexName()).setParameter(Parameters.OP_TYPE, "index") //$NON-NLS-1$
.type("api").id(id).build(); //$NON-NLS-1$
JestResult result = getClient().execute(index);
if (!result.isSucceeded()) {
throw new IOException(result.getErrorMessage());
} else {
handler.handle(AsyncResultImpl.create((Void) null));
}
} catch (Exception e) {
handler.handle(AsyncResultImpl.create(
new PublishingException(Messages.i18n.format("ESRegistry.ErrorPublishingApi"), e), //$NON-NLS-1$
Void.class));
}
}
示例15: registerClient
import io.apiman.gateway.engine.async.IAsyncResultHandler; //导入依赖的package包/类
/**
* @see io.apiman.gateway.engine.es.CachingESRegistry#registerClient(io.apiman.gateway.engine.beans.Client, io.apiman.gateway.engine.async.IAsyncResultHandler)
*/
@Override
public void registerClient(Client client, final IAsyncResultHandler<Void> handler) {
super.registerClient(client, new IAsyncResultHandler<Void>() {
/**
* @see io.apiman.gateway.engine.async.IAsyncHandler#handle(java.lang.Object)
*/
@Override
public void handle(IAsyncResult<Void> result) {
if (result.isSuccess()) {
updateDataVersion();
}
handler.handle(result);
}
});
}