line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl -w |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Apache::Sling::JsonQueryServlet; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
3065
|
use 5.008001; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
39
|
|
6
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
7
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
29
|
|
8
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
82
|
|
9
|
1
|
|
|
1
|
|
1235
|
use Getopt::Long qw(:config bundling); |
|
1
|
|
|
|
|
17156
|
|
|
1
|
|
|
|
|
7
|
|
10
|
1
|
|
|
1
|
|
237
|
use Apache::Sling; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
37
|
|
11
|
1
|
|
|
1
|
|
655
|
use Apache::Sling::JsonQueryServletUtil; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
48
|
|
12
|
1
|
|
|
1
|
|
6
|
use Apache::Sling::Print; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
34
|
|
13
|
1
|
|
|
1
|
|
5
|
use Apache::Sling::Request; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
require Exporter; |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
5
|
use base qw(Exporter); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1040
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our @EXPORT_OK = qw(command_line); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $VERSION = '0.27'; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
#{{{sub new |
24
|
|
|
|
|
|
|
sub new { |
25
|
2
|
|
|
2
|
1
|
1503
|
my ( $class, $authn, $verbose, $log ) = @_; |
26
|
2
|
100
|
|
|
|
9
|
if ( !defined $authn ) { croak 'no authn provided!'; } |
|
1
|
|
|
|
|
72
|
|
27
|
1
|
|
|
|
|
3
|
my $response; |
28
|
1
|
50
|
|
|
|
6
|
$verbose = ( defined $verbose ? $verbose : 0 ); |
29
|
1
|
|
|
|
|
16
|
my $json_query_servlet = { |
30
|
1
|
|
|
|
|
4
|
BaseURL => ${$authn}->{'BaseURL'}, |
31
|
|
|
|
|
|
|
Authn => $authn, |
32
|
|
|
|
|
|
|
Message => q{}, |
33
|
|
|
|
|
|
|
Response => \$response, |
34
|
|
|
|
|
|
|
Verbose => $verbose, |
35
|
|
|
|
|
|
|
Log => $log |
36
|
|
|
|
|
|
|
}; |
37
|
1
|
|
|
|
|
5
|
bless $json_query_servlet, $class; |
38
|
1
|
|
|
|
|
4
|
return $json_query_servlet; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
#}}} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
#{{{sub set_results |
44
|
|
|
|
|
|
|
sub set_results { |
45
|
1
|
|
|
1
|
1
|
2884
|
my ( $json_query_servlet, $message, $response ) = @_; |
46
|
1
|
|
|
|
|
5
|
$json_query_servlet->{'Message'} = $message; |
47
|
1
|
|
|
|
|
3
|
$json_query_servlet->{'Response'} = $response; |
48
|
1
|
|
|
|
|
3
|
return 1; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
#}}} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
#{{{sub all_nodes |
54
|
|
|
|
|
|
|
sub all_nodes { |
55
|
0
|
|
|
0
|
1
|
0
|
my ($json_query_servlet) = @_; |
56
|
0
|
|
|
|
|
0
|
my $res = Apache::Sling::Request::request( |
57
|
|
|
|
|
|
|
\$json_query_servlet, |
58
|
|
|
|
|
|
|
Apache::Sling::JsonQueryServletUtil::all_nodes_setup( |
59
|
|
|
|
|
|
|
$json_query_servlet->{'BaseURL'} |
60
|
|
|
|
|
|
|
) |
61
|
|
|
|
|
|
|
); |
62
|
0
|
|
|
|
|
0
|
my $success = Apache::Sling::JsonQueryServletUtil::all_nodes_eval($res); |
63
|
0
|
|
|
|
|
0
|
my $message = ( |
64
|
|
|
|
|
|
|
$success |
65
|
0
|
0
|
|
|
|
0
|
? ${$res}->content |
66
|
|
|
|
|
|
|
: "Problem fetching all nodes" |
67
|
|
|
|
|
|
|
); |
68
|
0
|
|
|
|
|
0
|
$json_query_servlet->set_results( "$message", $res ); |
69
|
0
|
|
|
|
|
0
|
return $success; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
#}}} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
#{{{ sub command_line |
75
|
|
|
|
|
|
|
sub command_line { |
76
|
0
|
|
|
0
|
0
|
0
|
my ( $json_query_servlet, @ARGV ) = @_; |
77
|
0
|
|
|
|
|
0
|
my $sling = Apache::Sling->new; |
78
|
0
|
|
|
|
|
0
|
my $config = $json_query_servlet->config( $sling, @ARGV ); |
79
|
0
|
|
|
|
|
0
|
return $json_query_servlet->run( $sling, $config ); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
#}}} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
#{{{sub config |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub config { |
87
|
1
|
|
|
1
|
1
|
876
|
my ( $json_query_servlet, $sling, @ARGV ) = @_; |
88
|
|
|
|
|
|
|
|
89
|
1
|
|
|
|
|
8
|
my $json_query_servlet_config = $json_query_servlet->config_hash( $sling, @ARGV ); |
90
|
|
|
|
|
|
|
|
91
|
1
|
50
|
|
|
|
9
|
GetOptions( |
92
|
|
|
|
|
|
|
$json_query_servlet_config, 'auth=s', |
93
|
|
|
|
|
|
|
'help|?', 'log|L=s', |
94
|
|
|
|
|
|
|
'man|M', 'pass|p=s', |
95
|
|
|
|
|
|
|
'threads|t=s', 'url|U=s', |
96
|
|
|
|
|
|
|
'user|u=s', 'verbose|v+', |
97
|
|
|
|
|
|
|
'all_nodes|a' |
98
|
|
|
|
|
|
|
) or $json_query_servlet->help(); |
99
|
|
|
|
|
|
|
|
100
|
1
|
|
|
|
|
801
|
return $json_query_servlet_config; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
#}}} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
#{{{sub config_hash |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub config_hash { |
108
|
1
|
|
|
1
|
0
|
3
|
my ( $json_query_servlet, $sling, @ARGV ) = @_; |
109
|
1
|
|
|
|
|
3
|
my $all_nodes; |
110
|
|
|
|
|
|
|
|
111
|
1
|
|
|
|
|
20
|
my %json_query_servlet_config = ( |
112
|
|
|
|
|
|
|
'auth' => \$sling->{'Auth'}, |
113
|
|
|
|
|
|
|
'help' => \$sling->{'Help'}, |
114
|
|
|
|
|
|
|
'log' => \$sling->{'Log'}, |
115
|
|
|
|
|
|
|
'man' => \$sling->{'Man'}, |
116
|
|
|
|
|
|
|
'pass' => \$sling->{'Pass'}, |
117
|
|
|
|
|
|
|
'threads' => \$sling->{'Threads'}, |
118
|
|
|
|
|
|
|
'url' => \$sling->{'URL'}, |
119
|
|
|
|
|
|
|
'user' => \$sling->{'User'}, |
120
|
|
|
|
|
|
|
'verbose' => \$sling->{'Verbose'}, |
121
|
|
|
|
|
|
|
'all_nodes' => \$all_nodes |
122
|
|
|
|
|
|
|
); |
123
|
|
|
|
|
|
|
|
124
|
1
|
|
|
|
|
4
|
return \%json_query_servlet_config; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
#}}} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
#{{{ sub help |
130
|
|
|
|
|
|
|
sub help { |
131
|
|
|
|
|
|
|
|
132
|
1
|
|
|
1
|
0
|
1641
|
print <<"EOF"; |
133
|
|
|
|
|
|
|
Usage: perl $0 [-OPTIONS [-MORE_OPTIONS]] [--] [PROGRAM_ARG1 ...] |
134
|
|
|
|
|
|
|
The following options are accepted: |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
--all_nodes or -a - Return a JSON representation of all nodes in the system. |
137
|
|
|
|
|
|
|
--auth (type) - Specify auth type. If ommitted, default is used. |
138
|
|
|
|
|
|
|
--help or -? - view the script synopsis and options. |
139
|
|
|
|
|
|
|
--log or -L (log) - Log script output to specified log file. |
140
|
|
|
|
|
|
|
--man or -M - view the full script documentation. |
141
|
|
|
|
|
|
|
--pass or -p (password) - Password of user performing json queries. |
142
|
|
|
|
|
|
|
--threads or -t (threads) - Used with -A, defines number of parallel |
143
|
|
|
|
|
|
|
processes to have running through file. |
144
|
|
|
|
|
|
|
--url or -U (URL) - URL for system being tested against. |
145
|
|
|
|
|
|
|
--user or -u (username) - Name of user to perform queries as. |
146
|
|
|
|
|
|
|
--verbose or -v or -vv or -vvv - Increase verbosity of output. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Options may be merged together. -- stops processing of options. |
149
|
|
|
|
|
|
|
Space is not required between options and their arguments. |
150
|
|
|
|
|
|
|
For full details run: perl $0 --man |
151
|
|
|
|
|
|
|
EOF |
152
|
|
|
|
|
|
|
|
153
|
1
|
|
|
|
|
4
|
return 1; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
#}}} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
#{{{ sub man |
159
|
|
|
|
|
|
|
sub man { |
160
|
|
|
|
|
|
|
|
161
|
0
|
|
|
0
|
0
|
0
|
my ($json_query_servlet) = @_; |
162
|
|
|
|
|
|
|
|
163
|
0
|
|
|
|
|
0
|
print <<'EOF'; |
164
|
|
|
|
|
|
|
json_query_servlet perl script. Provides a means of querying content in sling |
165
|
|
|
|
|
|
|
from the command line. The script also acts as a reference implementation for |
166
|
|
|
|
|
|
|
the JSON Query Servlet perl library. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
EOF |
169
|
|
|
|
|
|
|
|
170
|
0
|
|
|
|
|
0
|
$json_query_servlet->help(); |
171
|
|
|
|
|
|
|
|
172
|
0
|
|
|
|
|
0
|
print <<"EOF"; |
173
|
|
|
|
|
|
|
Example Usage |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
* Query all nodes in the system: |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
perl $0 -U http://localhost:8080 -a -u admin -p admin |
178
|
|
|
|
|
|
|
EOF |
179
|
|
|
|
|
|
|
|
180
|
0
|
|
|
|
|
0
|
return 1; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
#}}} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
#{{{sub run |
186
|
|
|
|
|
|
|
sub run { |
187
|
2
|
|
|
2
|
1
|
42
|
my ( $json_query_servlet, $sling, $config ) = @_; |
188
|
2
|
100
|
|
|
|
9
|
if ( !defined $config ) { |
189
|
1
|
|
|
|
|
20
|
croak 'No json query servlet config supplied!'; |
190
|
|
|
|
|
|
|
} |
191
|
1
|
|
|
|
|
7
|
$sling->check_forks; |
192
|
1
|
|
|
|
|
3
|
${ $config->{'remote'} } = |
|
1
|
|
|
|
|
9
|
|
193
|
1
|
|
|
|
|
2
|
Apache::Sling::URL::strip_leading_slash( ${ $config->{'remote'} } ); |
194
|
1
|
|
|
|
|
3
|
${ $config->{'remote-source'} } = Apache::Sling::URL::strip_leading_slash( |
|
1
|
|
|
|
|
5
|
|
195
|
1
|
|
|
|
|
3
|
${ $config->{'remote-source'} } ); |
196
|
|
|
|
|
|
|
|
197
|
1
|
|
|
|
|
11
|
my $authn = new Apache::Sling::Authn( \$sling ); |
198
|
1
|
|
|
|
|
6
|
$authn->login_user(); |
199
|
1
|
|
|
|
|
3
|
my $success = 1; |
200
|
1
|
50
|
|
|
|
7
|
if ( $sling->{'Help'} ) { $json_query_servlet->help(); } |
|
0
|
50
|
|
|
|
0
|
|
|
|
50
|
|
|
|
|
|
201
|
0
|
|
|
|
|
0
|
elsif ( $sling->{'Man'} ) { $json_query_servlet->man(); } |
|
1
|
|
|
|
|
6
|
|
202
|
|
|
|
|
|
|
elsif ( defined ${ $config->{'all_nodes'} } ) { |
203
|
0
|
|
|
|
|
0
|
$json_query_servlet = |
204
|
|
|
|
|
|
|
new Apache::Sling::JsonQueryServlet( \$authn, $sling->{'Verbose'}, |
205
|
|
|
|
|
|
|
$sling->{'Log'} ); |
206
|
0
|
|
|
|
|
0
|
$success = $json_query_servlet->all_nodes(); |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
else { |
209
|
1
|
|
|
|
|
21
|
$json_query_servlet->help(); |
210
|
1
|
|
|
|
|
8
|
return 1; |
211
|
|
|
|
|
|
|
} |
212
|
0
|
|
|
|
|
|
Apache::Sling::Print::print_result($json_query_servlet); |
213
|
0
|
|
|
|
|
|
return $success; |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
#}}} |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
1; |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
__END__ |