Skip to content

Commit c6548a6

Browse files
committed
and closer
1 parent bd31a50 commit c6548a6

File tree

8 files changed

+2041
-509
lines changed

8 files changed

+2041
-509
lines changed

clients/renderProblem.pl

+110-382
Large diffs are not rendered by default.

clients/webwork_xmlrpc_client.pl

+36-63
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
}
5454

5555

56-
# print "credentials: ", join(" | ", %credentials), "\n";
56+
#print "credentials: ", join(" | ", %credentials), "\n";
5757

5858
my @COMMANDS = qw( listLibraries renderProblem listLib readFile tex2pdf );
5959

@@ -62,7 +62,7 @@
6262

6363
# end configuration section
6464

65-
our $courseName = $credentials{courseID};
65+
our $courseID = $credentials{courseID};
6666

6767
print STDERR "inputs are ", join (" | ", @ARGV), "\n";
6868
our $source;
@@ -80,8 +80,6 @@
8080
userID => $credentials{userID},
8181
session_key => $credentials{session_key},
8282
);
83-
# initialize client with source
84-
# $xmlrpc_client->encodeSource($source);
8583

8684
# prepare additional input values
8785

@@ -97,8 +95,17 @@
9795
if (-r $ARGV[1] ) {
9896
$source = `cat $ARGV[1]`;
9997
$xmlrpc_client->encodeSource($source);
100-
my $input = { password => $credentials{password},};
98+
my $input = {
99+
userID => $credentials{userID}||'',
100+
session_key => $credentials{session_key}||'',
101+
courseID => $credentials{courseID}||'',
102+
courseName => $credentials{courseID}||'',
103+
password => $credentials{password}||'',
104+
site_password => $credentials{site_password}||'',
105+
};
106+
#print STDERR "input is ", %$input,"\n";
101107
$result = $xmlrpc_client->xmlrpcCall($command, $input);
108+
print "\n\n Result of renderProblem \n\n";
102109
print pretty_print_rh($result);
103110
} else {
104111
print STDERR "Can't read source file $ARGV[1]\n";
@@ -107,24 +114,34 @@
107114
print STDERR "Useage: ./webwork_xmlrpc_client.pl command <file_name>\n";
108115
}
109116
} when ('listLibraries') {
110-
my $input = { password => $credentials{password},};
111-
$result = $xmlrpc_client->xmlrpcCall($command, $input);
117+
my $input = {
118+
userID => $credentials{userID}||'',
119+
session_key => $credentials{session_key}||'',
120+
courseID => $credentials{courseID}||'',
121+
password => $credentials{password}||'',
122+
site_password => $credentials{site_password}||'',
123+
};
124+
# print STDERR "ww_xmlrpc_client: input for listLibraries command is ", %$input,"\n";
125+
eval {
126+
$result = $xmlrpc_client->xmlrpcCall($command, $input);
127+
};
112128
if (defined($result) ) {
113129
my @lib_array = @ { $result->{ra_out} };
114-
print STDOUT "The libraries available in course $courseName are:\n\t ", join("\n\t ", @lib_array ), "\n";
130+
print STDOUT "ww_xmlrpc_client: The libraries available in course $courseID are:\n\t ", join("\n\t ", @lib_array ), "\n";
115131
} else {
116-
print STDOUT "No libraries available for course $courseName\n";
132+
print STDOUT "ww_xmlrpc_client: No libraries available for course $courseID\n";
117133
}
118134
} when ('listLib') {
119135
$result = listLib( @ARGV );
120136
my $command = $ARGV[1];
121-
137+
print "listLib returned\n";
122138
print pretty_print_rh($result);
139+
print "\n";
123140

124141
} when ('listSets') {
125142
$input = { site_password => 'xmluser',
126143
password => $credentials{password},
127-
user => $credentials{userID},
144+
userID => $credentials{userID},
128145
courseID => $credentials{courseID},
129146
};
130147
my $result = $xmlrpc_client->xmlrpcCall($command, $input);
@@ -133,6 +150,8 @@
133150
print STDERR "Command $command not yet implemented\n"
134151
} when ('tex2pdf') {
135152
print STDERR "Command $command not yet implemented\n"
153+
} default {
154+
print STDERR "Command '$command' not recognized. Commands ",@COMMANDS;
136155
}
137156
}
138157

@@ -151,53 +170,7 @@
151170

152171

153172

154-
# sub xmlrpcCall {
155-
# my $command = shift;
156-
# my $input = shift||{};
157-
# $command = 'listLibraries' unless defined $command;
158-
# my $std_input = standard_input();
159-
#
160-
# $input = {%$std_input, %$input}; # concatenate and override standard_input
161-
#
162-
# my $requestResult = TRANSPORT_METHOD
163-
# #->uri('http://'.HOSTURL.':'.HOSTPORT.'/'.REQUEST_CLASS)
164-
# -> proxy(PROTOCOL.'://'.HOSTURL.':'.HOSTPORT.'/'.REQUEST_URI);
165-
#
166-
# if ($UNIT_TESTS_ON) {
167-
# print STDERR "WebworkClient.pm ".__LINE__." xmlrpcCall issued with command $command\n";
168-
# print STDERR "WebworkClient.pm ".__LINE__." input is: ",join(" ", %$input);
169-
# print STDERR "WebworkClient.pm ".__LINE__." xmlrpcCall $command returned $requestResult\n";
170-
# }
171-
# local( $result);
172-
# # use eval to catch errors
173-
# eval { $result = $requestResult->call(REQUEST_CLASS.'.'.$command,$input) };
174-
# print STDERR "There were a lot of errors\n" if $@;
175-
# print "Errors: \n $@\n End Errors\n" if $@;
176-
#
177-
#
178-
# unless (ref($result) and $result->fault) {
179-
#
180-
# if (ref($result->result())=~/HASH/ and defined($result->result()->{text}) ) {
181-
# $result->result()->{text} = decode_base64($result->result()->{text});
182-
# }
183-
# print pretty_print_rh($result->result()),"\n"if $UNIT_TESTS_ON;
184-
# $self->{output} = $result->result();
185-
# $self->{session_key}=$self->{output}->{session_key}; # update session key
186-
# return $result->result();
187-
#
188-
# } else {
189-
# print STDERR 'oops ', join ', ',
190-
# "command:",
191-
# $command,
192-
# "\nfaultcode:",
193-
# $result->faultcode,
194-
# "\nfaultstring:",
195-
# $result->faultstring;
196-
# return undef;
197-
#
198-
# }
199-
# }
200-
173+
201174
sub source {
202175
return "" unless $source;
203176
return encode_base64($source);
@@ -208,9 +181,9 @@ sub listLib {
208181
my $result;
209182
given($ARGS[1]) {
210183
when ("all") {
211-
$input = { site_password => 'xmluser',
184+
$input = { site_password => 'xmluser',
212185
password => $credentials{password},
213-
user => $credentials{userID},
186+
userID => $credentials{userID},
214187
courseID => $credentials{courseID},
215188
command => 'all',
216189
};
@@ -220,9 +193,9 @@ sub listLib {
220193
my %options = @ARGS[2..$#ARGS];
221194
my $path = $options{-path} || '';
222195
my $maxdepth = defined($options{-depth}) ? $options{-depth}: 10000;
223-
$input = { site_password => 'xmluser',
196+
$input = { site_password => 'xmluser',
224197
password => $credentials{password},
225-
user => $credentials{userID},
198+
userID => $credentials{userID},
226199
courseID => $credentials{courseID},
227200
command => 'dirOnly',
228201
dirPath => $path,
@@ -236,7 +209,7 @@ sub listLib {
236209
my $path = $options{-path} || '';
237210
$input = { site_password => 'xmluser',
238211
password => $credentials{password},
239-
user => $credentials{userID},
212+
userID => $credentials{userID},
240213
courseID => $credentials{courseID},
241214
command => 'files',
242215
dirPath => $path,

lib/WeBWorK/ContentGenerator/renderViaXMLRPC.pm

+18-12
Original file line numberDiff line numberDiff line change
@@ -135,24 +135,30 @@ sub pre_header_initialize {
135135
my ($self) = @_;
136136
my $r = $self->r;
137137

138+
my %inputs_ref;
139+
my @keys = $r->mutable_param; # $r->param;
140+
foreach my $key ( @keys ) {
141+
$inputs_ref{$key} = $r->param("$key");
142+
}
143+
my $user_id = $inputs_ref{userID};
144+
my $session_key = $inputs_ref{session_key};
145+
my $courseName = $inputs_ref{courseID};
146+
138147
#######################
139148
# setup xmlrpc client
140149
#######################
141150
my $xmlrpc_client = new WebworkClient;
142151

143-
$xmlrpc_client->{encodedSource} = $r->param('problemSource') ; # this source has already been encoded
152+
$xmlrpc_client->{encodedSource} = $r->param('problemSource') ; # this source has already been encoded
144153
$xmlrpc_client->url($XML_URL);
145-
$xmlrpc_client->{form_action_url}= $FORM_ACTION_URL;
146-
$xmlrpc_client->{displayMode} = DISPLAYMODE();
147-
$xmlrpc_client->{user} = 'xmluser';
148-
$xmlrpc_client->{password} = $XML_PASSWORD;
149-
$xmlrpc_client->{course} = $XML_COURSE;
150-
my %inputs_ref;
151-
my @keys = $r->mutable_param; # $r->param;
152-
foreach my $key ( @keys ) {
153-
$inputs_ref{$key} = $r->param("$key");
154-
}
154+
$xmlrpc_client->{form_action_url} = $FORM_ACTION_URL;
155+
$xmlrpc_client->{displayMode} = DISPLAYMODE();
156+
$xmlrpc_client->{userID} = $inputs_ref{userID};
157+
# $xmlrpc_client->{password} = $XML_PASSWORD;
158+
$xmlrpc_client->{session_key} = $inputs_ref{session_key};
159+
$xmlrpc_client->{courseID} = $inputs_ref{courseID};
155160

161+
156162
$xmlrpc_client->{inputs_ref} = \%inputs_ref;
157163
# print STDERR WebworkClient::pretty_print($r->{paramcache});
158164

@@ -163,7 +169,7 @@ sub pre_header_initialize {
163169
# from which it will eventually be returned to the browser
164170
#
165171
##############################
166-
if ( $xmlrpc_client->xmlrpcCall('renderProblem') ) {
172+
if ( $xmlrpc_client->xmlrpcCall('renderProblem', $xmlrpc_client->{inputs_ref}) ) {
167173
$self->{output} = $xmlrpc_client->formatRenderedProblem;
168174
} else {
169175
$self->{output} = $xmlrpc_client->{output}; # error report

0 commit comments

Comments
 (0)