Perl
Use Perl to invoke web services using various techniques such
as HTTP::Request
and SOAP::Lite
.
HTTP::Request
Use HTTP::Request to directly construct and process the XML for the SOAP web services.
-
Construct an xml payload to invoke the service. This example code passes a hard coded string, which is encoded to UTF-8 byte array, to the request.
-
Construct a Base64-encoded string for the credentials of the service call.
-
Create a POST request for the service.
-
Configure the request content type to be
xml
, to use basic authentication with Base64-encoded credentials. -
Set the
SOAPAction
to be invoked. Though the service call works without this value, it is a recommended standard. -
Write the xml payload to the request.
-
Call the service.
-
Process the response. This example just prints the response.
#!/usr/bin/perl -w
use strict;
use LWP::UserAgent;
use HTTP::Request::Common;
use MIME::Base64;
my $ua = LWP::UserAgent->new(agent => 'perl post');
# Construct xml payload to invoke the service. In the example, it is hard coded.
my $envelope = <<END;
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<findRule
xmlns="http://xmlns.oracle.com/apps/incentiveCompensation/cn/creditSetup/creditRule/creditRuleService/types/">
<findCriteria>
<fetchStart xmlns="http://xmlns.oracle.com/adf/svc/types/">0</fetchStart>
<fetchSize xmlns="http://xmlns.oracle.com/adf/svc/types/">-1</fetchSize>
<filter xmlns="http://xmlns.oracle.com/adf/svc/types/">
<group>
<upperCaseCompare>false</upperCaseCompare>
<item>
<upperCaseCompare>false</upperCaseCompare>
<attribute>RuleId</attribute>
<operator>=</operator>
<value>300000000851162</value>
</item>
</group>
</filter>
<excludeAttribute xmlns="http://xmlns.oracle.com/adf/svc/types/">false</excludeAttribute>
</findCriteria>
<findControl>
<retrieveAllTranslations xmlns="http://xmlns.oracle.com/adf/svc/types/">false</retrieveAllTranslations>
</findControl>
</findRule>
</soap:Body>
</soap:Envelope>
END
# Construct the base 64 encoded string used as the credentials for the service call.
my $credentials = encode_base64('username:password');
my $url = 'https://host:port/icCnSetupCreditRulesPublicService/CreditRuleService';
# Create new POST request
my $req=new HTTP::Request 'POST',$url;
# Configure the request to use basic authentication, with base64-encoded user name and password to invoke the service.
$req->header('Authorization' => "Basic " . $credentials);
# Set the SOAP action to be invoked; while the call works without this, the value is expected to be set based on standards
$req->header('SOAPAction' =>
'http://xmlns.oracle.com/apps/incentiveCompensation/cn/creditSetup/creditRule/creditRuleService/findRule');
# Configure the request content type to be xml, HTTP method to be POST, and set the content length
$req->header('Content-Type' => 'text/xml;charset=UTF-8');
# Write the xml payload to the request.
$req->content($envelope);
# Call the service
my $response=$ua->request($req);
# Process the response. In this example, we simply print the response.
print $response->error_as_HTML unless $response->is_success;
print $response->as_string;
SOAP::Lite
-
Create a new of the SOAP Lite.
-
Register the namespaces for the envelope.
-
Create a SOAP header with security information.
-
Call the service.
-
Process the response. This example just prints the response.
#!/usr/bin/perl
use lib '/usr/lib/perl5/5.8.8/';
use MIME::Base64;
use SOAP::Lite;
SOAP::Lite->import(trace => debug);
# Create a new instance for the SOAP Lite
my $soap = SOAP::Lite->new(
proxy => 'http://host:port/hcmEmploymentCoreWorker/WorkerService',
service => 'http://host:port/hcmEmploymentCoreWorker/WorkerService?wsdl',
);
# Register namespace(s) for the envelope
my $serializer = $soap->serializer();
$serializer->register_ns( 'http://xmlns.oracle.com/apps/hcm/employment/core/workerService/types/', 'typ' );
# Create SOAP header with security information
my $auth = SOAP::Header->new( name => "wsse:Security" );
$auth->attr( { "xmlns:wsse" => "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecuritysecext-1.0.xsd"});
$auth->mustUnderstand(1);
$auth->value( \SOAP::Data->value(
SOAP::Data->name("wsse:UsernameToken" => \SOAP::Data->value(
SOAP::Data->name("wsse:Username" => 'username')->type(""),
SOAP::Data->name("wsse:Password" => 'password')->type("")
->attr( {"Type" => "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-usernametoken-profile-1.0#PasswordText"}),
SOAP::Data->name("wsse:nonce" => 'jwCzGGijT90Wml6eZe4cxg==')->type("")
->attr( {"EncodingType" => "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wsssoap-message-security-1.0#Base64Binary"}),
SOAP::Data->name("wsse:created" => '2012-07-04T06:49:48.981Z')->type("")
)->type("")
)->attr( {"wsu:Id" => "UsernameToken-2",
"xmlns:wsu" => "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wsswssecurity-utility-1.0.xsd"
})
)->type("")
);
# Populate parameters to call the service
my $parameters =SOAP::Data->name("typ:personId" => '300000010363707')->type("");
# Call the service
my $result = $soap->call(SOAP::Data->name('typ:getWorker') => $parameters, $auth);
# Process the response. In this example, we simply print the response
die $result->faultstring if ($result->fault);
print $result->result, "\n";