blib/lib/JMX/Jmx4Perl/Agent.pm

filter: Statementstmt 23.9% 47 / 196 Branchbran 2.8% 3 / 106 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 46.1% 12 / 26 Podpod 80.0% 4 / 5 totaltotal 18.4% 66 / 358 SCAR 78.6
CC
65
Cov
16%
request_url
272.0
request
182.0
_from_http_response
56.0
CRAP 2589.5
« blib/lib/JMX/Jmx4Perl/Product/BaseHandler.pm ↑ Summary blib/lib/JMX/Jmx4Perl/Agent/Jolokia/Meta.pm »
1 #!/usr/bin/perl
2 package JMX::Jmx4Perl::Agent;
3  
4 2 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use URI::Escape qw(uri_escape_utf8);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use vars qw($VERSION $DEBUG);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use base qw(JMX::Jmx4Perl);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use JMX::Jmx4Perl::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use JMX::Jmx4Perl::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use JMX::Jmx4Perl::Agent::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16  
17 2 $VERSION = $JMX::Jmx4Perl::VERSION;
18  
19 =head1 NAME
20  
21 JMX::Jmx4Perl::Agent - JSON-HTTP based acess to a remote JMX agent
22  
23 =head1 SYNOPSIS
24  
25 my $agent = new JMX::Jmx4Perl(mode=>"agent", url => "http://jeeserver/j4p");
26 my $answer = $agent->get_attribute("java.lang:type=Memory","HeapMemoryUsage");
27 print Dumper($answer);
28  
29 {
30 request => {
31 attribute => "HeapMemoryUsage",
32 name => "java.lang:type=Memory"
33 },
34 status => 200,
35 value => {
36 committed => 18292736,
37 init => 0,
38 max => 532742144,
39 used => 15348352
40 }
41 }
42  
43 =head1 DESCRIPTION
44  
45 This module is not used directly, but via L<JMX::Jmx4Perl>, which acts as a
46 proxy to this module. You can think of L<JMX::Jmx4Perl> as the interface which
47 is backed up by this module. Other implementations (e.g.
48  
49 =head1 METHODS
50  
51 =over 4
52  
53 =item $jjagent = JMX::Jmx4Perl::Agent->new(url => $url, ....)
54  
55 Creates a new local agent for a given url
56  
57 =over
58  
59 =item url => <url to JEE server>
60  
61 The url where the agent is deployed. This is a mandatory parameter. The url
62 must include the context within the server, which is typically based on the
63 name of the war archive. Example: C<http://localhost:8080/j4p> for a drop
64 in deployment of the agent in a standard Tomcat's webapp directory.
65  
66 =item timeout => <timeout>
67  
68 Timeout in seconds after which a request should be stopped if it not suceeds
69 within this time. This parameter is given through directly to the underlying
70 L<LWP::UserAgent>
71  
72 =item user => <user>, password => <password>
73  
74 Credentials to use for the HTTP request
75  
76 =item method => <method>
77  
78 The HTTP method to use for contacting the agent. Must be either "GET" or
79 "POST". This method is used, if the request to send dosen't specify the method
80 and no other parameters forces a POST context.
81  
82 =item proxy => { http => '<http_proxy>', https => '<https_proxy>', ... }
83  
84 =item proxy => <http_proxy>
85  
86 =item proxy => { url => <http_proxy> }
87  
88 Optional proxy to use
89  
90 =item proxy_user => <user>, proxy_password => <password>
91  
92 Credentials to use for accessing the proxy
93  
94 =item target
95  
96 Add a target which is used for any request served by this object if not already
97 a target is present in the request. This way you can setup the default target
98 configuration if you are using the agent servlet as a proxy, e.g.
99  
100 ... target => { url => "service:jmx:...", user => "...", password => "..." }
101  
102 =item legacy-escape
103  
104 Before version 1.0 a quite strange escaping scheme is used, when the part of a
105 GET requests contains a slash (/). Starting with 1.0 this scheme has changed,
106 but in order to allow post 1.0 Jmx4perl clients acess pre 1.0 Jolokia agents,
107 this option can be set to true to switch to the old escape mechanism.
108  
109 =back
110  
111 =cut
112  
113 # HTTP Parameters to be used for transmitting the request
114 2 my @PARAMS = ("maxDepth","maxCollectionSize","maxObjects","ignoreErrors");
115  
116 # Regexp for detecting invalid chars which can not be used securily in pathinfos
117 2 my $INVALID_PATH_CHARS = qr/%(5C|3F|3B|2F)/i; # \ ? ; /
118  
119 # Init called by parent package within 'new' for specific initialization. See
120 # above for the parameters recognized
121 sub init {
122 4 ▶ my $self = shift;
Subroutine init: called CC=8 SCAR=29.3
Pod undocumented
123
124 4 ▶ croak "No URL provided" unless $self->cfg('url');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->cfg("url") 0 4 4
125 4 my $ua = JMX::Jmx4Perl::Agent::UserAgent->new();
126 4 $ua->jjagent_config($self->{cfg});
127 #push @{ $ua->requests_redirectable }, 'POST';
128 4 ▶ $ua->timeout($self->cfg('timeout')) if $self->cfg('timeout');
Branch: 1 branch
BranchTrueFalseTotal
if $self->cfg("timeout") 0 4 4
129 #print "TO: ",$ua->timeout(),"\n";
130 4 $ua->agent("JMX::Jmx4Perl::Agent $VERSION");
131 # $ua->env_proxy;
132 4 my $proxy = $self->cfg('proxy');
133 4 ▶ if ($proxy) {
Branch: 1 branch
BranchTrueFalseTotal
if ($proxy) 0 4 4
134 0 ▶ my $url = ref($proxy) eq "HASH" ? $proxy->{url} : $proxy;
Branch: 1 branch
BranchTrueFalseTotal
ref $proxy eq 'HASH' ? : 0 0 0
135 0 ▶ if (ref($url) eq "HASH") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $url eq 'HASH') { } 0 0 0
136 0 for my $k (keys %$url) {
137 0 $ua->proxy($k,$url->{$k});
138 }
139 } else {
140 0 ▶ if ($self->cfg('url') =~ m|^(.*?)://|) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->cfg('url') =~ m[^(.*?)://]) { } 0 0 0
141 # Set proxy for URL scheme used
142 0 $ua->proxy($1,$url);
143 } else {
144 0 $ua->proxy('http',$proxy);
145 }
146 }
147 }
148 4 $self->{ua} = $ua;
149 4 return $self;
150 }
151  
152 =item $url = $agent->url()
153  
154 Get the base URL for connecting to the agent. You cannot change the URL via this
155 method, it is immutable for a given agent.
156  
157 =cut
158  
159 sub url {
160 0 ▶ my $self = shift;
Subroutine url: not called CC=1 SCAR=6.9
Pod documented
161 0 return $self->cfg('url');
162 }
163  
164 =item $resp = $agent->request($request)
165  
166 Implementation of the JMX request as specified in L<JMX::Jmx4Perl>. It uses a
167 L<HTTP::Request> sent via an L<LWP::UserAgent> for posting a JSON representation
168 of the request. This method shouldn't be called directly but via
169 L<JMX::Jmx4Perl>->request().
170  
171 =cut
172  
173 sub request {
174 0 ▶ my $self = shift;
Subroutine request: not called CC=13 SCAR=52.0
Pod documented
175 0 ▶ my @jmx_requests = $self->cfg('target') ? $self->_update_targets(@_) : @_;
Branch: 1 branch
BranchTrueFalseTotal
$self->cfg('target') ? : 0 0 0
176 0 my $ua = $self->{ua};
177 0 my $http_req = $self->_to_http_request(@jmx_requests);
178 0 ▶ if ($self->{cfg}->{verbose}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"cfg"}{"verbose"}) 0 0 0
179 0 print $http_req->as_string;
180 0 print "===========================================================\n";
181 }
182 #print Dumper($http_req);
183 0 my $http_resp = $ua->request($http_req);
184 0 my $json_resp = {};
185 0 ▶ if ($self->{cfg}->{verbose}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"cfg"}{"verbose"}) 0 0 0
186 0 print $http_resp->as_string,"\n";
187 0 print "===========================================================\n";
188 }
189 0 eval {
190 0 $json_resp = from_json($http_resp->content());
191 };
192 0 my $json_error = $@;
193 0 ▶ if ($http_resp->is_error) {
Branch: 2 branches
BranchTrueFalseTotal
if ($http_resp->is_error) { } 0 0 0
elsif ($json_error) { } 0 0 0
194 return JMX::Jmx4Perl::Response->new
195 (
196 status => $http_resp->code,
197 value => $json_error ? $http_resp->content : $json_resp,
198 error => $json_error ? $self->_prepare_http_error_text($http_resp) :
199 0 ▶ ref($json_resp) eq "ARRAY" ? join "\n", map { $_->{error} } grep { $_->{error} } @$json_resp : $json_resp->{error},
Branch: 2 branches
BranchTrueFalseTotal
ref $json_resp eq 'ARRAY' ? : 0 0 0
@jmx_requests == 1 ? : 0 0 0
200 stacktrace => ref($json_resp) eq "ARRAY" ? $self->_extract_stacktraces($json_resp) : $json_resp->{stacktrace},
201 0 ▶ request => @jmx_requests == 1 ? $jmx_requests[0] : \@jmx_requests
Branch: 3 branches
BranchTrueFalseTotal
$json_error ? : 0 0 0
$json_error ? : 0 0 0
ref $json_resp eq 'ARRAY' ? : 0 0 0
202 );
203 } elsif ($json_error) {
204 # If is not an HTTP-Error and deserialization fails, then we
205 # probably got a wrong URL and get delivered some server side
206 # document (with HTTP code 200)
207 0 my $e = $json_error;
208 0 $e =~ s/(.*)at .*?line.*$/$1/;
209 0 return JMX::Jmx4Perl::Response->new
210 (
211 status => 400,
212 error =>
213 "Error while deserializing JSON answer (Wrong URL ?)\n" . $e,
214 value => $http_resp->content
215 );
216 }
217
218 0 my @responses = ($self->_from_http_response($json_resp,@jmx_requests));
219 0 ▶ if (!wantarray && scalar(@responses) == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (not wantarray and scalar @responses == 1) { } 0 0 0
Condition0%0/3
not wantarray and scalar @responses == 1
!ll&&!rl&&r
000
MC/DC0%0/2
not wantarray and scalar @responses == 1
not wantarray scalar @responses == 1
Truth table0%0/3
not(A) and B
A= not wantarrayB= scalar @responses == 1
ABresult
0X0
100
111
220 0 return shift @responses;
221 } else {
222 0 return @responses;
223 }
224 }
225  
226 =item $encrypted = $agent->encrypt($plain)
227  
228 Encrypt a password which can be used in configuration files in order to
229 obfuscate the clear text password.
230  
231 =cut
232  
233 sub encrypt {
234 0 ▶ return "[[" . &JMX::Jmx4Perl::Agent::UserAgent::encrypt(shift) . "]]";
Subroutine encrypt: not called CC=1 SCAR=6.9
Pod documented
235 }
236  
237  
238 # Create an HTTP-Request for calling the server
239 sub _to_http_request {
240 0 ▶ my $self = shift;
Subroutine _to_http_request: not called CC=5 SCAR=34.0
241 0 my @reqs = @_;
242 0 ▶ if ($self->_use_GET_request(\@reqs)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_use_GET_request(\@reqs)) { } 0 0 0
243 # Old, rest-style
244 0 my $url = $self->request_url($reqs[0]);
245 0 return HTTP::Request->new(GET => $url);
246 } else {
247 0 ▶ my $url = $self->cfg('url') || croak "No URL provided";
Condition0%0/3
$self->cfg('url') || croak('No URL provided')
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->cfg('url') || croak('No URL provided')
$self->cfg('url') croak('No URL provided')
Truth table0%0/3
A || B
A= $self->cfg('url')B= croak('No URL provided')
ABresult
1X1
011
000
248 0 ▶ $url .= "/" unless $url =~ m|/$|;
Branch: 1 branch
BranchTrueFalseTotal
unless $url =~ m[/$] 0 0 0
249 0 my $request = HTTP::Request->new(POST => $url);
250 0 ▶ my $content = to_json(@reqs > 1 ? \@reqs : $reqs[0], { convert_blessed => 1 });
Branch: 1 branch
BranchTrueFalseTotal
@reqs > 1 ? : 0 0 0
251 #print Dumper($reqs[0],$content);
252 0 $request->content($content);
253 0 return $request;
254 }
255 }
256  
257 sub _use_GET_request {
258 0 ▶ my $self = shift;
Subroutine _use_GET_request: not called CC=5 SCAR=34.0
259 0 my $reqs = shift;
260 0 ▶ if (@$reqs == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$reqs == 1) { } 0 0 0
261 0 my $req = $reqs->[0];
262 # For proxy configs and explicite set POST request, get can not be
263 # used
264 0 ▶ return 0 if defined($req->get("target"));
Branch: 1 branch
BranchTrueFalseTotal
if defined $req->get("target") 0 0 0
265 #print Dumper($req);
266 0 for my $r ($req->method,$self->cfg('method')) {
267 0 ▶ return lc($r) eq "get" if defined($r);
Branch: 1 branch
BranchTrueFalseTotal
if defined $r 0 0 0
268 }
269 # GET by default
270 0 return 1;
271 } else {
272 0 return 0;
273 }
274 }
275  
276 # Create one or more response objects for a given request
277 sub _from_http_response {
278 0 ▶ my $self = shift;
Subroutine _from_http_response: not called CC=7 SCAR=40.3
279 0 my $json_resp = shift;
280 0 my @reqs = @_;
281 0 ▶ if (ref($json_resp) eq "HASH") {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $json_resp eq 'HASH') { } 0 0 0
elsif (ref $json_resp eq 'ARRAY') { } 0 0 0
282 0 return JMX::Jmx4Perl::Response->new(%{$json_resp},request => $reqs[0]);
283 } elsif (ref($json_resp) eq "ARRAY") {
284 0 ▶ die "Internal: Number of request and responses doesn't match (",scalar(@reqs)," vs. ",scalar(@$json_resp)
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @reqs == scalar @$json_resp 0 0 0
285 unless scalar(@reqs) == scalar(@$json_resp);
286
287 0 my @ret = ();
288 0 ▶ for (my $i=0;$i<@reqs;$i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @reqs) 0 0 0
289 0 ▶ die "Internal: Not a hash --> ",$json_resp->[$i] unless ref($json_resp->[$i]) eq "HASH";
Branch: 1 branch
BranchTrueFalseTotal
unless ref $json_resp->[$i] eq "HASH" 0 0 0
290 0 my $response = JMX::Jmx4Perl::Response->new(%{$json_resp->[$i]},request => $reqs[$i]);
291 0 push @ret,$response;
292 }
293 0 return @ret;
294 } else {
295 0 ▶ die "Internal: Not a hash nor an array but ",ref($json_resp) ? ref($json_resp) : $json_resp;
Branch: 1 branch
BranchTrueFalseTotal
ref $json_resp ? : 0 0 0
296 }
297 }
298  
299 # Update targets if not set in request.
300 sub _update_targets {
301 0 ▶ my $self = shift;
Subroutine _update_targets: not called CC=4 SCAR=30.0
302 0 my @requests = @_;
303 0 my $target = $self->_clone_target;
304 0 for my $req (@requests) {
305 0 ▶ $req->{target} = $target unless exists($req->{target});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $req->{"target"} 0 0 0
306 # A request with existing but undefined target removes
307 # any default
308 0 ▶ delete $req->{target} unless defined($req->{target});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $req->{"target"} 0 0 0
309 }
310 0 return @requests;
311 }
312  
313 sub _clone_target {
314 0 ▶ my $self = shift;
Subroutine _clone_target: not called CC=3 SCAR=24.8
315 0 ▶ die "Internal: No target set" unless $self->cfg('target');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->cfg("target") 0 0 0
316 0 my $target = { %{$self->cfg('target')} };
317 0 ▶ if ($target->{env}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target->{"env"}) 0 0 0
318 0 $target->{env} = { %{$target->{env}}};
319 }
320 0 return $target;
321 }
322  
323 =item $url = $agent->request_url($request)
324  
325 Generate the URL for accessing the java agent based on a given request.
326  
327 =cut
328  
329 sub request_url {
330 0 ▶ my $self = shift;
Subroutine request_url: not called CC=16 SCAR=56.1
Pod documented
331 0 my $request = shift;
332 0 ▶ my $url = $self->cfg('url') || croak "No base url given in configuration";
Condition0%0/3
$self->cfg('url') || croak('No base url given in configuration')
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->cfg('url') || croak('No base url given in configuration')
$self->cfg('url') croak('No base url given in configuration')
Truth table0%0/3
A || B
A= $self->cfg('url')B= croak('No base url given in configuration')
ABresult
1X1
011
000
333 0 ▶ $url .= "/" unless $url =~ m|/$|;
Branch: 1 branch
BranchTrueFalseTotal
unless $url =~ m[/$] 0 0 0
334
335 0 my $type = $request->get("type");
336 0 my $req = $type . "/";
337 0 $req .= $self->_escape($request->get("mbean"));
338
339 0 ▶ if ($type eq READ) {
Branch: 5 branches
BranchTrueFalseTotal
if ($type eq 'read') { } 0 0 0
elsif ($type eq 'write') { } 0 0 0
elsif ($type eq 'list') { } 0 0 0
elsif ($type eq 'exec') { } 0 0 0
elsif ($type eq 'search') { } 0 0 0
340 0 $req .= "/" . $self->_escape($request->get("attribute"));
341 0 $req .= $self->_extract_path($request->get("path"));
342 } elsif ($type eq WRITE) {
343 0 $req .= "/" . $self->_escape($request->get("attribute"));
344 0 $req .= "/" . $self->_escape($self->_null_escape($request->get("value")));
345 0 $req .= $self->_extract_path($request->get("path"));
346 } elsif ($type eq LIST) {
347 0 $req .= $self->_extract_path($request->get("path"));
348 } elsif ($type eq EXEC) {
349 0 $req .= "/" . $self->_escape($request->get("operation"));
350 0 for my $arg (@{$request->get("arguments")}) {
351 # Array refs are sticked together via ","
352 0 ▶ my $a = ref($arg) eq "ARRAY" ? join ",",@{$arg} : $arg;
Branch: 1 branch
BranchTrueFalseTotal
ref $arg eq 'ARRAY' ? : 0 0 0
353 0 $req .= "/" . $self->_escape($self->_null_escape($a));
354 }
355 } elsif ($type eq SEARCH) {
356 # Nothing further to append.
357 }
358 # Squeeze multiple slashes
359 0 $req =~ s|((?:!/)?/)/*|$1|g;
360 #print "R: $req\n";
361  
362 0 ▶ if ($req =~ $INVALID_PATH_CHARS || $request->{use_query}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req =~ /$INVALID_PATH_CHARS/ or $request->{"use_query"}) 0 0 0
Condition0%0/3
$req =~ /$INVALID_PATH_CHARS/ or $request->{"use_query"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$req =~ /$INVALID_PATH_CHARS/ or $request->{"use_query"}
$req =~ /$INVALID_PATH_CHARS/ $request->{"use_query"}
Truth table0%0/3
A or B
A= $req =~ /$INVALID_PATH_CHARS/B= $request->{"use_query"}
ABresult
1X1
011
000
363 0 $req = "?p=$req";
364 }
365 0 my @params;
366 0 for my $k (@PARAMS) {
367 0 ▶ push @params, $k . "=" . $request->get($k)
Branch: 1 branch
BranchTrueFalseTotal
if $request->get($k) 0 0 0
368 if $request->get($k);
369 }
370 0 ▶ $req .= ($req =~ /\?/ ? "&" : "?") . join("&",@params) if @params;
Branch: 2 branches
BranchTrueFalseTotal
if @params 0 0 0
$req =~ /\?/ ? : 0 0 0
371 0 return $url . $req;
372 }
373  
374  
375 # =============================================================================
376  
377  
378 # Return an (optional) path which must already be escaped
379 sub _extract_path {
380 0 ▶ my $self = shift;
Subroutine _extract_path: not called CC=2 SCAR=17.9
381 0 my $path = shift;
382 0 ▶ return $path ? "/" . $path : "";
Branch: 1 branch
BranchTrueFalseTotal
$path ? : 0 0 0
383 }
384  
385  
386 # Escaping is simple:
387 # ! --> !!
388 # / --> !/
389 # It is not done by backslashes '\' since often they get magically get
390 # translated into / when part of an URL
391 sub _escape {
392 0 ▶ my $self = shift;
Subroutine _escape: not called CC=2 SCAR=17.9
393 0 my $input = shift;
394 0 ▶ if ($self->cfg('legacy-escape')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->cfg('legacy-escape')) { } 0 0 0
395 # Pre 1.0 escaping:
396 0 $input =~ s|(/+)|"/" . ('-' x length($1)) . "/"|eg;
397 0 $input =~ s|^/-|/^|; # The first slash needs to be escaped (first)
398 0 $input =~ s|-/$|+/|; # as well as last slash. They need a special
399 # escape, because two subsequent slashes get
400 # squeezed to one on the server side
401  
402 } else {
403 # Simpler escaping since 1.0:
404 0 $input =~ s/!/!!/g;
405 0 $input =~ s/\//!\//g;
406 }
407
408 0 return URI::Escape::uri_escape_utf8($input,"^A-Za-z0-9\-_.!~*'()/"); # Added "/" to
409 # default
410 # set. See L<URI>
411 }
412  
413 # Escape empty and undef values so that they can be detangled
414 # on the server side
415 sub _null_escape {
416 0 ▶ my $self = shift;
Subroutine _null_escape: not called CC=3 SCAR=24.8
417 0 my $value = shift;
418 0 ▶ if (!defined($value)) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $value) { } 0 0 0
elsif (not length $value) { } 0 0 0
419 0 return "[null]";
420 } elsif (! length($value)) {
421 0 return "\"\"";
422 } else {
423 0 return $value;
424 }
425 }
426  
427 # Prepare some readable error text
428 sub _prepare_http_error_text {
429 0 ▶ my $self = shift;
Subroutine _prepare_http_error_text: not called CC=4 SCAR=30.0
430 0 my $http_resp = shift;
431 0 my $content = $http_resp->content;
432 0 my $error = "Error while fetching ".$http_resp->request->uri." :\n\n" . $http_resp->status_line . "\n";
433 0 chomp $content;
434 0 ▶ if ($content && $content ne $http_resp->status_line) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content and $content ne $http_resp->status_line) 0 0 0
Condition0%0/3
$content and $content ne $http_resp->status_line
!ll&&!rl&&r
000
MC/DC0%0/2
$content and $content ne $http_resp->status_line
$content $content ne $http_resp->status_line
Truth table0%0/3
A and B
A= $contentB= $content ne $http_resp->status_line
ABresult
0X0
100
111
435 0 my $error .= "=" x length($http_resp->status_line) . "\n\n";
436 0 my $short = substr($content,0,600);
437 0 ▶ $error .= $short . (length($short) < length($content) ? "\n\n... [truncated] ...\n\n" : "") . "\n"
Branch: 1 branch
BranchTrueFalseTotal
length $short < length $content ? : 0 0 0
438 }
439 0 return $error;
440 }
441  
442 # Extract all stacktraces stored in the given array ref of json responses
443 sub _extract_stacktraces {
444 0 ▶ my $self = shift;
Subroutine _extract_stacktraces: not called CC=5 SCAR=34.0
445 0 my $json_resp = shift;
446 0 my @ret = ();
447 0 for my $j (@$json_resp) {
448 0 ▶ push @ret,$j->{stacktrace} if $j->{stacktrace};
Branch: 1 branch
BranchTrueFalseTotal
if $j->{"stacktrace"} 0 0 0
449 }
450 0 ▶ return @ret ? (scalar(@ret) == 1 ? $ret[0] : \@ret) : undef;
Branch: 2 branches
BranchTrueFalseTotal
@ret ? : 0 0 0
scalar @ret == 1 ? : 0 0 0
451 }
452  
453 =back
454  
455 =cut
456  
457 # ===================================================================
458 # Specialized UserAgent for passing in credentials:
459  
460 =head1 LICENSE
461  
462 This file is part of jmx4perl.
463  
464 Jmx4perl is free software: you can redistribute it and/or modify
465 it under the terms of the GNU General Public License as published by
466 the Free Software Foundation, either version 2 of the License, or
467 (at your option) any later version.
468  
469 jmx4perl is distributed in the hope that it will be useful,
470 but WITHOUT ANY WARRANTY; without even the implied warranty of
471 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
472 GNU General Public License for more details.
473  
474 You should have received a copy of the GNU General Public License
475 along with jmx4perl. If not, see <http://www.gnu.org/licenses/>.
476  
477 A commercial license is available as well. Please contact roland@cpan.org for
478 further details.
479  
480 =head1 AUTHOR
481  
482 roland@cpan.org
483  
484 =cut
485  
486 2 1;
« blib/lib/JMX/Jmx4Perl/Product/BaseHandler.pm ↑ Summary blib/lib/JMX/Jmx4Perl/Agent/Jolokia/Meta.pm »