use of com.tomasio.projects.trainning.jackson.Course in project trainning by fernandotomasio.
the class TesteMoodle2 method main.
public static void main(String[] args) {
String token = ConfigHelper.getValue("moodle.token");
String domainName = ConfigHelper.getValue("moodle.domain");
// Also possible in Moodle 2.2 and later: 'json'
String restformat = "json";
// Setting it to 'json' will fail all calls on earlier Moodle version
if (restformat.equals("json")) {
restformat = "&moodlewsrestformat=" + restformat;
} else {
restformat = "";
}
String postFunctionName = "core_course_create_courses";
String serverurl = domainName + "/webservice/rest/server.php" + "?wstoken=" + token + "&wsfunction=" + postFunctionName + restformat;
RestTemplate restTemplate = new RestTemplate();
List<HttpMessageConverter<?>> list = new ArrayList<HttpMessageConverter<?>>();
list.add(new MappingJackson2HttpMessageConverter());
restTemplate.setMessageConverters(list);
Course myCourse = new Course();
myCourse.setFullname("my course");
myCourse.setShortname("MC");
myCourse.setId(5);
restTemplate.postForObject(serverurl, myCourse, Object.class);
// System.out.println(courses.length);
//
// MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
// map.add("fullname", "sadfasdfasdf");
// map.add("shortname", "asdfasdfasdfasdf");
// HttpHeaders headers = new HttpHeaders();
// headers.setContentType(MediaType.APPLICATION_JSON);
//
// HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(map, headers);
//
// List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
// messageConverters.add(new MappingJackson2HttpMessageConverter());
// messageConverters.add(new FormHttpMessageConverter());
// restTemplate.setMessageConverters(messageConverters);
// Course response = restTemplate.postForObject(serverurl, request, Course.class);
//
// System.out.println(response.getFullname());
// Course c = new Course();
// c.setFullname("alskjdfçasdf");
// c.setShortname("ldslkdf");
// c.setCategoryid(1);
// List<HttpMessageConverter<?>> list = new ArrayList<HttpMessageConverter<?>>();
// list.add(new MappingJackson2HttpMessageConverter());
// restTemplate.setMessageConverters(list);
// Course course = restTemplate.postForObject(serverurl, c, Course.class);
// System.out.println(course.getFullname());
}
Aggregations