Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do a SOAP request for EUR-Lex API with R?

How would you do a SOAP request for EUR-Lex's API using R?

EUR-Lex is an EU database containing many legal acts. In the manual for their web services, they describe their SOAP system but not how to use R for it. I've tried for a while now to employ httr and RCurl but with no luck. I would like to use R instead of SOAPUI.

Does anyone here have any experience with this?

From the link below, should I define the body as follows?

body <- "<sear:searchRequest>
<sear:expertQuery>${expert query}</sear:expertQuery> <sear:page>${page}</sear:page>
<sear:pageSize>${pageSize}</sear:pageSize> <sear:searchLanguage>${search language
</sear:searchLanguage>
          </sear:searchRequest>"

How do I then combine that with the headerfields to use either the RCurl or httr package?

The following three answers seem related but I cannot figure out how to apply them to my EUR-Lex example:

  1. How to convert SOAP request curl to RCurl
  2. SOAP Client with WSDL for R
  3. SOAP request in R

EUR-Lex API links:

  1. WSDL: https://eur-lex.europa.eu/eurlex-ws?wsdl
  2. Manual: https://eur-lex.europa.eu/content/tools/webservices/SearchWebServiceUserManual_v2.00.pdf
like image 254
Will M Avatar asked Nov 06 '22 06:11

Will M


1 Answers

The answers you linked to have pretty good examples to work off of. Adding in the various URLs from the WSDL and information from the manual, you end up with the code below.

Unfortunately due to the EUR-Lex security restrictions I couldn't test this (you need a username and password from them, which I assume you have), but it should at the very least get you on the right track.

library(RCurl)

headerFields =
  c(Accept = "text/xml",
    Accept = "multipart/*",
    'Content-Type' = "text/xml; charset=utf-8",
    SOAPAction = "https://eur-lex.europa.eu/EURLexWebService/doQuery")

body = '<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:sear="http://eur-lex.europa.eu/search">
    <soap:Header>
        <wsse:Security soap:mustUnderstand="true" xmlns:wsse="http://docs.oasisopen.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
        <wsse:UsernameToken wsu:Id="UsernameToken-3" xmlns:wsu="http://docs.oasisopen.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
        <wsse:Username>${EUR-Lex username}</wsse:Username>
        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-
wss-username-token-profile-1.0#PasswordText">${WS password}</wsse:Password>
        </wsse:UsernameToken>
        </wsse:Security>
   </soap:Header> 
   <soap:Body>
      <sear:searchRequest>
         <sear:expertQuery>${expert query}</sear:expertQuery>
         <sear:page>${page}</sear:page>
         <sear:pageSize>${pageSize}</sear:pageSize>
         <sear:searchLanguage>${search language}</sear:searchLanguage>
      </sear:searchRequest>
   </soap:Body>
</soap:Envelope>'

reader = basicTextGatherer()

curlPerform(url = "https://eur-lex.europa.eu/EURLexWebService",
                          httpheader = headerFields,
                          postfields = body,
                          writefunction = reader$update
                          )

xml <- reader$value()
xml
like image 187
jdaz Avatar answered Nov 12 '22 14:11

jdaz