Java Code Examples for org.apache.commons.httpclient.methods.PutMethod#getResponseBodyAsString()
The following examples show how to use
org.apache.commons.httpclient.methods.PutMethod#getResponseBodyAsString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CoursesITCase.java From olat with Apache License 2.0 | 6 votes |
@Test public void testCreateEmptyCourse() throws IOException { final HttpClient c = loginWithCookie("administrator", "olat"); final URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("courses").queryParam("shortTitle", "course3").queryParam("title", "course3 long name") .build(); final PutMethod method = createPut(uri, MediaType.APPLICATION_JSON, true); final int code = c.executeMethod(method); assertEquals(code, 200); final String body = method.getResponseBodyAsString(); final CourseVO course = parse(body, CourseVO.class); assertNotNull(course); assertEquals("course3", course.getTitle()); // check repository entry final RepositoryEntry re = RepositoryServiceImpl.getInstance().lookupRepositoryEntry(course.getRepoEntryKey()); assertNotNull(re); assertNotNull(re.getOlatResource()); assertNotNull(re.getOwnerGroup()); }
Example 2
Source File: CoursesContactElementITCase.java From olat with Apache License 2.0 | 6 votes |
@Test public void testBareBoneConfig() throws IOException { final HttpClient c = loginWithCookie("administrator", "olat"); // create an contact node final URI newContactUri = getElementsUri(course1).path("contact").queryParam("parentNodeId", rootNodeId).queryParam("position", "0") .queryParam("shortTitle", "Contact-0").queryParam("longTitle", "Contact-long-0").queryParam("objectives", "Contact-objectives-0").build(); final PutMethod method = createPut(newContactUri, MediaType.APPLICATION_JSON, true); final int code = c.executeMethod(method); final String body = method.getResponseBodyAsString(); method.releaseConnection(); assertEquals(200, code); final CourseNodeVO contactNode = parse(body, CourseNodeVO.class); assertNotNull(contactNode); assertNotNull(contactNode.getId()); assertEquals(contactNode.getShortTitle(), "Contact-0"); assertEquals(contactNode.getLongTitle(), "Contact-long-0"); assertEquals(contactNode.getLearningObjectives(), "Contact-objectives-0"); assertEquals(contactNode.getParentId(), rootNodeId); }
Example 3
Source File: CoursesContactElementITCase.java From olat with Apache License 2.0 | 6 votes |
@Test public void testBareBoneConfig() throws IOException { final HttpClient c = loginWithCookie("administrator", "olat"); // create an contact node final URI newContactUri = getElementsUri(course1).path("contact").queryParam("parentNodeId", rootNodeId).queryParam("position", "0") .queryParam("shortTitle", "Contact-0").queryParam("longTitle", "Contact-long-0").queryParam("objectives", "Contact-objectives-0").build(); final PutMethod method = createPut(newContactUri, MediaType.APPLICATION_JSON, true); final int code = c.executeMethod(method); final String body = method.getResponseBodyAsString(); method.releaseConnection(); assertEquals(200, code); final CourseNodeVO contactNode = parse(body, CourseNodeVO.class); assertNotNull(contactNode); assertNotNull(contactNode.getId()); assertEquals(contactNode.getShortTitle(), "Contact-0"); assertEquals(contactNode.getLongTitle(), "Contact-long-0"); assertEquals(contactNode.getLearningObjectives(), "Contact-objectives-0"); assertEquals(contactNode.getParentId(), rootNodeId); }
Example 4
Source File: RepositoryEntriesITCase.java From olat with Apache License 2.0 | 5 votes |
@Test public void testImportWiki() throws HttpException, IOException, URISyntaxException { final URL cpUrl = RepositoryEntriesITCase.class.getResource("wiki-demo.zip"); assertNotNull(cpUrl); final File cp = new File(cpUrl.toURI()); final HttpClient c = loginWithCookie("administrator", "olat"); final PutMethod method = createPut("repo/entries", MediaType.APPLICATION_JSON, true); method.addRequestHeader("Content-Type", MediaType.MULTIPART_FORM_DATA); final Part[] parts = { new FilePart("file", cp), new StringPart("filename", "wiki-demo.zip"), new StringPart("resourcename", "Wiki demo"), new StringPart("displayname", "Wiki demo") }; method.setRequestEntity(new MultipartRequestEntity(parts, method.getParams())); final int code = c.executeMethod(method); assertTrue(code == 200 || code == 201); final String body = method.getResponseBodyAsString(); method.releaseConnection(); final RepositoryEntryVO vo = parse(body, RepositoryEntryVO.class); assertNotNull(vo); final Long key = vo.getKey(); final RepositoryEntry re = RepositoryServiceImpl.getInstance().lookupRepositoryEntry(key); assertNotNull(re); assertNotNull(re.getOwnerGroup()); assertNotNull(re.getOlatResource()); assertEquals("Wiki demo", re.getDisplayname()); log.info(re.getOlatResource().getResourceableTypeName()); }
Example 5
Source File: UserMgmtITCase.java From olat with Apache License 2.0 | 5 votes |
/** * Test machine format for gender and date */ @Test public void testCreateUser2() throws IOException { final HttpClient c = loginWithCookie("administrator", "olat"); final UserVO vo = new UserVO(); final String username = UUID.randomUUID().toString(); vo.setLogin(username); vo.setFirstName("John"); vo.setLastName("Smith"); vo.setEmail(username + "@frentix.com"); vo.putProperty("telOffice", "39847592"); vo.putProperty("telPrivate", "39847592"); vo.putProperty("telMobile", "39847592"); vo.putProperty("gender", "female");// male or female vo.putProperty("birthDay", "20091212"); final String stringuifiedAuth = stringuified(vo); final PutMethod method = createPut("/users", MediaType.APPLICATION_JSON, true); final RequestEntity entity = new StringRequestEntity(stringuifiedAuth, MediaType.APPLICATION_JSON, "UTF-8"); method.setRequestEntity(entity); method.addRequestHeader("Accept-Language", "en"); final int code = c.executeMethod(method); assertTrue(code == 200 || code == 201); final String body = method.getResponseBodyAsString(); method.releaseConnection(); final UserVO savedVo = parse(body, UserVO.class); final Identity savedIdent = securityManager.findIdentityByName(username); assertNotNull(savedVo); assertNotNull(savedIdent); assertEquals(savedVo.getKey(), savedIdent.getKey()); assertEquals(savedVo.getLogin(), savedIdent.getName()); assertEquals("Female", userService.getUserProperty(savedIdent.getUser(), UserConstants.GENDER, Locale.ENGLISH)); assertEquals("39847592", userService.getUserProperty(savedIdent.getUser(), UserConstants.TELPRIVATE, Locale.ENGLISH)); assertEquals("12/12/09", userService.getUserProperty(savedIdent.getUser(), UserConstants.BIRTHDAY, Locale.ENGLISH)); }
Example 6
Source File: CatalogITCase.java From olat with Apache License 2.0 | 5 votes |
@Test public void testPutCatalogEntryJson() throws IOException { final RepositoryEntry re = createRepository("put-cat-entry-json", 6458438l); final HttpClient c = loginWithCookie("administrator", "olat"); final CatalogEntryVO subEntry = new CatalogEntryVO(); subEntry.setName("Sub-entry-1"); subEntry.setDescription("Sub-entry-description-1"); subEntry.setType(CatalogEntry.TYPE_NODE); subEntry.setRepositoryEntryKey(re.getKey()); final String entity = stringuified(subEntry); final URI uri = UriBuilder.fromUri(getContextURI()).path("catalog").path(entry1.getKey().toString()).build(); final PutMethod method = createPut(uri, MediaType.APPLICATION_JSON, true); method.addRequestHeader("Content-Type", MediaType.APPLICATION_JSON); final RequestEntity requestEntity = new StringRequestEntity(entity, MediaType.APPLICATION_JSON, "UTF-8"); method.setRequestEntity(requestEntity); final int code = c.executeMethod(method); assertEquals(200, code); final String body = method.getResponseBodyAsString(); method.releaseConnection(); final CatalogEntryVO vo = parse(body, CatalogEntryVO.class); assertNotNull(vo); final List<CatalogEntry> children = catalogService.getChildrenOf(entry1); CatalogEntry ce = null; for (final CatalogEntry child : children) { if (vo.getKey().equals(child.getKey())) { ce = child; break; } } assertNotNull(ce); assertNotNull(ce.getRepositoryEntry()); assertEquals(re.getKey(), ce.getRepositoryEntry().getKey()); }
Example 7
Source File: CatalogITCase.java From olat with Apache License 2.0 | 5 votes |
@Test public void testPutCategoryJson() throws IOException { final HttpClient c = loginWithCookie("administrator", "olat"); final CatalogEntryVO subEntry = new CatalogEntryVO(); subEntry.setName("Sub-entry-1"); subEntry.setDescription("Sub-entry-description-1"); subEntry.setType(CatalogEntry.TYPE_NODE); final String entity = stringuified(subEntry); final URI uri = UriBuilder.fromUri(getContextURI()).path("catalog").path(entry1.getKey().toString()).build(); final PutMethod method = createPut(uri, MediaType.APPLICATION_JSON, true); method.addRequestHeader("Content-Type", MediaType.APPLICATION_JSON); final RequestEntity requestEntity = new StringRequestEntity(entity, MediaType.APPLICATION_JSON, "UTF-8"); method.setRequestEntity(requestEntity); final int code = c.executeMethod(method); assertEquals(200, code); final String body = method.getResponseBodyAsString(); method.releaseConnection(); final CatalogEntryVO vo = parse(body, CatalogEntryVO.class); assertNotNull(vo); final List<CatalogEntry> children = catalogService.getChildrenOf(entry1); boolean saved = false; for (final CatalogEntry child : children) { if (vo.getKey().equals(child.getKey())) { saved = true; break; } } assertTrue(saved); }
Example 8
Source File: ForumITCase.java From olat with Apache License 2.0 | 5 votes |
@Test public void testNewThread() throws IOException { final HttpClient c = loginWithCookie("administrator", "olat"); final URI uri = getForumUriBuilder().path("threads").queryParam("authorKey", id1.getKey()).queryParam("title", "New thread") .queryParam("body", "A very interesting thread").build(); final PutMethod method = createPut(uri, MediaType.APPLICATION_JSON, true); final int code = c.executeMethod(method); assertEquals(code, 200); final String body = method.getResponseBodyAsString(); final MessageVO thread = parse(body, MessageVO.class); assertNotNull(thread); assertNotNull(thread.getKey()); assertEquals(thread.getForumKey(), forum.getKey()); assertEquals(thread.getAuthorKey(), id1.getKey()); // really saved? boolean saved = false; final ForumService fm = getForumService(); final List<Message> allMessages = fm.getMessagesByForum(forum); for (final Message message : allMessages) { if (message.getKey().equals(thread.getKey())) { saved = true; } } assertTrue(saved); }
Example 9
Source File: CatalogITCase.java From olat with Apache License 2.0 | 5 votes |
@Test public void testPutCategoryQuery() throws IOException { final HttpClient c = loginWithCookie("administrator", "olat"); final URI uri = UriBuilder.fromUri(getContextURI()).path("catalog").path(entry1.getKey().toString()).build(); final PutMethod method = createPut(uri, MediaType.APPLICATION_JSON, true); method.setQueryString(new NameValuePair[] { new NameValuePair("name", "Sub-entry-2"), new NameValuePair("description", "Sub-entry-description-2"), new NameValuePair("type", String.valueOf(CatalogEntry.TYPE_NODE)) }); final int code = c.executeMethod(method); assertEquals(200, code); final String body = method.getResponseBodyAsString(); method.releaseConnection(); final CatalogEntryVO vo = parse(body, CatalogEntryVO.class); assertNotNull(vo); final List<CatalogEntry> children = catalogService.getChildrenOf(entry1); boolean saved = false; for (final CatalogEntry child : children) { if (vo.getKey().equals(child.getKey())) { saved = true; break; } } assertTrue(saved); }
Example 10
Source File: CatalogITCase.java From olat with Apache License 2.0 | 5 votes |
@Test public void testPutCategoryJson() throws IOException { final HttpClient c = loginWithCookie("administrator", "olat"); final CatalogEntryVO subEntry = new CatalogEntryVO(); subEntry.setName("Sub-entry-1"); subEntry.setDescription("Sub-entry-description-1"); subEntry.setType(CatalogEntry.TYPE_NODE); final String entity = stringuified(subEntry); final URI uri = UriBuilder.fromUri(getContextURI()).path("catalog").path(entry1.getKey().toString()).build(); final PutMethod method = createPut(uri, MediaType.APPLICATION_JSON, true); method.addRequestHeader("Content-Type", MediaType.APPLICATION_JSON); final RequestEntity requestEntity = new StringRequestEntity(entity, MediaType.APPLICATION_JSON, "UTF-8"); method.setRequestEntity(requestEntity); final int code = c.executeMethod(method); assertEquals(200, code); final String body = method.getResponseBodyAsString(); method.releaseConnection(); final CatalogEntryVO vo = parse(body, CatalogEntryVO.class); assertNotNull(vo); final List<CatalogEntry> children = catalogService.getChildrenOf(entry1); boolean saved = false; for (final CatalogEntry child : children) { if (vo.getKey().equals(child.getKey())) { saved = true; break; } } assertTrue(saved); }
Example 11
Source File: CourseGroupMgmtITCase.java From olat with Apache License 2.0 | 5 votes |
@Test public void testPutCourseGroup() throws IOException { final HttpClient c = loginWithCookie("administrator", "olat"); final GroupVO vo = new GroupVO(); vo.setName("hello"); vo.setDescription("hello description"); vo.setMinParticipants(new Integer(-1)); vo.setMaxParticipants(new Integer(-1)); final String stringuifiedAuth = stringuified(vo); final RequestEntity entity = new StringRequestEntity(stringuifiedAuth, MediaType.APPLICATION_JSON, "UTF-8"); final String request = "/repo/courses/" + course.getResourceableId() + "/groups"; final PutMethod method = createPut(request, MediaType.APPLICATION_JSON, true); method.setRequestEntity(entity); final int code = c.executeMethod(method); assertEquals(200, code); final String body = method.getResponseBodyAsString(); method.releaseConnection(); final GroupVO responseVo = parse(body, GroupVO.class); assertNotNull(responseVo); assertEquals(vo.getName(), responseVo.getName()); final BusinessGroup bg = businessGroupService.loadBusinessGroup(responseVo.getKey(), false); assertNotNull(bg); assertEquals(bg.getKey(), responseVo.getKey()); assertEquals(bg.getName(), vo.getName()); assertEquals(bg.getDescription(), vo.getDescription()); assertEquals(new Integer(0), bg.getMinParticipants()); assertEquals(new Integer(0), bg.getMaxParticipants()); }
Example 12
Source File: ChatRoomDecorator.java From Spark with Apache License 2.0 | 5 votes |
private void uploadFile(File file, UploadRequest response, ChatRoom room, Message.Type type) { Log.warning("uploadFile request " + room.getRoomJid() + " " + response.putUrl); URLConnection urlconnection = null; try { PutMethod put = new PutMethod(response.putUrl); int port = put.getURI().getPort(); if (port > 0) { Protocol.registerProtocol( "https", new Protocol( "https", new EasySSLProtocolSocketFactory(), port ) ); } HttpClient client = new HttpClient(); RequestEntity entity = new FileRequestEntity(file, "application/binary"); put.setRequestEntity(entity); put.setRequestHeader("User-Agent", "Spark HttpFileUpload"); client.executeMethod(put); int statusCode = put.getStatusCode(); String responseBody = put.getResponseBodyAsString(); Log.warning("uploadFile response " + statusCode + " " + responseBody); if ((statusCode >= 200) && (statusCode <= 202)) { broadcastUploadUrl(room.getRoomJid(), response.getUrl, type); } } catch (Exception e) { Log.error("uploadFile error", e); } }
Example 13
Source File: UserMgmtITCase.java From olat with Apache License 2.0 | 5 votes |
@Test public void testCreateUser() throws IOException { final HttpClient c = loginWithCookie("administrator", "olat"); final UserVO vo = new UserVO(); final String username = UUID.randomUUID().toString(); vo.setLogin(username); vo.setFirstName("John"); vo.setLastName("Smith"); vo.setEmail(username + "@frentix.com"); vo.putProperty("telOffice", "39847592"); vo.putProperty("telPrivate", "39847592"); vo.putProperty("telMobile", "39847592"); vo.putProperty("gender", "Female");// male or female vo.putProperty("birthDay", "12/12/2009"); final String stringuifiedAuth = stringuified(vo); final PutMethod method = createPut("/users", MediaType.APPLICATION_JSON, true); final RequestEntity entity = new StringRequestEntity(stringuifiedAuth, MediaType.APPLICATION_JSON, "UTF-8"); method.setRequestEntity(entity); method.addRequestHeader("Accept-Language", "en"); final int code = c.executeMethod(method); assertTrue(code == 200 || code == 201); final String body = method.getResponseBodyAsString(); method.releaseConnection(); final UserVO savedVo = parse(body, UserVO.class); final Identity savedIdent = securityManager.findIdentityByName(username); assertNotNull(savedVo); assertNotNull(savedIdent); assertEquals(savedVo.getKey(), savedIdent.getKey()); assertEquals(savedVo.getLogin(), savedIdent.getName()); assertEquals("Female", userService.getUserProperty(savedIdent.getUser(), UserConstants.GENDER, Locale.ENGLISH)); assertEquals("39847592", userService.getUserProperty(savedIdent.getUser(), UserConstants.TELPRIVATE, Locale.ENGLISH)); assertEquals("12/12/09", userService.getUserProperty(savedIdent.getUser(), UserConstants.BIRTHDAY, Locale.ENGLISH)); }
Example 14
Source File: CoursesContactElementITCase.java From olat with Apache License 2.0 | 5 votes |
@Test public void testFullConfig() throws IOException { final HttpClient c = loginWithCookie("administrator", "olat"); // create an contact node final URI newContactUri = getElementsUri(course1).path("contact").queryParam("parentNodeId", rootNodeId).queryParam("position", "0") .queryParam("shortTitle", "Contact-1").queryParam("longTitle", "Contact-long-1").queryParam("objectives", "Contact-objectives-1") .queryParam("coaches", "true").queryParam("participants", "true").queryParam("groups", "").queryParam("areas", "") .queryParam("to", "[email protected];[email protected]").queryParam("defaultSubject", "Hello by contact 1") .queryParam("defaultBody", "Hello by contact 1 body").build(); final PutMethod method = createPut(newContactUri, MediaType.APPLICATION_JSON, true); final int code = c.executeMethod(method); final String body = method.getResponseBodyAsString(); method.releaseConnection(); // check the return values assertEquals(200, code); final CourseNodeVO contactNode = parse(body, CourseNodeVO.class); assertNotNull(contactNode); assertNotNull(contactNode.getId()); // check the persisted value final ICourse course = CourseFactory.loadCourse(course1.getResourceableId()); final TreeNode node = course.getEditorTreeModel().getNodeById(contactNode.getId()); assertNotNull(node); final CourseEditorTreeNode editorCourseNode = (CourseEditorTreeNode) node; final CourseNode courseNode = editorCourseNode.getCourseNode(); final ModuleConfiguration config = courseNode.getModuleConfiguration(); assertNotNull(config); assertEquals(config.getBooleanEntry(CONFIG_KEY_EMAILTOCOACHES), true); assertEquals(config.getBooleanEntry(CONFIG_KEY_EMAILTOPARTICIPANTS), true); final List<String> tos = (List<String>) config.get(CONFIG_KEY_EMAILTOADRESSES); assertNotNull(tos); assertEquals(2, tos.size()); assertEquals(config.get(CONFIG_KEY_MSUBJECT_DEFAULT), "Hello by contact 1"); assertEquals(config.get(CONFIG_KEY_MBODY_DEFAULT), "Hello by contact 1 body"); }
Example 15
Source File: RepositoryEntriesITCase.java From olat with Apache License 2.0 | 5 votes |
@Test public void testImportWiki() throws HttpException, IOException, URISyntaxException { final URL cpUrl = RepositoryEntriesITCase.class.getResource("wiki-demo.zip"); assertNotNull(cpUrl); final File cp = new File(cpUrl.toURI()); final HttpClient c = loginWithCookie("administrator", "olat"); final PutMethod method = createPut("repo/entries", MediaType.APPLICATION_JSON, true); method.addRequestHeader("Content-Type", MediaType.MULTIPART_FORM_DATA); final Part[] parts = { new FilePart("file", cp), new StringPart("filename", "wiki-demo.zip"), new StringPart("resourcename", "Wiki demo"), new StringPart("displayname", "Wiki demo") }; method.setRequestEntity(new MultipartRequestEntity(parts, method.getParams())); final int code = c.executeMethod(method); assertTrue(code == 200 || code == 201); final String body = method.getResponseBodyAsString(); method.releaseConnection(); final RepositoryEntryVO vo = parse(body, RepositoryEntryVO.class); assertNotNull(vo); final Long key = vo.getKey(); final RepositoryEntry re = RepositoryServiceImpl.getInstance().lookupRepositoryEntry(key); assertNotNull(re); assertNotNull(re.getOwnerGroup()); assertNotNull(re.getOlatResource()); assertEquals("Wiki demo", re.getDisplayname()); log.info(re.getOlatResource().getResourceableTypeName()); }
Example 16
Source File: RepositoryEntriesITCase.java From olat with Apache License 2.0 | 5 votes |
@Test public void testImportQuestionnaire() throws HttpException, IOException, URISyntaxException { final URL cpUrl = RepositoryEntriesITCase.class.getResource("questionnaire-demo.zip"); assertNotNull(cpUrl); final File cp = new File(cpUrl.toURI()); final HttpClient c = loginWithCookie("administrator", "olat"); final PutMethod method = createPut("repo/entries", MediaType.APPLICATION_JSON, true); method.addRequestHeader("Content-Type", MediaType.MULTIPART_FORM_DATA); final Part[] parts = { new FilePart("file", cp), new StringPart("filename", "questionnaire-demo.zip"), new StringPart("resourcename", "Questionnaire demo"), new StringPart("displayname", "Questionnaire demo") }; method.setRequestEntity(new MultipartRequestEntity(parts, method.getParams())); final int code = c.executeMethod(method); assertTrue(code == 200 || code == 201); final String body = method.getResponseBodyAsString(); method.releaseConnection(); final RepositoryEntryVO vo = parse(body, RepositoryEntryVO.class); assertNotNull(vo); final Long key = vo.getKey(); final RepositoryEntry re = RepositoryServiceImpl.getInstance().lookupRepositoryEntry(key); assertNotNull(re); assertNotNull(re.getOwnerGroup()); assertNotNull(re.getOlatResource()); assertEquals("Questionnaire demo", re.getDisplayname()); log.info(re.getOlatResource().getResourceableTypeName()); }
Example 17
Source File: RepositoryEntriesITCase.java From olat with Apache License 2.0 | 5 votes |
@Test public void testImportTest() throws HttpException, IOException, URISyntaxException { final URL cpUrl = RepositoryEntriesITCase.class.getResource("qti-demo.zip"); assertNotNull(cpUrl); final File cp = new File(cpUrl.toURI()); final HttpClient c = loginWithCookie("administrator", "olat"); final PutMethod method = createPut("repo/entries", MediaType.APPLICATION_JSON, true); method.addRequestHeader("Content-Type", MediaType.MULTIPART_FORM_DATA); final Part[] parts = { new FilePart("file", cp), new StringPart("filename", "qti-demo.zip"), new StringPart("resourcename", "QTI demo"), new StringPart("displayname", "QTI demo") }; method.setRequestEntity(new MultipartRequestEntity(parts, method.getParams())); final int code = c.executeMethod(method); assertTrue(code == 200 || code == 201); final String body = method.getResponseBodyAsString(); method.releaseConnection(); final RepositoryEntryVO vo = parse(body, RepositoryEntryVO.class); assertNotNull(vo); final Long key = vo.getKey(); final RepositoryEntry re = RepositoryServiceImpl.getInstance().lookupRepositoryEntry(key); assertNotNull(re); assertNotNull(re.getOwnerGroup()); assertNotNull(re.getOlatResource()); assertEquals("QTI demo", re.getDisplayname()); log.info(re.getOlatResource().getResourceableTypeName()); }
Example 18
Source File: RepositoryEntriesITCase.java From olat with Apache License 2.0 | 5 votes |
@Test public void testImportCp() throws HttpException, IOException, URISyntaxException { final URL cpUrl = RepositoryEntriesITCase.class.getResource("cp-demo.zip"); assertNotNull(cpUrl); final File cp = new File(cpUrl.toURI()); final HttpClient c = loginWithCookie("administrator", "olat"); final PutMethod method = createPut("repo/entries", MediaType.APPLICATION_JSON, true); method.addRequestHeader("Content-Type", MediaType.MULTIPART_FORM_DATA); final Part[] parts = { new FilePart("file", cp), new StringPart("filename", "cp-demo.zip"), new StringPart("resourcename", "CP demo"), new StringPart("displayname", "CP demo") }; method.setRequestEntity(new MultipartRequestEntity(parts, method.getParams())); final int code = c.executeMethod(method); assertTrue(code == 200 || code == 201); final String body = method.getResponseBodyAsString(); method.releaseConnection(); final RepositoryEntryVO vo = parse(body, RepositoryEntryVO.class); assertNotNull(vo); final Long key = vo.getKey(); final RepositoryEntry re = RepositoryServiceImpl.getInstance().lookupRepositoryEntry(key); assertNotNull(re); assertNotNull(re.getOwnerGroup()); assertNotNull(re.getOlatResource()); assertEquals("CP demo", re.getDisplayname()); }
Example 19
Source File: SystemRegistrationWorker.java From olat with Apache License 2.0 | 4 votes |
protected boolean doTheWork(String registrationData, String url, String version) { String registrationKey = propertyService.getStringProperty(PropertyLocator.SYSTEM_REG_SECRET_KEY); boolean regStatus = false; if (StringHelper.containsNonWhitespace(registrationData)) { // only send when there is something to send final HttpClient client = HttpClientFactory.getHttpClientInstance(); client.getParams().setParameter("http.useragent", "OLAT Registration Agent ; " + version); log.info("URL:" + url, null); final PutMethod method = new PutMethod(url); if (registrationKey != null) { // updating method.setRequestHeader("Authorization", registrationKey); if (log.isDebugEnabled()) { log.debug("Authorization: " + registrationKey, null); } else { log.debug("Authorization: EXISTS", null); } } else { log.info("Authorization: NONE", null); } method.setRequestHeader("Content-Type", "application/xml; charset=utf-8"); try { method.setRequestEntity(new StringRequestEntity(registrationData, "application/xml", "UTF8")); client.executeMethod(method); final int status = method.getStatusCode(); if (status == HttpStatus.SC_NOT_MODIFIED || status == HttpStatus.SC_OK) { log.info("Successfully registered OLAT installation on olat.org server, thank you for your support!", null); registrationKey = method.getResponseBodyAsString(); propertyService.setProperty(PropertyLocator.SYSTEM_REG_SECRET_KEY, registrationKey); regStatus = true; } else if (method.getStatusCode() == HttpStatus.SC_NOT_FOUND) { log.error("File could be created not on registration server::" + method.getStatusLine().toString(), null); regStatus = false; } else if (method.getStatusCode() == HttpStatus.SC_NO_CONTENT) { log.info(method.getResponseBodyAsString() + method.getStatusText()); regStatus = false; } else { log.error("Unexpected HTTP Status::" + method.getStatusLine().toString() + " during registration call", null); regStatus = false; } } catch (final Exception e) { log.error("Unexpected exception during registration call", e); regStatus = false; } } else { log.warn( "****************************************************************************************************************************************************************************", null); log.warn( "* This OLAT installation is not registered. Please, help us with your statistical data and register your installation under Adminisration - Systemregistration. THANK YOU! *", null); log.warn( "****************************************************************************************************************************************************************************", null); } return regStatus; }
Example 20
Source File: SystemRegistrationWorker.java From olat with Apache License 2.0 | 4 votes |
protected boolean doTheWork(String registrationData, String url, String version) { String registrationKey = propertyService.getStringProperty(PropertyLocator.SYSTEM_REG_SECRET_KEY); boolean regStatus = false; if (StringHelper.containsNonWhitespace(registrationData)) { // only send when there is something to send final HttpClient client = HttpClientFactory.getHttpClientInstance(); client.getParams().setParameter("http.useragent", "OLAT Registration Agent ; " + version); log.info("URL:" + url, null); final PutMethod method = new PutMethod(url); if (registrationKey != null) { // updating method.setRequestHeader("Authorization", registrationKey); if (log.isDebugEnabled()) { log.debug("Authorization: " + registrationKey, null); } else { log.debug("Authorization: EXISTS", null); } } else { log.info("Authorization: NONE", null); } method.setRequestHeader("Content-Type", "application/xml; charset=utf-8"); try { method.setRequestEntity(new StringRequestEntity(registrationData, "application/xml", "UTF8")); client.executeMethod(method); final int status = method.getStatusCode(); if (status == HttpStatus.SC_NOT_MODIFIED || status == HttpStatus.SC_OK) { log.info("Successfully registered OLAT installation on olat.org server, thank you for your support!", null); registrationKey = method.getResponseBodyAsString(); propertyService.setProperty(PropertyLocator.SYSTEM_REG_SECRET_KEY, registrationKey); regStatus = true; } else if (method.getStatusCode() == HttpStatus.SC_NOT_FOUND) { log.error("File could be created not on registration server::" + method.getStatusLine().toString(), null); regStatus = false; } else if (method.getStatusCode() == HttpStatus.SC_NO_CONTENT) { log.info(method.getResponseBodyAsString() + method.getStatusText()); regStatus = false; } else { log.error("Unexpected HTTP Status::" + method.getStatusLine().toString() + " during registration call", null); regStatus = false; } } catch (final Exception e) { log.error("Unexpected exception during registration call", e); regStatus = false; } } else { log.warn( "****************************************************************************************************************************************************************************", null); log.warn( "* This OLAT installation is not registered. Please, help us with your statistical data and register your installation under Adminisration - Systemregistration. THANK YOU! *", null); log.warn( "****************************************************************************************************************************************************************************", null); } return regStatus; }