本文整理汇总了Java中io.apiman.gateway.engine.async.IAsyncResult类的典型用法代码示例。如果您正苦于以下问题:Java IAsyncResult类的具体用法?Java IAsyncResult怎么用?Java IAsyncResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IAsyncResult类属于io.apiman.gateway.engine.async包,在下文中一共展示了IAsyncResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: verifyResult
import io.apiman.gateway.engine.async.IAsyncResult; //导入依赖的package包/类
/**
* Verify the session data.
*
* @param result the result of retrieving session data
* @param sessionId the ID of the session
* @param request the service request
* @param context the policy context
* @param config the policy configuration
* @return the result of the validation
*/
private ValidationResult verifyResult(IAsyncResult<Session> result, String sessionId, ApiRequest request,
IPolicyContext context, CookieValidateConfigBean config) {
final ValidationResult validationResult;
final Session sessionData = result.getResult();
if (result.isSuccess() && null != sessionData && StringUtils.isNotBlank(sessionData.getSessionId())) {
validationResult = verifySessionData(sessionData, sessionId, request, context, config);
} else {
//noinspection ThrowableResultOfMethodCallIgnored
if (null != result.getError()) {
LOGGER.error(MESSAGES.format("ErrorReadingSessionData", sessionId), result.getError());
}
// session not present
validationResult = new ValidationResult(false,
MESSAGES.format("MissingSessionData", sessionId));
}
return validationResult;
}
示例2: fetchSession
import io.apiman.gateway.engine.async.IAsyncResult; //导入依赖的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.IAsyncResult; //导入依赖的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: handle
import io.apiman.gateway.engine.async.IAsyncResult; //导入依赖的package包/类
@Override
public void handle(IAsyncResult<IHttpClientResponse> result) {
if (result.isSuccess()) {
IHttpClientResponse postResponse = result.getResult();
if ((postResponse.getResponseCode() / 100) == 2) {
resultHandler.handle(RESULT_OK);
} else {
try {
// ReportResponse reportResponse = parseReport(postResponse.getBody());
// RuntimeException re = new RuntimeException(String.format("Backend report failed. Code: %s, Message: %s",
// reportResponse.getErrorCode(), reportResponse.getErrorMessage()));
ReportResponse reportResponse = parseReport(postResponse.getBody());
resultHandler.handle(AsyncResultImpl.create(reportResponse));
} catch (Exception e) {
RuntimeException re = new RuntimeException("Unable to parse report response", e); // TODO more specific //$NON-NLS-1$
resultHandler.handle(AsyncResultImpl.create(re));
}
}
}
}
示例5: shouldSucceedWhenAllowedSelfSigned
import io.apiman.gateway.engine.async.IAsyncResult; //导入依赖的package包/类
/**
* Scenario:
* - no CA inherited trust
* - gateway does not explicitly trust the API, but automatically validates against self-signed
* - API trusts gateway certificate
*/
@Test
public void shouldSucceedWhenAllowedSelfSigned() {
config.put(TLSOptions.TLS_TRUSTSTORE, getResourcePath("2waytest/basic_mutual_auth/gateway_ts.jks"));
config.put(TLSOptions.TLS_TRUSTSTOREPASSWORD, "password");
config.put(TLSOptions.TLS_KEYSTORE, getResourcePath("2waytest/basic_mutual_auth/gateway_ks.jks"));
config.put(TLSOptions.TLS_KEYSTOREPASSWORD, "password");
config.put(TLSOptions.TLS_KEYPASSWORD, "password");
config.put(TLSOptions.TLS_ALLOWANYHOST, "true");
config.put(TLSOptions.TLS_ALLOWSELFSIGNED, "true");
HttpConnectorFactory factory = new HttpConnectorFactory(config);
IApiConnector connector = factory.createConnector(request, api, RequiredAuthType.MTLS, false);
IApiConnection connection = connector.connect(request,
new IAsyncResultHandler<IApiConnectionResponse>() {
@Override
public void handle(IAsyncResult<IApiConnectionResponse> result) {
Assert.assertTrue(result.isSuccess());
}
});
connection.end();
}
示例6: shouldFailWithInValidKeyAlias
import io.apiman.gateway.engine.async.IAsyncResult; //导入依赖的package包/类
/**
* Scenario:
* - Select invalid key alias (no such key).
* - Negotiation will fail
* @throws CertificateException the certificate exception
* @throws IOException the IO exception
*/
@Test
public void shouldFailWithInValidKeyAlias() throws CertificateException, IOException {
config.put(TLSOptions.TLS_TRUSTSTORE, getResourcePath("2waytest/basic_mutual_auth_2/gateway_ts.jks"));
config.put(TLSOptions.TLS_TRUSTSTOREPASSWORD, "password");
config.put(TLSOptions.TLS_KEYSTORE, getResourcePath("2waytest/basic_mutual_auth_2/gateway_ks.jks"));
config.put(TLSOptions.TLS_KEYSTOREPASSWORD, "password");
config.put(TLSOptions.TLS_KEYPASSWORD, "password");
config.put(TLSOptions.TLS_ALLOWANYHOST, "true");
config.put(TLSOptions.TLS_ALLOWSELFSIGNED, "false");
// No such key exists in the keystore
config.put(TLSOptions.TLS_KEYALIASES, "xxx");
HttpConnectorFactory factory = new HttpConnectorFactory(config);
IApiConnector connector = factory.createConnector(request, api, RequiredAuthType.MTLS, false);
IApiConnection connection = connector.connect(request,
new IAsyncResultHandler<IApiConnectionResponse>() {
@Override
public void handle(IAsyncResult<IApiConnectionResponse> result) {
Assert.assertTrue(result.isError());
}
});
connection.end();
}
示例7: shouldFailWithDevModeAndNoClientKeys
import io.apiman.gateway.engine.async.IAsyncResult; //导入依赖的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();
}
示例8: shouldSucceedWithValidTLS
import io.apiman.gateway.engine.async.IAsyncResult; //导入依赖的package包/类
/**
* Scenario:
* - CA inherited trust
* - gateway trusts API via CA
* - API does not evaluate trust
*/
@Test
public void shouldSucceedWithValidTLS() {
config.put(TLSOptions.TLS_TRUSTSTORE, getResourcePath("2waytest/mutual_trust_via_ca/common_ts.jks"));
config.put(TLSOptions.TLS_TRUSTSTOREPASSWORD, "password");
config.put(TLSOptions.TLS_ALLOWANYHOST, "true");
config.put(TLSOptions.TLS_ALLOWSELFSIGNED, "false");
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) {
if (result.isError())
throw new RuntimeException(result.getError());
Assert.assertTrue(result.isSuccess());
}
});
connection.end();
}
示例9: shouldFailWhenCANotTrusted
import io.apiman.gateway.engine.async.IAsyncResult; //导入依赖的package包/类
/**
* Scenario:
* - CA is only in API trust store, missing from gateway trust store
* - Gateway does not trust API, as it does not trust CA
* - API trusts gateway via CA
*/
@Test
public void shouldFailWhenCANotTrusted() {
// Keystore does not trust the root CA API is signed with.
config.put(TLSOptions.TLS_TRUSTSTORE, getResourcePath("2waytest/basic_mutual_auth/gateway_ts.jks"));
config.put(TLSOptions.TLS_TRUSTSTOREPASSWORD, "password");
config.put(TLSOptions.TLS_ALLOWANYHOST, "true");
config.put(TLSOptions.TLS_ALLOWSELFSIGNED, "false");
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());
Assert.assertTrue(result.getError() instanceof ConnectorException);
}
});
connection.end();
}
示例10: shouldAllowAllWhenDevMode
import io.apiman.gateway.engine.async.IAsyncResult; //导入依赖的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: shouldFailWithNoSettings
import io.apiman.gateway.engine.async.IAsyncResult; //导入依赖的package包/类
/**
* Scenario:
* - No settings whatsoever.
* - Will fail, as defaults are relatively safe,
* and API certificate will not be recognised.
*/
@Test
public void shouldFailWithNoSettings() {
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();
}
示例12: shouldSucceedWithBasicAuth
import io.apiman.gateway.engine.async.IAsyncResult; //导入依赖的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();
}
}
示例13: shouldSucceedWithBasicAuthAndSSL
import io.apiman.gateway.engine.async.IAsyncResult; //导入依赖的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();
}
}
示例14: shouldFailWithNoSSL
import io.apiman.gateway.engine.async.IAsyncResult; //导入依赖的package包/类
/**
* Scenario successful connection to the back end API via basic auth.
*/
@Test
public void shouldFailWithNoSSL() {
endpointProperties.put(BasicAuthOptions.BASIC_USERNAME, "user");
endpointProperties.put(BasicAuthOptions.BASIC_PASSWORD, "user123!");
endpointProperties.put(BasicAuthOptions.BASIC_REQUIRE_SSL, "true");
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 an error due to not using SSL.", result.isError());
Assert.assertTrue("Expected a ConnectorException due to not using SSL.", result.getError() instanceof ConnectorException);
Assert.assertEquals("Endpoint security requested (BASIC auth) but endpoint is not secure (SSL).", result.getError().getMessage());
}
});
if (connection.isConnected()) {
connection.end();
}
}
示例15: shouldFailWithBadCredentials
import io.apiman.gateway.engine.async.IAsyncResult; //导入依赖的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();
}
}