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:
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 <?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(); ?>
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"> </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"> </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.
Partager