Java Code Examples for org.restlet.data.MediaType#APPLICATION_JSON
The following examples show how to use
org.restlet.data.MediaType#APPLICATION_JSON .
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: StatusUpdateResource.java From helix with Apache License 2.0 | 6 votes |
StringRepresentation getInstanceStatusUpdateRepresentation(String clusterName, String instanceName, String resourceGroup) throws JsonGenerationException, JsonMappingException, IOException { ZkClient zkClient = (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT); String instanceSessionId = ClusterRepresentationUtil.getInstanceSessionId(zkClient, clusterName, instanceName); Builder keyBuilder = new PropertyKey.Builder(clusterName); String message = ClusterRepresentationUtil.getInstancePropertiesAsString(zkClient, clusterName, keyBuilder.stateTransitionStatus(instanceName, instanceSessionId, resourceGroup), // instanceSessionId // + "__" // + resourceGroup, MediaType.APPLICATION_JSON); StringRepresentation representation = new StringRepresentation(message, MediaType.APPLICATION_JSON); return representation; }
Example 2
Source File: ClustersResource.java From helix with Apache License 2.0 | 6 votes |
StringRepresentation getClustersRepresentation() throws JsonGenerationException, JsonMappingException, IOException { ZkClient zkClient = ResourceUtil.getAttributeFromCtx(getContext(), ResourceUtil.ContextKey.ZKCLIENT); ClusterSetup setupTool = new ClusterSetup(zkClient); List<String> clusters = setupTool.getClusterManagementTool().getClusters(); ZNRecord clustersRecord = new ZNRecord("Clusters Summary"); clustersRecord.setListField("clusters", clusters); StringRepresentation representation = new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(clustersRecord), MediaType.APPLICATION_JSON); return representation; }
Example 3
Source File: CurrentStatesResource.java From helix with Apache License 2.0 | 6 votes |
StringRepresentation getInstanceCurrentStatesRepresentation(String clusterName, String instanceName) throws JsonGenerationException, JsonMappingException, IOException { ZkClient zkClient = (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT); ; String instanceSessionId = ClusterRepresentationUtil.getInstanceSessionId(zkClient, clusterName, instanceName); String message = ClusterRepresentationUtil .getInstancePropertyNameListAsString(zkClient, clusterName, instanceName, PropertyType.CURRENTSTATES, instanceSessionId, MediaType.APPLICATION_JSON); StringRepresentation representation = new StringRepresentation(message, MediaType.APPLICATION_JSON); return representation; }
Example 4
Source File: DefaultResponseWriter.java From attic-polygene-java with Apache License 2.0 | 6 votes |
@Override public boolean writeResponse( final Object result, final Response response ) throws ResourceException { MediaType type = getVariant( response.getRequest(), ENGLISH, supportedMediaTypes ).getMediaType(); if( MediaType.APPLICATION_JSON.equals( type ) ) { if( result instanceof String || result instanceof Number || result instanceof Boolean ) { StringRepresentation representation = new StringRepresentation( result.toString(), MediaType.APPLICATION_JSON ); response.setEntity( representation ); return true; } } return false; }
Example 5
Source File: EntitiesResource.java From attic-polygene-java with Apache License 2.0 | 6 votes |
private Representation representJson() throws ResourceException { try { final Iterable<EntityReference> query = entityFinder.findEntities( EntityComposite.class, null, null, null, null, Collections.emptyMap() ) .collect( toList() ); return new OutputRepresentation( MediaType.APPLICATION_JSON ) { @Override public void write( OutputStream outputStream ) throws IOException { stateSerialization.serialize( new OutputStreamWriter( outputStream ), query ); } }; } catch( Exception e ) { throw new ResourceException( e ); } }
Example 6
Source File: CurrentStateResource.java From helix with Apache License 2.0 | 6 votes |
StringRepresentation getInstanceCurrentStateRepresentation(String clusterName, String instanceName, String resourceGroup) throws JsonGenerationException, JsonMappingException, IOException { ZkClient zkClient = (ZkClient) getRequest().getAttributes().get(RestAdminApplication.ZKCLIENT); String instanceSessionId = ClusterRepresentationUtil.getInstanceSessionId(zkClient, clusterName, instanceName); Builder keyBuilder = new PropertyKey.Builder(clusterName); String message = ClusterRepresentationUtil.getInstancePropertyAsString(zkClient, clusterName, keyBuilder.currentState(instanceName, instanceSessionId, resourceGroup), MediaType.APPLICATION_JSON); StringRepresentation representation = new StringRepresentation(message, MediaType.APPLICATION_JSON); return representation; }
Example 7
Source File: StateModelsResource.java From helix with Apache License 2.0 | 6 votes |
StringRepresentation getStateModelsRepresentation() throws JsonGenerationException, JsonMappingException, IOException { String clusterName = (String) getRequest().getAttributes().get("clusterName"); ZkClient zkClient = (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT); ClusterSetup setupTool = new ClusterSetup(zkClient); List<String> models = setupTool.getClusterManagementTool().getStateModelDefs(clusterName); ZNRecord modelDefinitions = new ZNRecord("modelDefinitions"); modelDefinitions.setListField("models", models); StringRepresentation representation = new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(modelDefinitions), MediaType.APPLICATION_JSON); return representation; }
Example 8
Source File: SwaggerResource.java From geowave with Apache License 2.0 | 6 votes |
/** This resource returns the swagger.json */ @Get("json") public String listResources() { final ServletContext servlet = (ServletContext) getContext().getAttributes().get("org.restlet.ext.servlet.ServletContext"); final String realPath = servlet.getRealPath("/"); final JacksonRepresentation<ApiDeclaration> result = new JacksonRepresentation<>( new FileRepresentation(realPath + "swagger.json", MediaType.APPLICATION_JSON), ApiDeclaration.class); try { return result.getText(); } catch (final IOException e) { LOGGER.warn("Error building swagger json", e); } return "Not Found: swagger.json"; }
Example 9
Source File: ResourceGroupResource.java From helix with Apache License 2.0 | 5 votes |
StringRepresentation getIdealStateRepresentation(String clusterName, String resourceName) throws JsonGenerationException, JsonMappingException, IOException { Builder keyBuilder = new PropertyKey.Builder(clusterName); ZkClient zkclient = ResourceUtil.getAttributeFromCtx(getContext(), ResourceUtil.ContextKey.RAW_ZKCLIENT); String idealStateStr = ResourceUtil.readZkAsBytes(zkclient, keyBuilder.idealStates(resourceName)); StringRepresentation representation = new StringRepresentation(idealStateStr, MediaType.APPLICATION_JSON); return representation; }
Example 10
Source File: StateModelResource.java From helix with Apache License 2.0 | 5 votes |
StringRepresentation getStateModelRepresentation(String clusterName, String modelName) throws JsonGenerationException, JsonMappingException, IOException { Builder keyBuilder = new PropertyKey.Builder(clusterName); ZkClient zkClient = (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT); String message = ClusterRepresentationUtil.getClusterPropertyAsString(zkClient, clusterName, keyBuilder.stateModelDef(modelName), MediaType.APPLICATION_JSON); StringRepresentation representation = new StringRepresentation(message, MediaType.APPLICATION_JSON); return representation; }
Example 11
Source File: EntityResource.java From attic-polygene-java with Apache License 2.0 | 5 votes |
private Representation representJson( EntityState entityState ) { // TODO This guy needs to represent an Entity as JSON if( entityState instanceof JSONEntityState ) { JSONEntityState jsonState = (JSONEntityState) entityState; return new StringRepresentation( jsonState.state().toString(), MediaType.APPLICATION_JSON ); } else { throw new ResourceException( Status.CLIENT_ERROR_NOT_ACCEPTABLE ); } }
Example 12
Source File: ControllerResource.java From helix with Apache License 2.0 | 5 votes |
StringRepresentation getControllerRepresentation(String clusterName) throws JsonGenerationException, JsonMappingException, IOException { Builder keyBuilder = new PropertyKey.Builder(clusterName); ZkClient zkClient = ResourceUtil.getAttributeFromCtx(getContext(), ResourceUtil.ContextKey.ZKCLIENT); ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(zkClient)); ZNRecord record = null; LiveInstance leader = accessor.getProperty(keyBuilder.controllerLeader()); if (leader != null) { record = leader.getRecord(); } else { record = new ZNRecord(""); DateFormat formatter = new SimpleDateFormat("yyyyMMdd-HHmmss.SSSSSS"); String time = formatter.format(new Date()); Map<String, String> contentMap = new TreeMap<String, String>(); contentMap.put("AdditionalInfo", "No leader exists"); record.setMapField(Level.HELIX_INFO + "-" + time, contentMap); } boolean paused = (accessor.getProperty(keyBuilder.pause()) == null ? false : true); record.setSimpleField(PropertyType.PAUSE.toString(), "" + paused); String retVal = ClusterRepresentationUtil.ZNRecordToJson(record); StringRepresentation representation = new StringRepresentation(retVal, MediaType.APPLICATION_JSON); return representation; }
Example 13
Source File: ClusterResource.java From helix with Apache License 2.0 | 5 votes |
StringRepresentation getClusterRepresentation(String clusterName) throws JsonGenerationException, JsonMappingException, IOException { ZkClient zkClient = ResourceUtil.getAttributeFromCtx(getContext(), ResourceUtil.ContextKey.ZKCLIENT); ClusterSetup setupTool = new ClusterSetup(zkClient); List<String> instances = setupTool.getClusterManagementTool().getInstancesInCluster(clusterName); ZNRecord clusterSummayRecord = new ZNRecord("Cluster Summary"); clusterSummayRecord.setListField("participants", instances); List<String> resources = setupTool.getClusterManagementTool().getResourcesInCluster(clusterName); clusterSummayRecord.setListField("resources", resources); List<String> models = setupTool.getClusterManagementTool().getStateModelDefs(clusterName); clusterSummayRecord.setListField("stateModelDefs", models); HelixDataAccessor accessor = ClusterRepresentationUtil.getClusterDataAccessor(zkClient, clusterName); Builder keyBuilder = accessor.keyBuilder(); LiveInstance leader = accessor.getProperty(keyBuilder.controllerLeader()); if (leader != null) { clusterSummayRecord.setSimpleField("LEADER", leader.getInstanceName()); } else { clusterSummayRecord.setSimpleField("LEADER", ""); } StringRepresentation representation = new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(clusterSummayRecord), MediaType.APPLICATION_JSON); return representation; }
Example 14
Source File: ExternalViewResource.java From helix with Apache License 2.0 | 5 votes |
StringRepresentation getExternalViewRepresentation(String clusterName, String resourceName) throws JsonGenerationException, JsonMappingException, IOException { Builder keyBuilder = new PropertyKey.Builder(clusterName); ZkClient zkclient = ResourceUtil.getAttributeFromCtx(getContext(), ResourceUtil.ContextKey.RAW_ZKCLIENT); String extViewStr = ResourceUtil.readZkAsBytes(zkclient, keyBuilder.externalView(resourceName)); StringRepresentation representation = new StringRepresentation(extViewStr, MediaType.APPLICATION_JSON); return representation; }
Example 15
Source File: InstancesResource.java From helix with Apache License 2.0 | 4 votes |
StringRepresentation getInstancesRepresentation(String clusterName) throws JsonGenerationException, JsonMappingException, IOException { ZkClient zkClient = (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT); HelixDataAccessor accessor = ClusterRepresentationUtil.getClusterDataAccessor(zkClient, clusterName); Map<String, LiveInstance> liveInstancesMap = accessor.getChildValuesMap(accessor.keyBuilder().liveInstances()); Map<String, InstanceConfig> instanceConfigsMap = accessor.getChildValuesMap(accessor.keyBuilder().instanceConfigs()); Map<String, List<String>> tagInstanceLists = new TreeMap<String, List<String>>(); for (String instanceName : instanceConfigsMap.keySet()) { boolean isAlive = liveInstancesMap.containsKey(instanceName); instanceConfigsMap.get(instanceName).getRecord().setSimpleField("Alive", isAlive + ""); InstanceConfig config = instanceConfigsMap.get(instanceName); for (String tag : config.getTags()) { if (!tagInstanceLists.containsKey(tag)) { tagInstanceLists.put(tag, new LinkedList<String>()); } if (!tagInstanceLists.get(tag).contains(instanceName)) { tagInstanceLists.get(tag).add(instanceName); } } } // Wrap raw data into an object, then serialize it List<ZNRecord> recordList = Lists.newArrayList(); for (InstanceConfig instanceConfig : instanceConfigsMap.values()) { recordList.add(instanceConfig.getRecord()); } ListInstancesWrapper wrapper = new ListInstancesWrapper(); wrapper.instanceInfo = recordList; wrapper.tagInfo = tagInstanceLists; StringRepresentation representation = new StringRepresentation(ClusterRepresentationUtil.ObjectToJson(wrapper), MediaType.APPLICATION_JSON); return representation; }
Example 16
Source File: GsonRepresentation.java From unitime with Apache License 2.0 | 4 votes |
public GsonRepresentation(T object) { super(MediaType.APPLICATION_JSON); iObject = object; iObjectClass = ((Class<T>) ((object == null) ? null : object.getClass())); }
Example 17
Source File: JsonRepresentation.java From attic-polygene-java with Apache License 2.0 | 4 votes |
public JsonRepresentation() { super( MediaType.APPLICATION_JSON ); }
Example 18
Source File: LinksResponseWriter.java From attic-polygene-java with Apache License 2.0 | 4 votes |
private StringRepresentation createJsonRepresentation( Links result ) { String json = jsonSerializer.serialize( result ); return new StringRepresentation( json, MediaType.APPLICATION_JSON ); }
Example 19
Source File: JsonRepresentation.java From DeviceConnect-Android with MIT License | 2 votes |
/** * Constructor from a JSON string. * * @param jsonString * The JSON string. */ public JsonRepresentation(String jsonString) { super(MediaType.APPLICATION_JSON); setCharacterSet(CharacterSet.UTF_8); this.jsonRepresentation = new StringRepresentation(jsonString); }
Example 20
Source File: JsonRepresentation.java From DeviceConnect-Android with MIT License | 2 votes |
/** * Constructor from a JSON stringer. * * @param jsonStringer * The JSON stringer. */ public JsonRepresentation(JSONStringer jsonStringer) { super(MediaType.APPLICATION_JSON); init(jsonStringer); }