Hello, Thanks to the forum members for supporting me in this exercise.
Enclosed is the version that has the following features: 1) I use AXIS2C client side implementation. 1.1) In my case, I had to use a proxy setting. For this I made changes in the axis2.xml 1.2) For installation and use of AXIS2C, please visit the website http://ws.apache.org/axis2/c/ 2) Works for two REST services : Yahoo! Search & StrikeIron WebServices Search 3) I parse the output using the SAX implementation To Do: 1) Make it work for SOAP based Web Services. I was not able to make the C++ clients work. So, I have not tried the J version yet. 2) The structuring of the file can be better. Currently, I have one file that implements the dll calls, the SAX parsing and the tests. Some more work is required to structure it into framework, parser and clients. 3) Extensions into how to combine the web services, ui for the same etc can be thought off. As of now I have established the technical feasibility. Experience: 1) Overall I found the exercise satisfying. It took time [Jul - Sept] but eventually I made it work. Thanks to all forum members who patiently answered my queries. 2) I am still learning to program in J. As the code below will reflect, I have currently managed to translate from C++ code to J code. Suggestions for writing the code below better are welcome. 3) This is my first experience in using interop to Dlls. At the end it looks so simple! 4) The conciseness of J expressions is something I really like. This is what keeps getting me back to using J. Thanks to the providers of the language as J enriches my programming perspective greatly. Cheers, Yuva p.s: In case you face any problems, let me know. p.s: Is it a good idea to place all of this code + installation somewhere for others to use? Please advise. Implementation: require 'dll strings task coutil xml/sax' coclass 'ywebsvc' coinsert 'psax' ROOTDIR =: jpath '~user\projects\websvc\' NB. v1 : yahoo application d=. (<jhostpath ROOTDIR,'lib/') ,&.> cut 'axiom.dll axutil.dllaxis2_engine.dll ' 'AXIOM UTILITY ENGINE' =: ('"'&,@],&'" ') L:0 d cdu =: 1 : '(UTILITY,m)&cd' cde =: 1 : '(ENGINE,m)&cd' cda =: 1 : '(AXIOM,m)&cd' NB. Bill says these are part of dll.ijs symget=: 15!:6 symdat=: 3 : 0 NB. symdat symget <'name' had=. {.memr y,(IF64{4 8),1,JPTR had+{.memr had,0,1,JPTR ) iad=: [EMAIL PROTECTED]@boxopen NB. win32 setenv =: 'kernel32 SetEnvironmentVariableA > i *c *c'&cd getenv =: 'kernel32 GetEnvironmentVariableA > i *c *c i'&cd NB. methods strcmp =: '[EMAIL PROTECTED] > i *c *c' cdu env_create_all =: '[EMAIL PROTECTED] > i *c i' cdu get_message =: '[EMAIL PROTECTED] > i i' cdu endpoint_ref =: '[EMAIL PROTECTED] > i i *c' cde options_create =: '[EMAIL PROTECTED] > i i' cde options_set_to =: '[EMAIL PROTECTED] > i i i i' cde options_set_enable_rest=: '[EMAIL PROTECTED] > i i i i' cde options_set_http_method =: '[EMAIL PROTECTED] > i i i *c' cde options_set_soap_version =: '[EMAIL PROTECTED] > i i i i' cde svc_client_create =: '[EMAIL PROTECTED] > i i *c' cde svc_client_set_options=: '[EMAIL PROTECTED] > i i i i' cde svc_client_set_proxy=: '[EMAIL PROTECTED] > i i i *c *c' cde svc_client_send_receive =: '[EMAIL PROTECTED] > i i i i' cde svc_client_free =: '[EMAIL PROTECTED] > n i i' cde node_create =: '[EMAIL PROTECTED] > i i' cda element_create =: '[EMAIL PROTECTED] > i i i *c i i' cda element_set_text =: '[EMAIL PROTECTED] > i i i *c i' cda node_get_first_child =: '[EMAIL PROTECTED] > i i i' cda node_is_complete =: '[EMAIL PROTECTED] > i i i' cda node_to_string =: '[EMAIL PROTECTED] > i i i' cda node_get_next_sibling =: '[EMAIL PROTECTED] > i i i' cda NB. enumerations 'L_CRITICAL L_ERROR L_WARNING L_INFO L_DEBUG L_TRACE' =: 0 1 2 3 4 5 'TRUE FALSE' =: 1 0 HTTP_GET =: 'GET' 'SOAP11 SOAP12' =: 1 2 NB. verbs pwd =: 3 : 0 a=. spawn 'cmd pwd' b=. (}:a),'\' c =. <;.2 b d =. _3{.>{.c e =. }.c d,;e ) setpath =: 3 : 0 NB. a =. spawn 'cmd set path=%path%;',y, ';' b =. spawn 'cmd echo %path%' b ) NB. ========================================================= NB. Framework init=: 3 : 0 evp =: ROOTDIR evv =: 'AXIS2C_HOME' setenv evv;evp op =: 30000 # (0{a.) getenv 'Path';op;(#op) np =: ROOTDIR,'lib;' np =: np,op setenv 'Path';np ) get_err_mesg =: 3 : 0 mp =. get_message errp m =: memr mp,0,_1,JCHAR ) NB. '/logs/test_yahoo.log';' http://search.yahooapis.com/WebSearchService/V1/webSearch' clientInit =: 3 : 0 'log endpoint' =: y l =: ROOTDIR,log a =: endpoint e =: env_create_all l;L_TRACE errp =: _2 ic (memr e, 4, 4) smoutput 'using endpoint: ',endpoint ep =: endpoint_ref e;a ) createClient =: 3 : 0 op =: options_create <e options_set_to op;e;ep options_set_enable_rest op;e;TRUE options_set_http_method op;e;HTTP_GET c =: svc_client_create e;ROOTDIR NB. axis2.xml + modules/ + services/ svc_client_set_options c;e;op ) NB. send & receive the data. NB. Client Payload has to create the rn variable here. send_receive =: 3 : 0 retn =: svc_client_send_receive c;e;rn ) NB. the returned result node as string format =: 3 : 0 os =: '' if. retn do. NB. root node sp =. node_to_string retn;e s =: memr sp,0,_1,JCHAR level =. 0 os =: s else. smoutput 'nothing to format' end. os ) done =: 3 : 0 svc_client_free c;e ) NB. --------------------------------------------------------- NB. SAX parser to parse the response - basic implementation process=: 3 : 0 if. '' -: y do. return. end. smoutput y p =. '' conew 'ywebsvc' startDocument__p '' parse__p y attr =: }. parserAttr__p ([ destroy__p) endDocument__p'' ) showattrs=: (''"_)`(;:^:_1@:(([ , '='"_ , ])&.>/"1))@.([EMAIL PROTECTED]) startDocument =: 3 : 0 parserAll=: R=: $0 parserPath =: $0 L=: 0 parserAttr =: $0 ) startElement =: 4 : 0 NB. smoutput (L#' '),'[',y,(showattrs attributes x),']' smoutput (L#' '),'[',y,']' NB. smoutput ((L+2)#' '),'[', attributes x ,']' parserAttr =: parserAttr, (attributes x) L=: L+1 NB. c =. tolower ": y NB. smoutput c parserAll=: parserAll,<y parserPath =: parserPath, <y ) characters =: 3 : 0 L=: L+1 smoutput (L#' '),y L=: L-1 ) endElement =: 3 : 0 L=: L-1 smoutput (L#' '),'[/',y,']' parserPath =: }: parserPath ) endDocument=: 3 : 0 a =. '# total tags '; $parserAll a =. a, ('# attributes '; $parserAttr) smoutput a ) NB. ========================================================= NB. Test1 : yahoo search NB. --------------------------------------------------------- NB. http://developer.yahoo.com/search/web/V1/webSearch.html NB. boxed input: query string ; [number of results returned (as string)] yahooPayload =: 3 : 0 rn =: node_create <e an =: node_create <e qn =: node_create <e re =: element_create e;0;'yahoo_rest_search';0;(iad 'rn') ae =: element_create e;rn;'appid';0;(iad 'an') element_set_text ae;e;'Yahoo Demo';an qe =: element_create e;rn;'query';0;(iad 'qn') rsn =: node_create <e rse =: element_create e;rn;'results';0;(iad 'rsn') if. '' -: y do. element_set_text qe;e;'finance';qn element_set_text rse;e;(,'2');rsn NB. as string ":2 or ,'2' else. if. (#y) = 1 do. r =: ,'2' q =: >y else. 'q r' =: y end. element_set_text qe;e;q;qn element_set_text rse;e;r;rsn end. ) yahooSearch =: 3 : 0 if. '' -: y do. yahooPayload '' else. yahooPayload y end. send_receive '' format '' ) NB. --------------------------------------------------------- init '' NB. --------------------------------------------------------- NB. for yahoo search clientInit '/logs/test_yahoo.log';' http://search.yahooapis.com/WebSearchService/V1/webSearch' NB. --------------------------------------------------------- createClient '' NB. --------------------------------------------------------- NB. build yahooPayload yahooPayload '' NB. --------------------------------------------------------- NB. make the call send_receive '' NB. see what has come back resp=: format '' process resp done '' NB. NB. ========================================================= NB. NB. ========================================================= NB. NB. Test2: StrikeIron Webservices Search NB. NB. --------------------------------------------------------- NB. NB. http:http://ws.strikeiron.com/StrikeIronDirectoryService NB. NB. input: query string NB. siWssPayload =: 3 : 0 NB. rn =: node_create <e NB. an =: node_create <e NB. qn =: node_create <e NB. re =: element_create e;0;'si_rest_search';0;(iad 'rn') NB. ae =: element_create e;rn;'SearchWebServices.LicenseKey';0;(iad 'an') NB. element_set_text ae;e;'Get own license key from site';an NB. qe =: element_create e;rn;'SearchWebServices.KeyWord';0;(iad 'qn') NB. if. '' -: y do. NB. element_set_text qe;e;'finance';qn NB. else. NB. element_set_text qe;e;y;qn NB. end. NB. ) NB. NB. NB. --------------------------------------------------------- NB. NB. init '' NB. NB. NB. --------------------------------------------------------- NB. NB. for strikeIron search NB. clientInit '/logs/test_si_wss.log';' http://ws.strikeiron.com/StrikeIronDirectoryService/SearchWebServices' NB. NB. --------------------------------------------------------- NB. NB. createClient '' NB. siWssPayload 'utility' NB. NB. NB. make the call NB. send_receive '' NB. NB. see what has come back NB. resp=: format '' NB. process resp NB. done '' ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
