Skip to content

Commit

Permalink
Merge branch 'WeBWorK-2.15+instructorXML-errors-investigation' into w…
Browse files Browse the repository at this point in the history
…ebwork-2.15-new
  • Loading branch information
mgage committed Sep 26, 2019
2 parents 4258044 + e0648ef commit 0094ac8
Show file tree
Hide file tree
Showing 13 changed files with 102 additions and 83 deletions.
4 changes: 2 additions & 2 deletions clients/hello_world_apps/webwork_xmlrpc_client.pl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
use constant REQUEST_URI => 'mod_xmlrpc';
use constant TEMPOUTPUTFILE => '/Users/gage/Desktop/renderProblemOutput.html';

our $XML_URL = 'http://localhost:80';
our $SITE_URL = 'http://localhost:80';
our $FORM_ACTION_URL = 'http://localhost:80/webwork2/html2xml';
our $XML_PASSWORD = 'xmlwebwork';
our $XML_COURSE = 'gage_course';
Expand Down Expand Up @@ -98,7 +98,7 @@
# Build client
############################################
our $xmlrpc_client = new WebworkClient (
url => $XML_URL,
site_url => $SITE_URL,
form_action_url => $FORM_ACTION_URL,
displayMode => DISPLAYMODE(),

Expand Down
16 changes: 8 additions & 8 deletions clients/sendXMLRPC.pl
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ sub process_problem {

### build client
my $xmlrpc_client = new WebworkClient (
url => $credentials{site_url},
site_url => $credentials{site_url},
form_action_url => $credentials{form_action_url},
site_password => $credentials{site_password}//'',
courseID => $credentials{courseID},
Expand Down Expand Up @@ -964,7 +964,7 @@ sub process_problem {
WebworkClient::writeRenderLogEntry("",
"{script:$scriptName; file:$file_path; ".
sprintf("duration: %.3f sec;", $cg_duration).
" url: $credentials{site_url}; }",'');
" site_url: $credentials{site_url}; }",'');

#######################################################################
# End processing of the pg file
Expand Down Expand Up @@ -1440,12 +1440,12 @@ sub print_help_message {
or create a file with this information and specify it with the --credentials option.
%credentials = (
userID => "my login name for the webwork course",
course_password => "my password ",
courseID => "the name of the webwork course",
XML_URL => "url of rendering site
XML_PASSWORD => "site password" # preliminary access to site
$FORM_ACTION_URL = 'http://localhost:80/webwork2/html2xml'; #action url for form
userID => "my login name for the webwork course",
course_password => "my password ",
courseID => "the name of the webwork course",
SITE_URL => "url of rendering site",
XML_PASSWORD => "site password", # preliminary access to site
form_action_url => 'http://localhost:80/webwork2/html2xml' #action url for form
);
Options
Expand Down
34 changes: 17 additions & 17 deletions lib/FormatRenderedProblem.pm
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ sub new {
my $invocant = shift;
my $class = ref $invocant || $invocant;
$self = {
return_object => {},
encoded_source => {},
sourceFilePath => '',
url => 'https://demo.webwork.rochester.edu',
return_object => {},
encoded_source => {},
sourceFilePath => '',
site_url => 'https://demo.webwork.rochester.edu',
form_action_url =>'',
maketext => sub {return @_},
courseID => 'daemon_course', # optional?
userID => 'daemon', # optional?
maketext => sub {return @_},
courseID => 'daemon_course', # optional?
userID => 'daemon', # optional?
course_password => 'daemon',
inputs_ref => {},
@_,
Expand All @@ -103,11 +103,11 @@ sub encoded_source {
$self->{encoded_source} =$source if defined $source and $source =~/\S/; # source is non-empty
$self->{encoded_source};
}
sub url {
sub site_url {
my $self = shift;
my $new_url = shift;
$self->{url} = $new_url if defined($new_url) and $new_url =~ /\S/;
$self->{url};
$self->{site_url} = $new_url if defined($new_url) and $new_url =~ /\S/;
$self->{site_url};
}
sub formatRenderedProblem {
my $self = shift;
Expand Down Expand Up @@ -237,8 +237,8 @@ sub formatRenderedProblem {


$self->{outputformats}={};
my $XML_URL = $self->url;
my $FORM_ACTION_URL = $self->{form_action_url};
my $SITE_URL = $self->site_url//'';
my $FORM_ACTION_URL = $self->{form_action_url}//'';

#################################################
# Local docker usage with a port number sometimes misbehaves if the port number
Expand All @@ -257,11 +257,11 @@ sub formatRenderedProblem {

#################################################

my $courseID = $self->{courseID};
my $userID = $self->{userID};
my $course_password = $self->{course_password};
my $problemSeed = $self->{inputs_ref}->{problemSeed}//4444;
my $psvn = $self->{inputs_ref}->{psvn}//54321;
my $courseID = $self->{courseID}//'';
my $userID = $self->{userID}//'';
my $course_password = $self->{course_password}//'';
my $problemSeed = $self->{inputs_ref}->{problemSeed}//6666;
my $psvn = $self->{inputs_ref}->{psvn}//54321;
my $session_key = $rh_result->{session_key}//'';
my $displayMode = $self->{inputs_ref}->{displayMode};

Expand Down
18 changes: 9 additions & 9 deletions lib/WeBWorK/ContentGenerator/instructorXMLHandler.pm
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ use JSON;
=cut

# To configure the target webwork server two URLs are required
# 1. $XML_URL http://test.webwork.maa.org/mod_xmlrpc
# 1. http://test.webwork.maa.org/mod_xmlrpc
# points to the Webservice.pm and Webservice/RenderProblem modules
# Is used by the client to send the original XML request to the webservice
#
# Note: This not the same as the webworkClient->url which should NOT have
# the mod_xmlrpc segment.
# 2. $FORM_ACTION_URL http:http://test.webwork.maa.org/webwork2/html2xml
# points to the renderViaXMLRPC.pm module.
#
Expand Down Expand Up @@ -112,14 +113,14 @@ unless ($server_root_url) {
# child
############################

our ($XML_URL,$FORM_ACTION_URL, $XML_PASSWORD, $XML_COURSE);
our ($SITE_URL, $FORM_ACTION_URL, $XML_PASSWORD, $XML_COURSE);

$XML_PASSWORD = 'xmluser';
$XML_COURSE = 'daemon_course';



$XML_URL = "$server_root_url/mod_xmlrpc";
$SITE_URL = "$server_root_url" ;
$FORM_ACTION_URL = "$server_root_url/webwork2/instructorXMLHandler";

use constant DISPLAYMODE => 'images'; # Mathjax is another possibilities.
Expand Down Expand Up @@ -165,11 +166,10 @@ sub pre_header_initialize {
#######################
my $xmlrpc_client = new WebworkClient;

$xmlrpc_client->url($XML_URL);
$xmlrpc_client->site_url($SITE_URL); # does NOT include mod_xmlrpc ending
# $xmlrpc_client->{site_url} =''; # make this the site without the mod_xmlrpc ending? ~= s/mod_xmlrpc$
$xmlrpc_client->{form_action_url}= $FORM_ACTION_URL;
# $xmlrpc_client->{displayMode} = DISPLAYMODE();
$xmlrpc_client->{user} = 'xmluser';
# $xmlrpc_client->{password} = $XML_PASSWORD;
$xmlrpc_client->{site_password} = $XML_PASSWORD;
# $xmlrpc_client->{course} = $r->param('courseID');
$xmlrpc_client->{courseID} = $r->param('courseID');
Expand Down Expand Up @@ -263,8 +263,8 @@ sub pre_header_initialize {


if ($UNIT_TESTS_ON) {
print STDERR "instructorXMLHandler.pm ".__LINE__." values obtained from form parameters\n\t",
format_hash_ref($input);
print STDERR "\tinstructorXMLHandler.pm ".__LINE__." values obtained from form parameters\n\t",
format_hash_ref($input),"\n";
}
my $source = "";
#print $r->param('problemPath');
Expand Down
8 changes: 4 additions & 4 deletions lib/WeBWorK/ContentGenerator/renderViaXMLRPC.pm
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use CGI;
=cut

# To configure the target webwork server two URLs are required
# 1. $XML_URL http://test.webwork.maa.org/mod_xmlrpc
# 1. http://test.webwork.maa.org/mod_xmlrpc
# points to the Webservice.pm and Webservice/RenderProblem modules
# Is used by the client to send the original XML request to the webservice
#
Expand Down Expand Up @@ -111,14 +111,14 @@ unless ($server_root_url) {
# child
############################

our ($XML_URL,$FORM_ACTION_URL, $XML_PASSWORD, $XML_COURSE);
our ($SITE_URL,$FORM_ACTION_URL, $XML_PASSWORD, $XML_COURSE);

$XML_PASSWORD = 'xmlwebwork';
$XML_COURSE = 'daemon_course';



$XML_URL = "$server_root_url"; #"$server_root_url/mod_xmlrpc";
$SITE_URL = "$server_root_url";
$FORM_ACTION_URL = "$server_root_url/webwork2/html2xml";


Expand Down Expand Up @@ -173,7 +173,7 @@ sub pre_header_initialize {
my $xmlrpc_client = new WebworkClient;

$xmlrpc_client ->encoded_source($r->param('problemSource')) ; # this source has already been encoded
$xmlrpc_client-> url($XML_URL);
$xmlrpc_client-> site_url($SITE_URL);
$xmlrpc_client->{form_action_url} = $FORM_ACTION_URL;
$xmlrpc_client->{userID} = $inputs_ref{userID};
$xmlrpc_client->{course_password} = $inputs_ref{course_password};
Expand Down
69 changes: 44 additions & 25 deletions lib/WebworkClient.pm
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ WebworkClient.pm
=head1 SYNPOSIS
our $xmlrpc_client = new WebworkClient (
url => $XML_URL,
url => $ce->{server_site_url},
form_action_url => $FORM_ACTION_URL,
site_password => $XML_PASSWORD//'',
courseID => $credentials{courseID},
Expand Down Expand Up @@ -62,9 +62,11 @@ use warnings;

# To configure the target webwork server
# two URLs are required
# 1. $XML_URL http://test.webwork.maa.org/mod_xmlrpc
# 1. $SITE_URL http://test.webwork.maa.org/mod_xmlrpc
# points to the Webservice.pm and Webservice/RenderProblem modules
# Is used by the client to send the original XML request to the webservice
# Note: This is not the same as the webworkClient->url which should NOT have
# the mod_xmlrpc segment.
#
# 2. $FORM_ACTION_URL http:http://test.webwork.maa.org/webwork2/html2xml
# points to the renderViaXMLRPC.pm module.
Expand All @@ -87,10 +89,11 @@ use warnings;
# The renderViaXMLRPC.pm translates the WeBWorK form, has it processes by the webservice
# and returns the result to the browser.
# The The client renderProblem.pl script is no longer involved.
# 4. Summary: renderProblem.pl is only involved in the first round trip
# of the submitted problem. After that the communication is between the browser and
# renderViaXMLRPC using HTML forms and between renderViaXMLRPC and the WebworkWebservice.pm
# module using XML_RPC.
# 4. Summary: The WebworkWebservice (with command renderProblem) is called directly in the first round trip
# of submitting the problem via the https://mysite.edu/mod_xmlrpc route. After that the communication is
# between the browser and renderViaXMLRPC using HTML forms and the route https://mysite.edu/webwork2/html2xml
# and from there renderViaXMLRPC calls the WebworkWebservice using the route https://mysite.edu/mod_xmlrpc with the
# renderProblem command.


our @COMMANDS = qw( listLibraries renderProblem ); #listLib readFile tex2pdf
Expand Down Expand Up @@ -264,23 +267,33 @@ sub xmlrpcCall {

my $requestResult;
my $transporter = TRANSPORT_METHOD->new;

#FIXME -- transitional error fix to remove mod_xmlrpc from end of url call
my $site_url = $self->site_url;
if ($site_url =~ /mod_xmlrpc$/ ){
$site_url =~ s|/mod_xmlrpc/?||; # mod_xmlrpc from https://my.site.edu/mod_xmlrpc
$self->site_url($site_url);
# complain
print STDERR "\n\n\$self->site_url() should not end in /mod_xmlrpc \n\n";
}
eval {
$requestResult= $transporter
#->uri('http://'.HOSTURL.':'.HOSTPORT.'/'.REQUEST_CLASS)
#-> proxy(PROTOCOL.'://'.HOSTURL.':'.HOSTPORT.'/'.REQUEST_URI);
-> proxy(($self->url).'/'.REQUEST_URI);
-> proxy(($site_url).'/'.REQUEST_URI);
};
print STDERR "WebworkClient: Initiating xmlrpc request to url ",($self->url).'/'.REQUEST_URI, " \n Error: $@\n" if $@;
# END of FIXME section

print STDERR "WebworkClient: Initiating xmlrpc request to url ",($self->site_url).'/'.REQUEST_URI, " \n Error: $@\n" if $@;
# turn off verification of the ssl cert
$transporter->transport->ssl_opts(verify_hostname=>0,
SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE);

if ($UNIT_TESTS_ON) {
print STDERR "WebworkClient.pm ".__LINE__." xmlrpcCall sent to ", $self->url,"\n";
print STDERR "WebworkClient.pm ".__LINE__." xmlrpcCall issued with command $command\n";
print STDERR "WebworkClient.pm ".__LINE__." input is: ",join(" ", %{$self->request_object}),"\n";
print STDERR "WebworkClient.pm ".__LINE__." xmlrpcCall $command initiated webwork webservice object $requestResult\n";
print STDERR "\n\tWebworkClient.pm ".__LINE__." xmlrpcCall sent to site ", $self->site_url,"\n";
print STDERR "\tWebworkClient.pm ".__LINE__." full xmlrpcCall path ", ($self->site_url).'/'.REQUEST_URI,"\n";
print STDERR "\tWebworkClient.pm ".__LINE__." xmlrpcCall issued with command $command\n";
print STDERR "\tWebworkClient.pm ".__LINE__." input is: ",join(" ", map {$_//'--'} %{$self->request_object}),"\n";
print STDERR "\tWebworkClient.pm ".__LINE__." xmlrpcCall $command initiated webwork webservice object $requestResult\n";
}

local( $result);
Expand Down Expand Up @@ -353,7 +366,7 @@ sub jsXmlrpcCall {
my $transporter = TRANSPORT_METHOD->new;

my $requestResult = $transporter
-> proxy(($self->url).'/'.REQUEST_URI);
-> proxy(($self->site_url).'/'.REQUEST_URI);
$transporter->transport->ssl_opts(verify_hostname=>0,
SSL_verify_mode => 'SSL_VERIFY_NONE');

Expand Down Expand Up @@ -382,28 +395,26 @@ sub jsXmlrpcCall {
}
}

=head2 encodeSource


=cut
sub encodeSource {
my $self = shift;
my $source = shift||'';
$self->{encoded_source} =encode_utf8_base64($source);
}

=head2 Accessor methods
enconcodeSource # encode source string with utf8 and base64 and store in encoded_source
encoded_source
request_object
return_object
error_string
fault
url
site_url (https://mysite.edu)
form_data
=cut

sub encodeSource {
my $self = shift;
my $source = shift||'';
$self->{encoded_source} =encode_utf8_base64($source);
}

sub encoded_source {
my $self = shift;
my $source = shift;
Expand Down Expand Up @@ -434,9 +445,17 @@ sub fault {
$self->{fault_flag} =$fault_flag if defined $fault_flag and $fault_flag =~/\S/; # source is non-empty
$self->{fault_flag};
}
sub url {
sub site_url { #site_url https://mysite.edu
my $self = shift;
my $new_url = shift;
$self->{site_url} = $new_url if defined($new_url) and $new_url =~ /\S/;
$self->{site_url};
}

sub url { #site_url https://mysite.edu
my $self = shift;
my $new_url = shift;
die "use webworkClient->site_url instead of webworkClient->url";
$self->{url} = $new_url if defined($new_url) and $new_url =~ /\S/;
$self->{url};
}
Expand Down
6 changes: 3 additions & 3 deletions lib/WebworkClient/debug_format.pl
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<html $COURSE_LANG_AND_DIR>
<head>
<meta charset='utf-8'>
<base href="$XML_URL">
<title>$XML_URL WeBWorK using host: $XML_URL, course: $courseID format: debug</title>
<base href="$SITE_URL">
<title>$SITE_URL WeBWorK using host: $SITE_URL, course: $courseID format: debug</title>
</head>
<body>
<h2> WeBWorK using host: $XML_URL, course: $courseID format: debug</h2>
<h2> WeBWorK using host: $SITE_URL, course: $courseID format: debug</h2>
$pretty_print_self
</body>
</html>
Expand Down
4 changes: 2 additions & 2 deletions lib/WebworkClient/json_format.pl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
$nextBlock = <<'ENDPROBLEMTEMPLATE';
<head>
<meta charset='utf-8'>
<base href="TO_SET_LATER_XML_URL">
<base href="TO_SET_LATER_SITE_URL">
<link rel="shortcut icon" href="/webwork2_files/images/favicon.ico"/>
ENDPROBLEMTEMPLATE

Expand Down Expand Up @@ -145,7 +145,7 @@
# to communicate with WW, while the distant client must use URLs of the
# intermediate server (the man in the middle).

push( @pairs_for_json, "real_webwork_XML_URL", '$XML_URL' );
push( @pairs_for_json, "real_webwork_SITE_URL", '$SITE_URL' );
push( @pairs_for_json, "real_webwork_FORM_ACTION_URL", '$FORM_ACTION_URL' );
push( @pairs_for_json, "internal_problem_lang_and_dir", '$PROBLEM_LANG_AND_DIR');

Expand Down
2 changes: 1 addition & 1 deletion lib/WebworkClient/ptx_format.pl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$ptx_static_format = <<'ENDPROBLEMTEMPLATE';
<!--$XML_URL WeBWorK Editor using host: $XML_URL, course: $courseID format: ptx -->
<!--$SITE_URL WeBWorK Editor using host: $SITE_URL, course: $courseID format: ptx -->
<!--BEGIN PROBLEM-->
<webwork>
$problemText
Expand Down
Loading

0 comments on commit 0094ac8

Please sign in to comment.