Search in sources :

Example 1 with CreateContextCommand

use of com.canoo.dp.impl.remoting.commands.CreateContextCommand in project dolphin-platform by canoo.

the class ClientContextImpl method connect.

@Override
public CompletableFuture<Void> connect() {
    final CompletableFuture<Void> result = new CompletableFuture<>();
    clientConnector.connect();
    clientConfiguration.getBackgroundExecutor().execute(() -> {
        dolphinCommandHandler.invokeDolphinCommand(new CreateContextCommand()).handle((Void aVoid, Throwable throwable) -> {
            if (throwable != null) {
                result.completeExceptionally(new ClientInitializationException("Can't call init action!", throwable));
            } else {
            }
            result.complete(null);
            return null;
        });
    });
    return result;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ClientInitializationException(com.canoo.platform.remoting.client.ClientInitializationException) CreateContextCommand(com.canoo.dp.impl.remoting.commands.CreateContextCommand)

Example 2 with CreateContextCommand

use of com.canoo.dp.impl.remoting.commands.CreateContextCommand in project dolphin-platform by canoo.

the class TestDolphinPlatformHttpClientConnector method testBadResponse.

@Test(expectedExceptions = DolphinRemotingException.class)
public void testBadResponse() throws DolphinRemotingException, URISyntaxException {
    PlatformClient.init(new HeadlessToolkit());
    PlatformClient.getClientConfiguration().setHttpURLConnectionFactory(new HttpURLConnectionFactory() {

        @Override
        public HttpURLConnection create(URI url) throws IOException {
            return new HttpURLConnection(url.toURL()) {

                @Override
                public void disconnect() {
                }

                @Override
                public boolean usingProxy() {
                    return false;
                }

                @Override
                public void connect() throws IOException {
                }

                @Override
                public OutputStream getOutputStream() throws IOException {
                    return new ByteArrayOutputStream();
                }
            };
        }
    });
    final ClientModelStore clientModelStore = new ClientModelStore(new DefaultModelSynchronizer(() -> null));
    final DolphinPlatformHttpClientConnector connector = new DolphinPlatformHttpClientConnector(getDummyURL(), PlatformClient.getClientConfiguration(), clientModelStore, new JsonCodec(), new SimpleExceptionHandler(), new HttpClientImpl(new Gson(), PlatformClient.getClientConfiguration()));
    final List<Command> commands = new ArrayList<>();
    commands.add(new CreateContextCommand());
    connector.transmit(commands);
}
Also used : DolphinPlatformHttpClientConnector(com.canoo.dp.impl.client.DolphinPlatformHttpClientConnector) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) DefaultModelSynchronizer(com.canoo.dp.impl.client.legacy.DefaultModelSynchronizer) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SimpleExceptionHandler(com.canoo.dp.impl.client.legacy.communication.SimpleExceptionHandler) CreateContextCommand(com.canoo.dp.impl.remoting.commands.CreateContextCommand) HttpURLConnectionFactory(com.canoo.platform.core.http.HttpURLConnectionFactory) JsonCodec(com.canoo.dp.impl.remoting.legacy.communication.JsonCodec) CreateContextCommand(com.canoo.dp.impl.remoting.commands.CreateContextCommand) Command(com.canoo.dp.impl.remoting.legacy.communication.Command) CreatePresentationModelCommand(com.canoo.dp.impl.remoting.legacy.communication.CreatePresentationModelCommand) HeadlessToolkit(com.canoo.platform.client.HeadlessToolkit) HttpClientImpl(com.canoo.dp.impl.platform.client.http.HttpClientImpl) ClientModelStore(com.canoo.dp.impl.client.legacy.ClientModelStore) Test(org.testng.annotations.Test)

Aggregations

CreateContextCommand (com.canoo.dp.impl.remoting.commands.CreateContextCommand)2 DolphinPlatformHttpClientConnector (com.canoo.dp.impl.client.DolphinPlatformHttpClientConnector)1 ClientModelStore (com.canoo.dp.impl.client.legacy.ClientModelStore)1 DefaultModelSynchronizer (com.canoo.dp.impl.client.legacy.DefaultModelSynchronizer)1 SimpleExceptionHandler (com.canoo.dp.impl.client.legacy.communication.SimpleExceptionHandler)1 HttpClientImpl (com.canoo.dp.impl.platform.client.http.HttpClientImpl)1 Command (com.canoo.dp.impl.remoting.legacy.communication.Command)1 CreatePresentationModelCommand (com.canoo.dp.impl.remoting.legacy.communication.CreatePresentationModelCommand)1 JsonCodec (com.canoo.dp.impl.remoting.legacy.communication.JsonCodec)1 HeadlessToolkit (com.canoo.platform.client.HeadlessToolkit)1 HttpURLConnectionFactory (com.canoo.platform.core.http.HttpURLConnectionFactory)1 ClientInitializationException (com.canoo.platform.remoting.client.ClientInitializationException)1 Gson (com.google.gson.Gson)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Test (org.testng.annotations.Test)1