-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathREADME
More file actions
100 lines (66 loc) · 4.98 KB
/
Copy pathREADME
File metadata and controls
100 lines (66 loc) · 4.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
This is a collection of Java classes that allow easy access to OK Tech Moodle Web Service running in REST mode
from Java clients using Google GSON library such as Android/iPhone but also regular java programs
1) Usage :
----------
Copy the dist/moodlews_gson_x.x.x.jar in the classpath of your project and call its methods
See classes Test1.java in net.patrickpollet.moodlews_gson
Get the latest gson-xxxx.jar from Google site http://code.google.com/p/google-gson/ and add it to the classpath of your project.
All testings were done with gson-1.7.1.jar and latest gson-2.2.1.jar , that are also provided for your convenience in the lib/ directory.
2) Running the test classes against your Moodle server :
-------------------------------------------------------
The tests classes require the URL of a Moodle server and a login/password for an user with sufficient capabilities.
These data are expected to be in a file named net.patrickpollet.moodlews_gson.Constantes.java
- rename the provided file Constantes.java.dist to Constantes.java
- edit it to provide the actual informations
package net.patrickpollet.moodlews_gson;
public class Constantes {
// TESTING adjust to your site
public static final String MOODLE_URL = "http://localhost/moodle.195/";
public static final String LOGIN = "somemoodleuserwithgood capabilities";
public static final String PWD = "itspassword";
public static final boolean WS_DEBUG = false;
// END TESTING
}
- rebuild your project
3) What version of OK Tech WSDL to use ?
----------------------------------------
Historically the OK Tech WS was a SOAP only server using a manually edited WSDL file (wspp/moodlewsdl.xml) that was sent to clients
(and also used by server) by a call to http://yourmoodle/wspp/wsdl_pp.php.
In this WSDL returned data as arrays where placed in an XML attribute named courses, users ... and were extracted by an extraneous call
to a method getXXX() such as :
old java code when importing net.patrickpollet.moodlewsold.core.* (see net.patrickpollet.moodlewsold.Test1.java)
MoodleWSBindingStub moodle=new MoodleWSBindingStub(MOODLE_SERVICE,MOODLE_NAMESPACE,Constantes.WS_DEBUG);
LoginReturn lr = moodle.login(Constantes.LOGIN, Constantes.PWD);
int me =moodle.get_my_id(lr.getClient(),lr.getSessionkey());
System.out.println ("me "+me);
CourseRecord []ret = moodle.get_my_courses(lr.getClient(),lr.getSessionkey(), me,null).getCourses();
Starting at revision 1.8, another simpler wsdl file is provided that is automatically generated by the
wshelper utility from the PHP docs comments in the class mdl_soapserver.class.php file. by the script wspp/genwsdl.php :
The new address of the wsdl is http://yourmoodle/wspp/wsdl_pp2.php and the service script is at http://yourmoodle/wspp/service_pp2.php
In this new WSDL, returned arrays are directly available :
new java code when importing net.patrickpollet.moodlews.core.* (see net.patrickpollet.moodlews.Test1.java)
Mdl_soapserverBindingStub moodle = new Mdl_soapserverBindingStub(MOODLE_SERVICE,MOODLE_NAMESPACE, Constantes.WS_DEBUG);
LoginReturn lr = moodle.login(Constantes.LOGIN, Constantes.PWD);
int me = moodle.get_my_id(lr.getClient(),lr.getSessionkey());
System.out.println("me " + me);
// NO NEED TO CALL getCourses() to fetch the returned array , but parameter userid is now a String
CourseRecord[] ret = moodle.get_my_courses(lr.getClient(), lr.getSessionkey(), "" + me, null);
In REST mode, usage of this new version i.e. classes generated in net.patrickpollet.moodlews_gson is now mandatory for REST java clients.
4) Where is the list of available operations ?
-----------------------------------------------
The list of operations is exactly the same at the operations provided by the SOAP version and will be available here :
http://prope.insa-lyon.fr/~ppollet/moodlews/java/gson/moodlews/net/patrickpollet/moodlews_gson/core/Mdl_restserverBindingStub.html
In the meantime you may consult the ksoap2 version :
http://prope.insa-lyon.fr/~ppollet/moodlews/java/ksoap2/moodlews/net/patrickpollet/moodlews/core/Mdl_soapserverBindingStub.html
5) Updating the helper classes :
---------------------------------
In case of evolution of the WSDL emitted by OK Tech WS, you must regenerate your helper classes using the provided
WSDL2gson program (see net.patrickpollet.moodlews_gson.wsdl package) which is a modified version of Apache's axis 1.4 WSDL2Java utility modified for gson
to get a revised version with the new WSDL use
java java net.patrickpollet.gson.wsdl.WSDL2gson -p net.patrickpollet.moodlews_gson.core -o /tmp http://yourmoodle/wspp/wsdl_pp2.php
in both cases you MUST have the content of lib/ directory in your classpath so from the directory where your Java IDE is placing the compiled classes (bin in Eclipse)
you should type
java -cp '.:../lib/*' net.patrickpollet.gson.wsdl.WSDL2gson -p net.patrickpollet.moodlews_gson.core -o /tmp http://yourmoodle/wspp/wsdl_pp2.php
them make a jar file inside the bin directory and copy it to your actual projet.
enjoy
PP 23/04/2011