Package rocks.xmpp.extensions.rpc.model

Examples of rocks.xmpp.extensions.rpc.model.Value


        rpcManager.setEnabled(true);
        rpcManager.setRpcHandler(new RpcHandler() {
            @Override
            public Value process(Jid requester, String methodName, List<Value> parameters) throws RpcException {
                if (methodName.equals("square")) {
                    return new Value(parameters.get(0).getAsInteger() * parameters.get(0).getAsInteger());
                }
                return null;
            }
        });

        Value result = xmppSession2.getExtensionManager(RpcManager.class).call(ROMEO, "square", new Value(2));
        Assert.assertEquals(result.getAsInteger().intValue(), 4);
    }
View Full Code Here


                return null;
            }
        });

        try {
            xmppSession2.getExtensionManager(RpcManager.class).call(ROMEO, "fault", new Value(2));
        } catch (RpcException e) {
            Assert.assertEquals(e.getFaultCode(), 2);
            Assert.assertEquals(e.getFaultString(), "faulty");
            return;
        }
View Full Code Here

                                }
                                executorService.execute(new Runnable() {
                                    @Override
                                    public void run() {
                                        try {
                                            Value value = rpcHandler.process(iq.getFrom(), methodCall.getMethodName(), parameters);
                                            IQ result = iq.createResult();
                                            result.setExtension(new Rpc(value));
                                            xmppSession.send(result);
                                        } catch (RpcException e1) {
                                            IQ result = iq.createResult();
View Full Code Here

                            @Override
                            public Value process(Jid requester, String methodName, List<Value> parameters) throws RpcException {
                                if (methodName.equals("examples.getStateName")) {
                                    if (!parameters.isEmpty()) {
                                        if (parameters.get(0).getAsInteger() == 6) {
                                            return new Value("Colorado");
                                        }
                                    }
                                }
                                throw new RpcException(123, "Invalid method name or parameter.");
                            }
View Full Code Here

        Assert.assertEquals(rpc.getMethodCall().getParameters().get(3).getAsMap().get("key").getAsBoolean(), Boolean.TRUE);
    }

    @Test
    public void marshalRpcMethodCallWithInteger() throws JAXBException, XMLStreamException {
        Rpc rpc = new Rpc("testMethod", new Value(1));
        String xml = marshal(rpc);
        Assert.assertEquals(xml, "<query xmlns=\"jabber:iq:rpc\"><methodCall><methodName>testMethod</methodName><params><param><value><int>1</int></value></param></params></methodCall></query>");
    }
View Full Code Here

        Assert.assertEquals(xml, "<query xmlns=\"jabber:iq:rpc\"><methodCall><methodName>testMethod</methodName><params><param><value><int>1</int></value></param></params></methodCall></query>");
    }

    @Test
    public void marshalRpcMethodCallWithString() throws JAXBException, XMLStreamException {
        Rpc rpc = new Rpc("testMethod", new Value("test"));
        String xml = marshal(rpc);
        Assert.assertEquals(xml, "<query xmlns=\"jabber:iq:rpc\"><methodCall><methodName>testMethod</methodName><params><param><value><string>test</string></value></param></params></methodCall></query>");
    }
View Full Code Here

        Assert.assertEquals(xml, "<query xmlns=\"jabber:iq:rpc\"><methodCall><methodName>testMethod</methodName><params><param><value><string>test</string></value></param></params></methodCall></query>");
    }

    @Test
    public void marshalRpcMethodCallWithDouble() throws JAXBException, XMLStreamException {
        Rpc rpc = new Rpc("testMethod", new Value(10.4));
        String xml = marshal(rpc);
        Assert.assertEquals(xml, "<query xmlns=\"jabber:iq:rpc\"><methodCall><methodName>testMethod</methodName><params><param><value><double>10.4</double></value></param></params></methodCall></query>");
    }
View Full Code Here

    @Test
    public void marshalRpcMethodCallWithBase64() throws JAXBException, XMLStreamException {
        byte[] bytes = new byte[1];
        bytes[0] = 65;
        Rpc rpc = new Rpc("testMethod", new Value(bytes));
        String xml = marshal(rpc);
        Assert.assertEquals(xml, "<query xmlns=\"jabber:iq:rpc\"><methodCall><methodName>testMethod</methodName><params><param><value><base64>QQ==</base64></value></param></params></methodCall></query>");
    }
View Full Code Here

        calendar.set(Calendar.DATE, 23);
        calendar.set(Calendar.HOUR_OF_DAY, 22);
        calendar.set(Calendar.MINUTE, 37);
        calendar.set(Calendar.SECOND, 34);
        calendar.set(Calendar.MILLISECOND, 0);
        Rpc rpc = new Rpc("testMethod", new Value(calendar.getTime()));
        String xml = marshal(rpc);
        Assert.assertEquals(xml, "<query xmlns=\"jabber:iq:rpc\"><methodCall><methodName>testMethod</methodName><params><param><value><dateTime.iso8601>" + DatatypeConverter.printDateTime(calendar) + "</dateTime.iso8601></value></param></params></methodCall></query>");
    }
View Full Code Here

    }

    @Test
    public void marshalRpcMethodCallWithArray() throws JAXBException, XMLStreamException {
        List<Value> values = new ArrayList<>();
        values.add(new Value(1));
        values.add(new Value(2));
        Rpc rpc = new Rpc("testMethod", new Value(values));
        String xml = marshal(rpc);
        Assert.assertEquals(xml, "<query xmlns=\"jabber:iq:rpc\"><methodCall><methodName>testMethod</methodName><params><param><value><array><data><value><int>1</int></value><value><int>2</int></value></data></array></value></param></params></methodCall></query>");
    }
View Full Code Here

TOP

Related Classes of rocks.xmpp.extensions.rpc.model.Value

Copyright © 2018 www.massapicom. 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.