/** * Creates a JSON notification from the given data. * Closes the `writer`. * * @param writer the writer * @throws IOException */ protected void toJson(Writer writer, String method, Object... params) throws IOException { JsonRpc rpc = JsonRpc.create(); rpc.setMethod(method); if (params.length > 0) { for (Object obj : params) { rpc.addParam(obj); } } JsonBeanEncoder.create(writer).writeObject(rpc).flush(); } }
/** * Provides the JSON representation of the information. * * @return the json object */ public JsonObject toJsonValue() { JsonObject obj = JsonObject.create(); if (scriptUri != null) { obj.setField("uri", scriptUri.toString()); } if (scriptSource != null) { obj.setField("source", scriptSource); } JsonArray strArray = JsonArray.create(); for (String req : requires) { strArray.append(req); } obj.setField("requires", strArray); strArray = JsonArray.create(); for (String prov : provides) { strArray.append(prov); } obj.setField("provides", strArray); return obj; } }
public void run() { while (true) { JsonBeanDecoder jsonDecoder = JsonBeanDecoder.create(jsonSource); JsonRpc rpc = null; try { rpc = jsonDecoder.readObject(DefaultJsonRpc.class); } catch (JsonDecodeException e) { break; if ("disconnect".equals(rpc.method()) && portalSession.portalSessionId().equals( rpc.params().asString(0))) { portalSession.discard(); return; if ("keepAlive".equals(rpc.method())) { continue;
public void onJsonInput(JsonInput event, PortalSession channel) throws InterruptedException, IOException { if (!event.request().method().equals("retrievedLocalData")) { return; JsonArray params = (JsonArray) event.request().params(); params.asArray(0).arrayStream().forEach(item -> { String key = item.asString(0); if (key.startsWith(keyStart)) { data.put(key.substring( keyStart.length() - 1), item.asString(1));
/** * Handle JSON input. * * @param event the event * @param channel the channel * @throws InterruptedException the interrupted exception * @throws IOException Signals that an I/O exception has occurred. */ @SuppressWarnings("PMD.DataflowAnomalyAnalysis") @Handler(channels = PortalChannel.class) public void onJsonInput(JsonInput event, PortalSession channel) throws InterruptedException, IOException { // Send events to portlets on portal's channel JsonArray params = event.request().params(); switch (event.request().method()) { // NOPMD case "setTheme": { fire(new SetTheme(params.asString(0)), channel); break; } default: // Ignore unknown break; } }
public void onPortalLayoutChanged(PortalLayoutChanged event, IOSubchannel channel) throws IOException { persisted.put("previewLayout", event.previewLayout()); persisted.put("tabsLayout", event.tabsLayout()); persisted.put("xtraInfo", event.xtraInfo()); // Now store. JsonBeanEncoder encoder = JsonBeanEncoder.create(); encoder.writeObject(persisted); fire(new KeyValueStoreUpdate() .update(storagePath, encoder.toJson()), channel); }
public void onKeyValueStoreData( KeyValueStoreData event, IOSubchannel channel) throws JsonDecodeException { if (!event.event().query().equals(storagePath)) { return; } String data = event.data().get(storagePath); if (data != null) { JsonBeanDecoder decoder = JsonBeanDecoder.create(data); @SuppressWarnings({ "unchecked", "PMD.LooseCoupling" }) Class<Map<String, Object>> cls = (Class<Map<String, Object>>) (Class<?>) HashMap.class; persisted = decoder.readObject(cls); } }
@Override public void toJson(Writer writer) throws IOException { JsonArray scripts = JsonArray.create(); for (ScriptResource scriptResource : scriptResources()) { scripts.append(scriptResource.toJsonValue()); } toJson(writer, "addPageResources", Arrays.stream(cssUris()).map( uri -> uri.toString()).toArray(String[]::new), cssSource(), scripts); }
@Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append(Components.objectName(this)) .append(" ["); if (request().method() != null) { builder.append("method=") .append(request().method()) .append(", "); } if (request().id().isPresent()) { builder.append("id=") .append(request().id().get()); } if (channels() != null) { builder.append("channels=") .append(Channel.toString(channels())); } builder.append(']'); return builder.toString(); } }
public void run() { while (true) { JsonBeanDecoder jsonDecoder = JsonBeanDecoder.create(jsonSource); JsonRpc rpc = null; try { rpc = jsonDecoder.readObject(DefaultJsonRpc.class); } catch (JsonDecodeException e) { break; if ("disconnect".equals(rpc.method()) && portalSession.portalSessionId().equals( rpc.params().asString(0))) { portalSession.discard(); return; if ("keepAlive".equals(rpc.method())) { continue;
/** * Creates a JSON notification from the given data. * Closes the `writer`. * * @param writer the writer * @throws IOException */ protected void toJson(Writer writer, String method, Object... params) throws IOException { JsonRpc rpc = JsonRpc.create(); rpc.setMethod(method); if (params.length > 0) { for (Object obj : params) { rpc.addParam(obj); } } JsonBeanEncoder.create(writer).writeObject(rpc).flush(); } }
public void onJsonInput(JsonInput event, PortalSession channel) throws InterruptedException, IOException { if (!event.request().method().equals("retrievedLocalData")) { return; @SuppressWarnings("PMD.DataflowAnomalyAnalysis") Store data = getStore(channel); JsonArray params = (JsonArray) event.request().params(); params.asArray(0).arrayStream().forEach(item -> { String key = item.asString(0); if (key.startsWith(keyStart)) { data.put(key.substring( keyStart.length() - 1), item.asString(1));
JsonObject obj = JsonObject.create(); if (scriptUri != null) { obj.setField("uri", scriptUri.toString()); obj.setField("id", scriptId); obj.setField("type", scriptType); obj.setField("source", scriptSource); JsonArray strArray = JsonArray.create(); for (String req : requires) { strArray.append(req); obj.setField("requires", strArray); strArray = JsonArray.create(); for (String prov : provides) { strArray.append(prov); obj.setField("provides", strArray); return obj;
public void onPortalLayoutChanged(PortalLayoutChanged event, IOSubchannel channel) throws IOException { persisted.put("previewLayout", event.previewLayout()); persisted.put("tabsLayout", event.tabsLayout()); persisted.put("xtraInfo", event.xtraInfo()); // Now store. JsonBeanEncoder encoder = JsonBeanEncoder.create(); encoder.writeObject(persisted); fire(new KeyValueStoreUpdate() .update(storagePath, encoder.toJson()), channel); }
public void onKeyValueStoreData( KeyValueStoreData event, IOSubchannel channel) throws JsonDecodeException { if (!event.event().query().equals(storagePath)) { return; } String data = event.data().get(storagePath); if (data != null) { JsonBeanDecoder decoder = JsonBeanDecoder.create(data); @SuppressWarnings({ "unchecked", "PMD.LooseCoupling" }) Class<Map<String, Object>> cls = (Class<Map<String, Object>>) (Class<?>) HashMap.class; persisted = decoder.readObject(cls); } }
@Override public void toJson(Writer writer) throws IOException { JsonArray scripts = JsonArray.create(); for (ScriptResource scriptResource : scriptResources()) { scripts.append(scriptResource.toJsonValue()); } toJson(writer, "addPageResources", Arrays.stream(cssUris()).map( uri -> uri.toString()).toArray(String[]::new), cssSource(), scripts); }
@Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append(Components.objectName(this)) .append(" ["); if (request().method() != null) { builder.append("method=") .append(request().method()) .append(", "); } if (request().id().isPresent()) { builder.append("id=") .append(request().id().get()); } if (channels() != null) { builder.append("channels=") .append(Channel.toString(channels())); } builder.append(']'); return builder.toString(); } }
/** * Creates a new component with its channel set to the given * channel and the given file. * * @param componentChannel the channel * @param file the file used to store the JSON * @throws JsonDecodeException */ @SuppressWarnings("PMD.ShortVariable") public JsonConfigurationStore(Channel componentChannel, File file, boolean update) throws IOException { super(componentChannel); if (update) { Handler.Evaluator.add(this, "onConfigurationUpdate", channel().defaultCriterion()); } this.file = file; if (!file.exists()) { cache = new HashMap<>(); } try (Reader in = new InputStreamReader( Files.newInputStream(file.toPath()), "utf-8")) { @SuppressWarnings("unchecked") Map<String, Object> confCache = (Map<String, Object>) JsonBeanDecoder.create(in).readObject(); cache = confCache; } catch (JsonDecodeException e) { throw new IOException(e); } }
@Override public void toJson(Writer writer) throws IOException { JsonArray strArray = JsonArray.create(); for (ScriptResource scriptResource : scriptResources()) { strArray.append(scriptResource.toJsonValue()); } toJson(writer, "addPortletType", portletType(), displayName(), Arrays.stream(cssUris()).map( uri -> uri.toString()).toArray(String[]::new), strArray, isInstantiable()); } }
@Override public void toJson(Writer writer) throws IOException { JsonArray strArray = JsonArray.create(); for (ScriptResource scriptResource : scriptResources()) { strArray.append(scriptResource.toJsonValue()); } toJson(writer, "addPortletType", portletType(), displayName(), Arrays.stream(cssUris()).map( uri -> uri.toString()).toArray(String[]::new), strArray, isInstantiable()); } }