use of org.ballerinalang.util.codegen.PackageInfo in project ballerina by ballerina-lang.
the class HttpUtil method getHttpConnectorError.
public static BStruct getHttpConnectorError(Context context, Throwable throwable) {
PackageInfo httpPackageInfo = context.getProgramFile().getPackageInfo(HttpConstants.PROTOCOL_PACKAGE_HTTP);
StructInfo errorStructInfo = httpPackageInfo.getStructInfo(HttpConstants.HTTP_CONNECTOR_ERROR);
BStruct httpConnectorError = new BStruct(errorStructInfo.getType());
if (throwable.getMessage() == null) {
httpConnectorError.setStringField(0, IO_EXCEPTION_OCCURED);
} else {
httpConnectorError.setStringField(0, throwable.getMessage());
}
return httpConnectorError;
}
use of org.ballerinalang.util.codegen.PackageInfo in project ballerina by ballerina-lang.
the class AbstractHTTPAction method createStruct.
/**
* Creates a ballerina struct.
*
* @param context ballerina context
* @param structName name of the struct
* @param protocolPackage package name
* @return the ballerina struct
*/
protected BStruct createStruct(Context context, String structName, String protocolPackage) {
PackageInfo httpPackageInfo = context.getProgramFile().getPackageInfo(protocolPackage);
StructInfo structInfo = httpPackageInfo.getStructInfo(structName);
BStructType structType = structInfo.getType();
return new BStruct(structType);
}
use of org.ballerinalang.util.codegen.PackageInfo in project ballerina by ballerina-lang.
the class AbstractExecute method createStruct.
BStruct createStruct(Context context, String structName) {
PackageInfo httpPackageInfo = context.getProgramFile().getPackageInfo(PROTOCOL_STRUCT_PACKAGE_GRPC);
StructInfo structInfo = httpPackageInfo.getStructInfo(structName);
BStructType structType = structInfo.getType();
return new BStruct(structType);
}
use of org.ballerinalang.util.codegen.PackageInfo in project ballerina by ballerina-lang.
the class InitEndpoint method getConnectorError.
private static BStruct getConnectorError(Context context, Throwable throwable) {
PackageInfo grpcPackageInfo = context.getProgramFile().getPackageInfo(PROTOCOL_PACKAGE_GRPC);
StructInfo errorStructInfo = grpcPackageInfo.getStructInfo(CONNECTOR_ERROR);
BStruct grpcConnectorError = new BStruct(errorStructInfo.getType());
if (throwable.getMessage() == null) {
grpcConnectorError.setStringField(0, "Service Initialization error.");
} else {
grpcConnectorError.setStringField(0, throwable.getMessage());
}
return grpcConnectorError;
}
use of org.ballerinalang.util.codegen.PackageInfo in project ballerina by ballerina-lang.
the class BRunUtil method invokeStateful.
/**
* Invoke a ballerina function with state. Need to use compileAndSetup method in BCompileUtil to use this.
*
* @param compileResult CompileResult instance
* @param packageName Name of the package to invoke
* @param functionName Name of the function to invoke
* @param args Input parameters for the function
* @return return values of the function
*/
public static BValue[] invokeStateful(CompileResult compileResult, String packageName, String functionName, BValue[] args) {
if (compileResult.getErrorCount() > 0) {
throw new IllegalStateException(compileResult.toString());
}
ProgramFile programFile = compileResult.getProgFile();
Debugger debugger = new Debugger(programFile);
programFile.setDebugger(debugger);
PackageInfo packageInfo = programFile.getPackageInfo(packageName);
FunctionInfo functionInfo = packageInfo.getFunctionInfo(functionName);
if (functionInfo == null) {
throw new RuntimeException("Function '" + functionName + "' is not defined");
}
if (functionInfo.getParamTypes().length != args.length) {
throw new RuntimeException("Size of input argument arrays is not equal to size of function parameters");
}
BValue[] response = BLangFunctions.invokeCallable(functionInfo, compileResult.getContext(), args);
return spreadToBValueArray(response);
}
Aggregations