Examples of JettyJSONContextClient


Examples of org.cometd.common.JettyJSONContextClient

    public void init()
    {
        Object option = getOption(JSON_CONTEXT_OPTION);
        if (option == null)
        {
            jsonContext = new JettyJSONContextClient();
        }
        else
        {
            if (option instanceof String)
            {
View Full Code Here

Examples of org.cometd.common.JettyJSONContextClient

        transport.setOption(AbstractHttpTransport.MAX_SESSIONS_PER_BROWSER_OPTION, 1);
        transport.setOption(AbstractHttpTransport.MULTI_SESSION_INTERVAL_OPTION, multiSessionInterval);
        // Force re-initialization
        transport.init();

        JSONContext.Client parser = new JettyJSONContextClient();

        String handshakeContent = "[{" +
                "\"id\":\"1\"," +
                "\"channel\":\"/meta/handshake\"," +
                "\"version\":\"1.0\"," +
                "\"supportedConnectionTypes\":[\"long-polling\"]" +
                "}]";
        ContentResponse handshake = httpClient.newRequest("localhost", connector.getLocalPort())
                .method(HttpMethod.POST)
                .path(cometdServletPath)
                .content(new StringContentProvider(handshakeContent), "application/json;charset=UTF-8")
                .timeout(5, TimeUnit.SECONDS)
                .send();
        assertEquals(200, handshake.getStatus());
        HttpCookie browserCookie = httpClient.getCookieStore().get(URI.create(cometdURL)).get(0);
        assertEquals("BAYEUX_BROWSER", browserCookie.getName());
        Message.Mutable[] messages = parser.parse(handshake.getContentAsString());
        assertEquals(1, messages.length);
        String clientId = messages[0].getClientId();

        String connectContent1 = "[{" +
                "\"id\":\"2\"," +
                "\"channel\":\"/meta/connect\"," +
                "\"connectionType\":\"long-polling\"," +
                "\"clientId\":\"" + clientId + "\"," +
                "\"advice\": {\"timeout\":0}" +
                "}]";
        ContentResponse connect1 = httpClient.newRequest("localhost", connector.getLocalPort())
                .method(HttpMethod.POST)
                .path(cometdServletPath)
                .content(new StringContentProvider(connectContent1), "application/json;charset=UTF-8")
                .timeout(5, TimeUnit.SECONDS)
                .send();
        assertEquals(200, connect1.getStatus());

        // This /meta/connect is suspended.
        final CountDownLatch abortedConnectLatch = new CountDownLatch(1);
        String connectContent2 = "[{" +
                "\"id\":\"3\"," +
                "\"channel\":\"/meta/connect\"," +
                "\"connectionType\":\"long-polling\"," +
                "\"clientId\":\"" + clientId + "\"" +
                "}]";
        httpClient.newRequest("localhost", connector.getLocalPort())
                .method(HttpMethod.POST)
                .path(cometdServletPath)
                .content(new StringContentProvider(connectContent2), "application/json;charset=UTF-8")
                .timeout(5, TimeUnit.SECONDS)
                .send(new Response.CompleteListener()
                {
                    @Override
                    public void onComplete(Result result)
                    {
                        assertTrue(result.isSucceeded());
                        assertEquals(408, result.getResponse().getStatus());
                        abortedConnectLatch.countDown();
                    }
                });

        // Give some time to the long poll to happen.
        Thread.sleep(1000);

        // Send the second /meta/connect before the previous returns.
        String connectContent3 = "[{" +
                "\"id\":\"4\"," +
                "\"channel\":\"/meta/connect\"," +
                "\"connectionType\":\"long-polling\"," +
                "\"clientId\":\"" + clientId + "\"," +
                "\"advice\": {\"timeout\":0}" +
                "}]";
        ContentResponse connect3 = httpClient.newRequest("localhost", connector.getLocalPort())
                .method(HttpMethod.POST)
                .path(cometdServletPath)
                .content(new StringContentProvider(connectContent3), "application/json;charset=UTF-8")
                .timeout(5, TimeUnit.SECONDS)
                .send();
        assertEquals(200, connect3.getStatus());

        assertTrue(abortedConnectLatch.await(5, TimeUnit.SECONDS));

        // Make sure a subsequent connect does not have the multiple-clients advice.
        String connectContent4 = "[{" +
                "\"id\":\"5\"," +
                "\"channel\":\"/meta/connect\"," +
                "\"connectionType\":\"long-polling\"," +
                "\"clientId\":\"" + clientId + "\"" +
                "}]";
        ContentResponse connect4 = httpClient.newRequest("localhost", connector.getLocalPort())
                .method(HttpMethod.POST)
                .path(cometdServletPath)
                .content(new StringContentProvider(connectContent4), "application/json;charset=UTF-8")
                .timeout(2 * timeout, TimeUnit.MILLISECONDS)
                .send();
        assertEquals(200, connect4.getStatus());
        messages = parser.parse(connect4.getContentAsString());
        assertEquals(1, messages.length);
        Message.Mutable message = messages[0];
        Map<String, Object> advice = message.getAdvice(true);
        assertFalse(advice.containsKey("multiple-clients"));
    }
View Full Code Here

Examples of org.cometd.common.JettyJSONContextClient

                "\"data\": {}" +
                "}]");
        response = publish.send();
        Assert.assertEquals(200, response.getStatus());

        JSONContext.Client jsonContext = new JettyJSONContextClient();
        Message.Mutable[] messages = jsonContext.parse(response.getContentAsString());
        Assert.assertEquals(1, messages.length);
        Message message = messages[0];
        Assert.assertFalse(message.isSuccessful());

        publish = newBayeuxRequest("[{" +
                "\"channel\": \"/service/foo\"," +
                "\"clientId\": \"" + clientId + "\"," +
                "\"data\": {}" +
                "}]");
        response = publish.send();
        Assert.assertEquals(200, response.getStatus());

        messages = jsonContext.parse(response.getContentAsString());
        Assert.assertEquals(1, messages.length);
        message = messages[0];
        Assert.assertTrue(message.isSuccessful());
    }
View Full Code Here

Examples of org.cometd.common.JettyJSONContextClient

                "\"data\": {}" +
                "}]");
        response = publish.send();
        Assert.assertEquals(200, response.getStatus());

        JSONContext.Client jsonContext = new JettyJSONContextClient();
        Message.Mutable[] messages = jsonContext.parse(response.getContentAsString());
        Assert.assertEquals(1, messages.length);
        Message message = messages[0];
        Assert.assertFalse(message.isSuccessful());

        // Check that publishing to another channel does not involve authorizers
        Request grantedPublish = newBayeuxRequest("[{" +
                "\"channel\": \"/foo\"," +
                "\"clientId\": \"" + clientId + "\"," +
                "\"data\": {}" +
                "}]");
        response = grantedPublish.send();
        Assert.assertEquals(200, response.getStatus());

        messages = jsonContext.parse(response.getContentAsString());
        Assert.assertEquals(1, messages.length);
        message = messages[0];
        Assert.assertTrue(message.isSuccessful());
    }
View Full Code Here

Examples of org.cometd.common.JettyJSONContextClient

                "\"data\": {}" +
                "}]");
        response = publish.send();
        Assert.assertEquals(200, response.getStatus());

        JSONContext.Client jsonContext = new JettyJSONContextClient();
        Message.Mutable[] messages = jsonContext.parse(response.getContentAsString());
        Assert.assertEquals(1, messages.length);
        Message message = messages[0];
        Assert.assertTrue(message.isSuccessful());
    }
View Full Code Here

Examples of org.cometd.common.JettyJSONContextClient

                "\"data\": {}" +
                "}]");
        response = publish.send();
        Assert.assertEquals(200, response.getStatus());

        JSONContext.Client jsonContext = new JettyJSONContextClient();
        Message.Mutable[] messages = jsonContext.parse(response.getContentAsString());
        Assert.assertEquals(1, messages.length);
        Message message = messages[0];
        Assert.assertFalse(message.isSuccessful());

        // Check that publishing to another channel does not involve authorizers
        Request grantedPublish = newBayeuxRequest("[{" +
                "\"channel\": \"/foo\"," +
                "\"clientId\": \"" + clientId + "\"," +
                "\"data\": {}" +
                "}]");
        response = grantedPublish.send();
        Assert.assertEquals(200, response.getStatus());

        messages = jsonContext.parse(response.getContentAsString());
        Assert.assertEquals(1, messages.length);
        message = messages[0];
        Assert.assertTrue(message.isSuccessful());
    }
View Full Code Here

Examples of org.cometd.common.JettyJSONContextClient

                "\"data\": {}" +
                "}]");
        response = publish.send();
        Assert.assertEquals(200, response.getStatus());

        JSONContext.Client jsonContext = new JettyJSONContextClient();
        Message.Mutable[] messages = jsonContext.parse(response.getContentAsString());
        Assert.assertEquals(1, messages.length);
        Message message = messages[0];
        Assert.assertTrue(message.isSuccessful());

        // Check that publishing again fails (the authorizer has been removed)
        Request grantedPublish = newBayeuxRequest("[{" +
                "\"channel\": \"" + channelName + "\"," +
                "\"clientId\": \"" + clientId + "\"," +
                "\"data\": {}" +
                "}]");
        response = grantedPublish.send();
        Assert.assertEquals(200, response.getStatus());

        messages = jsonContext.parse(response.getContentAsString());
        Assert.assertEquals(1, messages.length);
        message = messages[0];
        Assert.assertFalse(message.isSuccessful());
    }
View Full Code Here

Examples of org.cometd.common.JettyJSONContextClient

        return response;
    }

    private void checkResponse(ContentResponse reply, String reconnectAdvice) throws ParseException, UnsupportedEncodingException
    {
        JSONContext.Client jsonContext = new JettyJSONContextClient();
        Message.Mutable[] responses = jsonContext.parse(reply.getContentAsString());
        Assert.assertEquals(1, responses.length);
        Message response = responses[0];
        Map<String, Object> advice = response.getAdvice();
        Assert.assertNotNull(advice);
        Assert.assertEquals(reconnectAdvice, advice.get(Message.RECONNECT_FIELD));
View Full Code Here

Examples of org.cometd.common.JettyJSONContextClient

        response = futureResponse.get(timeout * 2, TimeUnit.SECONDS);
        Assert.assertEquals(200, response.getStatus());

        Assert.assertTrue(response.getContentAsString().toLowerCase().contains("unknown"));

        JettyJSONContextClient parser = new JettyJSONContextClient();
        Message.Mutable connectReply2 = parser.parse(response.getContentAsString())[0];
        String error = (String)connectReply2.get(Message.ERROR_FIELD);
        Assert.assertNotNull(error);
        Assert.assertTrue(error.toLowerCase().contains("unknown"));
        Map<String,Object> advice = connectReply2.getAdvice();
        Assert.assertNotNull(advice);
        Assert.assertEquals(Message.RECONNECT_NONE_VALUE, advice.get(Message.RECONNECT_FIELD));

        Assert.assertNull(bayeux.getSession(clientId));

        // Test that sending a connect for an expired session
        // will return an advice with reconnect:"handshake"
        Request connect3 = newBayeuxRequest("[{" +
                "\"channel\": \"/meta/connect\"," +
                "\"clientId\": \"" + clientId + "\"," +
                "\"connectionType\": \"long-polling\"" +
                "}]");
        response = connect3.send();
        Assert.assertEquals(200, response.getStatus());
        Message.Mutable connectReply3 = parser.parse(response.getContentAsString())[0];
        advice = connectReply3.getAdvice();
        Assert.assertNotNull(advice);
        Assert.assertEquals(Message.RECONNECT_HANDSHAKE_VALUE, advice.get(Message.RECONNECT_FIELD));
    }
View Full Code Here

Examples of org.cometd.common.JettyJSONContextClient

                "}]");
        response = publish.send();
        Assert.assertEquals(200, response.getStatus());

        // Expect only the meta response to the publish
        JSONContext.Client jsonContext = new JettyJSONContextClient();
        Message.Mutable[] messages = jsonContext.parse(response.getContentAsString());
        Assert.assertEquals(1, messages.length);

        connect = newBayeuxRequest("[{" +
                "\"channel\": \"/meta/connect\"," +
                "\"clientId\": \"" + clientId + "\"," +
                "\"connectionType\": \"long-polling\"" +
                "}]");
        response = connect.send();
        Assert.assertEquals(200, response.getStatus());

        // Expect meta response to the connect plus the published message
        messages = jsonContext.parse(response.getContentAsString());
        Assert.assertEquals(2, messages.length);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.