[LON-CAPA-cvs] cvs: modules /studip studip.pm

www www at source.lon-capa.org
Thu Jul 21 16:01:20 EDT 2011


www		Thu Jul 21 20:01:20 2011 EDT

  Modified files:              
    /modules/studip	studip.pm 
  Log:
  Successfully getting back the username for the session
  
  
Index: modules/studip/studip.pm
diff -u modules/studip/studip.pm:1.1 modules/studip/studip.pm:1.2
--- modules/studip/studip.pm:1.1	Thu Jul 21 19:17:56 2011
+++ modules/studip/studip.pm	Thu Jul 21 20:01:20 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Landing point for incoming StudIP requests 
 #
-# $Id: studip.pm,v 1.1 2011/07/21 19:17:56 www Exp $
+# $Id: studip.pm,v 1.2 2011/07/21 20:01:20 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -54,6 +54,13 @@
 use Apache::loncommon;
 use Apache::lonlocal;
 use LONCAPA;
+use LWP::UserAgent;
+
+# Config parameters
+
+my $url='http://vm036.rz.uni-osnabrueck.de/studip/lc/xmlrpc.php';
+my $pwd='lc-test';
+
 
 sub handler {
     my $r = shift;
@@ -71,9 +78,42 @@
     $r->print('Course: '.$env{'form.course'}.'<br />');
     $r->print('Stud.IP Course: '.$env{'form.studip_course'}.'<br />');
     $r->print('Stud.IP Perm: '.$env{'form.studip_perm'}.'<br />');
+# Get session info
 
+    my ($commands,$error, at returned)=&send('get_session_username',$env{'form.sess_id'});
+    
+    $r->print('<hr />Talking to: '.$url.'<br />');
+    $r->print('Commands sent:<br /><textarea cols="80" rows="6">'.$commands.'</textarea><br />');
+    $r->print('Error:'.$error.'<br />');
+    $r->print('Responses: '.join(',', at returned).'<br />');
 
     $r->print(&Apache::loncommon::end_page());
     return OK;
 }
+
+sub send {
+    my ($cmd, at args)=@_;
+    my $commands='<methodCall><methodName>'.$cmd.'</methodName><params>';
+    foreach my $param ($pwd, at args) {
+        $commands.='<param><value><string>'.$param.'</string></value></param>';
+    }
+    $commands.='</params></methodCall>';
+    my $ua=new LWP::UserAgent;
+    $ua->timeout(4);
+    my $headers = HTTP::Headers->new() ;
+    my $request = new HTTP::Request('POST',$url.'?methodName='.$cmd,$headers);
+    $request->content($commands);
+    my $response=$ua->request($request);
+    my @returned=();
+    my $error='';
+    if ($response->is_success()) {
+        my $content = $response->content;
+        @returned=($content=~/\<(int|string|boolean)\>([^\<]+)/g);
+    } else {
+        $error = "ERROR: ".$response->status_line;
+    }
+    return ($commands,$error, at returned);
+}
+
+
 1;




More information about the LON-CAPA-cvs mailing list