當前位置: 首頁>>代碼示例>>Java>>正文


Java IAsyncResultHandler類代碼示例

本文整理匯總了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));
    }
}
 
開發者ID:outofcoffee,項目名稱:apiman-plugins-session,代碼行數:20,代碼來源:HazelcastSharedStateComponent.java

示例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();
}
 
開發者ID:outofcoffee,項目名稱:apiman-plugins-session,代碼行數:26,代碼來源:CommonTestUtil.java

示例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();
    }
}
 
開發者ID:outofcoffee,項目名稱:apiman-plugins-session,代碼行數:23,代碼來源:CommonTestUtil.java

示例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;
}
 
開發者ID:apiman,項目名稱:apiman-plugins,代碼行數:24,代碼來源:StandardAuth.java

示例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();
}
 
開發者ID:apiman,項目名稱:apiman-plugins,代碼行數:23,代碼來源:StandardAuth.java

示例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;
}
 
開發者ID:apiman,項目名稱:apiman-plugins,代碼行數:24,代碼來源:BatchedAuth.java

示例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);
        }
    });
}
 
開發者ID:apiman,項目名稱:apiman,代碼行數:19,代碼來源:SimpleSharedStatePolicy.java

示例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);
    }
}
 
開發者ID:apiman,項目名稱:apiman,代碼行數:26,代碼來源:URILoadingRegistry.java

示例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();
}
 
開發者ID:apiman,項目名稱:apiman,代碼行數:24,代碼來源:BasicMutualAuthTest.java

示例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();
}
 
開發者ID:apiman,項目名稱:apiman,代碼行數:22,代碼來源:StandardTLSTest.java

示例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();
    }
}
 
開發者ID:apiman,項目名稱:apiman,代碼行數:28,代碼來源:BasicAuthTest.java

示例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();
    }
}
 
開發者ID:apiman,項目名稱:apiman,代碼行數:28,代碼來源:BasicAuthTest.java

示例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();
    }
}
 
開發者ID:apiman,項目名稱:apiman,代碼行數:28,代碼來源:BasicAuthTest.java

示例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));
    }
}
 
開發者ID:apiman,項目名稱:apiman,代碼行數:23,代碼來源:ESRegistry.java

示例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);
        }
    });
}
 
開發者ID:apiman,項目名稱:apiman,代碼行數:19,代碼來源:PollCachingESRegistry.java


注:本文中的io.apiman.gateway.engine.async.IAsyncResultHandler類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。