Java Code Examples for com.mysql.fabric.xmlrpc.base.Value

The following examples show how to use com.mysql.fabric.xmlrpc.base.Value. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: r-course   Source File: InternalXmlRpcMethodCaller.java    License: MIT License 5 votes vote down vote up
/**
 * Unwrap the underlying object from the Value wrapper.
 */
private Object unwrapValue(Value v) {
    if (v.getType() == Value.TYPE_array) {
        return methodResponseArrayToList((Array) v.getValue());
    } else if (v.getType() == Value.TYPE_struct) {
        Map<String, Object> s = new HashMap<String, Object>();
        for (Member m : ((Struct) v.getValue()).getMember()) {
            s.put(m.getName(), unwrapValue(m.getValue()));
        }
        return s;
    }
    return v.getValue();
}
 
Example 2
Source Project: r-course   Source File: InternalXmlRpcMethodCaller.java    License: MIT License 5 votes vote down vote up
private List<Object> methodResponseArrayToList(Array array) {
    List<Object> result = new ArrayList<Object>();
    for (Value v : array.getData().getValue()) {
        result.add(unwrapValue(v));
    }
    return result;
}
 
Example 3
Source Project: r-course   Source File: InternalXmlRpcMethodCaller.java    License: MIT License 5 votes vote down vote up
public List<Object> call(String methodName, Object args[]) throws FabricCommunicationException {
    MethodCall methodCall = new MethodCall();
    Params p = new Params();
    if (args == null) {
        args = new Object[] {};
    }
    for (int i = 0; i < args.length; ++i) {
        if (args[i] == null) {
            throw new NullPointerException("nil args unsupported");
        } else if (String.class.isAssignableFrom(args[i].getClass())) {
            p.addParam(new Param(new Value((String) args[i])));
        } else if (Double.class.isAssignableFrom(args[i].getClass())) {
            p.addParam(new Param(new Value((Double) args[i])));
        } else if (Integer.class.isAssignableFrom(args[i].getClass())) {
            p.addParam(new Param(new Value((Integer) args[i])));
        } else {
            throw new IllegalArgumentException("Unknown argument type: " + args[i].getClass());
        }
    }
    methodCall.setMethodName(methodName);
    methodCall.setParams(p);
    try {
        MethodResponse resp = this.xmlRpcClient.execute(methodCall);
        return methodResponseArrayToList((Array) resp.getParams().getParam().get(0).getValue().getValue());
    } catch (Exception ex) {
        throw new FabricCommunicationException("Error during call to `" + methodName + "' (args=" + Arrays.toString(args) + ")", ex); //irrecoverable
    }
}
 
Example 4
/**
 * Unwrap the underlying object from the Value wrapper.
 */
private Object unwrapValue(Value v) {
    if (v.getType() == Value.TYPE_array) {
        return methodResponseArrayToList((Array) v.getValue());
    } else if (v.getType() == Value.TYPE_struct) {
        Map<String, Object> s = new HashMap<String, Object>();
        for (Member m : ((Struct) v.getValue()).getMember()) {
            s.put(m.getName(), unwrapValue(m.getValue()));
        }
        return s;
    }
    return v.getValue();
}
 
Example 5
private List<Object> methodResponseArrayToList(Array array) {
    List<Object> result = new ArrayList<Object>();
    for (Value v : array.getData().getValue()) {
        result.add(unwrapValue(v));
    }
    return result;
}
 
Example 6
public List<Object> call(String methodName, Object args[]) throws FabricCommunicationException {
    MethodCall methodCall = new MethodCall();
    Params p = new Params();
    if (args == null) {
        args = new Object[] {};
    }
    for (int i = 0; i < args.length; ++i) {
        if (args[i] == null) {
            throw new NullPointerException("nil args unsupported");
        } else if (String.class.isAssignableFrom(args[i].getClass())) {
            p.addParam(new Param(new Value((String) args[i])));
        } else if (Double.class.isAssignableFrom(args[i].getClass())) {
            p.addParam(new Param(new Value((Double) args[i])));
        } else if (Integer.class.isAssignableFrom(args[i].getClass())) {
            p.addParam(new Param(new Value((Integer) args[i])));
        } else {
            throw new IllegalArgumentException("Unknown argument type: " + args[i].getClass());
        }
    }
    methodCall.setMethodName(methodName);
    methodCall.setParams(p);
    try {
        MethodResponse resp = this.xmlRpcClient.execute(methodCall);
        return methodResponseArrayToList((Array) resp.getParams().getParam().get(0).getValue().getValue());
    } catch (Exception ex) {
        throw new FabricCommunicationException("Error during call to `" + methodName + "' (args=" + Arrays.toString(args) + ")", ex); //irrecoverable
    }
}
 
Example 7
Source Project: r-course   Source File: TestXmlRpcCore.java    License: MIT License 4 votes vote down vote up
public void testProtocol() throws Exception {
    if (!this.isSetForFabricTest) {
        return;
    }

    MethodCall mc = new MethodCall();
    MethodResponse resp = null;

    Client client = new Client(this.fabricUrl);

    Params pms = new Params();
    pms.addParam(new Param(new Value(0)));
    /*
     * pms.addParam(new Param(new Value("abc")));
     * pms.addParam(new Param(new Value(false)));
     * pms.addParam(new Param(new Value(-23.345D)));
     * pms.addParam(new Param(new Value((GregorianCalendar) GregorianCalendar.getInstance())));
     * // TODO base64
     * 
     * Struct s2 = new Struct();
     * s2.addMember(new Member("mem 2.1", new Value("qq")));
     * s2.addMember(new Member("mem 2.2", new Value(22.22)));
     * Struct s1 = new Struct();
     * s1.addMember(new Member("mem 1.1", new Value(false)));
     * s1.addMember(new Member("mem 1.2", new Value(22)));
     * s1.addMember(new Member("mem 1.3", new Value(s2)));
     * pms.addParam(new Param(new Value(s1)));
     * 
     * Array a = new Array();
     * a.addValue(new Value(true));
     * a.addValue(new Value(s1));
     * pms.addParam(new Param(new Value(a)));
     */
    mc.setMethodName("dump.servers");
    mc.setParams(pms);

    generateAuthHeaders(client);
    resp = client.execute(mc);
    System.out.println("Servers: " + resp.toString());
    System.out.println();

    mc = new MethodCall(); // to clean params
    mc.setMethodName("sharding.list_definitions");
    generateAuthHeaders(client);
    resp = client.execute(mc);
    System.out.println("Definitions: " + resp.toString());
    System.out.println();

    mc.setMethodName("dump.fabric_nodes");
    generateAuthHeaders(client);
    resp = client.execute(mc);
    System.out.println("Fabrics: " + resp.toString());
    System.out.println();

    mc.setMethodName("group.lookup_groups");
    generateAuthHeaders(client);
    resp = client.execute(mc);
    System.out.println("Groups: " + resp.toString());
    System.out.println();

    pms = new Params();
    pms.addParam(new Param(new Value("fabric_test1_global")));
    mc.setMethodName("group.lookup_servers");
    mc.setParams(pms);
    generateAuthHeaders(client);
    resp = client.execute(mc);
    System.out.println("Servers: " + resp.toString());
    System.out.println();

}
 
Example 8
Source Project: Komondor   Source File: TestXmlRpcCore.java    License: GNU General Public License v3.0 4 votes vote down vote up
public void testProtocol() throws Exception {
    if (!this.isSetForFabricTest) {
        return;
    }

    MethodCall mc = new MethodCall();
    MethodResponse resp = null;

    Client client = new Client(this.fabricUrl);

    Params pms = new Params();
    pms.addParam(new Param(new Value(0)));
    /*
     * pms.addParam(new Param(new Value("abc")));
     * pms.addParam(new Param(new Value(false)));
     * pms.addParam(new Param(new Value(-23.345D)));
     * pms.addParam(new Param(new Value((GregorianCalendar) GregorianCalendar.getInstance())));
     * // TODO base64
     * 
     * Struct s2 = new Struct();
     * s2.addMember(new Member("mem 2.1", new Value("qq")));
     * s2.addMember(new Member("mem 2.2", new Value(22.22)));
     * Struct s1 = new Struct();
     * s1.addMember(new Member("mem 1.1", new Value(false)));
     * s1.addMember(new Member("mem 1.2", new Value(22)));
     * s1.addMember(new Member("mem 1.3", new Value(s2)));
     * pms.addParam(new Param(new Value(s1)));
     * 
     * Array a = new Array();
     * a.addValue(new Value(true));
     * a.addValue(new Value(s1));
     * pms.addParam(new Param(new Value(a)));
     */
    mc.setMethodName("dump.servers");
    mc.setParams(pms);

    generateAuthHeaders(client);
    resp = client.execute(mc);
    System.out.println("Servers: " + resp.toString());
    System.out.println();

    mc = new MethodCall(); // to clean params
    mc.setMethodName("sharding.list_definitions");
    generateAuthHeaders(client);
    resp = client.execute(mc);
    System.out.println("Definitions: " + resp.toString());
    System.out.println();

    mc.setMethodName("dump.fabric_nodes");
    generateAuthHeaders(client);
    resp = client.execute(mc);
    System.out.println("Fabrics: " + resp.toString());
    System.out.println();

    mc.setMethodName("group.lookup_groups");
    generateAuthHeaders(client);
    resp = client.execute(mc);
    System.out.println("Groups: " + resp.toString());
    System.out.println();

    pms = new Params();
    pms.addParam(new Param(new Value("fabric_test1_global")));
    mc.setMethodName("group.lookup_servers");
    mc.setParams(pms);
    generateAuthHeaders(client);
    resp = client.execute(mc);
    System.out.println("Servers: " + resp.toString());
    System.out.println();

}