diff --git a/cfg/ConfigFile.txt b/cfg/ConfigFile.txt new file mode 100644 index 0000000..900d650 --- /dev/null +++ b/cfg/ConfigFile.txt @@ -0,0 +1,116 @@ +use java.io.File +declare File restBridgeFile! +declare File directory! +declare File adapterProgram! +declare BBjAdmin admin! +declare BBjJettyContextConfiguration contextConf! +declare BBjJettyServerConfiguration serverconfig! +declare BBjspServletConfiguration bridgeConf! + +user! = "" +password! = "" + +if (user! = "") then + if (password! = "") then + M=MSGBOX("No Username and Password set.") + bye + else + M=MSGBOX("No Username set.") + bye + endif +else + if (password! = "") then + M=MSGBOX("No Password and Password set.") + bye + endif +endif + +contextName! = "[[CONTEXTNAME]]" +bridgeName! = "[[BRIDGENAME]]" +configFilePath! = "[[CONFIGFILEPATH]]" +timeOut! = "[[TIMEOUT]]" +workingDirectory! = "[[WORKINGDIRECTORYPATH]]" +authPgm! = "[[AUTHPROGRAMPATH]]" +prefix! = "[[PREFIX]]" +suffix! = "[[SUFFIX]]" +useGetAllowedFilters! = [[USEGETALLOWEDFILTERS]] +requestLogPath! = "[[REQUESTLOGPATH]]" +inputHandler! = "[[INPUTHANDLER]]" +outputHandler! = "[[OUTPUTHANDLER]]" +adapterTerm! = "[[ADAPTERTERM]]" +charset! = "[[CHARSET]]" + +admin! = BBjAPI().getAdmin(user!,password!) + +serverConfig! = admin!.getJettyServerConfig() +directory! = new File(dsk("") + dir("")) + +REM Creating a new Context with default DocBase and a WelcomeFile +contextConf! = serverConfig!.createCustomContext(contextName!) +contextConf!.setDocBase("$basis_home/htdocs") +contextConf!.addWelcomeFile("index.html") +contextConf!.setPath("/" + contextName!) + +serverConfig!.saveConfig() + +restBridgeFile! = new File(directory!.getParentFile(),"RestBridge.bbj") + +bridgeConf! = contextConf!.addBBjspServlet("RestBridge",bridgeName!,restBridgeFile!.getAbsolutePath()) +bridgeConf!.setConfig(configFilePath!) + +adapterProgram! = new File(directory!.getParentFile(),"RestBCAdapter.bbj") + +REM Here you can add Parameter to your Bridge. +if !timeOut!.trim().isEmpty() then + bridgeConf!.addParam("REST_TIMEOUT",timeOut!.trim()) +endif + +if !workingDirectory!.trim().isEmpty() then + bridgeConf!.addParam("REST_WD",workingDirectory!.trim()) +endif + +if !authpgm!.trim().isEmpty() then + bridgeConf!.addParam("REST_AUTHPGM",authpgm!) +endif + +if !prefix!.trim().isEmpty() then + bridgeConf!.addParam("REST_PGM_PREFIX",prefix!) +endif + +if !suffix!.trim().isEmpty() then + bridgeConf!.addParam("REST_PGM_SUFFIX",suffix!) +endif + +if !useGetAllowedFilter!.trim().isEmpty() then + bridgeConf!.addParam("USE_GET_ALLOWED_FILTER",useGetAllowedFilter!) +endif + +if !requestLogPath!.trim().isEmpty() then + bridgeConf!.addParam("REST_REQUESTLOG",requestLogPath!.trim()) +endif + +if !requestLogPath!.trim().isEmpty() then + bridgeConf!.addParam("REST_REQUESTLOG",requestLogPath!.trim()) +endif + +if !inputHandler!.trim().isEmpty() then + bridgeConf!.addParam("REST_REQUESTLOG",inputHandler!.trim()) +endif + +if !outputHandler!.trim().isEmpty() then + bridgeConf!.addParam("REST_REQUESTLOG",outputHandler!.trim()) +endif + +if !adapterTerm!.trim().isEmpty() then + bridgeConf!.addParam("REST_ADAPTERTERM", adapterTerm!.trim()) +endif + +if !charset!.trim().isEmpty then + bridgeConf!.addParam("REST_DEFAULT_CHARSET", charset!.trim()) +endif + +if adapterProgram!.exists() then + bridgeConf!.addParam("REST_ADAPTERPGM", adapterProgram!.getAbsolutePath()) +endif + +serverConfig!.saveConfig() \ No newline at end of file diff --git a/cfg/RestBridge.arc b/cfg/RestBridge.arc new file mode 100644 index 0000000..6de34a8 --- /dev/null +++ b/cfg/RestBridge.arc @@ -0,0 +1,270 @@ +//#charset: windows-1252 + +VERSION "4.0" + +WINDOW 101 "REST Endpoint Configuration" 200 200 800 464 +BEGIN + EVENTMASK 0 + KEYBOARDNAVIGATION + NOT MAXIMIZABLE + NAME "Window101" + NOT SIZABLE + STATICTEXT 100, "Mapping:", 375, 25, 115, 25 + BEGIN + NAME "Static Text100" + NOT WORDWRAP + END + + INPUTE 102, "", 500, 20, 150, 25 + BEGIN + NAME "inpeMapping" + PADCHARACTER 32 + NOT TABTRAVERSABLE + NOT DRAGENABLED + END + + STATICTEXT 103, "Timeout:", 375, 55, 115, 25 + BEGIN + NAME "Static Text103" + NOT WORDWRAP + END + + INPUTN 104, "", 500, 50, 150, 25 + BEGIN + GROUP + NAME "inpnTimeout" + RESTORESTRING "0" + NOT DRAGENABLED + NOT INSERTMODE + END + + STATICTEXT 105, "Program Prefix:", 375, 85, 115, 25 + BEGIN + NAME "Static Text105" + NOT WORDWRAP + END + + INPUTE 106, "", 500, 80, 150, 25 + BEGIN + GROUP + NAME "inpeProgramPrefix" + PADCHARACTER 32 + NOT DRAGENABLED + END + + STATICTEXT 107, "Program Suffix:", 375, 115, 115, 25 + BEGIN + NAME "Static Text105" + NOT WORDWRAP + END + + INPUTE 108, "", 500, 111, 150, 25 + BEGIN + GROUP + NAME "inpeProgramSuffix" + PADCHARACTER 32 + NOT DRAGENABLED + END + + STATICTEXT 109, "Default Charset:", 375, 145, 115, 25 + BEGIN + NAME "Static Text105" + NOT WORDWRAP + END + + LISTEDIT 110, "", 500, 140, 150, 150 + BEGIN + NAME "leDefaultCharset" + SELECTIONHEIGHT 25 + NOT DRAGENABLED + END + + STATICTEXT 111, "Adapter Term: ", 375, 175, 115, 25 + BEGIN + NAME "Static Text105" + NOT WORDWRAP + END + + INPUTE 112, "", 500, 170, 150, 25 + BEGIN + GROUP + NAME "inpeAdapterTerm" + PADCHARACTER 32 + NOT DRAGENABLED + END + + CHECKBOX 113, "Use getAllowedFilters() if applicable", 376, 200, 200, 25 + BEGIN + GROUP + NAME "chbUseGetAllowedFilters" + END + + STATICTEXT 114, "Config File:", 375, 235, 115, 25 + BEGIN + NAME "Static Text105" + NOT WORDWRAP + END + + INPUTE 115, "", 500, 230, 241, 25 + BEGIN + GROUP + NAME "inpeConfigFile" + PADCHARACTER 32 + NOT DRAGENABLED + END + + BUTTON 116, "...", 750, 231, 30, 25 + BEGIN + GROUP + NAME "btnBrowseConfigFile" + END + + STATICTEXT 117, "Working Directory:", 375, 265, 115, 25 + BEGIN + NAME "Static Text105" + NOT WORDWRAP + END + + INPUTE 118, "", 500, 260, 241, 25 + BEGIN + GROUP + NAME "inpeWorkingDirectory" + PADCHARACTER 32 + NOT DRAGENABLED + END + + BUTTON 119, "...", 750, 261, 30, 25 + BEGIN + GROUP + NAME "btnBrowseWorkingDirectory" + END + + STATICTEXT 120, "Auth Program:", 375, 295, 115, 25 + BEGIN + NAME "Static Text105" + NOT WORDWRAP + END + + INPUTE 121, "", 500, 290, 241, 25 + BEGIN + GROUP + NAME "inpeAuthProgram" + PADCHARACTER 32 + NOT DRAGENABLED + END + + BUTTON 122, "...", 750, 291, 30, 25 + BEGIN + GROUP + NAME "btnBrowseAuthenticationFile" + END + + STATICTEXT 123, "Request Log:", 375, 325, 115, 25 + BEGIN + NAME "Static Text105" + NOT WORDWRAP + END + + INPUTE 124, "", 500, 320, 241, 25 + BEGIN + GROUP + NAME "inpeRequestLog" + PADCHARACTER 32 + NOT DRAGENABLED + END + + BUTTON 125, "...", 750, 321, 30, 25 + BEGIN + GROUP + NAME "btnBrowseRequestLogFile" + END + + STATICTEXT 126, "Input Handler:", 375, 355, 115, 25 + BEGIN + NAME "Static Text105" + NOT WORDWRAP + END + + INPUTE 127, "", 500, 350, 241, 25 + BEGIN + GROUP + NAME "inpeInputHandler" + PADCHARACTER 32 + NOT DRAGENABLED + END + + BUTTON 128, "...", 750, 351, 30, 25 + BEGIN + GROUP + NAME "btnBrowseInputHandler" + END + + STATICTEXT 129, "Output Handler:", 375, 385, 115, 25 + BEGIN + NAME "Static Text105" + NOT WORDWRAP + END + + INPUTE 130, "", 500, 380, 241, 25 + BEGIN + GROUP + NAME "inpeOutputHandler" + PADCHARACTER 32 + NOT DRAGENABLED + END + + BUTTON 131, "...", 750, 381, 30, 25 + BEGIN + GROUP + NAME "btnBrowseOutputHandler" + END + + BUTTON 132, "Add Context", 20, 430, 100, 25 + BEGIN + GROUP + NAME "btnAddContext" + END + + BUTTON 133, "Add Endpoint", 130, 430, 100, 25 + BEGIN + GROUP + NAME "btnAddBridge" + END + + BUTTON 134, "Remove Endpoint", 240, 430, 100, 25 + BEGIN + GROUP + NAME "btnRemoveBridge" + END + + BUTTON 135, "Cancel", 460, 430, 100, 25 + BEGIN + GROUP + NAME "btnCancel" + END + + BUTTON 136, "Save", 570, 430, 100, 25 + BEGIN + GROUP + NAME "btnSave" + END + + BUTTON 137, "OK", 680, 430, 100, 25 + BEGIN + GROUP + NAME "btnOK" + END + + BUTTON 138, "Preview Code", 680, 20, 100, 25 + BEGIN + GROUP + NAME "btnPreviewCode" + END + + TREE 139, 20, 20, 320, 385 + BEGIN + NAME "treeContext" + END + +END + diff --git a/cfg/RestBridgeConfigurationWindow.bbj b/cfg/RestBridgeConfigurationWindow.bbj index bf4223f..c354a9a 100644 --- a/cfg/RestBridgeConfigurationWindow.bbj +++ b/cfg/RestBridgeConfigurationWindow.bbj @@ -1,5 +1,8 @@ use java.io.File use java.util.HashMap +use java.util.Scanner +use java.io.FileWriter +use com.basiscomponents.db.constants.SimpleConstantsResolver use ::RestBridge/cfg/ContextNameInputWindow.bbj::ContextNameInputWindow use ::RestBridge/cfg/RestBridgeConfigurator.bbj::RestBridgeConfigurator @@ -25,6 +28,9 @@ class public RestBridgeConfigurationWindow field private BBjInputE inpeProgramPrefix! field private BBjInputE inpeProgramSuffix! field private BBjInputE inpeWorkingDirectory! + field private BBjInputE inpeInputHandler! + field private BBjInputE inpeOutputHandler! + field private BBjInputE inpeAdapterTerm! field private BBjCEdit previewField! @@ -39,7 +45,11 @@ class public RestBridgeConfigurationWindow field private BBjButton btnBrowseRequestLogFile! field private BBjButton btnBrowseWorkingDirectory! field private BBjButton btnBrowseAuthenticationFile! + field private BBjButton btnBrowseInputHandler! + field private BBjButton btnBrowseOutputHandler! + field private BBjListEdit leDefaultCharset! + field private BBjAdmin admin! field private RestBridgeConfigurator configurate! @@ -62,182 +72,95 @@ class public RestBridgeConfigurationWindow methodend method private void init() - #sysGui! = BBjApi().openSysGui("X0") - - screenWidth = #sysGui!.getSystemMetrics().getScreenBounds().getWidth() - screenHeight = #sysGui!.getSystemMetrics().getScreenSize().getHeight() - - #window! = #sysGui!.addWindow(#sysGui!.getAvailableContext(), (screenWidth/2)-200, (screenHeight/2)-250, 760, 400, "REST Endpoint Configuration", $00000002$) - - labelWidth = 115 - controlHeight = 25 - space = 10 - y = 25 + #sysGui! = BBjAPI().openSysGui("X0") + resID = #sysGui!.resOpen("RestBridge/cfg/RestBridge.arc") + #window! = #sysGui!.createTopLevelWindow(resID, 101) + #window!.setEnterAsTab(1) - controlWidth = 400 - - xorig = 340 - x = xorig - controlWidth = labelWidth - controlID = #window!.getAvailableControlID() - #window!.addStaticText(controlID, x, y, controlWidth, controlHeight, "Mapping:") - x = x + controlWidth + space - - controlWidth = 150 - controlID = #window!.getAvailableControlID() - #inpeMapping! = #window!.addInputE(controlID, x, y-5, controlWidth, controlHeigh) + #inpeMapping! = #window!.getInputE("inpeMapping") #inpeMapping!.setEnabled(0) #inpeMapping!.setInsertMode(1) - x = xorig - y = y + 30 - controlWidth = labelWidth - controlID = #window!.getAvailableControlID() - #window!.addStaticText(controlID, x, y, controlWidth, controlHeight, "Timeout:") - x = x + controlWidth + space - - controlWidth = 150 - controlID = #window!.getAvailableControlID() - #inpnTimeout! = #window!.addInputN(controlID, x, y-5, controlWidth, controlHeight) + #inpnTimeout! = #window!.getInputN("inpnTimeout") #inpnTimeout!.setValue(1000) #inpnTimeout!.setInsertMode(1) - x = xorig - y = y + 30 - controlWidth = labelWidth - controlID = #window!.getAvailableControlID() - #window!.addStaticText(controlID, x, y, controlWidth, controlHeight, "Program Prefix:") - x = x + controlWidth + space - - controlWidth = 150 - controlID = #window!.getAvailableControlID() - #inpeProgramPrefix! = #window!.addInputE(controlID, x, y-5, controlWidth, controlHeight) + #inpeProgramPrefix! = #window!.getInputE("inpeProgramPrefix") #inpeProgramPrefix!.setInsertMode(1) - x = xorig - y = y + 30 - controlWidth = labelWidth - controlID = #window!.getAvailableControlID() - #window!.addStaticText(controlID, x, y, controlWidth, controlHeight, "Program Suffix:") - x = x + controlWidth + space - - controlWidth = 150 - controlID = #window!.getAvailableControlID() - #inpeProgramSuffix! = #window!.addInputE(controlID, x, y-5, controlWidth, controlHeight) + #inpeProgramSuffix! = #window!.getInputE("inpeProgramSuffix") #inpeProgramSuffix!.setText(".bbj") #inpeProgramSuffix!.setInsertMode(1) + + #chbUseGetAllowedFilters! = #window!.getCheckBox("chbUseGetAllowedFilters") - x = xorig - y = y + 20 - controlWidth = 250 - controlID = #window!.getAvailableControlID() - #chbUseGetAllowedFilters! = #window!.addCheckBox(controlID, x, y, controlWidth, controlHeight, "Use getAllowedFilters() if applicable") - - x = xorig - y = y + 50 - controlWidth = labelWidth - controlID = #window!.getAvailableControlID() - #window!.addStaticText(controlID, x, y, controlWidth, controlHeight, "Config File:") - x = x + controlWidth + space - - controlWidth = 200 - controlID = #window!.getAvailableControlID() - #inpeConfigFile! = #window!.addInputE(controlID, x, y-5, controlWidth, controlHeight) + #inpeConfigFile! = #window!.getInputE("inpeConfigFile") #inpeConfigFile!.setInsertMode(1) - x = x + controlWidth + space - - controlWidth = 75 - controlID = #window!.getAvailableControlID() - #btnBrowseConfigFile! = #window!.addButton(controlID, x, y-5, 30, controlHeight, "...") + + #btnBrowseConfigFile! = #window!.getButton("btnBrowseConfigFile") #btnBrowseConfigFile!.setCallback(BBjAPI.ON_BUTTON_PUSH, #this!, "browseConfigFileButtonPush") - - x = xorig - y = y + 30 - controlWidth = labelWidth - controlID = #window!.getAvailableControlID() - #window!.addStaticText(controlID, x, y, controlWidth, controlHeight, "Working Directory:") - x = x + controlWidth + space - - controlWidth = 200 - controlID = #window!.getAvailableControlID() - #inpeWorkingDirectory! = #window!.addInputE(controlID, x, y-5, controlWidth, controlHeight) + + #inpeWorkingDirectory! = #window!.getInputE("inpeWorkingDirectory") #inpeWorkingDirectory!.setInsertMode(1) - x = x + controlWidth + space - controlWidth = 75 - controlID = #window!.getAvailableControlID() - #btnBrowseWorkingDirectory! = #window!.addButton(controlID, x, y-5, 30, controlHeight, "...") + #btnBrowseWorkingDirectory! = #window!.getButton("btnBrowseWorkingDirectory") #btnBrowseWorkingDirectory!.setCallback(BBjAPI.ON_BUTTON_PUSH, #this!, "browseWorkingDirectoryButtonPush") - x = xorig - y = y + 30 - controlWidth = labelWidth - controlID = #window!.getAvailableControlID() - #window!.addStaticText(controlID, x, y, controlWidth, controlHeight, "Auth Program:") - x = x + controlWidth + space - - controlWidth = 200 - controlID = #window!.getAvailableControlID() - #inpeAuthProgram! = #window!.addInputE(controlID, x, y-5, controlWidth, controlHeight) + #inpeAuthProgram! = #window!.getInputE("inpeAuthProgram") #inpeAuthProgram!.setInsertMode(1) - x = x + controlWidth + space - controlWidth = 75 - controlID = #window!.getAvailableControlID() - #btnBrowseAuthenticationFile! = #window!.addButton(controlID, x, y-5, 30, controlHeight, "...") + #btnBrowseAuthenticationFile! = #window!.getButton("btnBrowseAuthenticationFile") #btnBrowseAuthenticationFile!.setCallback(BBjAPI.ON_BUTTON_PUSH, #this!, "browseAuthFileButtonPush") - x = xorig - y = y + 30 - controlWidth = labelWidth - controlID = #window!.getAvailableControlID() - #window!.addStaticText(controlID, x, y, controlWidth, controlHeight, "Request Log:") - x = x + controlWidth + space - - controlWidth = 200 - controlID = #window!.getAvailableControlID() - #inpeRequestLog! = #window!.addInputE(controlID, x, y-5, controlWidth, controlHeight) + #inpeRequestLog! = #window!.getInputE("inpeRequestLog") #inpeRequestLog!.setInsertMode(1) - x = x + controlWidth + space - controlWidth = 100 - controlID = #window!.getAvailableControlID() - #btnBrowseRequestLogFile! = #window!.addButton(controlID, x, y-5, 30, controlHeight, "...") + #btnBrowseRequestLogFile! = #window!.getButton("btnBrowseRequestLogFile") #btnBrowseRequestLogFile!.setCallback(BBjAPI.ON_BUTTON_PUSH, #this!, "browseRequestLogButtonPush") - - controlID = #window!.getAvailableControlID() - #btnPreviewCode! = #window!.addButton(controlID, x -30, 20, controlWidth, controlHeight, "Preview Code") + + #inpeInputHandler! = #window!.getInputE("inpeInputHandler") + #inpeInputHandler!.setInsertMode(1) + + #btnBrowseInputHandler! = #window!.getButton("btnBrowseInputHandler") + #btnBrowseInputHandler!.setCallback(BBjButton.ON_BUTTON_PUSH, #this!, "browseInputHandlerButtonPush") + + #inpeOutputHandler! = #window!.getInputE("inpeOutputHandler") + #inpeOutputHandler!.setInsertMode(1) + + #btnBrowseOutputHandler! = #window!.getButton("btnBrowseOutputHandler") + #btnBrowseOutputHandler!.setCallback(BBjButton.ON_BUTTON_PUSH, #this!, "browseOutputHandlerButtonPush") + + #inpeAdapterTerm! = #window!.getInputE("inpeAdapterTerm") + #inpeAdapterTerm!.setText("IO") + #inpeAdapterTerm!.setInsertMode(1) + + #btnPreviewCode! = #window!.getButton("btnPreviewCode") #btnPreviewCode!.setCallback(BBjAPI.ON_BUTTON_PUSH, #this!, "previewCode") - controlID = #window!.getAvailableControlID() - #btnOK! = #window!.addButton(controlID,x-30,365,controlWidth,controlHeight,"OK") + #btnOK! = #window!.getButton("btnOK") #btnOK!.setCallback(BBjButton.ON_BUTTON_PUSH,#this!,"okOnClick") - controlID = #window!.getAvailableControlID() - #btnSave! = #window!.addButton(controlID, x - 30-controlWidth - space, 365, controlWidth, controlHeight, "Save") + #btnSave! = #window!.getButton("btnSave") #btnSave!.setCallback(BBjAPI.ON_BUTTON_PUSH, #this!, "saveClicked") - x = x - controlWidth - space - controlID = #window!.getAvailableControlID() - #btnCancel! = #window!.addButton(controlID, x- 30-controlWidth - space, 365, controlWidth, controlHeight, "Cancel") + #btnCancel! = #window!.getButton("btnCancel") #btnCancel!.setCallback(BBjAPI.ON_BUTTON_PUSH, #this!, "cancelClicked") - controlID = #window!.getAvailableControlID() - #btnAddContext! = #window!.addButton(controlID, 20, 365, controlWidth, controlHeight, "Add Context") + #btnAddContext! = #window!.getButton("btnAddContext") #btnAddContext!.setCallback(BBjAPI.ON_BUTTON_PUSH, #this!, "addContextButtonPush") - controlID = #window!.getAvailableControlID() - #btnAddBridge! = #window!.addButton(controlID,130,365,controlWidth,controlHeight, "Add Endpoint") + #btnAddBridge! = #window!.getButton("btnAddBridge") #btnAddBridge!.setCallback(BBjAPI.ON_BUTTON_PUSH, #this!,"addBridge") #btnAddBridge!.setEnabled(0) - controlID = #window!.getAvailableControlID() - #btnRemoveBridge! = #window!.addButton(controlID,240, 365, controlWidth, controlHeight, "Remove Endpoint") + #btnRemoveBridge! = #window!.getButton("btnRemoveBridge") #btnRemoveBridge!.setCallback(BBjButton.ON_BUTTON_PUSH,#this!,"removeBridge") #btnRemoveBridge!.setEnabled(0) - controlID = #window!.getAvailableControlID() - #treeContext! = #window!.addTree(controlID, 20,20,300,335) + #leDefaultCharset! = #window!.getListEdit("leDefaultCharset") + #fillListEdit() + + #treeContext! = #window!.getTree("treeContext") #treeContext!.setSelectionMode(BBjTree.SINGLE_TREE_SELECTION) #treeContext!.setCallback(BBjTree.ON_TREE_SELECT,#this!,"onSelect") #treeContext!.setRoot(0,"contexts") @@ -247,6 +170,18 @@ class public RestBridgeConfigurationWindow #updateUI() methodend + + method public void fillListEdit() + #leDefaultCharset!.addItem(INFO(1,2)) + #leDefaultCharset!.addItem("US-ASCII") + #leDefaultCharset!.addItem("ISO-8859-1") + #leDefaultCharset!.addItem("UTF-8") + #leDefaultCharset!.addItem("UTF-16BE") + #leDefaultCharset!.addItem("UTF-16LE") + #leDefaultCharset!.addItem("UTF-16") + + #leDefaultCharset!.selectIndex(0) + methodend method public void show() BBjAPI().setCustomEventCallback("CloseWindowEvent", "CloseWindow") @@ -315,12 +250,18 @@ class public RestBridgeConfigurationWindow #inpeProgramPrefix!.setEnabled(enable!) #inpeProgramSuffix!.setEnabled(enable!) #inpeWorkingDirectory!.setEnabled(enable!) + #inpeOutputHandler!.setEnabled(enable!) + #inpeInputHandler!.setEnabled(enable!) #inpnTimeout!.setEnabled(enable!) #btnPreviewCode!.setEnabled(enable!) #btnBrowseConfigFile!.setEnabled(enable!) #btnBrowseRequestLogFile!.setEnabled(enable!) #btnBrowseWorkingDirectory!.setEnabled(enable!) #btnBrowseAuthenticationFile!.setEnabled(enable!) + #btnBrowseInputHandler!.setEnabled(enable!) + #btnBrowseOutputHandler!.setEnabled(enable!) + #inpeAdapterTerm!.setEnabled(enable!) + #leDefaultCharset!.setEnabled(enable!) #chbUseGetAllowedFilters!.setEnabled(enable!) #btnSave!.setEnabled(enable!) methodend @@ -346,6 +287,10 @@ class public RestBridgeConfigurationWindow #setAuthProgramPath(servlet!.getParameter("REST_AUTHPGM")) #setRequestLogPath(servlet!.getParameter("REST_REQUESTLOG")) #setConfigFilePath(servlet!.getConfig()) + #setInputHandlerPath(servlet!.getParameter("REST_INPUT_HANDLER")) + #setOutputHandlerPath(servlet!.getParameter("REST_OUTPUT_HANDLER")) + #setAdapterTerm(servlet!.getParameter("REST_ADAPTERTERM")) + #setCharset(servlet!.getParameter("REST_DEFAULT_CHARSET")) error = 1; #setUseGetAllowedFilters(num(servlet!.getParameter("USE_GET_ALLOWED_FILTER")),err=*next); error = 0 if error = 1 then #setUseGetAllowedFilters(0) @@ -409,7 +354,11 @@ class public RestBridgeConfigurationWindow params!.put("REST_PGM_SUFFIX", #getProgramSuffix()) params!.put("USE_GET_ALLOWED_FILTER", str(int(#useGetAllowedFilters()))) params!.put("REST_REQUESTLOG", #getRequestLogPath()) - + params!.put("REST_INPUT_HANDLER", #getInputHandler()) + params!.put("REST_OUTPUT_HANDLER", #getOutputHandler()) + params!.put("REST_ADAPTERTERM", #getAdapterTerm()) + params!.put("REST_DEFAULT_CHARSET",#getCharset()) + #window!.setCursor(32514) #configurate!.editRestBridgeConfiguration(#selected!.getName(), #selectedBridge!.getMapping(), params!, #getConfigFilePath()) #window!.setCursor(32512) @@ -503,17 +452,23 @@ class public RestBridgeConfigurationWindow name! = name!.replaceAll(" ","") buffer! = System.getProperty("basis.BBjHome") + "\plugins\RestBridge\authenticate.bbj" + bbjHome! = new File(buffer!) - auth! = bbjHome!.getAbsolutePath().replaceAll("\\|\/", java.io.File.separator,err=*next) + auth! = bbjHome!.getAbsolutePath().replaceAll("\|/", java.io.File.separator,err=*next) params! = new HashMap() params!.put("REST_TIMEOUT","1000") params!.put("REST_WD", "") + params!.put("REST_AUTHPGM",auth!) params!.put("REST_PGM_PREFIX","") params!.put("REST_PGM_SUFFIX",".bbj") params!.put("USE_GET_ALLOWED_FILTER","0") params!.put("REST_REQUESTLOG","") + params!.put("REST_INPUT_HANDLER", "") + params!.put("REST_OUTPUT_HANDLER", "") + params!.put("REST_ADAPTERTERM", "IO") + params!.put("REST_DEFAULT_CHARSET", INFO(1,2)) if (#selected!.getBridge(name!) = null()) then #configurate!.configureRestBridge(#selected!.getName(),name!,params!,"") @@ -650,7 +605,19 @@ class public RestBridgeConfigurationWindow logPath! = #browse(path!,"Request Log File Selection", Boolean.FALSE, "","All files"+$0a$+"*.*") #inpeRequestLog!.setText(logPath!) methodend + + method public void browseInputHandlerButtonPush(BBjButtonPushEvent event!) + path! = #inpeRequestLog!.getText() + logPath! = #browse(path!,"Input Handler Selection", Boolean.FALSE, "","All files"+$0a$+"*.*") + #inpeInputHandler!.setText(logPath!) + methodend + method public void browseOutputHandlerButtonPush(BBjButtonPushEvent event!) + path! = #inpeRequestLog!.getText() + logPath! = #browse(path!,"Output Handler Selection", Boolean.FALSE, "","All files"+$0a$+"*.*") + #inpeInputHandler!.setText(logPath!) + methodend + method public void browseWorkingDirectoryButtonPush(BBjButtonPushEvent event!) path! = #inpeWorkingDirectory!.getText() wdPath! = #browse(path!,"Working Directory Selection", Boolean.TRUE, "","") @@ -664,17 +631,22 @@ class public RestBridgeConfigurationWindow methodend method public void previewCode(BBjButtonPushEvent e!) - - #prevWindow! = #sysGui!.addWindow(#sysGui!.getAvailableContext(), #window!.getX(), #window!.getY(),#window!.getWidth()+100,#window!.getHeight(), "Codepreview", $00000002$) + #prevWindow! = #sysGui!.addWindow(#sysGui!.getAvailableContext(), #window!.getX(), #window!.getY(),#window!.getWidth()+100,#window!.getHeight(), "Codepreview") + #prevWindow!.setCallback(#prevWindow!.ON_RESIZE, #this!, "onPreviewResize") #opend! = Boolean.TRUE #prevWindow!.setCallback(BBjWindow.ON_KEYPRESS,#this!,"windowKeypressEvent") #window!.setEnabled(0) - - controlID = #prevWindow!.getAvailableControlID() - #prevWindow!.addStaticText(controlID,20,0,80,20,"Example Code:") - + + declare BBjButton btnCopy! + btnCopy! = #prevWindow!.addButton(#prevWindow!.getAvailableControlID(),10,10,100,25,"Copy to Clipboard") + btnCopy!.setCallback(BBjButton.ON_BUTTON_PUSH , #this!, "onClickCopy") + + declare BBjButton btnSaveAs! + btnSaveAs! = #prevWindow!.addButton(#prevWindow!.getAvailableControlID(),130,10,100,25,"Save as") + btnSaveAs!.setCallback(BBjButton.ON_BUTTON_PUSH, #this!, "onClickSaveAs") + controlID = #prevWindow!.getAvailableControlID() - #previewField! = #prevWindow!.addCEdit(controlID,20,20,#prevWindow!.getWidth() - 40,#prevWindow!.getHeight() - 40,"",$0306$) + #previewField! = #prevWindow!.addCEdit(controlID,0,45,#prevWindow!.getWidth(),#prevWindow!.getHeight() - 45,"",$0306$) declare BBjFont font! font! = #sysGui!.makeFont("Consolas",12,0) @@ -682,71 +654,46 @@ class public RestBridgeConfigurationWindow #prevWindow!.setCallback(BBjAPI.ON_CLOSE, #this!,"closePrevWindow") - #previewField!.setText(#assembleCode()) - methodend - - method private String assembleCode() - declare java.lang.StringBuilder builder! - builder! = new java.lang.StringBuilder() - - builder!.append("use java.io.File"+$0A$+$0A$) - builder!.append("declare File restBridgeFile!"+$0A$) - builder!.append("declare File directory!"+$0A$) - builder!.append("declare File adapterProgram!"+$0A$) - builder!.append("declare BBjAdmin admin!"+$0A$) - builder!.append("declare BBjJettyContextConfiguration contextConf!"+$0A$) - builder!.append("declare BBjJettyServerConfiguration serverconfig!"+$0A$) - builder!.append("declare BBjspServletConfiguration bridgeConf!"+$0A$+$0A$) - builder!.append("declare String user!"+$0A$) - builder!.append("declare String password!"+$0A$) - builder!.append("declare String contextName!"+$0A$) - builder!.append("declare String bridgeName!"+$0A$) - builder!.append("declare String configFilePath!"+$0A$) - builder!.append("declare String timeOut!"+$0A$) - builder!.append("declare String workingDirectory!"+$0A$) - builder!.append("declare String authPgm!"+$0A$) - builder!.append("declare String preffix!"+$0A$) - builder!.append("declare String suffix!"+$0A$) - builder!.append("declare String useGetAllowedFilter!"+$0A$) - builder!.append("declare String requestLogPath!"+$0A$+$0A$) - builder!.append("user! = """"" +$0A$) - builder!.append("password! = """""+$0A$) - builder!.append("contextName! = """+#selected!.getName()+""""+$0A$) - builder!.append("bridgeName! = """+#selectedBridge!.getMapping()+""""+$0A$) - builder!.append("configFilePath! = """+#getConfigFilePath()+""""+$0A$) - builder!.append("timeOut! = """+str(#getTimeout())+""""+$0A$) - builder!.append("workingDirectory! = """+#getWorkingDirectoryPath()+""""+$0A$) - builder!.append("authPgm! = """+#getAuthProgramPath()+""""+$0A$) - builder!.append("preffix! = """+#getProgramPrefix()+""""+$0A$) - builder!.append("suffix! = """+#getProgramSuffix()+""""+$0A$) - builder!.append("useGetAllowedFilter! = """+str(#useGetAllowedFilters())+""""+$0A$) - builder!.append("requestLogPath! = """+#getRequestLogPath()+""""+$0A$+$0A$) - builder!.append("admin! = BBjAPI().getAdmin(user!,password!)"+$0A$) - builder!.append("serverConfig! = admin!.getJettyServerConfig()"+$0A$) - builder!.append("directory! = new File(dsk("""") + dir(""""))"+$0A$+$0A$) - builder!.append("REM Creating a new Context with default DocBase and a WelcomeFile"+$0A$) - builder!.append("contextConf! = serverConfig!.createCustomContext(contextName!)"+$0A$) - builder!.append("contextConf!.setDocBase(""$basis_home/htdocs"")"+$0A$) - builder!.append("contextConf!.addWelcomeFile(""index.html"")"+$0A$) - builder!.append("contextConf!.setPath(""/"" + contextName!)"+$0A$) - builder!.append("serverConfig!.saveConfig()"+$0A$+$0A$) - builder!.append("restBridgeFile! = new File(directory!.getParentFile(),""RestBridge.bbj"")"+$0A$) - builder!.append("bridgeConf! = contextConf!.addBBjspServlet(""RestBridge"",bridgeName!,restBridgeFile!.getAbsolutePath())"+$0A$+$0A$) - builder!.append("bridgeConf!.setConfig(configFilePath!)"+$0A$) - builder!.append("adapterProgram! = new File(directory!.getParentFile(),""RestBCAdapter.bbj"")"+$0A$+$0A$) - builder!.append("REM Here you can add Parameter to your Birdge."+$0A$) - builder!.append("bridgeConf!.addParam(""REST_ADAPTERPGM"", adapterProgram!.getAbsolutePath())"+$0A$) - builder!.append("bridgeConf!.addParam(""REST_ADAPTERTERM"", ""IO"")"+$0A$) - builder!.append("bridgeConf!.addParam(""REST_TIMEOUT"",timeOut!)"+$0A$) - builder!.append("bridgeConf!.addParam(""REST_WD"",workingDirectory!)"+$0A$) - builder!.append("bridgeConf!.addParam(""REST_AUTHPGM"",authpgm!)"+$0A$) - builder!.append("bridgeConf!.addParam(""REST_PGM_PREFIX"",preffix!)"+$0A$) - builder!.append("bridgeConf!.addParam(""REST_PGM_SUFFIX"",suffix!)"+$0A$) - builder!.append("bridgeConf!.addParam(""USE_GET_ALLOWED_FILTER"",useGetAllowedFilter!)"+$0A$) - builder!.append("bridgeConf!.addParam(""REST_REQUESTLOG"",requestLogPath!)"+$0A$) - builder!.append("serverConfig!.saveConfig()"+$0A$) - - methodret builder!.toString() + #previewField!.setText(#getConfigCode()) + methodend + + method public void onPreviewResize(BBjResizeEvent ev!) + #previewField!.setSize(ev!.getWidth(), ev!.getHeight() - 45) + methodend + + method private String getConfigCode() + declare File file! + file! = new File(DIR("") + "RestBridge/cfg/ConfigFile.txt") + + declare Scanner scan! + scan! = new Scanner(file!) + + string! = "" + while(scan!.hasNextLine()) + string! = string! + scan!.nextLine() + System.getProperty("line.separator") + wend + scan!.close() + + declare SimpleConstantsResolver scr! + scr! = new SimpleConstantsResolver() + scr!.put("CONTEXTNAME", #selected!.getName()) + scr!.put("BRIDGENAME", #selectedBridge!.getMapping()) + scr!.put("CONFIGFILEPATH", #getConfigFilePath().replace("\", "\\")) + scr!.put("TIMEOUT",str(#getTimeout())) + scr!.put("WORKINGDIRECTORYPATH", #getWorkingDirectoryPath().replace("\", "\\")) + scr!.put("AUTHPROGRAMPATH",#getAuthProgramPath().replace("\", "\\")) + scr!.put("PREFIX", #getProgramPrefix()) + scr!.put("SUFFIX", #getProgramSuffix()) + scr!.put("USEGETALLOWEDFILTERS", str(#useGetAllowedFilters())) + scr!.put("REQUESTLOGPATH", #getRequestLogPath().replace("\", "\\")) + scr!.put("INPUTHANDLER", #getInputHandler().replace("\", "\\")) + scr!.put("OUTPUTHANDLER", #getOutputHandler().replace("\", "\\")) + scr!.put("ADAPTERTERM", #getAdapterTerm()) + scr!.put("CHARSET", #getCharset()) + + declare String res! + res! = scr!.resolveConstants(string!) + methodret res! methodend method public void okOnClick(BBjButtonPushEvent e!) @@ -756,9 +703,37 @@ class public RestBridgeConfigurationWindow BBjAPI().postCustomEvent("CloseWindowEvent", "") methodend + + rem /** + rem * Copy Config Code to Clipboard. + rem */ + method public void onClickCopy(BBjButtonPushEvent e!) + CLIPFROMSTR 1, #previewField!.getText() + methodend + + rem /** + rem * Saves the Code as an actual Config to run. + rem */ + method public void onClickSaveAs(BBjButtonPushEvent e!) + FILE_NAME!=FILESAVE("Save File As...",DIR(""),"Restconfig","bbj") + declare File file! + file! = new File(FILE_NAME!) - + declare FileWriter fw! + fw! = new FileWriter(FILE_NAME!) + + setErr Error + fw!.write(#previewField!.getText()) + fw!.close() + M=MSGBOX("Save successfull. admin! und user! have to be set before launching the Code!") + + methodret + + Error: + M=MSGBOX("Error occured. File couldn't be saved to " + FILE_NAME!.replace("Restconfig.bbj", "")) + methodend + rem /** rem * Returns the user entered value for the Timeout property. rem * @@ -771,8 +746,7 @@ class public RestBridgeConfigurationWindow method public void setTimeout(BBjInt timeout%) #inpnTimeout!.setValue(timeout%) methodend - - + method public String getMapping() methodret #inpeMapping!.getText() methodend @@ -780,7 +754,7 @@ class public RestBridgeConfigurationWindow method public void setMapping(String mapping!) #inpeMapping!.setText(mapping!) methodend - + method public String getProgramPrefix() methodret #inpeProgramPrefix!.getText() methodend @@ -809,12 +783,12 @@ class public RestBridgeConfigurationWindow methodend method public void setConfigFilePath(String path!) - if (path! = null()) then - path! = "" + if (path! = "") then + path! = BBjAPI().getConfig().getConfigFileName() endif #inpeConfigFile!.setText(path!) methodend - + method public String getWorkingDirectoryPath() methodret #inpeWorkingDirectory!.getText() methodend @@ -832,12 +806,59 @@ class public RestBridgeConfigurationWindow method public void setAuthProgramPath(String path!) if (path! = null()) then - path! = "" + buffer! = System.getProperty("basis.BBjHome") + "\plugins\RestBridge\authenticate.bbj" + + declare File bbjHome! + bbjHome! = new File(buffer!) + + path! = bbjHome!.getAbsolutePath().replaceAll("\|/", java.io.File.separator,err=*next) endif - #inpeAuthProgram!.setText(path!) methodend + + method public void setInputHandlerPath(String path!) + if (path! = null()) then + path! = "" + endif + + #inpeInputHandler!.setText(path!) + methodend + + method public void setOutputHandlerPath(String path!) + if (path! = null()) then + path! = "" + endif + #inpeOutputHandler!.setText(path!) + methodend + + method public void setAdapterTerm(String string!) + if (string! = null()) then + string! = "" + endif + + #inpeAdapterTerm!.setText(string!) + methodend + + method public void setCharset(String charset!) + if (charset! = null()) then + charset! = "" + #leDefaultCharset!.selectIndex(0) + methodret + endif + + i% = 0 + WHILE (i% < #leDefaultCharset!.getAllItems().size() - 1) + if (#leDefaultCharset!.getItemAt(i%) = charset!) then + break + endif + + i% = i% + 1 + WEND + + #leDefaultCharset!.selectIndex(i%) + methodend + method public Boolean useGetAllowedFilters() methodret #chbUseGetAllowedFilters!.isSelected() methodend @@ -853,7 +874,23 @@ class public RestBridgeConfigurationWindow method public String getRequestLogPath() methodret #inpeRequestLog!.getText() methodend - + + method public String getInputHandler() + methodret #inpeInputHandler!.getText() + methodend + + method public String getOutputHandler() + methodret #inpeOutputHandler!.getText() + methodend + + method public String getAdapterTerm() + methodret #inpeAdapterTerm!.getText() + methodend + + method public String getCharset() + methodret #leDefaultCharset!.getText() + methodend + method public void setRequestLogPath(String path!) if (path! = null()) then path! = "" @@ -861,5 +898,4 @@ class public RestBridgeConfigurationWindow #inpeRequestLog!.setText(path!) methodend - classend \ No newline at end of file diff --git a/cfg/RestBridgeConfigurator.bbj b/cfg/RestBridgeConfigurator.bbj index 59d34d4..d36e03a 100644 --- a/cfg/RestBridgeConfigurator.bbj +++ b/cfg/RestBridgeConfigurator.bbj @@ -157,9 +157,15 @@ class public RestBridgeConfigurator declare File adapterProgram! adapterProgram! = new File(#pluginDirectory!, "RestBCAdapter.bbj") - conf!.addParam("REST_ADAPTERPGM", adapterProgram!.getAbsolutePath()) - conf!.addParam("REST_ADAPTERTERM", "IO") - + + if params!.get("REST_ADAPTERPGM") = null() then + conf!.addParam("REST_ADAPTERPGM", adapterProgram!.getAbsolutePath()) + endif + + if params!.get("REST_ADAPTERTERM") = null() then + conf!.addParam("REST_ADAPTERTERM", "IO") + endif + declare Iterator it! it! = params!.entrySet().iterator() while(it!.hasNext())