Skip to content

Commit

Permalink
[WPS-Remote Community Module] - gracefully handle JSONNull keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Alessio Fabiani committed Sep 26, 2018
1 parent 4db9204 commit adb5522
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 160 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import net.razorvine.pickle.PickleUtils; import net.razorvine.pickle.PickleUtils;
import net.razorvine.pickle.Pickler; import net.razorvine.pickle.Pickler;
import net.razorvine.pickle.Unpickler; import net.razorvine.pickle.Unpickler;
import net.sf.json.JSONNull;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.http.conn.ssl.TrustSelfSignedStrategy; import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
import org.apache.http.ssl.SSLContexts; import org.apache.http.ssl.SSLContexts;
Expand Down Expand Up @@ -661,7 +662,9 @@ private Object getFixedInputs(Map<String, Object> input) throws IOException {
} }
} }


fixedInputs.put(key, fixedValue); if (value != null && !(value instanceof JSONNull)) {
fixedInputs.put(key, fixedValue);
}
} }


return fixedInputs; return fixedInputs;
Expand Down
Original file line number Original file line Diff line number Diff line change
@@ -1,23 +1,18 @@
/* (c) 2014 - 2016 Open Source Geospatial Foundation - all rights reserved /* (c) 2014 - 2018 Open Source Geospatial Foundation - all rights reserved
* This code is licensed under the GPL 2.0 license, available at the root * This code is licensed under the GPL 2.0 license, available at the root
* application directory. * application directory.
*/ */
package org.geoserver.wps.remote.plugin; package org.geoserver.wps.remote.plugin;


import java.io.IOException; import java.io.IOException;
import java.net.URLDecoder;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger;
import net.razorvine.pickle.PickleException; import net.razorvine.pickle.PickleException;
import net.sf.json.JSONObject;
import net.sf.json.JSONSerializer;
import org.geoserver.wps.remote.RemoteProcessClientListener; import org.geoserver.wps.remote.RemoteProcessClientListener;
import org.geoserver.wps.remote.plugin.output.XMPPOutputDefaultProducer; import org.geoserver.wps.remote.plugin.output.XMPPOutputDefaultProducer;
import org.geotools.util.logging.Logging;
import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet; import org.jivesoftware.smack.packet.Packet;


Expand All @@ -26,16 +21,10 @@
* *
* @author Alessio Fabiani, GeoSolutions * @author Alessio Fabiani, GeoSolutions
*/ */
public class XMPPCompletedMessage implements XMPPMessage { public class XMPPCompletedMessage extends XMPPOutputMessage {


/** The LOGGER */ public XMPPCompletedMessage() {
public static final Logger LOGGER = Logging.getLogger(XMPPMessage.class.getPackage().getName()); super("completed");

@Override
public boolean canHandle(Map<String, String> signalArgs) {
if (signalArgs != null && signalArgs.get("topic") != null)
return signalArgs.get("topic").equals("completed");
return false;
} }


@Override @Override
Expand All @@ -49,131 +38,33 @@ public void handleSignal(
final XMPPOutputDefaultProducer outputProducer = new XMPPOutputDefaultProducer(); final XMPPOutputDefaultProducer outputProducer = new XMPPOutputDefaultProducer();


// NOTIFY THE LISTENERS // NOTIFY THE LISTENERS
if (msg != null && msg.equals("completed")) { if (msg != null && msg.equals(this.topic)) {
final Map<String, Object> outputs = new HashMap<String, Object>(); final Map<String, Object> outputs = new HashMap<String, Object>();
try { try {
for (Entry<String, String> result : for (Entry<String, String> result :
new TreeMap<String, String>(signalArgs).entrySet()) { new TreeMap<String, String>(signalArgs).entrySet()) {
if (result.getKey().startsWith("result")) { if (result.getKey().startsWith("result")) {
final String serviceResultString = final String key = result.getKey();
URLDecoder.decode(result.getValue(), "UTF-8"); final Object output = getOutPuts(xmppClient, result);
final JSONObject serviceResultJSON =
(JSONObject) JSONSerializer.toJSON(serviceResultString);
final Object output =
xmppClient.unPickle(xmppClient.pickle(serviceResultJSON));

// XMPP Output Visitor // XMPP Output Visitor
if (output instanceof Map) { if (output instanceof Map) {
final Map<String, Object> resultParams = (Map<String, Object>) output; final Map<String, Object> resultParams = (Map<String, Object>) output;
// transform the textual value into a real WPS // transform the textual value into a real WPS
// output // output
try { try {
final Object value =
(resultParams.get(result.getKey() + "_value") != null
? resultParams.get(result.getKey() + "_value")
: null);
final String type =
(String)
(resultParams.get(result.getKey() + "_type") != null
? resultParams.get(
result.getKey() + "_type")
: null);
final String description =
(resultParams.get(result.getKey() + "_description") != null
&& resultParams.get(
result.getKey()
+ "_description")
instanceof String
? (String)
resultParams.get(
result.getKey() + "_description")
: null);
final String title =
(resultParams.get(result.getKey() + "_title") != null
&& resultParams.get(
result.getKey() + "_title")
instanceof String
? (String)
resultParams.get(result.getKey() + "_title")
: null);
final String layerName =
(resultParams.get(result.getKey() + "_layer_name") != null
&& resultParams.get(
result.getKey()
+ "_layer_name")
instanceof String
? (String)
resultParams.get(
result.getKey() + "_layer_name")
: null);
final String defaultStyle =
(resultParams.get(result.getKey() + "_style") != null
&& resultParams.get(
result.getKey() + "_style")
instanceof String
? (String)
resultParams.get(result.getKey() + "_style")
: null);
final String targetWorkspace =
(resultParams.get(result.getKey() + "_workspace") != null
&& resultParams.get(
result.getKey()
+ "_workspace")
instanceof String
? (String)
resultParams.get(
result.getKey() + "_workspace")
: null);
final String metadata =
(resultParams.get(result.getKey() + "_metadata") != null
&& resultParams.get(
result.getKey()
+ "_metadata")
instanceof String
? (String)
resultParams.get(
result.getKey() + "_metadata")
: null);

Boolean publish = true;

if (resultParams.get(result.getKey() + "_pub") != null) {
if (resultParams.get(result.getKey() + "_pub")
instanceof String)
publish =
Boolean.valueOf(
(String)
resultParams.get(
result.getKey() + "_pub"));
else if (resultParams.get(result.getKey() + "_pub")
instanceof Boolean)
publish =
(Boolean)
resultParams.get(result.getKey() + "_pub");
}

Object wpsOutputValue = Object wpsOutputValue =
outputProducer.produceOutput( transformOutputs(
value, xmppClient,
type,
pID, pID,
baseURL, baseURL,
xmppClient, outputProducer,
publish, key,
layerName, resultParams);
title,
description,
defaultStyle,
targetWorkspace,
metadata);

LOGGER.finest(
"[XMPPCompletedMessage] wpsOutputValue:" + wpsOutputValue);


// add the transformed result to the process // add the transformed result to the process
// outputs // outputs
if (wpsOutputValue != null) { if (wpsOutputValue != null) {
outputs.put(result.getKey(), wpsOutputValue); outputs.put(key, wpsOutputValue);
continue; continue;
} else { } else {
// throw new Exception("All the Output // throw new Exception("All the Output
Expand Down Expand Up @@ -218,4 +109,90 @@ else if (resultParams.get(result.getKey() + "_pub")
final String serviceJID = message.getFrom(); final String serviceJID = message.getFrom();
xmppClient.sendMessage(serviceJID, "topic=finish"); xmppClient.sendMessage(serviceJID, "topic=finish");
} }

/**
* @param xmppClient
* @param pID
* @param baseURL
* @param outputProducer
* @param key
* @param resultParams
* @return
* @throws Exception
*/
protected Object transformOutputs(
XMPPClient xmppClient,
final String pID,
final String baseURL,
final XMPPOutputDefaultProducer outputProducer,
final String key,
final Map<String, Object> resultParams)
throws Exception {
final Object value =
(resultParams.get(key + "_value") != null
? resultParams.get(key + "_value")
: null);
final String type =
(String)
(resultParams.get(key + "_type") != null
? resultParams.get(key + "_type")
: null);
final String description =
(resultParams.get(key + "_description") != null
&& resultParams.get(key + "_description") instanceof String
? (String) resultParams.get(key + "_description")
: null);
final String title =
(resultParams.get(key + "_title") != null
&& resultParams.get(key + "_title") instanceof String
? (String) resultParams.get(key + "_title")
: null);
final String layerName =
(resultParams.get(key + "_layer_name") != null
&& resultParams.get(key + "_layer_name") instanceof String
? (String) resultParams.get(key + "_layer_name")
: null);
final String defaultStyle =
(resultParams.get(key + "_style") != null
&& resultParams.get(key + "_style") instanceof String
? (String) resultParams.get(key + "_style")
: null);
final String targetWorkspace =
(resultParams.get(key + "_workspace") != null
&& resultParams.get(key + "_workspace") instanceof String
? (String) resultParams.get(key + "_workspace")
: null);
final String metadata =
(resultParams.get(key + "_metadata") != null
&& resultParams.get(key + "_metadata") instanceof String
? (String) resultParams.get(key + "_metadata")
: null);

Boolean publish = true;

if (resultParams.get(key + "_pub") != null) {
if (resultParams.get(key + "_pub") instanceof String)
publish = Boolean.valueOf((String) resultParams.get(key + "_pub"));
else if (resultParams.get(key + "_pub") instanceof Boolean)
publish = (Boolean) resultParams.get(key + "_pub");
}

Object wpsOutputValue =
outputProducer.produceOutput(
value,
type,
pID,
baseURL,
xmppClient,
publish,
layerName,
title,
description,
defaultStyle,
targetWorkspace,
metadata);

LOGGER.finest("[XMPPCompletedMessage] wpsOutputValue:" + wpsOutputValue);
return wpsOutputValue;
}
} }

0 comments on commit adb5522

Please sign in to comment.