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

Services Web Java Discussion :

Creation client Java


Sujet :

Services Web Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Décembre 2002
    Messages
    34
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2002
    Messages : 34
    Par défaut Creation client Java
    Bonjour,

    J'ai crée un WebService en utilisant le Framework WSO2 Php ainsi que le client.
    Tout fonctionne, sur le serveur.

    Je voudrais déployer le client sur un autre serveur qui est un mutualisé, je ne peux donc pas utiliser mon client PHP, car il faudrait modifier le php.ini ce qui est très chaud.

    Je dois donc crée un client Java, mais alors là je suis nulle
    Est-ce que vous pourriez me mettre sur une piste.

    voici le code du serveur:
    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
     
    <?php
     
    require_once("DataService.php");
    // database configurations
    $config = array(
          "db" => "mysql",
          "username"=>"user",
          "password"=> "motdepasse",
          "dbname"=>"exemple",
          "dbhost"=>"127.0.0.1");
     
    // input format array(param_name => SQL_TYPE)
    $inputFormat = array("customerNumber" => "INT");
     
    // output format, please check the API from http://wso2.org/wiki/display/wsfphp/API+for+Data+Services+Revised
    $outputFormat = array("resultElement" => "Orders",
                          "rowElement" => "Order",
                          "elements" => array( "order-number" => "OrderNumber",
                                               "order-date" => "OrderDate",
                                               "status" => "status"));
    // SQL statement to execute
    $sql="select o.OrderNumber, o.OrderDate, o.status from Customers c, Orders o where c.customerNumber=o.customerNumber and c.customerNumber=?";
     
    // operations are consist of inputFormat (optional), outputFormat(required), sql(sql), input_mapping(optional)
    $operations = array("customerOrders"=>array("inputFormat"=>$inputFormat,
                                    "outputFormat"=>$outputFormat,
                                    "sql"=>$sql));
     
    $my_data_service = new DataService(array("config"=>$config,
                                "operations"=>$operations));
    $my_data_service->reply();
    ?>
    Mon client:
    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
     
    <?
     
     // Paramétres d'entrées
            $param = NULL;
            if(array_key_exists("parameter", $_GET)) {
            $param = $_GET["parameter"];
            }
     
        if(!isset($param))
        {
            $param =1;
        }
     
    $requestPayloadString = <<<XML
    <customerOrders>
    <customerNumber>{$param}</customerNumber>
    </customerOrders>
    XML;
    try {
        $client = new WSClient(array("to" => "http://mondomaine.com/DataServices/serveur.php"));
        $responseMessage = $client->request( $requestPayloadString );
    //    printf("Response = %s <br>", htmlspecialchars($responseMessage->str));
       $response = $responseMessage->str;
     /* Mettre la réponse au format xml  */
     
           $response = format_xml($response);
     
     
     
    } catch (Exception $e) {
          $error = TRUE;
     
        if ($e instanceof WSFault) {
    //        printf("Soap Fault: %s\n", $e->Reason);
              $response = "Soap Fault: ". $e->Reason;
     
        } else {
    //       printf("Message = %s\n",$e->getMessage());
                $response = "Message = ".$e->getMessage();
     
        }
    }
     
    ?>
     <h2> Liste des commandes pour un N° de Client donné </h2>
     
            <!-- Mettre le résultat sous forme de tableau -->
            <form method="GET">
                <p>
                <input name="parameter" type="text" value="<?php echo $param; ?>"/>
      </p>
                <p>
                    <input type="hidden" name="demo" value="3"/>
                    <input type="submit" value="Envoyer"/>
                </p>
                <p>
                <?php //echo render_result_table($response); ?>
                </p>
            </form>
            <div class="clear">
                    &nbsp;
            </div>
      <!-- Affichage des messages dans 2 colonnes -->
            <h2>Messages en XML</h2>
            <div>
                <div class="content-left">
                    <p>
                       La demande
                    </p>
                    <textarea class="config-textarea" readonly="readonly"><?php echo $requestPayloadString;?></textarea>
                </div>
                <div class="content-middle">
                </div>
                <div class="content-right">
                    <p>
                        Le résultat
                    </p>
                    <textarea class="config-textarea" readonly="readonly"><?php echo $response;?></textarea>
                </div>
            </div>
            <div class="clear">
                    &nbsp;
                    </div>
     
    <?php
        // some utility functions
        /**
         * format the given xml to some print every tag in new line
         * @param $xml the xml string
         * @return format xml
         */
        function format_xml($xml)
        {
            $xml = str_replace(">", ">\n", $xml);
            $xml = str_replace("</", "\n</", $xml);
            $xml = str_replace(">\n\n</", ">\n</", $xml);
     
            return $xml;
        }
       }
     
     
     
     
        /**
         * render the result table
         * @param $xml the response xml or the result error message
     * @return the html code for the table or the error message
         */
        function render_result_table($xml)
        {
            $html = "";
     
            if(empty($xml)) {
                $html .= "<div style=\"font:#ff0000\">";
                $html .= "Réponse non trouvée";
                $html .= "</div>";
     
                return $html;
            }
            $dom = new DOMDocument();
            try  {
                $status = $dom->loadXML($xml);
     
                $root = $dom->documentElement;
     
                if($status == TRUE || $root != NULL) {
     $title = $root->tagName;
     
                    $first_child = $root->firstChild;
                    while($first_child && $first_child ->nodeType != XML_ELEMENT_NODE)
                    {
                        $first_child = $first_child->nextSibling;
                    }
     
                    if($first_child)
                    {
                        $html .= "<h3>{$title}</h3>";
                        $html .= "<div>";
                        $html .= "<table border=\"1\">";
     
                        /* render the fields column */
                        $html .= "<tr style=\"background:#ccccdd\">";
                        foreach($first_child->childNodes as $field)
                        {
                            if($field->nodeType != XML_ELEMENT_NODE)
                                continue;
                                                             $field_name = $field->tagName;
                            $html.= "<td>{$field_name}</td>";
      }
                        $html .= "</tr>";
     
                        /* render the data */
     
                        foreach($root->childNodes as $data)
                        {
                            if($data->nodeType != XML_ELEMENT_NODE)
                            {
                                continue;
                            }
                            $html .= "<tr>";
                            foreach($data->childNodes as $field)
                            {
                                if($field->nodeType != XML_ELEMENT_NODE)
                                {
                                    continue;
                                }
                                $field_value = $field->nodeValue;
                                $html.= "<td>{$field_value}</td>";
                                                             }
                            $html .= "</tr>";
                        }
                        $html .= "</table>";
     
                        $html .= "</div>";
                    }
                    else {
                        $html .= "<div style=\"font:#ff0000\">";
                        $html .= "Pas de résultat";
                        $html .= "</div>";
                    }
                }
                else {
                    $html .= "<div style=\"font:#ff0000\">";
                    $html .= $xml;
                    $html .= "</div>";
                }
                return $html;
            } catch (Exception $e) {
                     $html .= "<div style=\"font:#ff0000\">";
                    $html .= $e->getMessage();
                    $html .= "</div>";
                    return $html;
            }
        }
    ?>

    Merci pour votre aide.

  2. #2
    Membre éclairé Avatar de liquideshark
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Septembre 2006
    Messages
    347
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : Service public

    Informations forums :
    Inscription : Septembre 2006
    Messages : 347
    Par défaut
    Salut ,

    1. Télécharge l'ide netbeans sur le site www.netbeans.org

    2. créé un projet java application

    3. suit ce tuto à partir de
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    Client 1: Java Class in Java SE Application
    In this section, you create a standard Java application. The wizard that you use  ...
    voici le tuto NETBEANS WS TUTO

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Décembre 2002
    Messages
    34
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2002
    Messages : 34
    Par défaut
    Merci liquideshark, j'ai suivi le tuto et bien sur je bloque !!!!


    A l'endroit ul il faut configurer les variables, il me dit que le package org.wso2.types est introuvable ... Je suis bien d'accord mais ou faut-il l'ajouter ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     private static org.wso2.types.GetQuoteResponse getQuote(org.wso2.types.GetQuoteRequest part1) {
            org.wso2.CommodityQuote service = new org.wso2.CommodityQuote();
            org.wso2.CommodityQuotePortType port = service.getCommodityQuotePort();
            return port.getQuote(part1);
    Merci encore pour l'aide apportée.

  4. #4
    Membre éclairé Avatar de liquideshark
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Septembre 2006
    Messages
    347
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : Service public

    Informations forums :
    Inscription : Septembre 2006
    Messages : 347
    Par défaut
    Citation Envoyé par belugha Voir le message
    Merci liquideshark, j'ai suivi le tuto et bien sur je bloque !!!!


    A l'endroit ul il faut configurer les variables, il me dit que le package org.wso2.types est introuvable ... Je suis bien d'accord mais ou faut-il l'ajouter ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     private static org.wso2.types.GetQuoteResponse getQuote(org.wso2.types.GetQuoteRequest part1) {
            org.wso2.CommodityQuote service = new org.wso2.CommodityQuote();
            org.wso2.CommodityQuotePortType port = service.getCommodityQuotePort();
            return port.getQuote(part1);
    Merci encore pour l'aide apportée.
    Salut ,

    Je ne vois pas ce que t'essaye de faire mais un conseil essaye de déployer un webservice simple comme un helloword qui retourne un string sur ton serveur, et suis l'exemple sur le tuto avant de compliquer

    Post l'erreur pour voir plus clair

Discussions similaires

  1. probleme de connection serveur C client java
    Par ricardvince dans le forum Réseau
    Réponses: 4
    Dernier message: 03/11/2006, 19h45
  2. probleme de connection serveur C client java
    Par ricardvince dans le forum Entrée/Sortie
    Réponses: 5
    Dernier message: 03/11/2006, 14h38
  3. Pear SOAP et client java
    Par llax dans le forum Services Web
    Réponses: 1
    Dernier message: 30/10/2006, 14h56
  4. Comment connecter un client java à JBoss ?
    Par elscorcho dans le forum Wildfly/JBoss
    Réponses: 2
    Dernier message: 06/10/2006, 17h28
  5. Creation client serveur DDE
    Par groovyroe dans le forum Delphi .NET
    Réponses: 1
    Dernier message: 16/05/2006, 21h24

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