Search in sources :

Example 1 with CrtRuntimeException

use of software.amazon.awssdk.crt.CrtRuntimeException in project aws-crt-java by awslabs.

the class ServerListenerTest method testBindErrorPropagates.

@Test
public void testBindErrorPropagates() throws ExecutionException, InterruptedException, TimeoutException {
    SocketOptions socketOptions = new SocketOptions();
    socketOptions.connectTimeoutMs = 3000;
    socketOptions.domain = SocketOptions.SocketDomain.IPv4;
    socketOptions.type = SocketOptions.SocketType.STREAM;
    EventLoopGroup elGroup = new EventLoopGroup(1);
    ServerBootstrap bootstrap = new ServerBootstrap(elGroup);
    ServerListener listener1 = new ServerListener("127.0.0.1", (short) 8039, socketOptions, null, bootstrap, new ServerListenerHandler() {

        public ServerConnectionHandler onNewConnection(ServerConnection serverConnection, int errorCode) {
            return null;
        }

        public void onConnectionShutdown(ServerConnection serverConnection, int errorCode) {
        }
    });
    assertNotNull(listener1);
    boolean exceptionThrown = false;
    try {
        ServerListener listener2 = new ServerListener("127.0.0.1", (short) 8039, socketOptions, null, bootstrap, new ServerListenerHandler() {

            public ServerConnectionHandler onNewConnection(ServerConnection serverConnection, int errorCode) {
                return null;
            }

            public void onConnectionShutdown(ServerConnection serverConnection, int errorCode) {
            }
        });
    } catch (CrtRuntimeException ex) {
        assertTrue(ex.getMessage().contains("AWS_IO_SOCKET_ADDRESS_IN_USE(1054), Socket address already in use."));
        exceptionThrown = true;
    }
    assertTrue(exceptionThrown);
    listener1.close();
    listener1.getShutdownCompleteFuture().get(1, TimeUnit.SECONDS);
    bootstrap.close();
    elGroup.close();
    elGroup.getShutdownCompleteFuture().get(1, TimeUnit.SECONDS);
    socketOptions.close();
}
Also used : EventLoopGroup(software.amazon.awssdk.crt.io.EventLoopGroup) SocketOptions(software.amazon.awssdk.crt.io.SocketOptions) CrtRuntimeException(software.amazon.awssdk.crt.CrtRuntimeException) ServerBootstrap(software.amazon.awssdk.crt.io.ServerBootstrap) Test(org.junit.Test)

Example 2 with CrtRuntimeException

use of software.amazon.awssdk.crt.CrtRuntimeException in project aws-crt-java by awslabs.

the class Pkcs11LibTest method testPkcs11LibInitializeFinalizeBehavior.

@Test
public void testPkcs11LibInitializeFinalizeBehavior() {
    assumeEnvironmentSetUpForPkcs11Tests();
    // check that the behavior enum is passed to native.
    // we expect OMIT behavior to cause failure here because no one else
    // has called C_Initialize.
    CrtRuntimeException crtException = null;
    try (Pkcs11Lib pkcs11Lib = new Pkcs11Lib(TEST_PKCS11_LIB, Pkcs11Lib.InitializeFinalizeBehavior.OMIT)) {
    } catch (Exception ex) {
        crtException = (CrtRuntimeException) ex;
    }
    assertNotNull(crtException);
    assertTrue(crtException.errorName.contains("CKR_CRYPTOKI_NOT_INITIALIZED"));
}
Also used : CrtRuntimeException(software.amazon.awssdk.crt.CrtRuntimeException) Pkcs11Lib(software.amazon.awssdk.crt.io.Pkcs11Lib) CrtRuntimeException(software.amazon.awssdk.crt.CrtRuntimeException) Test(org.junit.Test)

Example 3 with CrtRuntimeException

use of software.amazon.awssdk.crt.CrtRuntimeException in project aws-crt-java by awslabs.

the class ProxyTest method doCredentialsProviderProxyTest.

private void doCredentialsProviderProxyTest(CredentialsProvider provider) {
    try {
        Credentials credentials = provider.getCredentials().get();
        Assert.assertNotNull(credentials);
    } catch (Exception e) {
        throw new CrtRuntimeException(e.toString());
    }
}
Also used : CrtRuntimeException(software.amazon.awssdk.crt.CrtRuntimeException) Credentials(software.amazon.awssdk.crt.auth.credentials.Credentials) URISyntaxException(java.net.URISyntaxException) CrtRuntimeException(software.amazon.awssdk.crt.CrtRuntimeException)

Example 4 with CrtRuntimeException

use of software.amazon.awssdk.crt.CrtRuntimeException in project aws-crt-java by awslabs.

the class ProxyTest method doHttpConnectionManagerProxyTest.

private void doHttpConnectionManagerProxyTest(HttpClientConnectionManager manager) {
    HttpRequest request = new HttpRequest("GET", "/");
    CompletableFuture requestCompleteFuture = new CompletableFuture();
    manager.acquireConnection().whenComplete((conn, throwable) -> {
        if (throwable != null) {
            requestCompleteFuture.completeExceptionally(throwable);
        }
        HttpStream stream = conn.makeRequest(request, new HttpStreamResponseHandler() {

            @Override
            public void onResponseHeaders(HttpStream stream, int responseStatusCode, int blockType, HttpHeader[] nextHeaders) {
                ;
            }

            @Override
            public void onResponseComplete(HttpStream stream, int errorCode) {
                // When this Request is complete, release the conn back to the pool
                manager.releaseConnection(conn);
                stream.close();
                if (errorCode != CRT.AWS_CRT_SUCCESS) {
                    requestCompleteFuture.completeExceptionally(new CrtRuntimeException(errorCode));
                } else {
                    requestCompleteFuture.complete(null);
                }
            }
        });
        if (stream != null) {
            stream.activate();
        }
    });
    requestCompleteFuture.join();
}
Also used : HttpRequest(software.amazon.awssdk.crt.http.HttpRequest) CompletableFuture(java.util.concurrent.CompletableFuture) HttpHeader(software.amazon.awssdk.crt.http.HttpHeader) HttpStreamResponseHandler(software.amazon.awssdk.crt.http.HttpStreamResponseHandler) CrtRuntimeException(software.amazon.awssdk.crt.CrtRuntimeException) HttpStream(software.amazon.awssdk.crt.http.HttpStream)

Example 5 with CrtRuntimeException

use of software.amazon.awssdk.crt.CrtRuntimeException in project aws-crt-java by awslabs.

the class TlsContextOptionsTest method testMtlsPkcs11.

@Test
public void testMtlsPkcs11() {
    Assume.assumeTrue(System.getProperty("NETWORK_TESTS_DISABLED") == null);
    Pkcs11LibTest.assumeEnvironmentSetUpForPkcs11Tests();
    try (Pkcs11Lib pkcs11Lib = new Pkcs11Lib(Pkcs11LibTest.TEST_PKCS11_LIB);
        TlsContextPkcs11Options pkcs11Options = new TlsContextPkcs11Options(pkcs11Lib).withUserPin(Pkcs11LibTest.TEST_PKCS11_PIN).withTokenLabel(Pkcs11LibTest.TEST_PKCS11_TOKEN_LABEL).withPrivateKeyObjectLabel(Pkcs11LibTest.TEST_PKCS11_PKEY_LABEL).withCertificateFilePath(Pkcs11LibTest.TEST_PKCS11_CERT_FILE);
        TlsContextOptions tlsOptions = TlsContextOptions.createWithMtlsPkcs11(pkcs11Options);
        TlsContext tls = new TlsContext(tlsOptions)) {
    } catch (CrtRuntimeException ex) {
        // This is expected to fail on platforms where we don't yet support mTLS with PKCS#11
        assertEquals("AWS_ERROR_UNIMPLEMENTED", ex.errorName);
    }
}
Also used : TlsContextOptions(software.amazon.awssdk.crt.io.TlsContextOptions) CrtRuntimeException(software.amazon.awssdk.crt.CrtRuntimeException) Pkcs11Lib(software.amazon.awssdk.crt.io.Pkcs11Lib) TlsContext(software.amazon.awssdk.crt.io.TlsContext) TlsContextPkcs11Options(software.amazon.awssdk.crt.io.TlsContextPkcs11Options) Test(org.junit.Test)

Aggregations

CrtRuntimeException (software.amazon.awssdk.crt.CrtRuntimeException)22 CompletableFuture (java.util.concurrent.CompletableFuture)11 Test (org.junit.Test)11 GetObjectOutput (com.amazonaws.s3.model.GetObjectOutput)7 ByteBuffer (java.nio.ByteBuffer)7 CredentialsProvider (software.amazon.awssdk.crt.auth.credentials.CredentialsProvider)6 HttpRequest (software.amazon.awssdk.crt.http.HttpRequest)5 Duration (java.time.Duration)3 List (java.util.List)3 CompletionException (java.util.concurrent.CompletionException)3 HttpHeader (software.amazon.awssdk.crt.http.HttpHeader)3 DeleteObjectOutput (com.amazonaws.s3.model.DeleteObjectOutput)2 DeleteObjectRequest (com.amazonaws.s3.model.DeleteObjectRequest)2 GetObjectRequest (com.amazonaws.s3.model.GetObjectRequest)2 ListObjectsOutput (com.amazonaws.s3.model.ListObjectsOutput)2 ListObjectsRequest (com.amazonaws.s3.model.ListObjectsRequest)2 PutObjectOutput (com.amazonaws.s3.model.PutObjectOutput)2 PutObjectRequest (com.amazonaws.s3.model.PutObjectRequest)2 AwsClientTestFixture (com.amazonaws.test.AwsClientTestFixture)2 IOException (java.io.IOException)2