org.apache.commons.httpclient.methods.RequestEntity Java Examples
The following examples show how to use
org.apache.commons.httpclient.methods.RequestEntity.
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: SolrWaveIndexerImpl.java From swellrt with Apache License 2.0 | 7 votes |
private void postUpdateToSolr(ReadableWaveletData wavelet, JsonArray docsJson) { PostMethod postMethod = new PostMethod(solrBaseUrl + "/update/json?commit=true"); try { RequestEntity requestEntity = new StringRequestEntity(docsJson.toString(), "application/json", "UTF-8"); postMethod.setRequestEntity(requestEntity); HttpClient httpClient = new HttpClient(); int statusCode = httpClient.executeMethod(postMethod); if (statusCode != HttpStatus.SC_OK) { throw new IndexException(wavelet.getWaveId().serialise()); } } catch (IOException e) { throw new IndexException(String.valueOf(wavelet.getWaveletId()), e); } finally { postMethod.releaseConnection(); } }
Example #2
Source File: TestCaldav.java From davmail with GNU General Public License v2.0 | 6 votes |
SearchReportMethod(String path, final byte[] content) { super(path); setRequestEntity(new RequestEntity() { public boolean isRepeatable() { return true; } public void writeRequest(OutputStream outputStream) throws IOException { outputStream.write(content); } public long getContentLength() { return content.length; } public String getContentType() { return "text/xml;charset=UTF-8"; } }); }
Example #3
Source File: GroupMgmtITCase.java From olat with Apache License 2.0 | 6 votes |
@Test public void testUpdateCourseGroup() throws IOException { final HttpClient c = loginWithCookie("administrator", "olat"); final GroupVO vo = new GroupVO(); vo.setKey(g1.getKey()); vo.setName("rest-g1-mod"); vo.setDescription("rest-g1 description"); vo.setMinParticipants(g1.getMinParticipants()); vo.setMaxParticipants(g1.getMaxParticipants()); vo.setType(g1.getType()); final String stringuifiedAuth = stringuified(vo); final RequestEntity entity = new StringRequestEntity(stringuifiedAuth, MediaType.APPLICATION_JSON, "UTF-8"); final String request = "/groups/" + g1.getKey(); final PostMethod method = createPost(request, MediaType.APPLICATION_JSON, true); method.setRequestEntity(entity); final int code = c.executeMethod(method); assertTrue(code == 200 || code == 201); final BusinessGroup bg = businessGroupService.loadBusinessGroup(g1.getKey(), false); assertNotNull(bg); assertEquals(bg.getKey(), vo.getKey()); assertEquals(bg.getName(), "rest-g1-mod"); assertEquals(bg.getDescription(), "rest-g1 description"); }
Example #4
Source File: ESBJAVA4846HttpProtocolVersionTestCase.java From product-ei with Apache License 2.0 | 6 votes |
@Test(groups = "wso2.esb", description = "Sending HTTP1.1 message") public void sendingHTTP11Message() throws Exception { PostMethod post = new PostMethod(getProxyServiceURLHttp("StockQuoteProxyTestHTTPVersion")); RequestEntity entity = new StringRequestEntity(getPayload(), "text/xml", "UTF-8"); post.setRequestEntity(entity); post.setRequestHeader("SOAPAction", "urn:getQuote"); HttpMethodParams params = new HttpMethodParams(); params.setVersion(HttpVersion.HTTP_1_1); post.setParams(params); HttpClient httpClient = new HttpClient(); String httpVersion = ""; try { httpClient.executeMethod(post); post.getResponseBodyAsString(); httpVersion = post.getStatusLine().getHttpVersion(); } finally { post.releaseConnection(); } Assert.assertEquals(httpVersion, HttpVersion.HTTP_1_1.toString(), "Http version mismatched"); }
Example #5
Source File: CourseGroupMgmtITCase.java From olat with Apache License 2.0 | 6 votes |
@Test public void testBasicSecurityPutCall() throws IOException { final HttpClient c = loginWithCookie("rest-c-g-3", "A6B7C8"); final GroupVO vo = new GroupVO(); vo.setName("hello dont put"); vo.setDescription("hello description dont put"); 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(401, code); }
Example #6
Source File: PropertyIntegrationHTTP_SCTestCase.java From product-ei with Apache License 2.0 | 6 votes |
@Test(groups = "wso2.esb", description = "Getting HTTP status code number ") public void testHttpResponseCode() throws Exception { int responseStatus = 0; String strXMLFilename = FrameworkPathUtil.getSystemResourceLocation() + "artifacts" + File.separator + "ESB" + File.separator + "mediatorconfig" + File.separator + "property" + File.separator + "GetQuoteRequest.xml"; File input = new File(strXMLFilename); PostMethod post = new PostMethod(getProxyServiceURLHttp("HTTP_SCTestProxy")); RequestEntity entity = new FileRequestEntity(input, "text/xml"); post.setRequestEntity(entity); post.setRequestHeader("SOAPAction", "getQuote"); HttpClient httpclient = new HttpClient(); try { responseStatus = httpclient.executeMethod(post); } finally { post.releaseConnection(); } assertEquals(responseStatus, 404, "Response status should be 404"); }
Example #7
Source File: CourseGroupMgmtITCase.java From olat with Apache License 2.0 | 6 votes |
@Test public void testBasicSecurityPutCall() throws IOException { final HttpClient c = loginWithCookie("rest-c-g-3", "A6B7C8"); final GroupVO vo = new GroupVO(); vo.setName("hello dont put"); vo.setDescription("hello description dont put"); 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(401, code); }
Example #8
Source File: HttpSOAPClient.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Creates the request entity that makes up the POST message body. * * @param message message to be sent * @param charset character set used for the message * * @return request entity that makes up the POST message body * * @throws SOAPClientException thrown if the message could not be marshalled */ protected RequestEntity createRequestEntity(Envelope message, Charset charset) throws SOAPClientException { try { Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(message); ByteArrayOutputStream arrayOut = new ByteArrayOutputStream(); OutputStreamWriter writer = new OutputStreamWriter(arrayOut, charset); if (log.isDebugEnabled()) { log.debug("Outbound SOAP message is:\n" + XMLHelper.prettyPrintXML(marshaller.marshall(message))); } XMLHelper.writeNode(marshaller.marshall(message), writer); return new ByteArrayRequestEntity(arrayOut.toByteArray(), "text/xml"); } catch (MarshallingException e) { throw new SOAPClientException("Unable to marshall SOAP envelope", e); } }
Example #9
Source File: ESBJAVA4846HttpProtocolVersionTestCase.java From product-ei with Apache License 2.0 | 6 votes |
@Test(groups = "wso2.esb", description = "Sending HTTP1.0 message") public void sendingHTTP10Message() throws Exception { PostMethod post = new PostMethod(getProxyServiceURLHttp("StockQuoteProxyTestHTTPVersion")); RequestEntity entity = new StringRequestEntity(getPayload(), "text/xml", "UTF-8"); post.setRequestEntity(entity); post.setRequestHeader("SOAPAction", "urn:getQuote"); HttpMethodParams params = new HttpMethodParams(); params.setVersion(HttpVersion.HTTP_1_0); post.setParams(params); HttpClient httpClient = new HttpClient(); String httpVersion = ""; try { httpClient.executeMethod(post); post.getResponseBodyAsString(); httpVersion = post.getStatusLine().getHttpVersion(); } finally { post.releaseConnection(); } Assert.assertEquals(httpVersion, HttpVersion.HTTP_1_0.toString(), "Http version mismatched"); }
Example #10
Source File: GroupMgmtITCase.java From olat with Apache License 2.0 | 6 votes |
@Test public void testUpdateCourseGroup() throws IOException { final HttpClient c = loginWithCookie("administrator", "olat"); final GroupVO vo = new GroupVO(); vo.setKey(g1.getKey()); vo.setName("rest-g1-mod"); vo.setDescription("rest-g1 description"); vo.setMinParticipants(g1.getMinParticipants()); vo.setMaxParticipants(g1.getMaxParticipants()); vo.setType(g1.getType()); final String stringuifiedAuth = stringuified(vo); final RequestEntity entity = new StringRequestEntity(stringuifiedAuth, MediaType.APPLICATION_JSON, "UTF-8"); final String request = "/groups/" + g1.getKey(); final PostMethod method = createPost(request, MediaType.APPLICATION_JSON, true); method.setRequestEntity(entity); final int code = c.executeMethod(method); assertTrue(code == 200 || code == 201); final BusinessGroup bg = businessGroupService.loadBusinessGroup(g1.getKey(), false); assertNotNull(bg); assertEquals(bg.getKey(), vo.getKey()); assertEquals(bg.getName(), "rest-g1-mod"); assertEquals(bg.getDescription(), "rest-g1 description"); }
Example #11
Source File: SolrWaveIndexerImpl.java From incubator-retired-wave with Apache License 2.0 | 6 votes |
private void postUpdateToSolr(ReadableWaveletData wavelet, JsonArray docsJson) { PostMethod postMethod = new PostMethod(solrBaseUrl + "/update/json?commit=true"); try { RequestEntity requestEntity = new StringRequestEntity(docsJson.toString(), "application/json", "UTF-8"); postMethod.setRequestEntity(requestEntity); HttpClient httpClient = new HttpClient(); int statusCode = httpClient.executeMethod(postMethod); if (statusCode != HttpStatus.SC_OK) { throw new IndexException(wavelet.getWaveId().serialise()); } } catch (IOException e) { throw new IndexException(String.valueOf(wavelet.getWaveletId()), e); } finally { postMethod.releaseConnection(); } }
Example #12
Source File: ESBJAVA4846HttpProtocolVersionTestCase.java From micro-integrator with Apache License 2.0 | 6 votes |
@Test(groups = "wso2.esb", description = "Sending HTTP1.1 message") public void sendingHTTP11Message() throws Exception { PostMethod post = new PostMethod(getProxyServiceURLHttp("StockQuoteProxyTestHTTPVersion")); RequestEntity entity = new StringRequestEntity(getPayload(), "text/xml", "UTF-8"); post.setRequestEntity(entity); post.setRequestHeader("SOAPAction", "urn:getQuote"); HttpMethodParams params = new HttpMethodParams(); params.setVersion(HttpVersion.HTTP_1_1); post.setParams(params); HttpClient httpClient = new HttpClient(); String httpVersion = ""; try { httpClient.executeMethod(post); post.getResponseBodyAsString(); httpVersion = post.getStatusLine().getHttpVersion(); } finally { post.releaseConnection(); } Assert.assertEquals(httpVersion, HttpVersion.HTTP_1_1.toString(), "Http version mismatched"); }
Example #13
Source File: PropertyIntegrationHTTP_SCTestCase.java From micro-integrator with Apache License 2.0 | 6 votes |
@Test(groups = "wso2.esb", description = "Getting HTTP status code number ") public void testHttpResponseCode() throws Exception { int responseStatus = 0; String strXMLFilename = FrameworkPathUtil.getSystemResourceLocation() + "artifacts" + File.separator + "ESB" + File.separator + "mediatorconfig" + File.separator + "property" + File.separator + "GetQuoteRequest.xml"; File input = new File(strXMLFilename); PostMethod post = new PostMethod(getProxyServiceURLHttp("HTTP_SCTestProxy")); RequestEntity entity = new FileRequestEntity(input, "text/xml"); post.setRequestEntity(entity); post.setRequestHeader("SOAPAction", "getQuote"); HttpClient httpclient = new HttpClient(); try { responseStatus = httpclient.executeMethod(post); } finally { post.releaseConnection(); } assertEquals(responseStatus, 404, "Response status should be 404"); }
Example #14
Source File: PropertyIntegrationForceSCAcceptedPropertyTestCase.java From micro-integrator with Apache License 2.0 | 6 votes |
@Test(groups = "wso2.esb", description = "Testing functionality of FORCE_SC_ACCEPTED " + "Enabled True - " + "Client should receive 202 message", dependsOnMethods = "testFORCE_SC_ACCEPTEDPropertyEnabledFalseScenario") public void testWithFORCE_SC_ACCEPTEDPropertyEnabledTrueScenario() throws Exception { int responseStatus = 0; String strXMLFilename = FrameworkPathUtil.getSystemResourceLocation() + "artifacts" + File.separator + "ESB" + File.separator + "mediatorconfig" + File.separator + "property" + File.separator + "PlaceOrder.xml"; File input = new File(strXMLFilename); PostMethod post = new PostMethod(getProxyServiceURLHttp("FORCE_SC_ACCEPTED_TrueTestProxy")); RequestEntity entity = new FileRequestEntity(input, "text/xml"); post.setRequestEntity(entity); post.setRequestHeader("SOAPAction", "placeOrder"); HttpClient httpclient = new HttpClient(); try { responseStatus = httpclient.executeMethod(post); } finally { post.releaseConnection(); } assertEquals(responseStatus, 202, "Response status should be 202"); }
Example #15
Source File: PropertyIntegrationForceSCAcceptedPropertyTestCase.java From micro-integrator with Apache License 2.0 | 6 votes |
@Test(groups = "wso2.esb", description = "Testing functionality of FORCE_SC_ACCEPTED " + "- Enabled False") public void testFORCE_SC_ACCEPTEDPropertyEnabledFalseScenario() throws Exception { int responseStatus = 0; String strXMLFilename = FrameworkPathUtil.getSystemResourceLocation() + "artifacts" + File.separator + "ESB" + File.separator + "mediatorconfig" + File.separator + "property" + File.separator + "GetQuoteRequest.xml"; File input = new File(strXMLFilename); PostMethod post = new PostMethod(getProxyServiceURLHttp("FORCE_SC_ACCEPTED_FalseTestProxy")); RequestEntity entity = new FileRequestEntity(input, "text/xml"); post.setRequestEntity(entity); post.setRequestHeader("SOAPAction", "getQuote"); HttpClient httpclient = new HttpClient(); try { responseStatus = httpclient.executeMethod(post); } finally { post.releaseConnection(); } assertEquals(responseStatus, 200, "Response status should be 200"); }
Example #16
Source File: CrucibleSessionImpl.java From Crucible4IDEA with MIT License | 6 votes |
protected JsonObject buildJsonResponseForPost(@NotNull final String urlString, @NotNull final RequestEntity requestEntity) throws IOException { final PostMethod method = new PostMethod(urlString); method.setRequestEntity(requestEntity); executeHttpMethod(method); final String response = method.getResponseBodyAsString(); try { return JsonParser.parseString(response).getAsJsonObject(); } catch (JsonSyntaxException ex) { LOG.error("Malformed Json"); LOG.error(response); } return new JsonObject(); }
Example #17
Source File: RestConsumer.java From RestServices with Apache License 2.0 | 5 votes |
private static RequestEntity buildMultiPartEntity(final IContext context, final IMendixObject source, Map<String, String> params) throws IOException, CoreException { // MWE: don't set contenttype to CONTENTTYPE_MULTIPART; this will be // done by the request entity and add the boundaries List<Part> parts = Lists.newArrayList(); // This object self could be a filedocument if (Core.isSubClassOf(FileDocument.entityName, source.getType())) { String partName = getFileDocumentFileName(context, source); if (partName == null || partName.isEmpty()) throw new IllegalArgumentException("The filename of a System.FileDocument in a multipart request should reflect the part name and cannot be empty"); addFilePart(context, partName, source, parts); } // .. or one of its children could be a filedocument. This way multiple // file parts, or specifically named file parts can be send for (String name : getAssociationsReferingToFileDocs(source .getMetaObject())) { IMendixIdentifier subObject = (IMendixIdentifier) source.getValue( context, name); params.remove(Utils.getShortMemberName(name)); if (subObject != null) { addFilePart(context, Utils.getShortMemberName(name), Core.retrieveId(context, subObject), parts); } } // serialize any other members as 'normal' key value pairs for (Entry<String, String> e : params.entrySet()) { parts.add(new StringPart(e.getKey(), e.getValue(), RestServices.UTF8)); } params.clear(); return new MultipartRequestEntity(parts.toArray(new Part[0]), new HttpMethodParams()); }
Example #18
Source File: HttpClient3EntityExtractor.java From pinpoint with Apache License 2.0 | 5 votes |
@Override public String getEntity(HttpMethod httpMethod) { if (httpMethod instanceof EntityEnclosingMethod) { final EntityEnclosingMethod entityEnclosingMethod = (EntityEnclosingMethod) httpMethod; final RequestEntity entity = entityEnclosingMethod.getRequestEntity(); if (entity != null && entity.isRepeatable() && entity.getContentLength() > 0) { try { String entityValue; String charSet = entityEnclosingMethod.getRequestCharSet(); if (StringUtils.isEmpty(charSet)) { charSet = HttpConstants.DEFAULT_CONTENT_CHARSET; } if (entity instanceof ByteArrayRequestEntity || entity instanceof StringRequestEntity) { entityValue = entityUtilsToString(entity, charSet); } else { entityValue = entity.getClass() + " (ContentType:" + entity.getContentType() + ")"; } return entityValue; } catch (Exception e) { if (isDebug) { logger.debug("Failed to get entity. httpMethod={}", httpMethod, e); } } } } return null; }
Example #19
Source File: HttpClient3EntityExtractor.java From pinpoint with Apache License 2.0 | 5 votes |
private static String entityUtilsToString(final RequestEntity entity, final String charSet) throws Exception { final FixedByteArrayOutputStream outStream = new FixedByteArrayOutputStream(MAX_READ_SIZE); entity.writeRequest(outStream); final String entityValue = outStream.toString(charSet); if (entity.getContentLength() > MAX_READ_SIZE) { StringBuilder sb = new StringBuilder(); sb.append(entityValue); sb.append(" (HTTP entity is large. length: "); sb.append(entity.getContentLength()); sb.append(" )"); return sb.toString(); } return entityValue; }
Example #20
Source File: CrucibleApi.java From Crucible4IDEA with MIT License | 5 votes |
public static RequestEntity createCommentRequest(@NotNull Comment comment, boolean isGeneral) throws UnsupportedEncodingException { BaseComment raw; if (isGeneral) { raw = new GeneralComment(); } else if (comment.getParentCommentId() != null) { raw = new ReplyComment(); } else { raw = new TopLevelComment(); } raw.message = comment.getMessage(); raw.draft = comment.isDraft(); raw.deleted = false; raw.defectRaised = false; if (!isGeneral && comment.getParentCommentId() == null) { raw.reviewItemId = new IdHolder(comment.getReviewItemId()); raw.toLineRange = comment.getLine(); } if (comment.getParentCommentId() != null) { raw.parentCommentId = new IdHolder(comment.getParentCommentId()); } String requestString = gson.toJson(raw); return new StringRequestEntity(requestString, "application/json", "UTF-8"); }
Example #21
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 #22
Source File: CourseGroupMgmtITCase.java From olat with Apache License 2.0 | 5 votes |
@Test public void testUpdateCourseGroup() throws IOException { final HttpClient c = loginWithCookie("administrator", "olat"); final GroupVO vo = new GroupVO(); vo.setKey(g1.getKey()); vo.setName("rest-g1-mod"); vo.setDescription("rest-g1 description"); vo.setMinParticipants(g1.getMinParticipants()); vo.setMaxParticipants(g1.getMaxParticipants()); vo.setType(g1.getType()); final String stringuifiedAuth = stringuified(vo); final RequestEntity entity = new StringRequestEntity(stringuifiedAuth, MediaType.APPLICATION_JSON, "UTF-8"); final String request = "/repo/courses/" + course.getResourceableId() + "/groups/" + g1.getKey(); final PostMethod method = createPost(request, MediaType.APPLICATION_JSON, true); method.setRequestEntity(entity); final int code = c.executeMethod(method); method.releaseConnection(); assertTrue(code == 200 || code == 201); final BusinessGroup bg = businessGroupService.loadBusinessGroup(g1.getKey(), false); assertNotNull(bg); assertEquals(bg.getKey(), vo.getKey()); assertEquals("rest-g1-mod", bg.getName()); assertEquals("rest-g1 description", bg.getDescription()); }
Example #23
Source File: CatalogITCase.java From olat with Apache License 2.0 | 5 votes |
@Test public void testUpdateCatalogEntryJson() throws IOException { final HttpClient c = loginWithCookie("administrator", "olat"); final CatalogEntryVO entry = new CatalogEntryVO(); entry.setName("Entry-1-b"); entry.setDescription("Entry-description-1-b"); entry.setType(CatalogEntry.TYPE_NODE); final String entity = stringuified(entry); final URI uri = UriBuilder.fromUri(getContextURI()).path("catalog").path(entry1.getKey().toString()).build(); final PostMethod method = createPost(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 CatalogEntry updatedEntry = catalogService.loadCatalogEntry(entry1); assertEquals("Entry-1-b", updatedEntry.getName()); assertEquals("Entry-description-1-b", updatedEntry.getDescription()); }
Example #24
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 #25
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 #26
Source File: CourseGroupMgmtITCase.java From olat with Apache License 2.0 | 5 votes |
@Test public void testUpdateCourseGroup() throws IOException { final HttpClient c = loginWithCookie("administrator", "olat"); final GroupVO vo = new GroupVO(); vo.setKey(g1.getKey()); vo.setName("rest-g1-mod"); vo.setDescription("rest-g1 description"); vo.setMinParticipants(g1.getMinParticipants()); vo.setMaxParticipants(g1.getMaxParticipants()); vo.setType(g1.getType()); final String stringuifiedAuth = stringuified(vo); final RequestEntity entity = new StringRequestEntity(stringuifiedAuth, MediaType.APPLICATION_JSON, "UTF-8"); final String request = "/repo/courses/" + course.getResourceableId() + "/groups/" + g1.getKey(); final PostMethod method = createPost(request, MediaType.APPLICATION_JSON, true); method.setRequestEntity(entity); final int code = c.executeMethod(method); method.releaseConnection(); assertTrue(code == 200 || code == 201); final BusinessGroup bg = businessGroupService.loadBusinessGroup(g1.getKey(), false); assertNotNull(bg); assertEquals(bg.getKey(), vo.getKey()); assertEquals("rest-g1-mod", bg.getName()); assertEquals("rest-g1 description", bg.getDescription()); }
Example #27
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 #28
Source File: UserMgmtITCase.java From olat with Apache License 2.0 | 5 votes |
@Test public void testCreateUserWithValidationError() throws IOException { final HttpClient c = loginWithCookie("administrator", "olat"); final UserVO vo = new UserVO(); vo.setLogin("rest-809"); vo.setFirstName("John"); vo.setLastName("Smith"); vo.setEmail(""); vo.putProperty("gender", "lu"); 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); final int code = c.executeMethod(method); assertTrue(code == 406); final String body = method.getResponseBodyAsString(); method.releaseConnection(); final List<ErrorVO> errors = parseErrorArray(body); assertNotNull(errors); assertFalse(errors.isEmpty()); assertTrue(errors.size() >= 2); assertNotNull(errors.get(0).getCode()); assertNotNull(errors.get(0).getTranslation()); assertNotNull(errors.get(1).getCode()); assertNotNull(errors.get(1).getTranslation()); final Identity savedIdent = securityManager.findIdentityByName("rest-809"); assertNull(savedIdent); }
Example #29
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 #30
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)); }