use of org.eclipse.hono.application.client.amqp.ProtonBasedApplicationClient in project hono by eclipse.
the class ApplicationClientIT method testConnectFailsWithClientErrorForNoSASLMechanismException.
/**
* Verifies that a connection attempt where no credentials are given fails after two retries with a
* ClientErrorException with status code 401.
*
* @param ctx The vert.x test context.
*/
@Test
public void testConnectFailsWithClientErrorForNoSASLMechanismException(final VertxTestContext ctx) {
// GIVEN a client that is configured with no username and password
final ClientConfigProperties downstreamProps = new ClientConfigProperties();
downstreamProps.setHost(IntegrationTestSupport.DOWNSTREAM_HOST);
downstreamProps.setPort(IntegrationTestSupport.DOWNSTREAM_PORT);
downstreamProps.setReconnectAttempts(2);
client = new ProtonBasedApplicationClient(HonoConnection.newConnection(vertx, downstreamProps));
// WHEN the client tries to connect
client.connect().onComplete(ctx.failing(t -> {
// THEN the connection attempt fails due to lack of authorization
ctx.verify(() -> {
assertThat(t).isInstanceOf(ClientErrorException.class);
assertThat(((ClientErrorException) t).getErrorCode()).isEqualTo(HttpURLConnection.HTTP_UNAUTHORIZED);
});
ctx.completeNow();
}));
}
use of org.eclipse.hono.application.client.amqp.ProtonBasedApplicationClient in project hono by eclipse.
the class IntegrationTestSupport method init.
/**
* Connects to the AMQP 1.0 Messaging Network.
* <p>
* Also creates an HTTP client for accessing the Device Registry.
*
* @param downstreamProps The properties for connecting to the AMQP Messaging
* Network.
* @return A future indicating the outcome of the operation.
*/
public Future<Void> init(final ClientConfigProperties downstreamProps) {
initRegistryClient();
protonBasedHonoConnection = HonoConnection.newConnection(vertx, downstreamProps);
applicationClient = new ProtonBasedApplicationClient(protonBasedHonoConnection);
return applicationClient.start().onSuccess(connected -> LOGGER.info("connected to AMQP Messaging Network [{}:{}]", downstreamProps.getHost(), downstreamProps.getPort()));
}
use of org.eclipse.hono.application.client.amqp.ProtonBasedApplicationClient in project hono by eclipse.
the class HonoExampleApplicationBase method createAmqpApplicationClient.
/**
* The consumer needs one connection to the AMQP 1.0 messaging network from which it can consume data.
* <p>
* The client for receiving data is instantiated here.
* <p>
* NB: if you want to integrate this code with your own software, it might be necessary to copy the trust
* store to your project as well and adopt the file path.
*/
private ApplicationClient<? extends MessageContext> createAmqpApplicationClient() {
final ClientConfigProperties props = new ClientConfigProperties();
props.setLinkEstablishmentTimeout(5000L);
props.setHost(HonoExampleConstants.HONO_MESSAGING_HOST);
props.setPort(port);
if (!USE_PLAIN_CONNECTION) {
props.setUsername(HONO_CLIENT_USER);
props.setPassword(HONO_CLIENT_PASSWORD);
props.setTlsEnabled(true);
props.setServerRole("AMQP Messaging Network");
props.setTrustStorePath("target/config/hono-demo-certs-jar/trusted-certs.pem");
props.setHostnameVerificationRequired(false);
}
return new ProtonBasedApplicationClient(HonoConnection.newConnection(vertx, props));
}
use of org.eclipse.hono.application.client.amqp.ProtonBasedApplicationClient in project hono by eclipse.
the class ApplicationClientIT method testConnectFailsWithClientErrorIfTlsHandshakeFails.
/**
* Verifies that a connection attempt where the TLS handshake cannot be finished successfully fails after two
* retries with a ClientErrorException with status code 400.
*
* @param ctx The vert.x test context.
*/
@Test
@Timeout(value = 10, timeUnit = TimeUnit.SECONDS)
public void testConnectFailsWithClientErrorIfTlsHandshakeFails(final VertxTestContext ctx) {
// GIVEN a client that is configured to try to connect using an unsupported TLS version
final ClientConfigProperties downstreamProps = new ClientConfigProperties();
downstreamProps.setHost(IntegrationTestSupport.DOWNSTREAM_HOST);
downstreamProps.setPort(IntegrationTestSupport.DOWNSTREAM_PORT);
downstreamProps.setTlsEnabled(true);
downstreamProps.setSecureProtocols(List.of("TLSv1.1"));
downstreamProps.setReconnectAttempts(2);
client = new ProtonBasedApplicationClient(HonoConnection.newConnection(vertx, downstreamProps));
// WHEN the client tries to connect
client.connect().onComplete(ctx.failing(t -> {
// THEN the connection attempt fails due to lack of authorization
ctx.verify(() -> {
assertThat(t).isInstanceOf(ClientErrorException.class);
assertThat(((ClientErrorException) t).getErrorCode()).isEqualTo(HttpURLConnection.HTTP_BAD_REQUEST);
});
ctx.completeNow();
}));
}
Aggregations