Web Service Samples for Ruby

Document created by resplin Employee on Jun 6, 2015
Version 1Show Document
  • View in full screen mode

Obsolete Pages{{Obsolete}}

The official documentation is at: http://docs.alfresco.com



Web Service APIWeb Service Samples
Back to Alfresco Content Management Web Services


Ruby Samples


The more simplistic way to access Alfresco from a ruby application using a web service is to use Soap4r, but the actual implementation does not offer the WS-Security standards feature directly. The following example use Wss4r that adds their security. You'll have to have this library installed in order to run these examples.

In addition to installing this library, and because this library is not fully implemented, you will have to patch it with the patch containing MessageText code instead of the default MessageDigest. This patch is actually a subclass of wss4r's SOAP::Header::SimpleHeader which is defined in the sample code that ships with Alfresco's Ruby library: testWebServices.rb


Starting a session



require 'soap/wsdlDriver'
require 'wss4r/rpc/wssdriver'

...

wsdl_url = 'file://' + <path-to-your-wsdl-directory> + '/authentication-service.wsdl'

soapDriver = SOAP::WSDLDriverFactory.new(wsdl_url).create_rpc_driver()

authentication_result = soapDriver.startSession {:username => '<username>', :password => '<password>'}

ticket = authentication_result.ticket

...

As you can see, once you've got your environment set up and a valid wsdl, a few lines of code make the rest.

The result of your authentication is a ticket, that you'll have to reuse each time you make a query.


Sending a query



require 'soap/wsdlDriver'
require 'wss4r/rpc/wssdriver'
require 'wss4r/tokenresolver/authenticateuserresolver'

...

wsdl_url = 'file://' + <path-to-your-wsdl-directory> + '/repository-service.wsdl'

soapDriver = SOAP::WSDLDriverFactory.new(wsdl_url).create_rpc_driver()

# adding authentication information
resolver = AuthenticateUserResolver.new()
soapDriver.security().add_security_resolver(resolver)
soapDriver.security().add_security_token(UsernameToken.new(user, ticket))


# the query itself
query_result = soapDriver.query({:store => {:scheme => 'workspace', :address => 'SpacesStore'},
                                 :query => {:language => 'lucene', :statement => 'TEXT:'<some text to seach>''},
                                 :includeMetaData => false})

...

Making a query requires a little bit more effort, as you need to include the previously obtained ticket.


Reading the results


Getting the number of rows returned:



number_of_results = query_result.queryReturn.resultSet.totalRowCount

You can refer to the WSDL file to see the other information that this resultSet contains.

Attachments

    Outcomes