line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package perfSONAR_PS::Transport; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
53638
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
35
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
284
|
|
5
|
1
|
|
|
1
|
|
6
|
use Exporter; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
6
|
1
|
|
|
1
|
|
9651
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
110516
|
|
|
1
|
|
|
|
|
32
|
|
7
|
1
|
|
|
1
|
|
1250
|
use Log::Log4perl qw(get_logger :nowarn); |
|
1
|
|
|
|
|
59818
|
|
|
1
|
|
|
|
|
7
|
|
8
|
1
|
|
|
1
|
|
712
|
use perfSONAR_PS::Common; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use perfSONAR_PS::Messages; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = 0.09; |
12
|
|
|
|
|
|
|
use base 'Exporter'; |
13
|
|
|
|
|
|
|
our @EXPORT = (); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use fields 'CONTACT_HOST', 'CONTACT_PORT', 'CONTACT_ENDPOINT'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
18
|
|
|
|
|
|
|
my ($package, $contactHost, $contactPort, $contactEndPoint) = @_; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $self = fields::new($package); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
if(defined $contactHost and $contactHost ne "") { |
23
|
|
|
|
|
|
|
$self->{"CONTACT_HOST"} = $contactHost; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
if(defined $contactPort and $contactPort ne "") { |
26
|
|
|
|
|
|
|
$self->{"CONTACT_PORT"} = $contactPort; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
if(defined $contactEndPoint and $contactEndPoint ne "") { |
29
|
|
|
|
|
|
|
$self->{"CONTACT_ENDPOINT"} = $contactEndPoint; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
return $self; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub setContactHost { |
36
|
|
|
|
|
|
|
my ($self, $contactHost) = @_; |
37
|
|
|
|
|
|
|
my $logger = get_logger("perfSONAR_PS::Transport"); |
38
|
|
|
|
|
|
|
if(defined $contactHost) { |
39
|
|
|
|
|
|
|
$self->{CONTACT_HOST} = $contactHost; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
else { |
42
|
|
|
|
|
|
|
$logger->error("Missing argument."); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
return; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub setContactPort { |
49
|
|
|
|
|
|
|
my ($self, $contactPort) = @_; |
50
|
|
|
|
|
|
|
my $logger = get_logger("perfSONAR_PS::Transport"); |
51
|
|
|
|
|
|
|
if(defined $contactPort) { |
52
|
|
|
|
|
|
|
$self->{CONTACT_PORT} = $contactPort; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
else { |
55
|
|
|
|
|
|
|
$logger->error("Missing argument."); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
return; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub splitURI { |
62
|
|
|
|
|
|
|
my ($uri) = @_; |
63
|
|
|
|
|
|
|
my $logger = get_logger("perfSONAR_PS::Transport"); |
64
|
|
|
|
|
|
|
my $host = undef; |
65
|
|
|
|
|
|
|
my $port= undef; |
66
|
|
|
|
|
|
|
my $endpoint = undef; |
67
|
|
|
|
|
|
|
if($uri =~ /^http:\/\/([^\/]*)\/?(.*)$/) { |
68
|
|
|
|
|
|
|
($host, $port) = split(':', $1); |
69
|
|
|
|
|
|
|
$endpoint = $2; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
if(not defined $port or $port eq '') { |
72
|
|
|
|
|
|
|
$port = 80; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
if($port =~ m/^:/) { |
75
|
|
|
|
|
|
|
$port =~ s/^://g; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
$endpoint = '/' . $endpoint unless $endpoint =~ /^\//; |
78
|
|
|
|
|
|
|
$logger->debug("Found host: " . $host . " port: " . $port . " endpoint: " . $endpoint); |
79
|
|
|
|
|
|
|
return ($host, $port, $endpoint); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub getHttpURI { |
84
|
|
|
|
|
|
|
my ($host, $port, $endpoint) = @_; |
85
|
|
|
|
|
|
|
my $logger = get_logger("perfSONAR_PS::Transport"); |
86
|
|
|
|
|
|
|
$logger->debug("Created URI: http://" . $host . ":" . $port . "/" . $endpoint); |
87
|
|
|
|
|
|
|
$endpoint = "/".$endpoint if ($endpoint =~ /^[^\/]/); |
88
|
|
|
|
|
|
|
return 'http://' . $host . ':' . $port . $endpoint; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub setContactEndPoint { |
93
|
|
|
|
|
|
|
my ($self, $contactEndPoint) = @_; |
94
|
|
|
|
|
|
|
my $logger = get_logger("perfSONAR_PS::Transport"); |
95
|
|
|
|
|
|
|
if(defined $contactEndPoint) { |
96
|
|
|
|
|
|
|
$self->{CONTACT_ENDPOINT} = $contactEndPoint; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
else { |
99
|
|
|
|
|
|
|
$logger->error("Missing argument."); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
return; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub sendReceive { |
105
|
|
|
|
|
|
|
my($self, $envelope, $timeout, $error) = @_; |
106
|
|
|
|
|
|
|
my $logger = get_logger("perfSONAR_PS::Transport"); |
107
|
|
|
|
|
|
|
my $method_uri = "http://ggf.org/ns/nmwg/base/2.0/message/"; |
108
|
|
|
|
|
|
|
my $httpEndpoint = &getHttpURI( $self->{CONTACT_HOST}, $self->{CONTACT_PORT}, $self->{CONTACT_ENDPOINT}); |
109
|
|
|
|
|
|
|
my $userAgent = ""; |
110
|
|
|
|
|
|
|
if(defined $timeout and $timeout ne "") { |
111
|
|
|
|
|
|
|
$userAgent = LWP::UserAgent->new('timeout' => $timeout); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
else { |
114
|
|
|
|
|
|
|
$userAgent = LWP::UserAgent->new('timeout' => 3000); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
$logger->debug("Sending information to \"".$httpEndpoint."\": $envelope"); |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
my $sendSoap = HTTP::Request->new('POST', $httpEndpoint, new HTTP::Headers, $envelope); |
120
|
|
|
|
|
|
|
$sendSoap->header('SOAPAction' => $method_uri); |
121
|
|
|
|
|
|
|
$sendSoap->content_type ('text/xml'); |
122
|
|
|
|
|
|
|
$sendSoap->content_length(length($envelope)); |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
my $httpResponse = $userAgent->request($sendSoap); |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
if (!($httpResponse->is_success)) { |
127
|
|
|
|
|
|
|
$logger->debug("Send to \"".$httpEndpoint."\" failed: ".$httpResponse->status_line); |
128
|
|
|
|
|
|
|
$$error = $httpResponse->status_line if defined $error; |
129
|
|
|
|
|
|
|
return ""; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
my $responseCode = $httpResponse->code(); |
133
|
|
|
|
|
|
|
my $responseContent = $httpResponse->content(); |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
$logger->debug("Response returned: ".$responseContent); |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
$$error = "" if defined $error; |
138
|
|
|
|
|
|
|
return $responseContent; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
1; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
__END__ |