ePages 6.15.1 - DE_EPAGES/Core/API/Object/RestClient.pm

Package DE_EPAGES::Core::API::Object::RestClient

base class for rest clients

Base
DE_EPAGES::Core::API::Object::BaseObject

Functions

getBaseURL
getServiceURL
logger
new
sendRequest

getBaseURL

Returns the rest service base URL like http://localhost:8088/rs/. This lookup method first checks epages.conf section [REST_SERVICE] key $Alias after that key 'default'. If both keys are not found in epages.conf this method checks the enviroment EPAGESJ_PORT and EPAGESJ_HOST to build an URI or use thier respective defaults. Default: http://localhost:8088/rs/.

optinal entries epages.conf
[REST_SERVICE]
; is used if service name is not known default to
default=http://localhost:8088/rs/
; dedicated host for pdf creating
pdf=http://otherhost:8099/rs/

It is also possible to overwrite this value with constructor parameter BaseURL. See new

Syntax
my $URI = $Client->getBaseURL();
Return
$URI (string)
rest service base URL, default: http://localhost:8088/rs/

getServiceURL

Returns the url for a service. (e.g. 'http://localhost:8088/rs/pdf')

Syntax
my $Url = $Client->getServiceURL();
Return
$Url (string)
service url

logger

Prints output to a file for logging and debugging purposes. Log4Perl Category is REST_SERVICE. e.g. "REST_SERVICE::pdf"

Syntax
$Client->logger($Type, $Status, $Content);
Input
$Type (string)
type of request (e.g. send, receive..)
$Status (string)
status of response (e.g. '200 OK')
$Content (string or binary)
processed content

new

Create a new rest-client object. Options Alias and Header are requiered. The provided Alias will be used as of part of request URL and some config lookups. Currently only 'pdf' service is compatible with this client (Other values will most likely yield a 404). RestClient

Syntax
my $Client = DE_EPAGES::Core::API::Object::RestClient->new(
    'Alias' => 'pdf',
    'Header' => { 'Content_Type'=>'text/html', },
);
Example
my $Client = DE_EPAGES::Core::API::Object::RestClient->new(
    'Alias' => 'pdf',
    'Header' => { 'Content_Type'=>'text/html', },
    'UserAgent' => $TestUserAgent,
    'BaseURL' => 'http://qa-test-vm:8088/rs/';
);
Input
%Options - used keys:
  • Alias - defines service name - string
  • Header - set HTTP headers needed for HTTP requests - ref.hash
  • UserAgent - provide custom LWP::UserAgent for testing (optional) - object
  • BaseURL (optional) - custom URL for testing purposes, default value is
    based on your configuration. See getBaseURL - string
  • Timeout (optional) - network timeout in seconds, default 180 seconds (from LWP::UserAgent)- integer
hash
Return
$Client (DE_EPAGES::Core::API::Object::RestClient)
blessed object

sendRequest

Send a request to the service provider and return the answer.

Syntax
my $Answer = $Client->sendRequest( $Content );
Input
$Content (string)
data to send to the service provider
Return
$Answer (string or binary)
data received from service provider