本文整理匯總了Java中io.apiman.gateway.engine.IApiConnectionResponse類的典型用法代碼示例。如果您正苦於以下問題:Java IApiConnectionResponse類的具體用法?Java IApiConnectionResponse怎麽用?Java IApiConnectionResponse使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
IApiConnectionResponse類屬於io.apiman.gateway.engine包,在下文中一共展示了IApiConnectionResponse類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: HttpApiConnection
import io.apiman.gateway.engine.IApiConnectionResponse; //導入依賴的package包/類
/**
* Constructor.
*
* @param client the http client to use
* @param sslStrategy the SSL strategy
* @param request the request
* @param api the API
* @param requiredAuthType the authorization type
* @param hasDataPolicy if policy chain contains data policies
* @param handler the result handler
* @throws ConnectorException when unable to connect
*/
public HttpApiConnection(OkHttpClient client, ApiRequest request, Api api,
RequiredAuthType requiredAuthType, SSLSessionStrategy sslStrategy,
boolean hasDataPolicy, IAsyncResultHandler<IApiConnectionResponse> handler) throws ConnectorException {
this.client = client;
this.request = request;
this.api = api;
this.requiredAuthType = requiredAuthType;
this.sslStrategy = sslStrategy;
this.hasDataPolicy = hasDataPolicy;
this.responseHandler = handler;
try {
connect();
} catch (Exception e) {
// Sometimes it's possible that multiple exceptions end up coming through. Ignore secondary ones.
if (!isError) {
handler.handle(AsyncResultImpl.<IApiConnectionResponse> create(e));
isError = true;
}
}
}
示例2: end
import io.apiman.gateway.engine.IApiConnectionResponse; //導入依賴的package包/類
/**
* @see io.apiman.gateway.engine.io.IWriteStream#end()
*/
@Override
public void end() {
try {
IOUtils.closeQuietly(outputStream);
if (isError) {
return;
} else if (!connected) {
throw new IOException("Not connected."); //$NON-NLS-1$
}
outputStream = null;
// Process the response, convert to an ApiResponse object, and return it
response = GatewayThreadContext.getApiResponse();
Map<String, List<String>> headerFields = connection.getHeaderFields();
for (String headerName : headerFields.keySet()) {
if (headerName != null && !SUPPRESSED_RESPONSE_HEADERS.contains(headerName)) {
response.getHeaders().add(headerName, connection.getHeaderField(headerName));
}
}
response.setCode(connection.getResponseCode());
response.setMessage(connection.getResponseMessage());
responseHandler.handle(AsyncResultImpl.<IApiConnectionResponse> create(this));
} catch (Exception e) {
handleConnectionError(e);
}
}
示例3: shouldSucceedWhenAllowedSelfSigned
import io.apiman.gateway.engine.IApiConnectionResponse; //導入依賴的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();
}
示例4: shouldFailWithInValidKeyAlias
import io.apiman.gateway.engine.IApiConnectionResponse; //導入依賴的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();
}
示例5: shouldFailWithDevModeAndNoClientKeys
import io.apiman.gateway.engine.IApiConnectionResponse; //導入依賴的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();
}
示例6: shouldSucceedWithValidTLS
import io.apiman.gateway.engine.IApiConnectionResponse; //導入依賴的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();
}
示例7: shouldFailWhenCANotTrusted
import io.apiman.gateway.engine.IApiConnectionResponse; //導入依賴的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();
}
示例8: shouldAllowAllWhenDevMode
import io.apiman.gateway.engine.IApiConnectionResponse; //導入依賴的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();
}
示例9: shouldFailWithNoSettings
import io.apiman.gateway.engine.IApiConnectionResponse; //導入依賴的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();
}
示例10: shouldSucceedWithBasicAuth
import io.apiman.gateway.engine.IApiConnectionResponse; //導入依賴的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();
}
}
示例11: shouldSucceedWithBasicAuthAndSSL
import io.apiman.gateway.engine.IApiConnectionResponse; //導入依賴的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();
}
}
示例12: shouldFailWithNoSSL
import io.apiman.gateway.engine.IApiConnectionResponse; //導入依賴的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();
}
}
示例13: shouldFailWithBadCredentials
import io.apiman.gateway.engine.IApiConnectionResponse; //導入依賴的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: shouldFailWithNoCredentials
import io.apiman.gateway.engine.IApiConnectionResponse; //導入依賴的package包/類
/**
* Should fail because no credentials were provided.
*/
@Test
public void shouldFailWithNoCredentials() {
endpointProperties.remove(BasicAuthOptions.BASIC_USERNAME);
endpointProperties.remove(BasicAuthOptions.BASIC_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();
}
}
示例15: HttpConnector
import io.apiman.gateway.engine.IApiConnectionResponse; //導入依賴的package包/類
/**
* Construct an {@link HttpConnector} instance. The {@link #resultHandler} must remain exclusive to a
* given instance.
*
* @param vertx a vertx
* @param client the vertx http client
* @param api an API
* @param request a request with fields filled
* @param options the connector options
* @param resultHandler a handler, called when reading is permitted
*/
public HttpConnector(Vertx vertx, HttpClient client, ApiRequest request, Api api, ApimanHttpConnectorOptions options,
IAsyncResultHandler<IApiConnectionResponse> resultHandler) {
this.client = client;
this.api = api;
this.apiRequest = request;
this.resultHandler = resultHandler;
this.exceptionHandler = new ExceptionHandler();
this.apiEndpoint = options.getUri();
this.options = options;
apiHost = apiEndpoint.getHost();
apiPort = getPort();
apiPath = apiEndpoint.getPath().isEmpty() || apiEndpoint.getPath().equals("/") ? "" : apiEndpoint.getPath();
destination = apiRequest.getDestination() == null ? "" : apiRequest.getDestination();
verifyConnection();
}