Using retrieveURL for REST webservice

0
Is it possible to use the retrieveURL javaaction from the community commons module to run the following PUT request? curl -v -H 'Accept: application/xml' -H 'Content-Type: application/xml; charset=utf-8' -H 'Content-Length: 0' -u [MyAPIKey]: -X PUT https://..... If it is possible to carry out such a request, what is the syntax to specify the header elements? Or do I have to do it in java myself? Thanks
asked
1 answers
2

Yes you can but there are some pitfalls

If you don't need the -u [MyApiKey] this may be a direction. Otherwise create you http request with httpclient.

  1. Create your request string (https://www.domain.com&param1=a&param2=2...)
  2. Encode that url (see java action at the end)
  3. Create reply document (xml)
  4. Call 'storeurltofiledocument'
  5. Import the returned filedocument (xmlimport, xsd etc). Add some error handling in there because the returned xml may have multiple formats. One for the correct result and the other for errors. If you are lucky you can read the status easily from the xml.

Good luck

EncodeUrl

    // create new encoded URL
    URI uri = new URI(httpPart, domainPart, sub, apiPart, null);
    java.net.URL url = uri.toURL();
    return url.toString();

Or use CommunityCommons HTMLEncode

answered