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