Hi, we are using v8.2 of webMethods. I would like to know if this version fully support REST API’s and json converstion. Unlike version 9.x, In 8.x there is no built in service to convert from json to document.
Hi Mishra,
For 8.2 you would have to write your own JSON handling/parsing services.
The ones that are OOTB came just in 9.something.
The code at the link might help which uses GSON else you can write one using the Jackson libs.
http://www.idn-kxchange.com/index.php/webmethods-blogs/entry/163-handling-json-in-the-esb
I have written below, it is attached.
but getting error as attached. It looks like, the libraries are not present.
–
package esiUtilities.json;
import com.wm.data.*;
import com.wm.util.Values;
import com.wm.app.b2b.server.Service;
import com.wm.app.b2b.server.ServiceException;
import com.softwareag.is.json.JSONSchema;
import com.softwareag.is.json.validator.JSONPayload;
import com.softwareag.is.json.validator.JSONPayload.PayloadBuilder;
import com.softwareag.is.json.validator.JSONValidatorFacade;
import com.softwareag.is.json.validator.ValidationReport;
import com.softwareag.util.IDataMap;
import com.wm.app.b2b.server.InvokeState;
import com.wm.data.IData;
import com.wm.data.IDataCursor;
import com.wm.util.coder.IDataJSONCoder;
import com.wm.util.coder.IDataJSONCoder.JSON_ENCODING;
import com.wm.util.text.Strings;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.lang.StringUtils;
import pub.resources.PubExceptionBundle;
public final class jsonStringToDocument_SVC
{
/**
* The primary method for the Java service
*
* @param pipeline
* The IData pipeline
* @throws ServiceException
*/
public static final void jsonStringToDocument(IData pipeline)
throws ServiceException {
IDataCursor idcPipeline = pipeline.getCursor();
try {
String jsonString = CommonUtils.getRequiredStrParam(idcPipeline, "jsonString");
String decodeRealAsDouble = (String)CommonUtils.getOptionalObjParam(idcPipeline, "decodeRealAsDouble", String.class);
String decodeIntegerAsLong = (String)CommonUtils.getOptionalObjParam(idcPipeline, "decodeIntegerAsLong", String.class);
String decodeRealAsString = (String)CommonUtils.getOptionalObjParam(idcPipeline, "decodeRealAsString", String.class);
IDataJSONCoder jsonCoder = new IDataJSONCoder();
if ((decodeRealAsDouble != null) &&
(decodeRealAsDouble.trim().length() > 0)) {
if (decodeRealAsDouble.equalsIgnoreCase("false")) {
jsonCoder.setDecodeRealAsDouble(false);
} else {
jsonCoder.setDecodeRealAsDouble(true);
}
}
if ((decodeIntegerAsLong != null) &&
(decodeIntegerAsLong.trim().length() > 0)) {
if (decodeIntegerAsLong.equalsIgnoreCase("false")) {
jsonCoder.setDecodeIntegerAsLong(false);
} else {
jsonCoder.setDecodeIntegerAsLong(true);
}
}
if (!Strings.isEmpty(decodeRealAsString)) {
if ((!decodeRealAsString.equalsIgnoreCase("true")) &&
(!decodeRealAsString.equalsIgnoreCase("false"))) {
throw new ServiceException(PubExceptionBundle.class, PubExceptionBundle.JSON_INVALID_INPUT_REAL_AS_STRING, "");
}
if ((decodeRealAsString.equalsIgnoreCase("true")) && (!Strings.isEmpty(decodeRealAsDouble)) && (decodeRealAsDouble.equalsIgnoreCase("true"))) {
throw new ServiceException(PubExceptionBundle.class, PubExceptionBundle.JSON_INVALID_INPUTS_REAL_AS_STRING_AND_DOUBLE, "");
}
if (decodeRealAsString.equalsIgnoreCase("true")) {
jsonCoder.setDecodeRealAsString(true);
} else {
jsonCoder.setDecodeRealAsString(false);
}
}
IData decodedValues = jsonCoder.decode(new ByteArrayInputStream(jsonString.getBytes("UTF8")));
idcPipeline.insertAfter("document", decodedValues);
}
catch (Exception e) {
CommonUtils.throwAsServiceException(e);
} finally {
idcPipeline.destroy();
}
}
// --- <<IS-BEGIN-SHARED-SOURCE-AREA>> ---
// --- <<IS-END-SHARED-SOURCE-AREA>> ---
}
code_jsonToDoc.txt (3.74 KB)
error_jsonToDoc.txt (5.72 KB)
It looks like some jar files are not supported/present in this version.
These classes are not part of IS 8.x version
import com.softwareag.is.json.JSONSchema;
import com.softwareag.is.json.validator.JSONPayload;
import com.softwareag.is.json.validator.JSONPayload.PayloadBuilder;
import com.softwareag.is.json.validator.JSONValidatorFacade;