@Override @Put("json") public Representation put(Representation entity) { try { String jsonRequest = entity.getText(); TopicPartition topicPartitionInfo = TopicPartition.init(jsonRequest); if (_autoTopicWhitelistingManager != null) { _autoTopicWhitelistingManager.removeFromBlacklist(topicPartitionInfo.getTopic()); } if (_helixMirrorMakerManager.isTopicExisted(topicPartitionInfo.getTopic())) { _helixMirrorMakerManager.expandTopicInMirrorMaker(topicPartitionInfo); return new StringRepresentation( String.format("Successfully expand topic: %s", topicPartitionInfo)); } else { getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND); return new StringRepresentation(String.format( "Failed to expand topic, topic: %s is not existed!", topicPartitionInfo.getTopic())); } } catch (IOException e) { LOGGER.error("Got error during processing Put request", e); getResponse().setStatus(Status.SERVER_ERROR_INTERNAL); return new StringRepresentation( String.format("Failed to expand topic, with exception: %s", e)); } }
try { final String topicName = (String) getRequest().getAttributes().get("topicName"); String jsonRequest = entity.getText(); TopicPartition topicPartitionInfo = null; if ((jsonRequest == null || jsonRequest.isEmpty()) && topicName != null
Representation repr = request.getEntity(); String content = repr.getText();
/** * Appends the representation to an appendable sequence of characters. This * method is ensured to write the full content for each invocation unless it * is a transient representation, in which case an exception is thrown.<br> * <br> * Note that {@link #getText()} is used by the default implementation. * * @param appendable * The appendable sequence of characters. * @throws IOException */ public void append(Appendable appendable) throws IOException { appendable.append(getText()); }
@Post("json") public Representation registerNumber(Representation entity) { System.out.println("JsonRepresentation : " + entity); String postContent; try { postContent = entity.getText(); System.out.println("POST Content : " + postContent); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
public RequestParametersJson(Representation request) throws IOException { super(); injectJsonParams(request.getText()); }
@Override public String getText() throws IOException { return getWrappedRepresentation().getText(); }
ClientResource cr = new ClientResource("http://whois.arin.net/rest/poc/KOSTE-ARIN"); Representation repr = cr.get(); // Display the XML content System.out.println(repr.getText());
ClientResource cr = new ClientResource("http://whois.arin.net/rest/poc/KOSTE-ARIN.txt"); Representation repr = cr.get(); // Display the text content System.out.println(repr.getText());
Representation entity = new ClientResource("your url").get(); JsonRepresentation jsonRepresentation = new JsonRepresentation(entity.getText()); JSONObject jsonObject = jsonRepresentation.getJsonObject();
ClientResource cr = new ClientResource("http://localhost:8888/users"); cr.setRequestEntityBuffering(true); Representation representation = cr.get(MediaType.APPLICATION_JSON); String jsonContentAsString = representation.getText();
@Override public String getText() throws IOException { if (canEncode()) { return IoUtils.toString(getStream(), getCharacterSet()); } else { return getWrappedRepresentation().getText(); } }
/** * Converts the representation to a string value. Be careful when using this * method as the conversion of large content to a string fully stored in * memory can result in OutOfMemoryErrors being thrown. * * @return The representation as a string value. */ @Override public String getText() throws IOException { if (isDecoding()) { return IoUtils.toString(getStream(), getCharacterSet()); } else { return getWrappedRepresentation().getText(); } }
@Test public void testGetAuditLogAuthenticatedAdminRdfJson() throws Exception { final ClientResource creationClientResource = new ClientResource(this.getUrl(this.propertyUtil.get(OasProps.PROP_AUDITLOG_PATH, OasProps.DEF_AUDITLOG_PATH))); final Representation results = RestletTestUtils.doTestAuthenticatedRequest(creationClientResource, Method.GET, null, RestletUtilMediaType.APPLICATION_RDF_JSON, Status.SUCCESS_OK, this.testWithAdminPrivileges); final String result = results.getText(); this.assertFreemarker(result); this.log.error(result); final Model model = this.assertRdf(new StringReader(result), RDFFormat.RDFJSON, 15); }
@Test public void testGetHelpNavigationExplicit() throws Exception { final ClientResource creationClientResource = new ClientResource(this.getUrl( this.propertyUtil.get(OasProps.PROP_HELP_SUBPAGE_PATH, OasProps.DEF_HELP_SUBPAGE_PATH)) .replace("{page}", "navigation")); final Representation representation = creationClientResource.get(); final String result = representation.getText(); // Assert.assertTrue( // "Did not find index page message", // result.contains("Provides ontology management and annotations services to researchers wishing to link to the Semantic Web")); this.assertFreemarker(result); }
@Test public void testGetHelpLogin() throws Exception { final ClientResource creationClientResource = new ClientResource(this.getUrl( this.propertyUtil.get(OasProps.PROP_HELP_SUBPAGE_PATH, OasProps.DEF_HELP_SUBPAGE_PATH)) .replace("{page}", "login")); final Representation representation = creationClientResource.get(); final String result = representation.getText(); // Assert.assertTrue( // "Did not find index page message", // result.contains("Provides ontology management and annotations services to researchers wishing to link to the Semantic Web")); this.assertFreemarker(result); }
@Test public void testGetHelpNavigationImplicit() throws Exception { final ClientResource creationClientResource = new ClientResource(this.getUrl( this.propertyUtil.get(OasProps.PROP_HELP_SUBPAGE_PATH, OasProps.DEF_HELP_SUBPAGE_PATH)) .replace("{page}", "")); final Representation representation = creationClientResource.get(); final String result = representation.getText(); // Assert.assertTrue( // "Did not find index page message", // result.contains("Provides ontology management and annotations services to researchers wishing to link to the Semantic Web")); this.assertFreemarker(result); }
@Test public void testGetAuditLogAuthenticatedAdminRdfXml() throws Exception { final ClientResource creationClientResource = new ClientResource(this.getUrl(this.propertyUtil.get(OasProps.PROP_AUDITLOG_PATH, OasProps.DEF_AUDITLOG_PATH))); final Representation results = RestletTestUtils.doTestAuthenticatedRequest(creationClientResource, Method.GET, null, MediaType.APPLICATION_RDF_XML, Status.SUCCESS_OK, this.testWithAdminPrivileges); final String result = results.getText(); this.assertFreemarker(result); final Model model = this.assertRdf(new StringReader(result), RDFFormat.RDFXML, 15); }
@Test public void testGetAuditLogAuthenticatedAdminTurtle() throws Exception { final ClientResource creationClientResource = new ClientResource(this.getUrl(this.propertyUtil.get(OasProps.PROP_AUDITLOG_PATH, OasProps.DEF_AUDITLOG_PATH))); final Representation results = RestletTestUtils.doTestAuthenticatedRequest(creationClientResource, Method.GET, null, MediaType.APPLICATION_RDF_TURTLE, Status.SUCCESS_OK, this.testWithAdminPrivileges); final String result = results.getText(); this.assertFreemarker(result); final Model model = this.assertRdf(new StringReader(result), RDFFormat.TURTLE, 15); }
@Test public void testGetIndexBasicUnauthenticated() throws Exception { final ClientResource creationClientResource = new ClientResource( this.getUrl(this.propertyUtil.get(OasProps.PROP_INDEX_PATH, OasProps.DEF_INDEX_PATH))); final Representation representation = creationClientResource.get(); final String result = representation.getText(); Assert.assertTrue( "Did not find index page message", result.contains("Provides ontology management and annotations services to researchers wishing to link to the Semantic Web")); this.assertFreemarker(result); } }