0001 #!/usr/bin/pscript
0002
0003 userlog("Generate java client");
0004
0005 //Include wizard base.
0006 compilestring(getwizardbase())();
0007
0008 //Provision class
0009 class JavaClient extends WizardBase {
0010
0011 constructor()
0012 {
0013 base.constructor();
0014 }
0015
0016 //Configure it:
0017 </ order=0, name = "Java class name of XATMI Client", type = "string",
0018 min=1, max=512 />
0019 classname = "Testcl";
0020
0021 </ order=1, name = "Java package name", type = "string", min=1, max=512 />
0022 pkgname = "testcl.jar";
0023
0024 </ order=2, name = "Use UBF?", type = "yn"/>
0025 useubf = "y";
0026
0027 </ order=3, name = "Service name to call", type = "path", min=1, max=30,
0028 depend="(::prov.useubf==\"y\")" />
0029 svcname = "TESTSV";
0030
0031 </ order=4, name = "UBF package name",
0032 type = "path" depend="(::prov.useubf==\"y\")" />
0033 ubfname = "ubftab.jar";
0034
0035 </ order=5, name = "INI File section (optional, will read config if set)",
0036 type = "string", depend="(::prov.useubf==\"y\")", min=0/>
0037 config = "";
0038
0039 </ order=6, name = "Gen makefile", type = "yn"/>
0040 genmake = "y";
0041
0042 </ order=7, name = "Full path (incl filename) to enduroxjava.jar",
0043 type = "path", min=1, max=512, depend="(::prov.makebin==\"y\")"/>
0044 enduroxjar = "/usr/share/java/enduroxjava.jar";
0045
0046 </ order=8, name = "Link as binary",
0047 type = "yn", depend="(::prov.genmake==\"y\")" />
0048 makebin = "y";
0049
0050 </ order=9, name = "Binary name",
0051 type = "path", depend="(::prov.makebin==\"y\")", min=1, max=512 />
0052 binname = "testcl";
0053
0054 </ order=10, name = "Lib path for libjava", min=1, max=512,
0055 type = "string" depend="(::prov.makebin==\"y\")" />
0056 libpath_java = "/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64";
0057
0058 </ order=11, name = "Lib path for libjvm", min=1, max=512,
0059 type = "string" depend="(::prov.makebin==\"y\")" />
0060 libpath_jvm = "/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server";
0061
0062 clientFile = "";
0063 makeFile = "";
0064
0065 function getOutputFiles()
0066 {
0067 clientFile=appHome+"/"+classname+".java";
0068 makeFile=appHome+"/Makefile";
0069 }
0070
0071 ////////////////////////////////////////////////////////////////////////
0072 //Build the ndrxconfig value
0073 ////////////////////////////////////////////////////////////////////////
0074 clientVal = "";
0075 function buildClient()
0076 {
0077
0078 clientVal = @"import org.endurox.*;
0079 import org.endurox.exceptions.*;
0080 import java.util.*;
0081
0082 public class "+classname+@" {
0083
0084 "+(config!=""?@"//ini file section for this server process
0085 static String PROGSECTION = """+config+"\";":"")+@"
0086
0087 public void apprun(AtmiCtx ctx) {
0088
0089 ctx.tplogDebug(""apprun called"");
0090 "+(useubf=="y"?@"
0091 TypedUbf ub = (TypedUbf)ctx.tpalloc(""UBF"", """", 1024);
0092
0093 //Add test field to buffer
0094 ub.Bchg(test.T_STRING_FLD, 0, ""Hello World"");
0095
0096 try {
0097 ub = (TypedUbf)ctx.tpcall("""+svcname+@""", ub, 0);
0098 //Print the buffer to stdout
0099 ub.tplogprintubf(AtmiConst.LOG_DEBUG, ""Got response:"");
0100 } catch (AtmiException e) {
0101 ctx.tplogInfo(""got exception: %s"", e.toString());
0102 }":"")+@"
0103 }
0104
0105 public void appinit(AtmiCtx ctx) {
0106 ctx.tplogDebug(""Into tpSvrInit()"");
0107 "+(config!=""?@"
0108 //Get the configuration
0109 String cctag = System.getenv(""NDRX_CCTAG"");
0110
0111 TypedUbf u = (TypedUbf) ctx.tpalloc(""UBF"", null, 160*1024);
0112
0113 u.Bchg(Exfields.EX_CC_CMD, 0, ""g"");
0114 u.Bchg(Exfields.EX_CC_LOOKUPSECTION, 0,
0115 String.format(""%s/%s"", PROGSECTION, System.getenv(""NDRX_CCTAG"")));
0116
0117 //Get the config...
0118 u = (TypedUbf)ctx.tpcall(""@CCONF"", u, 0);
0119
0120 int occs = u.Boccur(Exfields.EX_CC_KEY);
0121
0122 // Load in the config...
0123 for (int occ = 0; occ < occs; occ++) {
0124
0125 ctx.tplogDebug(""occ %d"", occ);
0126
0127 String key = u.BgetString(Exfields.EX_CC_KEY, occ);
0128
0129 ctx.tplogDebug(""Got config field [%s]"", key);
0130
0131 if (key.equals(""mykey1"")) {
0132 String myval = u.BgetString(Exfields.EX_CC_VALUE, occ);
0133 ctx.tplogDebug(""Got [%s] = [%s] "", key, myval);
0134 }
0135 //else if ...
0136 }":"")+@"
0137 }
0138
0139 public void unInit(AtmiCtx ctx) {
0140 ctx.tpterm();
0141 }
0142
0143 public static void main(String[] args) {
0144
0145 AtmiCtx ctx = new AtmiCtx();
0146
0147 "+classname+" cl = new "+classname+@"();
0148 cl.appinit(ctx);
0149 cl.apprun(ctx);
0150 cl.unInit(ctx);
0151 }
0152 }
0153 ";
0154 }
0155
0156 ////////////////////////////////////////////////////////////////////////
0157 //Client END
0158 ////////////////////////////////////////////////////////////////////////
0159
0160
0161 ////////////////////////////////////////////////////////////////////////
0162 //Build makefile
0163 ////////////////////////////////////////////////////////////////////////
0164
0165 makeFileVal = "";
0166 function buildMakefile()
0167 {
0168
0169 makeFileVal = @"
0170 SOURCEDIR=.
0171 SOURCES := $(shell find $(SOURCEDIR) -name '*.java')
0172 CLASSES = $(addsuffix .class, $(basename $(SOURCES)))
0173
0174 " + ( makebin=="y"?"BINARY="+binname:"") + @"
0175 PKG="+pkgname+@"
0176 MAINCLASS="+classname+@"
0177
0178 %.class: %.java
0179 javac -cp "+enduroxjar+@":../ubftab/"+ubfname+@" $<
0180
0181 $(PKG): $(CLASSES)
0182 @echo ""Manifest-Version: 1.0"" > manifest.txt
0183 @echo ""Main-Class: $(MAINCLASS)"" >> manifest.txt
0184 @echo """" >> manifest.txt
0185 jar -cmf manifest.txt $(PKG) $(CLASSES)
0186 - rm manifest.txt
0187 "+( makebin=="y"?" exjld -n -o $(BINARY) -m '$(MAINCLASS)' -L"+libpath_java+@" -L "+libpath_jvm+@" $(PKG)":"")+@"
0188
0189 .PHONY: clean
0190 clean:
0191 - rm *.class manifest.txt $(BINARY) $(PKG)
0192
0193 run:
0194 LD_LIBRARY_PATH="+libpath_java+@":"+libpath_jvm+@" java -classpath "+enduroxjar+@":./$(PKG) $(MAINCLASS)
0195 ";
0196 }
0197
0198 ////////////////////////////////////////////////////////////////////////
0199 //Build makefile, END
0200 ////////////////////////////////////////////////////////////////////////
0201
0202 }
0203
0204
0205 //Run the mater installer
0206 function install()
0207 {
0208 local root = getroottable();
0209
0210 //Create a provision object
0211 root["prov"] <- JavaClient();
0212
0213 if (!::prov.isDefaulted)
0214 {
0215 ::prov.runInteractive();
0216 }
0217
0218 if (::prov.validatAndPrintConfig())
0219 {
0220 ::prov.getOutputFiles();
0221 ::prov.buildClient();
0222
0223 if (!::prov.writeFile(::prov.clientFile, ::prov.clientVal))
0224 {
0225 return false;
0226 }
0227
0228 //Build makefile if needed...
0229 if ("y"==::prov.genmake)
0230 {
0231 ::prov.buildMakefile();
0232
0233 if (!::prov.writeFile(::prov.makeFile, ::prov.makeFileVal))
0234 {
0235 return false;
0236 }
0237 }
0238 }
0239 else
0240 {
0241 return false;
0242 }
0243
0244 return true;
0245 }
0246
0247 if (::install())
0248 {
0249 print("Client gen ok!\n");
0250
0251 return 0;
0252 }
0253 else
0254 {
0255 print("Client gen failed!\n");
0256 return -1;
0257 }