Parent Directory
|
Revision Log
merge with trunk
1 ################################################################################ 2 # WeBWorK Online Homework Delivery System 3 # Copyright © 2000-2007 The WeBWorK Project, http://openwebwork.sf.net/ 4 # $CVSHeader: webwork2/lib/WeBWorK/ContentGenerator/renderViaXMLRPC.pm,v 1.1 2010/05/11 15:27:08 gage Exp $ 5 # 6 # This program is free software; you can redistribute it and/or modify it under 7 # the terms of either: (a) the GNU General Public License as published by the 8 # Free Software Foundation; either version 2, or (at your option) any later 9 # version, or (b) the "Artistic License" which comes with this package. 10 # 11 # This program is distributed in the hope that it will be useful, but WITHOUT 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 # FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the 14 # Artistic License for more details. 15 ################################################################################ 16 17 =head1 NAME 18 19 WeBWorK::ContentGenerator::ProblemRenderer - renderViaXMLRPC is an HTML 20 front end for calls to the xmlrpc webservice 21 22 =cut 23 24 use strict; 25 use warnings; 26 27 package WeBWorK::ContentGenerator::renderViaXMLRPC; 28 use base qw(WeBWorK::ContentGenerator); 29 30 #use Crypt::SSLeay; 31 #use XMLRPC::Lite; 32 #use MIME::Base64 qw( encode_base64 decode_base64); 33 34 35 use strict; 36 use warnings; 37 use WebworkClient; 38 39 40 =head1 Description 41 42 43 ################################################# 44 renderViaXMLRPC -- a front end for the Webservice that accepts HTML forms 45 46 receives WeBWorK problems presented as HTML forms, 47 packages the form variables into an XML_RPC request 48 suitable for the Webservice/RenderProblem.pm 49 takes the answer returned by the webservice (which has HTML format) and 50 returns it to the browser. 51 ################################################# 52 53 =cut 54 55 # To configure the target webwork server two URLs are required 56 # 1. $XML_URL http://test.webwork.maa.org/mod_xmlrpc 57 # points to the Webservice.pm and Webservice/RenderProblem modules 58 # Is used by the client to send the original XML request to the webservice 59 # 60 # 2. $FORM_ACTION_URL http:http://test.webwork.maa.org/webwork2/html2xml 61 # points to the renderViaXMLRPC.pm module. 62 # 63 # This url is placed as form action url when the rendered HTML from the original 64 # request is returned to the client from Webservice/RenderProblem. The client 65 # reorganizes the XML it receives into an HTML page (with a WeBWorK form) and 66 # pipes it through a local browser. 67 # 68 # The browser uses this url to resubmit the problem (with answers) via the standard 69 # HTML webform used by WeBWorK to the renderViaXMLRPC.pm handler. 70 # 71 # This renderViaXMLRPC.pm handler acts as an intermediary between the browser 72 # and the webservice. It interprets the HTML form sent by the browser, 73 # rewrites the form data in XML format, submits it to the WebworkWebservice.pm 74 # which processes it and sends the the resulting HTML back to renderViaXMLRPC.pm 75 # which in turn passes it back to the browser. 76 # 3. The second time a problem is submitted renderViaXMLRPC.pm receives the WeBWorK form 77 # submitted directly by the browser. 78 # The renderViaXMLRPC.pm translates the WeBWorK form, has it processes by the webservice 79 # and returns the result to the browser. 80 # The The client renderProblem.pl script is no longer involved. 81 # 4. Summary: renderProblem.pl is only involved in the first round trip 82 # of the submitted problem. After that the communication is between the browser and 83 # renderViaXMLRPC using HTML forms and between renderViaXMLRPC and the WebworkWebservice.pm 84 # module using XML_RPC. 85 86 87 # Determine the root directory for webwork on this machine (e.g. /opt/webwork/webwork2 ) 88 # this is set in webwork.apache2-config 89 # it specifies the address of the webwork root directory 90 91 #my $webwork_dir = $ENV{WEBWORK_ROOT}; 92 my $webwork_dir = $WeBWorK::Constants::WEBWORK_DIRECTORY; 93 unless ($webwork_dir) { 94 die "renderViaXMLRPC.pm requires that the top WeBWorK directory be set in ". 95 "\$WeBWorK::Constants::WEBWORK_DIRECTORY by webwork.apache-config or webwork.apache2-config\n"; 96 } 97 98 # read the webwork2/conf/global.conf file to determine other parameters 99 # 100 my $seed_ce = new WeBWorK::CourseEnvironment({ webwork_dir => $webwork_dir }); 101 my $server_root_url = $seed_ce->{server_root_url}; 102 unless ($server_root_url) { 103 die "unable to determine apache server url using course environment |$seed_ce|.". 104 "check that the variable \$server_root_url has been properly set in conf/global.conf\n"; 105 } 106 107 ############################ 108 # These variables are set when the child process is started 109 # and remain constant through all of the calls handled by the 110 # child 111 ############################ 112 113 our ($XML_URL,$FORM_ACTION_URL, $XML_PASSWORD, $XML_COURSE); 114 115 $XML_PASSWORD = 'xmlwebwork'; 116 $XML_COURSE = 'daemon_course'; 117 118 119 120 $XML_URL = "$server_root_url/mod_xmlrpc"; 121 $FORM_ACTION_URL = "$server_root_url/webwork2/html2xml"; 122 123 use constant DISPLAYMODE => 'images'; # jsMath is another possibilities. 124 125 126 our @COMMANDS = qw( listLibraries renderProblem ); #listLib readFile tex2pdf 127 128 129 ################################################## 130 # end configuration section 131 ################################################## 132 133 134 sub pre_header_initialize { 135 my ($self) = @_; 136 my $r = $self->r; 137 138 ####################### 139 # setup xmlrpc client 140 ####################### 141 my $xmlrpc_client = new WebworkClient; 142 143 $xmlrpc_client->{encodedSource} = $r->param('problemSource') ; # this source has already been encoded 144 $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 } 155 156 $xmlrpc_client->{inputs_ref} = \%inputs_ref; 157 # print STDERR WebworkClient::pretty_print($r->{paramcache}); 158 159 ############################## 160 # xmlrpc_client calls webservice to have problem rendered 161 # 162 # and stores the resulting HTML output in $self->{output} 163 # from which it will eventually be returned to the browser 164 # 165 ############################## 166 if ( $xmlrpc_client->xmlrpcCall('renderProblem') ) { 167 $self->{output} = $xmlrpc_client->formatRenderedProblem; 168 } else { 169 $self->{output} = $xmlrpc_client->{output}; # error report 170 } 171 172 ################################ 173 } 174 175 sub content { 176 ########################### 177 # Return content of rendered problem to the browser that requested it 178 ########################### 179 my $self = shift; 180 print $self->{output}; 181 } 182 183 184 185 186 1;
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |