#!/usr/bin/perl ## Copyright (C) 2010 - 2013 ICM, Warsaw University ## ## Licensed under the Apache License, Version 2.0 (the "License"); ## you may not use this file except in compliance with the License. ## You may obtain a copy of the License at ## ## http://www.apache.org/licenses/LICENSE-2.0 ## ## Unless required by applicable law or agreed to in writing, software ## distributed under the License is distributed on an "AS IS" BASIS, ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ## See the License for the specific language governing permissions and ## limitations under the License. use REST::Client; use Google::ProtocolBuffers; use Config::Properties; #loads properties file client.properties sub loadPropfile() { my $confPath = "client.properties"; open my $fh, '<', "$confPath" or die "unable to open configuration file $confPath"; my $properties = Config::Properties->new(); $properties->load($fh); return $properties; } #ask service registry sub findService() { my $registryUrl = shift; my $serviceId = shift; my $serviceVer = shift; my $client = REST::Client->new(); #ask registry about: # ServiceId # Service Version # Client Name: some name to self introduce # Protocol: rest $url = "$registryUrl/$serviceId/$serviceVer/perlClient/rest"; #send request and expect result in Protocol Buffer format $client->GET($url,{Accept => 'application/x-protobuf;charset=UTF-8'}); if( $client->responseCode() ne '200' ){ die "Server return code ", $client->responseCode(), "\nService url: $url\n"; } die "Service $serviceId not found in registry " if(!$client->responseContent()); #parsing return service description my ServiceDescriptorProto $servDesc = ServiceDescriptorProto->decode($client->responseContent()); #read about service location: url for service my ConnectionDescriptorProto $location = $servDesc->{locations}[0]; print "$serviceId rest location: ",$location->{location},", protocol:", $location->{protocol}, "\n"; return $location->{location}; } 1;