Package rocks.xmpp.extensions.rpc.model

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


        xmppSession.addIQListener(new IQListener() {
            @Override
            public void handle(final IQEvent e) {
                final IQ iq = e.getIQ();
                if (e.isIncoming() && isEnabled() && !e.isConsumed() && iq.getType() == IQ.Type.SET) {
                    Rpc rpc = iq.getExtension(Rpc.class);
                    // If there's an incoming RPC
                    if (rpc != null) {
                        synchronized (RpcManager.this) {
                            if (rpcHandler != null) {
                                final Rpc.MethodCall methodCall = rpc.getMethodCall();
                                final List<Value> parameters = new ArrayList<>();
                                for (Value parameter : methodCall.getParameters()) {
                                    parameters.add(parameter);
                                }
                                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();
                                            result.setExtension(new Rpc(new Rpc.MethodResponse.Fault(e1.getFaultCode(), e1.getFaultString())));
                                            xmppSession.send(result);
                                        } catch (Throwable e1) {
                                            logger.log(Level.WARNING, e1.getMessage(), e1);
                                            xmppSession.send(iq.createError(new StanzaError(new InternalServerError())));
                                        }
View Full Code Here


     * @throws rocks.xmpp.core.session.NoResponseException  If the entity did not respond.
     * @throws rocks.xmpp.core.stanza.model.StanzaException If the RPC returned with an XMPP stanza error.
     * @throws RpcException                                 If the RPC returned with an application-level error ({@code <fault/>} element).
     */
    public Value call(Jid jid, String methodName, Value... parameters) throws XmppException, RpcException {
        IQ result = xmppSession.query(new IQ(jid, IQ.Type.SET, new Rpc(methodName, parameters)));
        if (result != null) {
            Rpc rpc = result.getExtension(Rpc.class);
            if (rpc != null) {
                Rpc.MethodResponse methodResponse = rpc.getMethodResponse();
                if (methodResponse != null) {
                    if (methodResponse.getFault() != null) {
                        throw new RpcException(methodResponse.getFault().getFaultCode(), methodResponse.getFault().getFaultString());
                    }
                    return methodResponse.getResponse();
View Full Code Here

                "    </methodResponse>\n" +
                "  </query>\n" +
                "</iq>";

        IQ iq = unmarshal(xml, IQ.class);
        Rpc rpc = iq.getExtension(Rpc.class);
        Assert.assertNotNull(rpc);
        Assert.assertEquals(rpc.getMethodResponse().getResponse().getAsString(), "Colorado");
    }
View Full Code Here

                "</methodResponse>" +
                "  </query>\n" +
                "</iq>";

        IQ iq = unmarshal(xml, IQ.class);
        Rpc rpc = iq.getExtension(Rpc.class);
        Assert.assertNotNull(rpc);
        Assert.assertNotNull(rpc.getMethodResponse().getFault());
        Assert.assertEquals(rpc.getMethodResponse().getFault().getFaultCode(), 4);
        Assert.assertEquals(rpc.getMethodResponse().getFault().getFaultString(), "Too many parameters.");
    }
View Full Code Here

                "      </params>\n" +
                "    </methodCall>\n" +
                "  </query>\n" +
                "</iq>\n";
        IQ iq = unmarshal(xml, IQ.class);
        Rpc rpc = iq.getExtension(Rpc.class);
        Assert.assertNotNull(rpc);
        Assert.assertEquals(rpc.getMethodCall().getMethodName(), "examples.getStateName");
        Assert.assertEquals(rpc.getMethodCall().getParameters().size(), 4);
        Assert.assertEquals(rpc.getMethodCall().getParameters().get(0).getAsInteger(), (Integer) 6);
        Assert.assertEquals(rpc.getMethodCall().getParameters().get(1).getAsBoolean(), Boolean.FALSE);
        Assert.assertEquals(rpc.getMethodCall().getParameters().get(2).getAsArray().get(0).getAsBoolean(), Boolean.TRUE);
        Assert.assertEquals(rpc.getMethodCall().getParameters().get(3).getAsMap().get("key").getAsBoolean(), Boolean.TRUE);
    }
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

TOP

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

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.