Android Open Source - openpomo Xml Rpc Client






From Project

Back to project page openpomo.

License

The source code is released under:

GNU General Public License

If you think the Android project openpomo listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/**
 * This file is part of Pomodroid.//from w w  w  .  j a  va 2  s  .c o  m
 *
 *   Pomodroid is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   Pomodroid is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with Pomodroid.  If not, see <http://www.gnu.org/licenses/>.
 */
package it.unibz.pomodroid.services;

import android.net.NetworkInfo;

import java.net.URI;

import org.xmlrpc.android.XMLRPCClient;

import it.unibz.pomodroid.exceptions.PomodroidException;

import android.content.Context;
import android.net.ConnectivityManager;
import android.util.Log;

/**
 * A class that uses the remote procedure call protocol XML-RPC to retrieve information through the HTTP
 * as a transport mechanism.
 *
 * @author Daniel Graziotin <d AT danielgraziotin DOT it>
 * @author Thomas Schievenin <thomas.schievenin@stud-inf.unibz.it> *
 */
public class XmlRpcClient {

    /**
     * @param url
     * @param method
     * @param params
     * @return a single object
     * @throws PomodroidException
     */
    public static Object fetchSingleResult(String url, String method,
                                           Object[] params) throws PomodroidException {

        URI uri = URI.create(url);
        XMLRPCClient client = new XMLRPCClient(uri);

        Object result = null;

        try {
            result = client.call(method, params);
        } catch (Exception e) {
            Log.e("XML-RPC exception", e.toString());
            throw new PomodroidException("Connection failed: " + e.toString());
        }
        return result;
    }

    /**
     * @param url
     * @param method
     * @param params
     * @return one or more objects
     * @throws PomodroidException
     */
    public static Object[] fetchMultiResults(String url, String method,
                                             Object[] params) throws PomodroidException {

        URI uri = URI.create(url);
        XMLRPCClient client = new XMLRPCClient(uri);

        Object[] result = null;

        try {
            result = (Object[]) client.call(method, params);
        } catch (Exception e) {
            Log.e("XML-RPC exception", e.toString());
            throw new PomodroidException("Connection failed: " + e.toString());
        }
        return result;
    }

    /**
     * @param url
     * @param username
     * @param password
     * @param method
     * @param params
     * @return signle object
     * @throws PomodroidException
     */
    public static Object fetchSingleResult(String url, String username,
                                           String password, String method, Object[] params) throws PomodroidException {

        URI uri = URI.create(url);
        XMLRPCClient client = new XMLRPCClient(uri);
        client.setBasicAuthentication(username, password);
        Object result = null;

        try {
            result = client.call(method, params);
        } catch (Exception e) {
            Log.e("XML-RPC exception", e.toString());
            throw new PomodroidException("Connection failed: " + e.toString());
        }
        return result;
    }

    /**
     * @param url
     * @param username
     * @param password
     * @param method
     * @param params
     * @return one or more objects
     * @throws PomodroidException
     */
    public static Object[] fetchMultiResults(String url, String username,
                                             String password, String method, Object[] params) throws PomodroidException {

        URI uri = URI.create(url);
        XMLRPCClient client = new XMLRPCClient(uri);
        client.setBasicAuthentication(username, password);
        Object[] result = null;

        try {
            result = (Object[]) client.call(method, params);
        } catch (Exception e) {
            Log.e("XML-RPC exception", e.toString());
            throw new PomodroidException("Connection failed: " + e.toString());
        }
        return result;
    }

    /**
     * @return boolean return true if the application can access the internet
     */
    public static boolean isInternetAvailable(Context context) {
        NetworkInfo connectionAvailable = ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
        if (connectionAvailable == null || !connectionAvailable.isConnected()) {
            return false;
        }
        if (connectionAvailable.isRoaming()) {
            return true;
        }
        return true;
    }
}




Java Source Code List

it.unibz.pomodroid.About.java
it.unibz.pomodroid.ActivityInventorySheet.java
it.unibz.pomodroid.CleanDatabase.java
it.unibz.pomodroid.EditActivity.java
it.unibz.pomodroid.EditService.java
it.unibz.pomodroid.ListServices.java
it.unibz.pomodroid.PomodoroService.java
it.unibz.pomodroid.Pomodoro.java
it.unibz.pomodroid.Pomodroid.java
it.unibz.pomodroid.Preferences.java
it.unibz.pomodroid.Services.java
it.unibz.pomodroid.SharedActivity.java
it.unibz.pomodroid.SharedListActivity.java
it.unibz.pomodroid.Statistics.java
it.unibz.pomodroid.TabPomodroid.java
it.unibz.pomodroid.TabPreferences.java
it.unibz.pomodroid.TodoTodaySheet.java
it.unibz.pomodroid.TrashSheet.java
it.unibz.pomodroid.exceptions.PomodroidException.java
it.unibz.pomodroid.factories.ActivityFactory.java
it.unibz.pomodroid.models.Activity.java
it.unibz.pomodroid.models.DBHelper.java
it.unibz.pomodroid.models.Event.java
it.unibz.pomodroid.models.Service.java
it.unibz.pomodroid.models.User.java
it.unibz.pomodroid.services.TracTicketFetcher.java
it.unibz.pomodroid.services.XmlRpcClient.java
org.xmlrpc.Test.java
org.xmlrpc.android.Base64Coder.java
org.xmlrpc.android.XMLRPCClient.java
org.xmlrpc.android.XMLRPCException.java
org.xmlrpc.android.XMLRPCFault.java
org.xmlrpc.android.XMLRPCSerializer.java