Refine search
@Override @Get public Representation get() { final String opt = (String) getRequest().getAttributes().get("opt"); if ("disable_autobalancing".equalsIgnoreCase(opt)) { _helixMirrorMakerManager.disableAutoBalancing(); LOGGER.info("Disabled autobalancing!"); return new StringRepresentation("Disabled autobalancing!\n"); } else if ("enable_autobalancing".equalsIgnoreCase(opt)) { _helixMirrorMakerManager.enableAutoBalancing(); LOGGER.info("Enabled autobalancing!"); return new StringRepresentation("Enabled autobalancing!\n"); } LOGGER.info("No valid input!"); return new StringRepresentation("No valid input!\n"); }
@Get public Representation represent() { StringRepresentation sr = new StringRepresentation("xml string.."); sr.setMediaType(MediaType.APPLICATION_XML); return sr; }
/** * Updates the expected size according to the current string value. */ protected void updateSize() { if (getText() != null) { try { if (getCharacterSet() != null) { setSize(getText().getBytes(getCharacterSet().getName()).length); } else { setSize(getText().getBytes().length); } } catch (UnsupportedEncodingException e) { Context.getCurrentLogger().log(Level.WARNING, "Unable to update size", e); setSize(UNKNOWN_SIZE); } } else { setSize(UNKNOWN_SIZE); } }
/** * Constructor. * * @param text * The string value. * @param mediaType * The media type. * @param language * The language. * @param characterSet * The character set. */ public StringRepresentation(CharSequence text, MediaType mediaType, Language language, CharacterSet characterSet) { super(mediaType); setMediaType(mediaType); if (language != null) { getLanguages().add(language); } setCharacterSet(characterSet); setText(text); }
@Override public InputStream getStream() throws IOException { CharacterSet charset = getCharacterSet() == null ? CharacterSet.ISO_8859_1 : getCharacterSet(); ByteArrayInputStream result = new ByteArrayInputStream(getText() .getBytes(charset.getName())); return result; }
@Override protected Representation get(Variant variant) { TreeWriter tree = new TreeWriter(getGlobalRuntime()); tree.startDocument(URI.create("http://example.com/")); tree.addStartElement(pr_pipelines); tree.startContent(); for (String id : getPipelines().keySet()) { PipelineConfiguration pipeconfig = getPipelines().get(id); tree.addStartElement(pr_pipeline); tree.startContent(); tree.addStartElement(pr_uri); tree.startContent(); tree.addText(pipelineUri(id)); tree.addEndElement(); tree.addStartElement(pr_has_run); tree.startContent(); tree.addText("" + pipeconfig.ran); tree.addEndElement(); formatExpires(tree, pipeconfig.expires); tree.addEndElement(); } tree.addEndElement(); tree.endDocument(); return new StringRepresentation(serialize(tree.getResult(), variant.getMediaType()), variant.getMediaType()); }
/** * Handle POST requests: create a new item. */ @Post public Representation acceptItem(Representation entity) { Representation result = null; // Parse the given representation and retrieve pairs of // "name=value" tokens. Form form = new Form(entity); String itemName = form.getFirstValue("name"); String itemDescription = form.getFirstValue("description"); // Register the new item if one is not already registered. if (!getItems().containsKey(itemName) && getItems().putIfAbsent(itemName, new Item(itemName, itemDescription)) == null) { // Set the response's status and entity setStatus(Status.SUCCESS_CREATED); Representation rep = new StringRepresentation("Item created", MediaType.TEXT_PLAIN); // Indicates where is located the new resource. rep.setLocationRef(getRequest().getResourceRef().getIdentifier() + "/" + itemName); result = rep; } else { // Item is already registered. setStatus(Status.CLIENT_ERROR_NOT_FOUND); result = generateErrorRepresentation("Item " + itemName + " already exists.", "1"); } return result; }
@Override @Get public Representation get() { return new StringRepresentation("OK"); }
ClientResource cr = new ClientResource("http://<same-domain>/war2-rootpath/dateformatter"); Representation repr = cr.put(new StringRepresentation(...)); StringRepresentation sRepr = new StringRepresentation(repr); String returnedText = sRepr.getText();
@Override public String toString() { return getText(); }
StringRepresentation sr = new StringRepresentation(form.toString()); sr.setCharacterSet(CharacterSet.UTF_8);
@Override protected Representation get(Variant variant) { TreeWriter tree = new TreeWriter(getGlobalRuntime()); tree.startDocument(URI.create("http://example.com/")); tree.addStartElement(pr_pipelines); tree.startContent(); for (String id : getPipelines().keySet()) { PipelineConfiguration pipeconfig = getPipelines().get(id); tree.addStartElement(pr_pipeline); tree.startContent(); tree.addStartElement(pr_uri); tree.startContent(); tree.addText(pipelineUri(id)); tree.addEndElement(); tree.addStartElement(pr_has_run); tree.startContent(); tree.addText("" + pipeconfig.ran); tree.addEndElement(); formatExpires(tree, pipeconfig.expires); tree.addEndElement(); } tree.addEndElement(); tree.endDocument(); return new StringRepresentation(serialize(tree.getResult(), variant.getMediaType()), variant.getMediaType()); }
/** * Handle POST requests: create a new item. */ @Post public Representation acceptItem(Representation entity) { Representation result = null; // Parse the given representation and retrieve pairs of // "name=value" tokens. Form form = new Form(entity); String itemName = form.getFirstValue("name"); String itemDescription = form.getFirstValue("description"); // Register the new item if one is not already registered. if (!getItems().containsKey(itemName) && getItems().putIfAbsent(itemName, new Item(itemName, itemDescription)) == null) { // Set the response's status and entity setStatus(Status.SUCCESS_CREATED); Representation rep = new StringRepresentation("Item created", MediaType.TEXT_PLAIN); // Indicates where is located the new resource. rep.setLocationRef(getRequest().getResourceRef().getIdentifier() + "/" + itemName); result = rep; } else { // Item is already registered. setStatus(Status.CLIENT_ERROR_NOT_FOUND); result = generateErrorRepresentation("Item " + itemName + " already exists.", "1"); } return result; }
@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)); } }
/** * Constructor. * * @param text * The string value. * @param mediaType * The media type. * @param language * The language. * @param characterSet * The character set. */ public StringRepresentation(CharSequence text, MediaType mediaType, Language language, CharacterSet characterSet) { super(mediaType); setMediaType(mediaType); if (language != null) { getLanguages().add(language); } setCharacterSet(characterSet); setText(text); }
@Override public String toString() { return getText(); }
@Override public InputStream getStream() throws IOException { CharacterSet charset = getCharacterSet() == null ? CharacterSet.ISO_8859_1 : getCharacterSet(); ByteArrayInputStream result = new ByteArrayInputStream(getText() .getBytes(charset.getName())); return result; }
@Override @Get public Representation get() { final String option = (String) getRequest().getAttributes().get("option"); if ("srcKafka".equals(option)) { if (_srcKafkaValidationManager == null) { LOGGER.warn("SourceKafkaClusterValidationManager is null!"); return new StringRepresentation("SrcKafkaValidationManager is not been initialized!"); } LOGGER.info("Trying to call validation on source kafka cluster!"); return new StringRepresentation(_srcKafkaValidationManager.validateSourceKafkaCluster()); } else { LOGGER.info("Trying to call validation on current cluster!"); return new StringRepresentation(_validationManager.validateExternalView()); } }
idealState.append(new StringRepresentation(resultList.toJSONString())); partitionAssignment.append(new StringRepresentation(resultList.toJSONString()));
/** * Returns the representation of the given error. The format of the JSON * document is according to 5.2. Error Response. * * @param ex * Any OAuthException with error * @return The representation of the given error. */ public static Representation responseErrorRepresentation(OAuthException ex) { try { return new JsonRepresentation(ex.createErrorDocument()); } catch (JSONException e) { StringRepresentation r = new StringRepresentation( "{\"error\":\"server_error\",\"error_description:\":\"" + e.getLocalizedMessage() + "\"}"); r.setMediaType(MediaType.APPLICATION_JSON); return r; } }