IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

API standards et tierces Android Discussion :

Problème de connexion avec la base de donnees mysql a l'aide de script Php


Sujet :

API standards et tierces Android

  1. #1
    Candidat au Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Avril 2016
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2016
    Messages : 3
    Points : 4
    Points
    4
    Par défaut Problème de connexion avec la base de donnees mysql a l'aide de script Php
    Bonjour,
    Y a-t-il quelqu'un qui peut m'aider pour résoudre un problème de connexion avec la base de données MySql à l'aide d'un fichier php.
    Je pense que le problème est en lien avec le script php.
    voici le code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    package com.example.sanaa.testlogin;
    import android.app.Activity;
    import android.app.ProgressDialog;
    import android.content.Intent;
    import android.os.Looper;
    import android.support.v7.app.AlertDialog;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
     
    import org.apache.http.params.HttpConnectionParams;
    import org.xml.sax.InputSource;
    import org.xml.sax.SAXException;
    import org.xml.sax.XMLReader;
    import org.xml.sax.helpers.DefaultHandler;
     
    import java.io.IOException;
    import java.io.InputStream;
    import java.security.MessageDigest;
    import java.security.NoSuchAlgorithmException;
    import java.util.jar.Attributes;
     
    import javax.xml.parsers.ParserConfigurationException;
    import javax.xml.parsers.SAXParser;
    import javax.xml.parsers.SAXParserFactory;
     
    public class Login extends AppCompatActivity {
     
        // Lien vers votre page php sur votre serveur
        private static final String	UPDATE_URL	= "http://paddesite.pa.ohost.de/login.php";
     
        public ProgressDialog progressDialog;
     
        private EditText UserEditText;
     
        private EditText						PassEditText;
     
        public void onCreate(Bundle savedInstanceState)
        {
     
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
     
            // initialisation d'une progress bar
            progressDialog = new ProgressDialog(this);
            progressDialog.setMessage("Please wait...");
            progressDialog.setIndeterminate(true);
            progressDialog.setCancelable(false);
            // Récupération des éléments de la vue définis dans le xml
            UserEditText = (EditText) findViewById(R.id.username);
     
            PassEditText = (EditText) findViewById(R.id.password);
            Button button = (Button) findViewById(R.id.okbutton);
     
            // Définition du listener du bouton
            button.setOnClickListener(new View.OnClickListener()
            {
     
                public void onClick(View v)
                {
     
                    int usersize = UserEditText.getText().length();
     
                    int passsize = PassEditText.getText().length();
                    // si les deux champs sont remplis
                    if (usersize > 0 && passsize > 0)
                    {
     
                        progressDialog.show();
     
                        String user = UserEditText.getText().toString();
     
                        String pass = PassEditText.getText().toString();
                        // On appelle la fonction doLogin qui va communiquer avec le PHP
                        doLogin(user, pass);
     
                    }
                    else
                        createDialog("Error", "Please enter Username and Password");
     
                }
     
            });
     
            button = (Button) findViewById(R.id.cancelbutton);
            // Création du listener du bouton cancel (on sort de l'appli)
            button.setOnClickListener(new View.OnClickListener()
            {
     
                public void onClick(View v)
                {
                    quit(false, null);
                }
     
            });
     
        }
     
        private void quit(boolean success, Intent i)
        {
            // On envoie un résultat qui va permettre de quitter l'appli
            setResult((success) ? Activity.RESULT_OK : Activity.RESULT_CANCELED, i);
            finish();
     
        }
     
        private void createDialog(String title, String text)
        {
            // Création d'une popup affichant un message
            AlertDialog ad = new AlertDialog.Builder(this)
                    .setPositiveButton("Ok", null).setTitle(title).setMessage(text)
                    .create();
            ad.show();
     
        }
     
        private void doLogin(final String login, final String pass)
        {
     
            final String pw = md5(pass);
            // Création d'un thread
            Thread t = new Thread()
            {
     
                public void run()
                {
     
                    Looper.prepare();
                    // On se connecte au serveur afin de communiquer avec le PHP
                    DefaultHttpClient client = new DefaultHttpClient();
                    HttpConnectionParams.setConnectionTimeout(client.getParams(), 15000);
     
                    HttpResponse response;
                    HttpEntity entity;
     
                    try
                    {
                        // On établit un lien avec le script PHP
                        HttpPost post = new HttpPost(UPDATE_URL);
     
                        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
     
                        nvps.add(new BasicNameValuePair("Login", login));
     
                        nvps.add(new BasicNameValuePair("Password", pw));
     
                        post.setHeader("Content-Type", "application/x-www-form-urlencoded");
                        // On passe les paramètres login et password qui vont être récupérés
                        // par le script PHP en post
                        post.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
                        // On récupère le résultat du script
                        response = client.execute(post);
     
                        entity = response.getEntity();
     
                        InputStream is = entity.getContent();
                        // On appelle une fonction définie plus bas pour traduire la réponse
                        read(is);
                        is.close();
     
                        if (entity != null)
                            entity.consumeContent();}
                    catch (Exception e)
                    {progressDialog.dismiss();
                        createDialog("Error", "Couldn't establish a connection");}
                    Looper.loop();}};
            t.start();}
        private void read(InputStream in) {
            // On traduit le résultat d'un flux
            SAXParserFactory spf = SAXParserFactory.newInstance();
            SAXParser sp;
            try
            {
                sp = spf.newSAXParser();
     
                XMLReader xr = sp.getXMLReader();
                // Cette classe est définie plus bas
                LoginContentHandler uch = new LoginContentHandler();
     
                xr.setContentHandler(uch);
     
                xr.parse(new InputSource(in));
     
            }
            catch (ParserConfigurationException e)
            {
     
            }
            catch (SAXException e)
            {
     
            }
            catch (IOException e)
            {
            }
     
        }
     
        private String md5(String in)
        {
     
            MessageDigest digest;
     
            try
            {
     
                digest = MessageDigest.getInstance("MD5");
     
                digest.reset();
     
                digest.update(in.getBytes());
     
                byte[] a = digest.digest();
     
                int len = a.length;
     
                StringBuilder sb = new StringBuilder(len << 1);
     
                for (int i = 0; i < len; i++)
                {
     
                    sb.append(Character.forDigit((a[i] & 0xf0) >> 4, 16));
     
                    sb.append(Character.forDigit(a[i] & 0x0f, 16));
     
                }
     
                return sb.toString();
     
            }
            catch (NoSuchAlgorithmException e)
            {
                e.printStackTrace();
            }
     
            return null;
     
        }
     
        private class LoginContentHandler extends DefaultHandler
        {
            // Classe traitant le message de retour du script PHP
            private boolean	in_loginTag		= false;
            private int			userID;
            private boolean	error_occured	= false;
     
            public void startElement(String n, String l, String q, Attributes a)
     
                    throws SAXException
     
            {
     
                if (l == "login")
                    in_loginTag = true;
                if (l == "error")
                {
     
                    progressDialog.dismiss();
     
                    switch (Integer.parseInt(a.getValue("value"))
                    {
                        case 1:
                            createDialog("Error", "Couldn't connect to Database");
                            break;
                        case 2:
                            createDialog("Error", "Error in Database: Table missing");
                            break;
                        case 3:
                            createDialog("Error", "Invalid username and/or password");
                            break;
                    }
                    error_occured = true;
     
                }
     
                if (l == "user" && in_loginTag && a.getValue("id") != "")
                    // Dans le cas où tout se passe bien on récupère l'ID de l'utilisateur
                    userID = Integer.parseInt(a.getValue("id"));
     
            }
     
            public void endElement(String n, String l, String q) throws SAXException
            {
                // on renvoie l'id si tout est ok
                if (l == "login")
                {
                    in_loginTag = false;
     
                    if (!error_occured)
                    {
                        progressDialog.dismiss();
                        Intent i = new Intent();
                        i.putExtra("userid", userID);
                        quit(true, i);
                    }
                }
            }
     
            public void characters(char ch[], int start, int length)
            {
            }
     
            public void startDocument() throws SAXException
            {
            }
     
            public void endDocument() throws SAXException
            {
            }
     
        }
     
    }

  2. #2
    Membre à l'essai Avatar de Flyzzx
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2016
    Messages
    10
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 30
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2016
    Messages : 10
    Points : 13
    Points
    13
    Par défaut
    Bonsoir,

    Essaie d'utiliser HttpURLConnection, au travers d'une classe qui dérive d'ASyncTask, ça marche plutôt bien chez moi

    Bonne soirée

  3. #3
    Membre régulier
    Homme Profil pro
    Développeur Java
    Inscrit en
    Octobre 2012
    Messages
    100
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Congo-Kinshasa

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : Enseignement

    Informations forums :
    Inscription : Octobre 2012
    Messages : 100
    Points : 91
    Points
    91
    Par défaut
    Bonjour,

    Pourquoi tu utilises le même thread pour l’exécution de ton application et pour la connexion à la base de donnée.
    De cette façon ça ne va pas marché. Il faut plutôt mettre le code qui doit se connecter avec ta base de donnée dans un autre thread, il faudrait alors utiliser la classe AsyncTask. Cherche les notes à l'internet, il y a des exemples comment l'utiliser.

  4. #4
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Mars 2016
    Messages
    40
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2016
    Messages : 40
    Points : 20
    Points
    20
    Par défaut
    j'ai un problème au niveau de mon code et je ne peux pas le resoudre , android studio can not resolve ( httprequest , httpresponse, ..)
    voici exemple de code ( du ligne 13 à 23 provoque des erreurs):
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
     
    package org.xmlrpc.android;
     
    import java.io.BufferedInputStream;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.Reader;
    import java.io.StringWriter;
    import java.net.URI;
    import java.net.URL;
    import java.util.Map;
     
    import org.apache.http.HttpEntity;
    import org.apache.http.HttpResponse;
    import org.apache.http.HttpStatus;
    import org.apache.http.auth.AuthScope;
    import org.apache.http.auth.UsernamePasswordCredentials;
    import org.apache.http.client.HttpClient;
    import org.apache.http.client.methods.HttpPost;
    import org.apache.http.entity.StringEntity;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.apache.http.params.HttpParams;
    import org.apache.http.params.HttpProtocolParams;
    import org.xmlpull.v1.XmlPullParser;
    import org.xmlpull.v1.XmlPullParserFactory;
     
    /**
     * XMLRPCClient allows to call remote XMLRPC method.
     *
     * <p>
     * The following table shows how XML-RPC types are mapped to java call parameters/response values.
     * </p>
     *
     * <p>
     * <table border="2" align="center" cellpadding="5">
     * <thead><tr><th>XML-RPC Type</th><th>Call Parameters</th><th>Call Response</th></tr></thead>
     *
     * <tbody>
     * <td>int, i4</td><td>byte<br />Byte<br />short<br />Short<br />int<br />Integer</td><td>int<br />Integer</td>
     * </tr>
     * <tr>
     * <td>i8</td><td>long<br />Long</td><td>long<br />Long</td>
     * </tr>
     * <tr>
     * <td>double</td><td>float<br />Float<br />double<br />Double</td><td>double<br />Double</td>
     * </tr>
     * <tr>
     * <td>string</td><td>String</td><td>String</td>
     * </tr>
     * <tr>
     * <td>boolean</td><td>boolean<br />Boolean</td><td>boolean<br />Boolean</td>
     * </tr>
     * <tr>
     * <td>dateTime.iso8601</td><td>java.util.Date<br />java.util.Calendar</td><td>java.util.Date</td>
     * </tr>
     * <tr>
     * <td>base64</td><td>byte[]</td><td>byte[]</td>
     * </tr>
     * <tr>
     * <td>array</td><td>java.util.List&lt;Object&gt;<br />Object[]</td><td>Object[]</td>
     * </tr>
     * <tr>
     * <td>struct</td><td>java.util.Map&lt;String, Object&gt;</td><td>java.util.Map&lt;String, Object&gt;</td>
     * </tr>
     * </tbody>
     * </table>
     * </p>
     * <p>
     * You can also pass as a parameter any object implementing XMLRPCSerializable interface. In this
     * case your object overrides getSerializable() telling how to serialize to XMLRPC protocol
     * </p>
     */
     
    public class XMLRPCClient extends XMLRPCCommon {
    	private HttpClient client;
    	private HttpPost postMethod;
    	private HttpParams httpParams;
     
    	/**
             * XMLRPCClient constructor. Creates new instance based on server URI */
    	/*
     
    	 * @param XMLRPC server URI
    	 */
    	public XMLRPCClient(URI uri) {
    		postMethod = new HttpPost(uri);
    		postMethod.addHeader("Content-Type", "text/xml");
     
    		// WARNING
    		// I had to disable "Expect: 100-Continue" header since I had 
    		// two second delay between sending http POST request and POST body 
    		httpParams = postMethod.getParams();
    		HttpProtocolParams.setUseExpectContinue(httpParams, false);
    		client = new DefaultHttpClient();
    	}
     
    	/**
             * Convenience constructor. Creates new instance based on server String address */
    	/*
    	 * @param XMLRPC server address
    	 */
    	public XMLRPCClient(String url) {
    		this(URI.create(url));
    	}
     
    	/**
             * Convenience XMLRPCClient constructor. Creates new instance based on server URL */
    	/*
    	 * @param XMLRPC server URL
    	 */
    	public XMLRPCClient(URL url) {
    		this(URI.create(url.toExternalForm()));
    	}
     
    	/**
             * Convenience constructor. Creates new instance based on server String address */
    	/*
    	 * @param XMLRPC server address
    	 * @param HTTP Server - Basic Authentication - Username
    	 * @param HTTP Server - Basic Authentication - Password
    	 */
    	public XMLRPCClient(URI uri, String username, String password) {
    		this(uri);
     
    		((DefaultHttpClient) client).getCredentialsProvider().setCredentials(
    				new AuthScope(uri.getHost(), uri.getPort(),AuthScope.ANY_REALM),
    				new UsernamePasswordCredentials(username, password));
    	}
     
    	/**
             * Convenience constructor. Creates new instance based on server String address */
    	/*
    	 * @param XMLRPC server address
    	 * @param HTTP Server - Basic Authentication - Username
    	 * @param HTTP Server - Basic Authentication - Password
    	 */
    	public XMLRPCClient(String url, String username, String password) {
    		this(URI.create(url), username, password);
    	}
     
    	/**
             * Convenience constructor. Creates new instance based on server String address */
    	/*
    	 * @param XMLRPC server url
    	 * @param HTTP Server - Basic Authentication - Username
    	 * @param HTTP Server - Basic Authentication - Password
    	 */
    	public XMLRPCClient(URL url, String username, String password) {
    		this(URI.create(url.toExternalForm()), username, password);
    	}
     
    	/**
             * Sets basic authentication on web request using plain credentials
             * @param username The plain text username
             * @param password The plain text password
             */
    	public void setBasicAuthentication(String username, String password) {
    		((DefaultHttpClient) client).getCredentialsProvider().setCredentials(
    				new AuthScope(postMethod.getURI().getHost(), postMethod.getURI().getPort(),
    						AuthScope.ANY_REALM),
    				new UsernamePasswordCredentials(username, password));
    	}
     
    	/**
             * Call method with optional parameters. This is general method.
             * If you want to call your method with 0-8 parameters, you can use more
             * convenience call() methods
             *
             * @param method name of method to call
             * @param params parameters to pass to method (may be null if method has no parameters)
             * @return deserialized method return value
             * @throws XMLRPCException
             */
    	@SuppressWarnings("unchecked")
    	public Object callEx(String method, Object[] params) throws XMLRPCException {
    		try {
    			// prepare POST body
    			String body = methodCall(method, params);
     
    			// set POST body
    			HttpEntity entity = new StringEntity(body);
    			postMethod.setEntity(entity);
     
    			//Log.d(Tag.LOG, "ros HTTP POST");
    			// execute HTTP POST request
    			HttpResponse response = client.execute(postMethod);
    			//Log.d(Tag.LOG, "ros HTTP POSTed");
     
    			// check status code
    			int statusCode = response.getStatusLine().getStatusCode();
    			//Log.d(Tag.LOG, "ros status code:" + statusCode);
    			if (statusCode != HttpStatus.SC_OK) {
    				throw new XMLRPCException("HTTP status code: " + statusCode + " != " + HttpStatus.SC_OK);
    			}
     
    			// parse response stuff
    			//
    			// setup pull parser
    			XmlPullParser pullParser = XmlPullParserFactory.newInstance().newPullParser();
    			entity = response.getEntity();
    			Reader reader = new InputStreamReader(new BufferedInputStream(entity.getContent()));
    // for testing purposes only
    // reader = new StringReader("<?xml version='1.0'?><methodResponse><params><param><value>\n\n\n</value></param></params></methodResponse>");
    			pullParser.setInput(reader);
     
    			// lets start pulling...
    			pullParser.nextTag();
    			pullParser.require(XmlPullParser.START_TAG, null, Tag.METHOD_RESPONSE);
     
    			pullParser.nextTag(); // either Tag.PARAMS (<params>) or Tag.FAULT (<fault>)  
    			String tag = pullParser.getName();
    			if (tag.equals(Tag.PARAMS)) {
    				// normal response
    				pullParser.nextTag(); // Tag.PARAM (<param>)
    				pullParser.require(XmlPullParser.START_TAG, null, Tag.PARAM);
    				pullParser.nextTag(); // Tag.VALUE (<value>)
    				// no parser.require() here since its called in XMLRPCSerializer.deserialize() below
     
    				// deserialize result
    				Object obj = iXMLRPCSerializer.deserialize(pullParser);
    				entity.consumeContent();
    				return obj;
    			} else
    			if (tag.equals(Tag.FAULT)) {
    				// fault response
    				pullParser.nextTag(); // Tag.VALUE (<value>)
    				// no parser.require() here since its called in XMLRPCSerializer.deserialize() below
     
    				// deserialize fault result
    				Map<String, Object> map = (Map<String, Object>) iXMLRPCSerializer.deserialize(pullParser);
    				String faultString = (String) map.get(Tag.FAULT_STRING);
    				int faultCode = (Integer) map.get(Tag.FAULT_CODE);
    				entity.consumeContent();
    				throw new XMLRPCFault(faultString, faultCode);
    			} else {
    				entity.consumeContent();
    				throw new XMLRPCException("Bad tag <" + tag + "> in XMLRPC response - neither <params> nor <fault>");
    			}
    		} catch (XMLRPCException e) {
    			// catch & propagate XMLRPCException/XMLRPCFault
    			throw e;
    		} catch (Exception e) {
    			e.printStackTrace();
    			// wrap any other Exception(s) around XMLRPCException
    			throw new XMLRPCException(e);
    		}
    	}
     
    	private String methodCall(String method, Object[] params)
    			throws IllegalArgumentException, IllegalStateException, IOException {
    		StringWriter bodyWriter = new StringWriter();
    		serializer.setOutput(bodyWriter);
    		serializer.startDocument(null, null);
    		serializer.startTag(null, Tag.METHOD_CALL);
    		// set method name
    		serializer.startTag(null, Tag.METHOD_NAME).text(method).endTag(null, Tag.METHOD_NAME);
     
    		serializeParams(params);
     
    		serializer.endTag(null, Tag.METHOD_CALL);
    		serializer.endDocument();
     
    		return bodyWriter.toString();
    	}
     
    	/**
             * Convenience method call with no parameters
             *
             * @param method name of method to call
             * @return deserialized method return value
             * @throws XMLRPCException
             */
    	public Object call(String method) throws XMLRPCException {
    		return callEx(method, null);
    	}
     
    	/**
             * Convenience method call with one parameter
             *
             * @param method name of method to call
             * @param p0 method's parameter
             * @return deserialized method return value
             * @throws XMLRPCException
             */
    	public Object call(String method, Object p0) throws XMLRPCException {
    		Object[] params = {
    				p0,
    		};
    		return callEx(method, params);
    	}
     
    	/**
             * Convenience method call with two parameters
             *
             * @param method name of method to call
             * @param p0 method's 1st parameter
             * @param p1 method's 2nd parameter
             * @return deserialized method return value
             * @throws XMLRPCException
             */
    	public Object call(String method, Object p0, Object p1) throws XMLRPCException {
    		Object[] params = {
    				p0, p1,
    		};
    		return callEx(method, params);
    	}
     
    	/**
             * Convenience method call with three parameters
             *
             * @param method name of method to call
             * @param p0 method's 1st parameter
             * @param p1 method's 2nd parameter
             * @param p2 method's 3rd parameter
             * @return deserialized method return value
             * @throws XMLRPCException
             */
    	public Object call(String method, Object p0, Object p1, Object p2) throws XMLRPCException {
    		Object[] params = {
    				p0, p1, p2,
    		};
    		return callEx(method, params);
    	}
     
    	/**
             * Convenience method call with four parameters
             *
             * @param method name of method to call
             * @param p0 method's 1st parameter
             * @param p1 method's 2nd parameter
             * @param p2 method's 3rd parameter
             * @param p3 method's 4th parameter
             * @return deserialized method return value
             * @throws XMLRPCException
             */
    	public Object call(String method, Object p0, Object p1, Object p2, Object p3) throws XMLRPCException {
    		Object[] params = {
    				p0, p1, p2, p3,
    		};
    		return callEx(method, params);
    	}
     
    	/**
             * Convenience method call with five parameters
             *
             * @param method name of method to call
             * @param p0 method's 1st parameter
             * @param p1 method's 2nd parameter
             * @param p2 method's 3rd parameter
             * @param p3 method's 4th parameter
             * @param p4 method's 5th parameter
             * @return deserialized method return value
             * @throws XMLRPCException
             */
    	public Object call(String method, Object p0, Object p1, Object p2, Object p3, Object p4) throws XMLRPCException {
    		Object[] params = {
    				p0, p1, p2, p3, p4,
    		};
    		return callEx(method, params);
    	}
     
    	/**
             * Convenience method call with six parameters
             *
             * @param method name of method to call
             * @param p0 method's 1st parameter
             * @param p1 method's 2nd parameter
             * @param p2 method's 3rd parameter
             * @param p3 method's 4th parameter
             * @param p4 method's 5th parameter
             * @param p5 method's 6th parameter
             * @return deserialized method return value
             * @throws XMLRPCException
             */
    	public Object call(String method, Object p0, Object p1, Object p2, Object p3, Object p4, Object p5) throws XMLRPCException {
    		Object[] params = {
    				p0, p1, p2, p3, p4, p5,
    		};
    		return callEx(method, params);
    	}
     
    	/**
             * Convenience method call with seven parameters
             *
             * @param method name of method to call
             * @param p0 method's 1st parameter
             * @param p1 method's 2nd parameter
             * @param p2 method's 3rd parameter
             * @param p3 method's 4th parameter
             * @param p4 method's 5th parameter
             * @param p5 method's 6th parameter
             * @param p6 method's 7th parameter
             * @return deserialized method return value
             * @throws XMLRPCException
             */
    	public Object call(String method, Object p0, Object p1, Object p2, Object p3, Object p4, Object p5, Object p6) throws XMLRPCException {
    		Object[] params = {
    				p0, p1, p2, p3, p4, p5, p6,
    		};
    		return callEx(method, params);
    	}
     
    	/**
             * Convenience method call with eight parameters
             *
             * @param method name of method to call
             * @param p0 method's 1st parameter
             * @param p1 method's 2nd parameter
             * @param p2 method's 3rd parameter
             * @param p3 method's 4th parameter
             * @param p4 method's 5th parameter
             * @param p5 method's 6th parameter
             * @param p6 method's 7th parameter
             * @param p7 method's 8th parameter
             * @return deserialized method return value
             * @throws XMLRPCException
             */
    	public Object call(String method, Object p0, Object p1, Object p2, Object p3, Object p4, Object p5, Object p6, Object p7) throws XMLRPCException {
    		Object[] params = {
    				p0, p1, p2, p3, p4, p5, p6, p7,
    		};
    		return callEx(method, params);
    	}
    }

Discussions similaires

  1. Réponses: 3
    Dernier message: 21/04/2012, 12h42
  2. [MySQL] Problème de connexion avec une base de données MySQL
    Par Debutant10 dans le forum PHP & Base de données
    Réponses: 8
    Dernier message: 19/12/2011, 09h39
  3. ORA-12162: Problème de connexion avec la base
    Par HAYTHOUM-TYPO3 dans le forum Connexions aux bases de données
    Réponses: 1
    Dernier message: 11/03/2009, 06h58
  4. Réponses: 6
    Dernier message: 20/09/2005, 22h28
  5. problème de connexion avec une base firebird
    Par vbcasimir dans le forum Bases de données
    Réponses: 1
    Dernier message: 30/05/2005, 11h40

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo