use of org.olat.restapi.RestConnection in project OpenOLAT by OpenOLAT.
the class UserRestClient method createRandomUser.
public UserVO createRandomUser(String name) throws IOException, URISyntaxException {
RestConnection restConnection = new RestConnection(deploymentUrl);
assertTrue(restConnection.login(username, password));
UserVO user = createUser(restConnection, name, "Rnd");
restConnection.shutdown();
return user;
}
use of org.olat.restapi.RestConnection in project OpenOLAT by OpenOLAT.
the class RepositoryRestClient method deployCourse.
public CourseVO deployCourse(File archive, String resourcename, String displayname) throws URISyntaxException, IOException {
RestConnection conn = new RestConnection(deploymentUrl);
assertTrue(conn.login(username, password));
URI request = UriBuilder.fromUri(deploymentUrl.toURI()).path("restapi").path("repo/courses").build();
HttpPost method = conn.createPost(request, MediaType.APPLICATION_JSON);
String softKey = UUID.randomUUID().toString();
HttpEntity entity = MultipartEntityBuilder.create().setMode(HttpMultipartMode.BROWSER_COMPATIBLE).addBinaryBody("file", archive, ContentType.APPLICATION_OCTET_STREAM, archive.getName()).addTextBody("filename", archive.getName()).addTextBody("resourcename", resourcename).addTextBody("displayname", displayname).addTextBody("access", "3").addTextBody("softkey", softKey).build();
method.setEntity(entity);
HttpResponse response = conn.execute(method);
assertTrue(response.getStatusLine().getStatusCode() == 200 || response.getStatusLine().getStatusCode() == 201);
CourseVO vo = conn.parse(response, CourseVO.class);
assertNotNull(vo);
assertNotNull(vo.getRepoEntryKey());
assertNotNull(vo.getKey());
return vo;
}
use of org.olat.restapi.RestConnection in project openolat by klemens.
the class RepositoryRestClient method deployCourse.
public CourseVO deployCourse(File archive, String resourcename, String displayname) throws URISyntaxException, IOException {
RestConnection conn = new RestConnection(deploymentUrl);
assertTrue(conn.login(username, password));
URI request = UriBuilder.fromUri(deploymentUrl.toURI()).path("restapi").path("repo/courses").build();
HttpPost method = conn.createPost(request, MediaType.APPLICATION_JSON);
String softKey = UUID.randomUUID().toString();
HttpEntity entity = MultipartEntityBuilder.create().setMode(HttpMultipartMode.BROWSER_COMPATIBLE).addBinaryBody("file", archive, ContentType.APPLICATION_OCTET_STREAM, archive.getName()).addTextBody("filename", archive.getName()).addTextBody("resourcename", resourcename).addTextBody("displayname", displayname).addTextBody("access", "3").addTextBody("softkey", softKey).build();
method.setEntity(entity);
HttpResponse response = conn.execute(method);
assertTrue(response.getStatusLine().getStatusCode() == 200 || response.getStatusLine().getStatusCode() == 201);
CourseVO vo = conn.parse(response, CourseVO.class);
assertNotNull(vo);
assertNotNull(vo.getRepoEntryKey());
assertNotNull(vo.getKey());
return vo;
}
Aggregations