-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdapter.p
411 lines (368 loc) · 19.1 KB
/
Adapter.p
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
/*------------------------------------------------------------------------
File: Adapter.P
Description: Builds the WebService procedure adapter for the
procedures defined in temp-tables generated by
procInfo.p, using the specified template.
Input Parameters: ttProcedure Procedures.
ttMethod Internal procedures and Functions
to include.
ttParam Procedure Parameters.
ttTable Temp-tables used by the procedures.
ttField Temp-tables Fields.
ichProgramFile Path to the generated adapter.
ichTemplate Path to the generated adapter.
ichNameSpace The name of the web service.
Output Parameters: ochResult Error message or "" if there
isn't any
Author: Lic. Edgar Medrano Pérez
edgarmedrano@gmail.com
Created: 2005.06.18
Company: Open 4GL webservices project
http://o4glws.sourceforge.net
Notes:
------------------------------------------------------------------------*/
{o4glws/procInfo.i}
&SCOPED-DEFINE WRITE-CODE PUT STREAM strFile UNFORMATTED
DEFINE INPUT PARAMETER TABLE FOR ttProcedure.
DEFINE INPUT PARAMETER TABLE FOR ttMethod.
DEFINE INPUT PARAMETER TABLE FOR ttParam.
DEFINE INPUT PARAMETER TABLE FOR ttTable.
DEFINE INPUT PARAMETER TABLE FOR ttField.
DEFINE INPUT PARAMETER ichProgramFile AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER ichTemplateFile AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER ichNameSpace AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER ichSecurity AS CHARACTER NO-UNDO.
DEFINE OUTPUT PARAMETER ochResult AS CHARACTER NO-UNDO.
DEFINE VARIABLE vchrBuffer AS CHARACTER NO-UNDO.
DEFINE VARIABLE vchrComma AS CHARACTER NO-UNDO.
DEFINE STREAM strTemplate.
DEFINE STREAM strFile.
IF ichProgramFile = "" OR ichProgramFile = ? THEN
DO:
ochResult = SUBSTITUTE("Unable to use WSDL File: [&1]", ichProgramFile).
RETURN.
END.
IF ichNameSpace = "" OR ichNameSpace = ? THEN
DO:
ochResult = ochResult + "~n" + SUBSTITUTE("Unable to use Namespace: [&1]", ichNameSpace).
RETURN.
END.
OUTPUT STREAM strFile TO VALUE(ichProgramFile).
/*Codigo previo a la identificacion*/
IF ichTemplateFile MATCHES "*.htm*" THEN
DO:
{&WRITE-CODE} "<script language=""SpeedScript"">~n".
END.
INPUT STREAM strTemplate FROM VALUE(ichTemplateFile).
REPEAT:
IMPORT STREAM strTemplate UNFORMATTED vchrBuffer.
{&WRITE-CODE} vchrBuffer "~n".
END.
INPUT STREAM strTemplate CLOSE.
/** Definir handles para super-procedures**/
{&WRITE-CODE} "~n".
{&WRITE-CODE} "/*Declarar handles para super-procedures*/~n".
FOR EACH ttProcedure
NO-LOCK:
{&WRITE-CODE} SUBSTITUTE("DEFINE VARIABLE vhnd&1 AS HANDLE NO-UNDO.~n", ichNameSpace + STRING(ttProcedure.iProcId)).
END.
/** Definir el procedimiento PROCESS-REQUEST **/
{&WRITE-CODE} "~n".
{&WRITE-CODE} "PROCEDURE PROCESS-REQUEST:~n".
{&WRITE-CODE} " DEFINE INPUT PARAMETER vhndRequestDoc AS HANDLE NO-UNDO.~n".
{&WRITE-CODE} " DEFINE OUTPUT PARAMETER vhndResponseDoc AS HANDLE NO-UNDO.~n".
{&WRITE-CODE} "~n".
{&WRITE-CODE} " DEFINE VARIABLE vintI AS INTEGER NO-UNDO.~n".
{&WRITE-CODE} " DEFINE VARIABLE vchrMessage AS CHARACTER NO-UNDO.~n".
{&WRITE-CODE} " DEFINE VARIABLE vhndRequestEnv AS HANDLE NO-UNDO. ~n".
{&WRITE-CODE} " DEFINE VARIABLE vhndResponseEnv AS HANDLE NO-UNDO. ~n".
{&WRITE-CODE} " DEFINE VARIABLE vhndRequestHead AS HANDLE NO-UNDO. ~n".
{&WRITE-CODE} " DEFINE VARIABLE vhndResponseHead AS HANDLE NO-UNDO. ~n".
{&WRITE-CODE} " DEFINE VARIABLE vhndRequestBody AS HANDLE NO-UNDO. ~n".
{&WRITE-CODE} " DEFINE VARIABLE vhndResponseBody AS HANDLE NO-UNDO. ~n".
{&WRITE-CODE} " DEFINE VARIABLE vhndRequestMessage AS HANDLE NO-UNDO. ~n".
{&WRITE-CODE} " DEFINE VARIABLE vhndResponseMessage AS HANDLE NO-UNDO. ~n".
{&WRITE-CODE} " DEFINE VARIABLE vchrEnvelopeNS AS CHARACTER NO-UNDO INITIAL ""s"".~n".
{&WRITE-CODE} " DEFINE VARIABLE vchrMessageNS AS CHARACTER NO-UNDO INITIAL ""n"".~n".
{&WRITE-CODE} SUBSTITUTE(" DEFINE VARIABLE vchrWebService AS CHARACTER NO-UNDO INITIAL ""&1"".~n",ichNameSpace).
{&WRITE-CODE} "~n".
{&WRITE-CODE} " vhndRequestEnv = findChild(vhndRequestDoc,""Envelope"").~n".
{&WRITE-CODE} " vhndRequestHead = findChild(vhndRequestEnv,""Header"").~n".
{&WRITE-CODE} " vhndRequestBody = findChild(vhndRequestEnv,""Body"").~n".
{&WRITE-CODE} "~n".
{&WRITE-CODE} " vhndResponseDoc = createResponse(vchrEnvelopeNS).~n".
{&WRITE-CODE} " vhndResponseEnv = findChild(vhndResponseDoc,""Envelope"").~n".
{&WRITE-CODE} " vhndResponseHead = findChild(vhndResponseDoc,""Header"").~n".
{&WRITE-CODE} " vhndResponseBody = findChild(vhndResponseEnv,""Body"").~n".
{&WRITE-CODE} "~n".
IF ichSecurity <> "" THEN
DO:
{&WRITE-CODE} SUBSTITUTE(" IF NOT SECURITY-TEST(vhndRequestHead,""&1"") THEN~n", ichSecurity).
{&WRITE-CODE} " DO:~n".
{&WRITE-CODE} " vhndResponseMessage = createFault(vhndResponseBody,""soap:Server.SecurityFault"",""The supplied parameters didn't pass the security test."",THIS-PROCEDURE:FILE-NAME,vchrEnvelopeNS).~n".
{&WRITE-CODE} " RETURN.~n".
{&WRITE-CODE} " END.~n".
{&WRITE-CODE} "~n".
END.
{&WRITE-CODE} " /*Buscar todas las llamadas*/~n".
{&WRITE-CODE} " CREATE X-NODEREF vhndRequestMessage.~n".
{&WRITE-CODE} " DO vintI = 1 TO vhndRequestBody:NUM-CHILDREN:~n".
{&WRITE-CODE} " IF vhndRequestBody:GET-CHILD(vhndRequestMessage,vintI) THEN~n".
{&WRITE-CODE} " DO:~n".
{&WRITE-CODE} " IF vhndRequestMessage:SUBTYPE = ""ELEMENT"" THEN~n".
{&WRITE-CODE} " DO:~n".
{&WRITE-CODE} " /*Indentificar el metodo que sera llamado*/~n".
{&WRITE-CODE} " vchrMessage = ~n".
{&WRITE-CODE} " IF vhndRequestMessage:LOCAL-NAME = """" THEN ~n".
{&WRITE-CODE} " vhndRequestMessage:NAME~n".
{&WRITE-CODE} " ELSE~n".
{&WRITE-CODE} " vhndRequestMessage:LOCAL-NAME.~n".
{&WRITE-CODE} "~n".
{&WRITE-CODE} " CASE vchrMessage:~n".
FOR EACH ttProcedure
NO-LOCK:
FOR EACH ttMethod
WHERE ttMethod.iProcId = ttProcedure.iProcId
NO-LOCK:
{&WRITE-CODE} SUBSTITUTE(
" WHEN ""&1"" THEN~n"
+ " DO:~n"
+ " vhndResponseMessage = createChild(vhndResponseBody,""&1Response"",vchrMessageNS).~n"
+ " vhndResponseMessage:SET-ATTRIBUTE(""xmlns:"" + vchrMessageNS,vchrWebService).~n"
+ " RUN &1Adapter(vhndRequestMessage,vhndResponseMessage) NO-ERROR.~n"
+ " DELETE PROCEDURE vhnd&2 NO-ERROR.~n"
+ " END.~n"
, ttProcedure.cName + (IF ttMethod.cName = "" THEN "" ELSE "_") + ttMethod.cName
, ichNameSpace + STRING(ttMethod.iProcId)).
END. /** for each ttmethod **/
END. /** for each ttProcedure **/
/*Discard unknown methods and nodes*/
{&WRITE-CODE} " WHEN ""multiRef"" THEN~n".
{&WRITE-CODE} " DO:~n".
{&WRITE-CODE} " /*IGNORE*/~n".
{&WRITE-CODE} " END.~n".
{&WRITE-CODE} " OTHERWISE~n".
{&WRITE-CODE} " DO:~n".
{&WRITE-CODE} " vhndResponseMessage = createFault(vhndResponseBody,""soap:Server.UnknownMethod"",""The specified method is unknown."",THIS-PROCEDURE:FILE-NAME,vchrEnvelopeNS).~n".
{&WRITE-CODE} " END.~n".
{&WRITE-CODE} " END CASE.~n".
{&WRITE-CODE} " END.~n".
{&WRITE-CODE} " END.~n".
{&WRITE-CODE} " END.~n".
{&WRITE-CODE} "~n".
{&WRITE-CODE} " DELETE OBJECT vhndRequestDoc. ~n".
{&WRITE-CODE} "END.~n".
{&WRITE-CODE} "~n".
/** First Create any Complex Types used for temp-tables **/
IF CAN-FIND(FIRST ttTable) THEN
DO:
{&WRITE-CODE} "/*Declarar aqui tablas temporales usadas por datos complejos*/~n".
FOR EACH ttProcedure
NO-LOCK:
FOR EACH ttTable
WHERE ttTable.iProcId = ttProcedure.iProcId
NO-LOCK:
{&WRITE-CODE} SUBSTITUTE("DEFINE TEMP-TABLE &1~n", ttProcedure.cName + "_" + ttTable.cName).
FOR EACH ttField
WHERE ttField.iProcId = ttTable.iProcId
AND ttField.cTableName = ttTable.cName
NO-LOCK
BY ttField.iSeq:
{&WRITE-CODE} SUBSTITUTE(" FIELD &1 AS &2~n", ttField.cName, ttField.cDataType).
END. /** for each ttfield **/
{&WRITE-CODE} " .~n~n".
END. /** for each tttable **/
END. /** for each ttProcedure **/
END.
/** Definir adaptadores **/
FOR EACH ttProcedure
NO-LOCK:
FOR EACH ttMethod
WHERE ttMethod.iProcId = ttProcedure.iProcId
NO-LOCK:
{&WRITE-CODE} SUBSTITUTE("PROCEDURE &1Adapter:~n", ttProcedure.cName + (IF ttMethod.cName = "" THEN "" ELSE "_") + ttMethod.cName).
{&WRITE-CODE} " DEFINE INPUT PARAMETER iphndRequestMessage AS HANDLE NO-UNDO.~n".
{&WRITE-CODE} " DEFINE INPUT PARAMETER iphndResponseMessage AS HANDLE NO-UNDO.~n".
{&WRITE-CODE} "~n".
/** Definir variables de salida **/
IF CAN-FIND(FIRST ttParam
WHERE ttParam.iProcId = ttMethod.iProcId
AND ttParam.cMethodName = ttMethod.cName
AND ttParam.cDirection <> "INPUT"
AND ttParam.cDataType <> "TABLE") THEN
DO:
{&WRITE-CODE} " /*Declarar variables de salida*/~n".
FOR EACH ttParam
WHERE ttParam.iProcId = ttMethod.iProcId
AND ttParam.cMethodName = ttMethod.cName
AND ttParam.cDirection <> "INPUT"
AND ttParam.cDataType <> "TABLE"
NO-LOCK
BY ttParam.iSeq:
{&WRITE-CODE} SUBSTITUTE(" DEFINE VARIABLE &1 AS &2 NO-UNDO.~n", ttParam.cName, ttParam.cDataType).
END. /** for each ttparam **/
{&WRITE-CODE} "~n".
END. /** can-find **/
/** Declarar handlers para leer/escribir temporales **/
/*
IF CAN-FIND(FIRST ttParam
WHERE ttParam.iProcId = ttMethod.iProcId
AND ttParam.cMethodName = ttMethod.cName
AND ttParam.cDataType = "TABLE") THEN
DO:
{&WRITE-CODE} " /*Declarar handlers para leer/escribir temporales*/~n".
FOR EACH ttParam
WHERE ttParam.iProcId = ttMethod.iProcId
AND ttParam.cMethodName = ttMethod.cName
AND ttParam.cDataType = "TABLE"
NO-LOCK
BY ttParam.iSeq:
{&WRITE-CODE} SUBSTITUTE(" DEFINE VARIABLE hnd&1 AS HANDLE NO-UNDO.~n", ttProcedure.cName + "_" + ttParam.cName).
END. /** for each ttparam **/
{&WRITE-CODE} "~n".
END. /** can-find **/
*/
/** Inicializar valores de variables de entrada/salida **/
IF CAN-FIND(FIRST ttParam
WHERE ttParam.iProcId = ttMethod.iProcId
AND ttParam.cMethodName = ttMethod.cName
AND ttParam.cDirection = "INPUT-OUTPUT"
AND ttParam.cDataType <> "TABLE") THEN
DO:
{&WRITE-CODE} " /*Inicializar valores de variables de entrada/salida*/~n".
FOR EACH ttParam
WHERE ttParam.iProcId = ttMethod.iProcId
AND ttParam.cMethodName = ttMethod.cName
AND ttParam.cDirection = "INPUT-OUTPUT"
AND ttParam.cDataType <> "TABLE"
NO-LOCK
BY ttParam.iSeq:
{&WRITE-CODE} SUBSTITUTE(" &1 = getIn&2(iphndRequestMessage,""&3"").~n", ttParam.cName, ttParam.cDataType, (IF ttParam.cMethodName = "" THEN ttProcedure.cName + "_" ELSE "") + ttParam.cName).
END. /** for each ttparam **/
{&WRITE-CODE} "~n".
END. /** can-find **/
/** Inicializar tablas de entrada/salida **/
/*
IF CAN-FIND(FIRST ttParam
WHERE ttParam.iProcId = ttMethod.iProcId
AND ttParam.cMethodName = ttMethod.cName
AND ttParam.cDataType = "TABLE") THEN
DO:
{&WRITE-CODE} " /*Inicializar tablas de entrada/salida*/~n".
FOR EACH ttParam
WHERE ttParam.iProcId = ttMethod.iProcId
AND ttParam.cMethodName = ttMethod.cName
AND ttParam.cDataType = "TABLE"
NO-LOCK
BY ttParam.iSeq:
{&WRITE-CODE} SUBSTITUTE(
" ASSIGN hnd&1 = BUFFER &1:HANDLE.~n"
, ttProcedure.cName + "_" + ttParam.cName).
IF ttParam.cDirection <> "OUTPUT" THEN
DO:
{&WRITE-CODE} SUBSTITUTE(
" getInTable(iphndRequestMessage,""&1Array"",hnd&1).~n"
, ttProcedure.cName + "_" + ttParam.cName).
END.
END. /** for each ttparam **/
{&WRITE-CODE} "~n".
END. /** can-find **/
*/
IF CAN-FIND(FIRST ttParam
WHERE ttParam.iProcId = ttMethod.iProcId
AND ttParam.cMethodName = ttMethod.cName
AND ttParam.cDataType = "TABLE"
AND ttParam.cDirection <> "OUTPUT") THEN
DO:
{&WRITE-CODE} " /*Inicializar tablas de entrada/salida*/~n".
FOR EACH ttParam
WHERE ttParam.iProcId = ttMethod.iProcId
AND ttParam.cMethodName = ttMethod.cName
AND ttParam.cDataType = "TABLE"
AND ttParam.cDirection <> "OUTPUT"
NO-LOCK
BY ttParam.iSeq:
{&WRITE-CODE} SUBSTITUTE(
" getInTable(iphndRequestMessage,""&1"",(BUFFER &2:HANDLE)).~n"
,ttParam.cName, ttProcedure.cName + "_" + ttParam.cName).
END. /** for each ttparam **/
{&WRITE-CODE} "~n".
END. /** can-find **/
/*Llamar al procedimiento*/
ASSIGN vchrComma = " ".
IF ttMethod.cName <> "" THEN
DO:
{&WRITE-CODE} SUBSTITUTE(" RUN &1Adapter(iphndRequestMessage,iphndResponseMessage).~n",ttProcedure.cName).
{&WRITE-CODE} SUBSTITUTE(" RUN &1 IN vhnd&2",ttMethod.cName, ichNameSpace + STRING(ttMethod.iProcId)).
END.
ELSE
DO:
{&WRITE-CODE} SUBSTITUTE(" RUN &1 PERSISTENT SET vhnd&2", ttProcedure.cPath, ichNameSpace + STRING(ttMethod.iProcId)).
END.
IF CAN-FIND(FIRST ttParam
WHERE ttParam.iProcId = ttMethod.iProcId
AND ttParam.cMethodName = ttMethod.cName) THEN
DO:
{&WRITE-CODE} " (~n".
FOR EACH ttParam
WHERE ttParam.iProcId = ttMethod.iProcId
AND ttParam.cMethodName = ttMethod.cName
NO-LOCK
BY ttParam.iSeq:
IF ttParam.cDataType = "TABLE" THEN
DO:
{&WRITE-CODE} SUBSTITUTE(" &1&2 TABLE &3~n", vchrComma, ttParam.cDirection, ttProcedure.cName + "_" + ttParam.cName).
END.
ELSE
DO:
IF ttParam.cDirection = "INPUT" THEN
DO:
{&WRITE-CODE} SUBSTITUTE(" &1getIn&2(iphndRequestMessage,""&3"")~n", vchrComma, ttParam.cDataType, (IF ttParam.cMethodName = "" THEN ttProcedure.cName + "_" ELSE "") + ttParam.cName).
END.
ELSE
DO:
{&WRITE-CODE} SUBSTITUTE(" &1&2 &3~n", vchrComma, ttParam.cDirection, ttParam.cName).
END.
END.
ASSIGN vchrComma = ",".
END. /** for each ttparam **/
{&WRITE-CODE} " )".
END.
{&WRITE-CODE} " NO-ERROR.~n".
{&WRITE-CODE} "~n".
/*Copiar los valores de las variables de salida*/
IF CAN-FIND(FIRST ttParam
WHERE ttParam.iProcId = ttMethod.iProcId
AND ttParam.cMethodName = ttMethod.cName
AND ttParam.cDirection <> "INPUT") THEN
DO:
{&WRITE-CODE} " /*Copiar los valores de las variables de salida*/~n".
FOR EACH ttParam
WHERE ttParam.iProcId = ttMethod.iProcId
AND ttParam.cMethodName = ttMethod.cName
AND ttParam.cDirection <> "INPUT"
NO-LOCK
BY ttParam.iSeq:
IF ttParam.cDataType = "TABLE" THEN
DO:
/*{&WRITE-CODE} SUBSTITUTE(" setOutTable(iphndResponseMessage,""&1Array"",hnd&2).~n", (IF ttParam.cMethodName = "" THEN ttProcedure.cName + "_" ELSE "") + ttParam.cName, ttProcedure.cName + "_" + ttParam.cName).*/
{&WRITE-CODE} SUBSTITUTE(" setOutTable(iphndResponseMessage,""&1"",(BUFFER &2:HANDLE)).~n", ttParam.cName, ttProcedure.cName + "_" + ttParam.cName).
END.
ELSE
DO:
/*{&WRITE-CODE} SUBSTITUTE(" setOut&1(iphndResponseMessage,""&2"",&2).~n", ttParam.cDataType, ttParam.cName).*/
{&WRITE-CODE} SUBSTITUTE(" setOut&1(iphndResponseMessage,""&2"",&2).~n", ttParam.cDataType, (IF ttParam.cMethodName = "" THEN ttProcedure.cName + "_" ELSE "") + ttParam.cName).
END.
END. /** for each ttparam **/
{&WRITE-CODE} "~n".
END. /** can-find **/
/*Fin del procedimiento Adaptador*/
{&WRITE-CODE} "END PROCEDURE.~n~n".
END. /** for each ttmethod **/
END. /** for each ttprocedure **/
IF ichTemplateFile MATCHES "*.htm*" THEN
DO:
{&WRITE-CODE} "</script>~n".
END.
OUTPUT STREAM strFile CLOSE.
RETURN.