From: Mike G. <ga...@de...> - 2005-05-19 00:57:01
|
Log Message: ----------- I've updated the clients so they work with the current configuration of the apache server running in my directory (http://devel.webwork.rochester.edu:8002) Once the webwork.apache-config files have been updated they should work on other systems that are up-to-date with the cvs. -- Mike Modified Files: -------------- webwork2/clients: README Added Files: ----------- webwork2/clients: hello_world_soap_client.pl hello_world_xmlrpc_client.pl webwork_soap_client.pl Removed Files: ------------- webwork2/clients: xmlrpc_client4.pl Revision Data ------------- --- /dev/null +++ clients/webwork_soap_client.pl @@ -0,0 +1,278 @@ +#!/usr/local/bin/perl -w + +use SOAP::Lite; + +# configuration section +use constant HOSTURL => 'devel.webwork.rochester.edu'; +use constant HOSTPORT => 8002; +use constant TRANSPORT_METHOD => 'SOAP::Lite'; +use constant REQUEST_CLASS =>'WebworkXMLRPC'; # WebworkXMLRPC is used for soap also!! +use constant REQUEST_URI =>'mod_soap'; + +my @COMMANDS = qw( listLibraries renderProblem ); #listLib readFile tex2pdf + +# $pg{displayModes} = [ +# "plainText", # display raw TeX for math expressions +# "formattedText", # format math expressions using TtH +# "images", # display math expressions as images generated by dvipng +# "jsMath", # render TeX math expressions on the client side using jsMath +# "asciimath", # render TeX math expressions on the client side using ASCIIMathML +# ]; +use constant DISPLAYMODE => 'images'; + +# end configuration section +use MIME::Base64 qw( encode_base64 decode_base64); + + +print STDERR "inputs are ", join (" | ", @ARGV), "\n"; +our $source; + +if (@ARGV) { + my $command = $ARGV[0]; + + warn "executing WebworkXMLRPC.$command"; + $source = (defined $ARGV[1]) ? `cat $ARGV[1]` : '' ; + xmlrpcCall($command); + + +} else { + + print STDERR "Useage: ./webwork_soap_client.pl command inputs\n"; + print STDERR "For example: ./webwork_soap_client renderProblem input.txt\n"; + print STDERR "For example: ./webwork_soap_client listLibraries \n"; + print STDERR "Commands are: ", join(" ", @COMMANDS), "\n"; + +} + + + +sub xmlrpcCall { + my $command = shift; + $command = 'listLibraries' unless $command; + + my $requestResult = TRANSPORT_METHOD + ->uri('http://'.HOSTURL.':'.HOSTPORT.'/'.REQUEST_CLASS) + -> proxy('http://'.HOSTURL.':'.HOSTPORT.'/'.REQUEST_URI); + + my $test = [3,4,5,6]; + my $input = setInputTable(); + print "displayMode=",$input->{envir}->{displayMode},"\n"; + local( $result); + # use eval to catch errors + eval { $result = $requestResult->call("$command",$input) }; + print STDERR "There were a lot of errors\n" if $@; + print "Errors: \n $@\n End Errors\n" if $@; + + print "result is|", ref($result),"|"; + + unless (ref($result) and $result->fault) { + + if (ref($result->result())=~/HASH/ and defined($result->result()->{text}) ) { + $result->result()->{text} = decode_base64($result->result()->{text}); + } + print pretty_print_rh($result->result()),"\n"; #$result->result() + } else { + print 'oops ', join ', ', + $result->faultcode, + $result->faultstring; + } +} + +sub source { + encode_base64($source); +} +sub pretty_print_rh { + shift if UNIVERSAL::isa($_[0] => __PACKAGE__); + my $rh = shift; + my $indent = shift || 0; + my $out = ""; + my $type = ref($rh); + + if (defined($type) and $type) { + $out .= " type = $type; "; + } elsif (! defined($rh )) { + $out .= " type = UNDEFINED; "; + } + return $out." " unless defined($rh); + + if ( ref($rh) =~/HASH/ or "$rh" =~/HASH/ ) { + $out .= "{\n"; + $indent++; + foreach my $key (sort keys %{$rh}) { + $out .= " "x$indent."$key => " . pretty_print_rh( $rh->{$key}, $indent ) . "\n"; + } + $indent--; + $out .= "\n"." "x$indent."}\n"; + + } elsif (ref($rh) =~ /ARRAY/ or "$rh" =~/ARRAY/) { + $out .= " ( "; + foreach my $elem ( @{$rh} ) { + $out .= pretty_print_rh($elem, $indent); + + } + $out .= " ) \n"; + } elsif ( ref($rh) =~ /SCALAR/ ) { + $out .= "scalar reference ". ${$rh}; + } elsif ( ref($rh) =~/Base64/ ) { + $out .= "base64 reference " .$$rh; + } else { + $out .= $rh; + } + + return $out." "; +} + +sub setInputTable_for_listLib { + $out = { + #password => 'geometry', + pw => 'geometry', + set => 'set0', + library_name => 'rochesterLibrary', + command => 'all', + }; + + $out; +} +sub setInputTable { + $out = { + #password => 'geometry', + pw => 'geometry', + set => 'set0', + library_name => 'rochesterLibrary', + command => 'all', + answer_form_submitted => 1, + course => 'daemon_course', + extra_packages_to_load => [qw( AlgParserWithImplicitExpand Expr + ExprWithImplicitExpand AnswerEvaluator + AnswerEvaluatorMaker + )], + mode => 'HTML_dpng', + modules_to_evaluate => [ qw( +Exporter + +DynaLoader + + +GD +WWPlot +Fun +Circle +Label + + +PGrandom +Units +Hermite + +List + + +Match +Multiple +Select + + +AlgParser + +AnswerHash + + +Fraction +VectorField + + +Complex1 +Complex + + +MatrixReal1 Matrix + + +Distributions + +Regression + + )], + envir => environment(), + problem_state => { + + num_of_correct_ans => 2, + num_of_incorrect_ans => 4, + recorded_score => 1.0, + }, + source => source(), #base64 encoded + + + + }; + + $out; +} + +sub environment { + my $envir = { + answerDate => '4014438528', + CAPA_Graphics_URL=>'http://webwork-db.math.rochester.edu/capa_graphics/', + CAPA_GraphicsDirectory =>'/ww/webwork/CAPA/CAPA_Graphics/', + CAPA_MCTools=>'/ww/webwork/CAPA/CAPA_MCTools/', + CAPA_Tools=>'/ww/webwork/CAPA/CAPA_Tools/', + cgiDirectory=>'Not defined', + cgiURL => 'Not defined', + classDirectory=> 'Not defined', + courseName=>'Not defined', + courseScriptsDirectory=>'/ww/webwork/system/courseScripts/', + displayMode=>DISPLAYMODE, + dueDate=> '4014438528', + externalGif2EpsPath=>'not defined', + externalPng2EpsPath=>'not defined', + externalTTHPath=>'/usr/local/bin/tth', + fileName=>'set0/prob1a.pg', + formattedAnswerDate=>'6/19/00', + formattedDueDate=>'6/19/00', + formattedOpenDate=>'6/19/00', + functAbsTolDefault=> 0.0000001, + functLLimitDefault=>0, + functMaxConstantOfIntegration=> 1000000000000.0, + functNumOfPoints=> 5, + functRelPercentTolDefault=> 0.000001, + functULimitDefault=>1, + functVarDefault=> 'x', + functZeroLevelDefault=> 0.000001, + functZeroLevelTolDefault=>0.000001, + htmlDirectory =>'/ww/webwork/courses/gage_course/html/', + htmlURL =>'http://webwork-db.math.rochester.edu/gage_course/', + inputs_ref => { + AnSwEr1 => '', + AnSwEr2 => '', + AnSwEr3 => '', + }, + macroDirectory=>'/ww/webwork/courses/gage_course/templates/macros/', + numAbsTolDefault=>0.0000001, + numFormatDefault=>'%0.13g', + numOfAttempts=> 0, + numRelPercentTolDefault => 0.0001, + numZeroLevelDefault =>0.000001, + numZeroLevelTolDefault =>0.000001, + openDate=> '3014438528', + PRINT_FILE_NAMES_FOR => [ 'gage'], + probFileName => 'set0/prob1a.pg', + problemSeed => 1234, + problemValue =>1, + probNum => 13, + psvn => 54321, + psvnNumber=> 54321, + questionNumber => 1, + scriptDirectory => 'Not defined', + sectionName => 'Gage', + sectionNumber => 1, + sessionKey=> 'Not defined', + setNumber =>'MAAtutorial', + studentLogin =>'gage', + studentName => 'Mike Gage', + tempDirectory => '/ww/htdocs/tmp/gage_course/', + templateDirectory=>'/ww/webwork/courses/gage_course/templates/', + tempURL=>'http://webwork-db.math.rochester.edu/tmp/gage_course/', + webworkDocsURL => 'http://webwork.math.rochester.edu/webwork_gage_system_html', + }; + $envir; +}; \ No newline at end of file --- /dev/null +++ clients/hello_world_xmlrpc_client.pl @@ -0,0 +1,19 @@ +#!/usr/bin/perl -w + +# +use XMLRPC::Lite; + my $soap = XMLRPC::Lite + # ->uri('http://webwork-db.math.rochester.edu/Demo/') + -> proxy('http://devel.webwork.rochester.edu:8002/mod_xmlrpc/'); + + + my $result = $soap->call("WebworkXMLRPC.hi"); + + + unless ($result->fault) { + print $result->result(),"\n"; + } else { + print join ', ', + $result->faultcode, + $result->faultstring; + } --- /dev/null +++ clients/hello_world_soap_client.pl @@ -0,0 +1,21 @@ +#!/usr/bin/perl -w + + +use SOAP::Lite; +my $soap = SOAP::Lite +-> uri('http://devel.webwork.rochester.edu:8002/WebworkXMLRPC') +-> proxy('http://devel.webwork.rochester.edu:8002/mod_soap/WebworkWebservice') +; + + +my $result = $soap->hi(); + +unless ($result->fault) { + print $result->result(); +} else { + print join ', ', + $result->faultcode, + $result->faultstring; +} + + --- clients/xmlrpc_client4.pl +++ /dev/null @@ -1,280 +0,0 @@ -#!/usr/bin/perl -w - -# configuration section -use constant HOSTURL => 'devel.webwork.rochester.edu'; -use constant HOSTPORT => 8002; - -my @COMMANDS = qw( listLibraries renderProblem ); #listLib tex2pdf - -# $pg{displayModes} = [ -# "plainText", # display raw TeX for math expressions -# "formattedText", # format math expressions using TtH -# "images", # display math expressions as images generated by dvipng -# "jsMath", # render TeX math expressions on the client side using jsMath -# "asciimath", # render TeX math expressions on the client side using ASCIIMathML -# ]; -use constant DISPLAYMODE => 'images'; - -# end configuration section -use MIME::Base64 qw( encode_base64 decode_base64); - - -# -- SOAP::Lite -- soaplite.com -- Copyright (C) 2001 Paul Kulchenko -- - -# use XMLRPC::Lite; -# -# print XMLRPC::Lite -# -> proxy('http://devel.webwork.rochester.edu:11002/mod_xmlrpc') -# -> call('Demo:bye', 25) -# -> result; -print STDERR "inputs are ", join (" | ", @ARGV), "\n"; -our $source; - -if (@ARGV) { - my $command = $ARGV[0]; - - warn "executing WebworkXMLRPC.$command"; - $source = (defined $ARGV[1]) ? `cat $ARGV[1]` : '' ; - xmlrpcCall($command); - - -} else { - - print STDERR "Useage: .xmlrpc_client4.pl command file_name\n"; - print STDERR "For example: .xmlrpc_client4.pl renderProblem input.txt\n"; - print STDERR "Commands are: ", join(" ", @COMMANDS), "\n"; - -} - - - - - - -sub xmlrpcCall { - my $command = shift; - $command = 'listLibraries' unless $command; - use XMLRPC::Lite; - my $xmlrpc = XMLRPC::Lite - # ->uri('http://webwork-db.math.rochester.edu/Demo/') - -> proxy('http://'.HOSTURL.':'.HOSTPORT.'/mod_xmlrpc'); - - my $test = [3,4,5,6]; - my $input = setInputTable(); - print "displayMode=",$input->{envir}->{displayMode},"\n"; - local( $result); - eval { $result = $xmlrpc->call("WebworkXMLRPC.$command",$input) }; - print STDERR "There were a lot of errors\n" if $@; - print "Errors: \n $@\n End Errors\n" if $@; - - print "result is|", ref($result),"|"; - - unless (ref($result) and $result->fault) { - - if (ref($result->result())=~/HASH/ and defined($result->result()->{text}) ) { - $result->result()->{text} = decode_base64($result->result()->{text}); - } - print pretty_print_rh($result->result()),"\n"; #$result->result() - } else { - print 'oops ', join ', ', - $result->faultcode, - $result->faultstring; - } -} - -sub source { - encode_base64($source); -} -sub pretty_print_rh { - shift if UNIVERSAL::isa($_[0] => __PACKAGE__); - my $rh = shift; - my $indent = shift || 0; - my $out = ""; - my $type = ref($rh); - - if (defined($type) and $type) { - $out .= " type = $type; "; - } elsif (! defined($rh )) { - $out .= " type = UNDEFINED; "; - } - if ( ref($rh) =~/HASH/ or "$rh" =~/HASH/ ) { - $out .= "{\n"; - $indent++; - foreach my $key (sort keys %{$rh}) { - $out .= " "x$indent."$key => " . pretty_print_rh( $rh->{$key}, $indent ) . "\n"; - } - $indent--; - $out .= "\n"." "x$indent."}\n"; - - } elsif (ref($rh) =~ /ARRAY/ or "$rh" =~/ARRAY/) { - $out .= " ( "; - foreach my $elem ( @{$rh} ) { - $out .= pretty_print_rh($elem, $indent); - - } - $out .= " ) \n"; - } elsif ( ref($rh) =~ /SCALAR/ ) { - $out .= "scalar reference ". ${$rh}; - } elsif ( ref($rh) =~/Base64/ ) { - $out .= "base64 reference " .$$rh; - } else { - $out .= $rh; - } - - return $out." "; -} - -sub setInputTable_for_listLib { - $out = { - #password => 'geometry', - pw => 'geometry', - set => 'set0', - library_name => 'rochesterLibrary', - command => 'all', - }; - - $out; -} -sub setInputTable { - $out = { - #password => 'geometry', - pw => 'geometry', - set => 'set0', - library_name => 'rochesterLibrary', - command => 'all', - answer_form_submitted => 1, - course => 'daemon_course', - extra_packages_to_load => [qw( AlgParserWithImplicitExpand Expr - ExprWithImplicitExpand AnswerEvaluator - AnswerEvaluatorMaker - )], - mode => 'HTML_dpng', - modules_to_evaluate => [ qw( -Exporter - -DynaLoader - - -GD -WWPlot -Fun -Circle -Label - - -PGrandom -Units -Hermite - -List - - -Match -Multiple -Select - - -AlgParser - -AnswerHash - - -Fraction -VectorField - - -Complex1 -Complex - - -MatrixReal1 Matrix - - -Distributions - -Regression - - )], - envir => environment(), - problem_state => { - - num_of_correct_ans => 2, - num_of_incorrect_ans => 4, - recorded_score => 1.0, - }, - source => source(), #base64 encoded - - - - }; - - $out; -} - -sub environment { - my $envir = { - answerDate => '4014438528', - CAPA_Graphics_URL=>'http://webwork-db.math.rochester.edu/capa_graphics/', - CAPA_GraphicsDirectory =>'/ww/webwork/CAPA/CAPA_Graphics/', - CAPA_MCTools=>'/ww/webwork/CAPA/CAPA_MCTools/', - CAPA_Tools=>'/ww/webwork/CAPA/CAPA_Tools/', - cgiDirectory=>'Not defined', - cgiURL => 'Not defined', - classDirectory=> 'Not defined', - courseName=>'Not defined', - courseScriptsDirectory=>'/ww/webwork/system/courseScripts/', - displayMode=>DISPLAYMODE, - dueDate=> '4014438528', - externalGif2EpsPath=>'not defined', - externalPng2EpsPath=>'not defined', - externalTTHPath=>'/usr/local/bin/tth', - fileName=>'set0/prob1a.pg', - formattedAnswerDate=>'6/19/00', - formattedDueDate=>'6/19/00', - formattedOpenDate=>'6/19/00', - functAbsTolDefault=> 0.0000001, - functLLimitDefault=>0, - functMaxConstantOfIntegration=> 1000000000000.0, - functNumOfPoints=> 5, - functRelPercentTolDefault=> 0.000001, - functULimitDefault=>1, - functVarDefault=> 'x', - functZeroLevelDefault=> 0.000001, - functZeroLevelTolDefault=>0.000001, - htmlDirectory =>'/ww/webwork/courses/gage_course/html/', - htmlURL =>'http://webwork-db.math.rochester.edu/gage_course/', - inputs_ref => { - AnSwEr1 => '', - AnSwEr2 => '', - AnSwEr3 => '', - }, - macroDirectory=>'/ww/webwork/courses/gage_course/templates/macros/', - numAbsTolDefault=>0.0000001, - numFormatDefault=>'%0.13g', - numOfAttempts=> 0, - numRelPercentTolDefault => 0.0001, - numZeroLevelDefault =>0.000001, - numZeroLevelTolDefault =>0.000001, - openDate=> '3014438528', - PRINT_FILE_NAMES_FOR => [ 'gage'], - probFileName => 'set0/prob1a.pg', - problemSeed => 1234, - problemValue =>1, - probNum => 13, - psvn => 54321, - psvnNumber=> 54321, - questionNumber => 1, - scriptDirectory => 'Not defined', - sectionName => 'Gage', - sectionNumber => 1, - sessionKey=> 'Not defined', - setNumber =>'MAAtutorial', - studentLogin =>'gage', - studentName => 'Mike Gage', - tempDirectory => '/ww/htdocs/tmp/gage_course/', - templateDirectory=>'/ww/webwork/courses/gage_course/templates/', - tempURL=>'http://webwork-db.math.rochester.edu/tmp/gage_course/', - webworkDocsURL => 'http://webwork.math.rochester.edu/webwork_gage_system_html', - }; - $envir; -}; \ No newline at end of file Index: README =================================================================== RCS file: /webwork/cvs/system/webwork2/clients/README,v retrieving revision 1.1 retrieving revision 1.2 diff -Lclients/README -Lclients/README -u -r1.1 -r1.2 --- clients/README +++ clients/README @@ -1,7 +1,12 @@ -Minimal commands to make this client work: +These test clients will process these two commands: -./xmlrpc_client4.pl renderProblem input.txt >foo.txt +./webwork_xmlrpc_client.pl renderProblem input.txt >foo.txt +./webwork_xmlrpc_client.pl listLibraries +or -You may need to adjust some hardwired parameters in xmlrpc_client4. :-) +./webwork_soap_client.pl renderProblem input.txt >foo.txt +./webwork_soap_client.pl listLibraries + + +You may need to adjust some hardwired parameters in the scripts. :-) -The |