Skip to content

Commit

Permalink
Merge pull request #46 from AAnastaBASIS/bbx_servlet_branch
Browse files Browse the repository at this point in the history
Upgraded RESTBridge to use BBx Servlets instead of BBjsp Servlets
  • Loading branch information
StephanWald authored Nov 7, 2022
2 parents 53deffa + eddbe6b commit effbf26
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 106 deletions.
12 changes: 6 additions & 6 deletions OutputHandler.bbj
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ class public OutputHandler
field protected HashMap invokeResult!

rem The actual request object which contains infromation about the client request
field protected BBjspWebRequest request!
field protected BBxServletRequest request!

rem The actual response object used to write the response
field protected BBjspWebResponse response!
field protected BBxServletResponse response!

rem /**
rem * The default constructor used to create an instance of the OutputHandler.
Expand Down Expand Up @@ -460,20 +460,20 @@ class public OutputHandler
methodend

rem /**
rem * Set the BBjspWebRequest object to use when handling the output.
rem * Set the BBxServletRequest object to use when handling the output.
rem *
rem * @param request! The request object to use.
rem */
method public void setRequest(BBjspWebRequest request!)
method public void setRequest(BBxServletRequest request!)
#request! = request!
methodend

rem /**
rem * Set the BBjspWebResponse object to use when handling the output.
rem * Set the BBxServletResponse object to use when handling the output.
rem *
rem * @param response! The response object to use.
rem */
method public void setResponse(BBjspWebResponse response!)
method public void setResponse(BBxServletResponse response!)
#response! = response!
methodend

Expand Down
14 changes: 7 additions & 7 deletions RestBridge.bbj
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class public RestBridge

field public static BBjString LOGTPL$="ID:C(16*),METHOD:C(1*),START:N(1*),END:N(1*),DURATION:N(1*),ADDR:C(1*),URL:C(1*),URI:C(1*),QUERY:C(1*),HEADERS:C(1*),PARAMS:C(1*),STATUS:C(1*)"

METHOD PUBLIC void service(BBjspServletContext context!)
declare BBjspWebRequest request!
declare BBjspWebResponse response!
METHOD PUBLIC void service(BBxServletContext context!)
declare BBxServletRequest request!
declare BBxServletResponse response!

request! = context!.getRequest()
response! = context!.getResponse()
Expand Down Expand Up @@ -847,7 +847,7 @@ class public RestBridge

methodend

method private BBjString logRequest(BBjspWebRequest request!)
method private BBjString logRequest(BBxServletRequest request!)

rlog$=stbl("REST_REQUESTLOG",err=skip)
System.out.println("Logging request into "+rlog$)
Expand Down Expand Up @@ -901,7 +901,7 @@ class public RestBridge

methodend

method private void logResponse(BBjString id$, BBjspWebResponse response!)
method private void logResponse(BBjString id$, BBxServletResponse response!)

if id$="" then
methodret
Expand Down Expand Up @@ -931,7 +931,7 @@ class public RestBridge

methodend

method private HashMap getRequestLog(BBjspWebRequest request!)
method private HashMap getRequestLog(BBxServletRequest request!)

answer! = new HashMap()
rs! = new ResultSet()
Expand Down Expand Up @@ -996,7 +996,7 @@ class public RestBridge
rem * @param context! The servlet context used to read the parameters defined for the RestBridge servlet
rem * @return a HashMap with the RestBridge parameters(=options) currenlty set.
rem */
method private static HashMap getServletParameters(BBjspServletContext context!)
method private static HashMap getServletParameters(BBxServletContext context!)

rem the list of available parameter names
declare BBjVector parameterNames!
Expand Down
48 changes: 24 additions & 24 deletions cfg/RestBridgeConfigurationWindow.bbj
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,11 @@ class public RestBridgeConfigurationWindow

methodend

method private BBjspServletConfiguration reciveBridgeInformation()
declare BBjspServletConfiguration servlet!
method private BBxServlet reciveBridgeInformation()
declare BBxServlet servlet!

if (!(#selectedBridge! = null()) AND !(#selected! = null())) then
servlet! = #configurate!.getBBjspServlet(#selected!.getName(),#selectedBridge!.getMapping())
servlet! = #configurate!.getBBxServlet(#selected!.getName(),#selectedBridge!.getMapping())
else
methodret null()
endif
Expand Down Expand Up @@ -331,7 +331,7 @@ class public RestBridgeConfigurationWindow
methodend

method private void updateUI()
declare BBjspServletConfiguration servlet!
declare BBxServlet servlet!

servlet! = #reciveBridgeInformation()
if (servlet! <> null()) then
Expand All @@ -345,12 +345,12 @@ class public RestBridgeConfigurationWindow
#setWorkingDirectoryPath(servlet!.getParameter("REST_WD"))
#setAuthProgramPath(servlet!.getParameter("REST_AUTHPGM"))
#setRequestLogPath(servlet!.getParameter("REST_REQUESTLOG"))
#setConfigFilePath(servlet!.getConfig())
#setConfigFilePath(servlet!.getConfigFile())

error = 1; #setUseGetAllowedFilters(num(servlet!.getParameter("USE_GET_ALLOWED_FILTER")),err=*next); error = 0
if error = 1 then #setUseGetAllowedFilters(0)

#setConfigFilePath(servlet!.getConfig())
#setConfigFilePath(servlet!.getConfigFile())
#enableUI(1)
#enableSubmitters(1)
else
Expand Down Expand Up @@ -575,7 +575,7 @@ class public RestBridgeConfigurationWindow
method public void loadTree()
declare BBjVector vector!
declare BBjVector vector2!
declare BBjspServletConfiguration bbjspServletConfiguration!
declare BBxServlet bbxServletConfiguration!

#contexts!.clear()

Expand All @@ -590,16 +590,16 @@ class public RestBridgeConfigurationWindow

#treeContext!.addExpandableNode(#node!,parent,vector!.getItem(i).toString())
#contexts!.add(new Context(vector!.getItem(i).toString(),#node!))
vector2! = #admin!.getJettyServerConfig().getCustomContext(vector!.getItem(i).toString()).getBBjspServlets()
vector2! = #admin!.getJettyServerConfig().getCustomContext(vector!.getItem(i).toString()).getBBxServlets()
branch_node! = #node!
if vector2!.size() > 0 then
for y=0 to vector2!.size()-1
bbjspServletConfiguration! = cast(BBjspServletConfiguration ,vector2!.getItem(y))
if bbjspServletConfiguration!.getClassName() = "RestBridge" then
bbxServletConfiguration! = cast(BBxServlet ,vector2!.getItem(y))
if bbxServletConfiguration!.getClassName() = "RestBridge" then
#node! = #node!+1
#treeContext!.addNode(#node!,branch_node!,bbjspServletConfiguration!.getMapping())
#treeContext!.addNode(#node!,branch_node!,bbxServletConfiguration!.getMapping())
buffer! = cast(Context,#contexts!.get(i))
buffer!.addBridge(new Bridge(bbjspServletConfiguration!.getMapping(),#node!))
buffer!.addBridge(new Bridge(bbxServletConfiguration!.getMapping(),#node!))
endif
next y
endif
Expand Down Expand Up @@ -696,7 +696,7 @@ class public RestBridgeConfigurationWindow
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 BBxServlet bridgeConf!"+$0A$+$0A$)
builder!.append("declare String user!"+$0A$)
builder!.append("declare String password!"+$0A$)
builder!.append("declare String contextName!"+$0A$)
Expand Down Expand Up @@ -731,19 +731,19 @@ class public RestBridgeConfigurationWindow
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("bridgeConf! = contextConf!.addBBxServlet(bridgeName!,restBridgeFile!.getAbsolutePath(),""RestBridge"",""service"")"+$0A$+$0A$)
builder!.append("bridgeConf!.setConfigFile(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("bridgeConf!.addParameter(""REST_ADAPTERPGM"", adapterProgram!.getAbsolutePath())"+$0A$)
builder!.append("bridgeConf!.addParameter(""REST_ADAPTERTERM"", ""IO"")"+$0A$)
builder!.append("bridgeConf!.addParameter(""REST_TIMEOUT"",timeOut!)"+$0A$)
builder!.append("bridgeConf!.addParameter(""REST_WD"",workingDirectory!)"+$0A$)
builder!.append("bridgeConf!.addParameter(""REST_AUTHPGM"",authpgm!)"+$0A$)
builder!.append("bridgeConf!.addParameter(""REST_PGM_PREFIX"",preffix!)"+$0A$)
builder!.append("bridgeConf!.addParameter(""REST_PGM_SUFFIX"",suffix!)"+$0A$)
builder!.append("bridgeConf!.addParameter(""USE_GET_ALLOWED_FILTER"",useGetAllowedFilter!)"+$0A$)
builder!.append("bridgeConf!.addParameter(""REST_REQUESTLOG"",requestLogPath!)"+$0A$)
builder!.append("serverConfig!.saveConfig()"+$0A$)

methodret builder!.toString()
Expand Down
70 changes: 35 additions & 35 deletions cfg/RestBridgeConfigurator.bbj
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class public RestBridgeConfigurator
declare BBjVector contextNames!
declare Iterator contextNameIterator!
declare Iterator bbjspConfigurationIterator!
declare BBjVector bbjspServletConfigurations!
declare BBjVector bbxServletConfigurations!
declare BBjJettyContextConfiguration contextConfiguration!
declare BBjspServletConfiguration bbjspServletConfiguration!
declare BBxServlet bbxServletConfiguration!

declare BBjVector restBridgeConfigurations!
restBridgeConfigurations! = new BBjVector()
Expand All @@ -40,15 +40,15 @@ class public RestBridgeConfigurator
contextName! = str(contextNameIterator!.next())
contextConfiguration! = #serverConfig!.getCustomContext(contextName!)

bbjspServletConfigurations! = contextConfiguration!.getBBjspServlets()
if(bbjspServletConfigurations! <> null() AND !bbjspServletConfigurations!.isEmpty()) then
bbxServletConfigurations! = contextConfiguration!.getBBxServlets()
if(bbxServletConfigurations! <> null() AND !bbxServletConfigurations!.isEmpty()) then

bbjspConfigurationIterator! = bbjspServletConfigurations!.iterator()
bbjspConfigurationIterator! = bbxServletConfigurations!.iterator()
while(bbjspConfigurationIterator!.hasNext())
bbjspServletConfiguration! = cast(BBjspServletConfiguration ,bbjspConfigurationIterator!.next())
bbxServletConfiguration! = cast(BBxServlet ,bbjspConfigurationIterator!.next())

className! = bbjspServletConfiguration!.getClassName()
sourceName! = bbjspServletConfiguration!.getSourceName()
className! = bbxServletConfiguration!.getClassName()
sourceName! = bbxServletConfiguration!.getSourceFile()

if(className! = "RestBridge" AND sourceName! = restBridgeFile!.getAbsolutePath()) then
restBridgeConfigurations!.add(contextName!)
Expand All @@ -71,7 +71,7 @@ class public RestBridgeConfigurator
methodret authenticationProgramFile!.getAbsolutePath()
methodend

method public BBjspServletConfiguration getBBjspServlet(String contextName!, String mapping!)
method public BBxServlet getBBxServlet(String contextName!, String mapping!)
declare BBjJettyContextConfiguration contextConf!
contextConf! = #serverConfig!.getCustomContext(contextName!)

Expand All @@ -87,7 +87,7 @@ class public RestBridgeConfigurator
methodret null()
endif

methodret contextConf!.getBBjspServlet(mapping!)
methodret contextConf!.getBBxServlet(mapping!)
methodend

rem /**
Expand All @@ -100,13 +100,13 @@ class public RestBridgeConfigurator
declare BBjJettyContextConfiguration contextConfiguration!
contextConfiguration! = #serverConfig!.getCustomContext(contextName!)

declare BBjspServletConfiguration bbjspServlet!
bbjspServlet! = contextConfiguration!.getBBjspServlet(mapping!)
if(bbjspServlet! = null()) then
declare BBxServlet bbxServlet!
bbxServlet! = contextConfiguration!.getBBxServlet(mapping!)
if(bbxServlet! = null()) then
methodret
endif

contextConfiguration!.removeBBjspServlet(mapping!)
contextConfiguration!.removeBBxServlet(mapping!)
#serverConfig!.saveConfig()
methodend

Expand All @@ -124,14 +124,14 @@ class public RestBridgeConfigurator
REM * @param params! The HashMap with the Rest Bridge Parameters
REM */
method public void editRestBridgeConfiguration(String contextName!, String mapping!, HashMap params!, String configFilePath!)
declare BBjspServletConfiguration conf!
conf! = #getBBjspServlet(contextName!, mapping!)
declare BBxServlet conf!
conf! = #getBBxServlet(contextName!, mapping!)

if(conf! = null()) then
methodret
endif

conf!.setConfig(configFilePath!)
conf!.setConfigFile(configFilePath!)

rem Clearing the parameters
rem This is actually a work-around for the
Expand All @@ -140,7 +140,7 @@ class public RestBridgeConfigurator
if ok then
rem remove the servlet parameters
while !conf!.getParameterNames().isEmpty()
conf!.clearParams()
conf!.clearParameters()
wend
endif

Expand All @@ -150,22 +150,22 @@ class public RestBridgeConfigurator
if ok then
rem remove the servlet parameters
while !conf!.getParamaterNames().isEmpty()
conf!.clearParams()
conf!.clearParameters()
wend
endif


declare File adapterProgram!
adapterProgram! = new File(#pluginDirectory!, "RestBCAdapter.bbj")
conf!.addParam("REST_ADAPTERPGM", adapterProgram!.getAbsolutePath())
conf!.addParam("REST_ADAPTERTERM", "IO")
conf!.addParameter("REST_ADAPTERPGM", adapterProgram!.getAbsolutePath())
conf!.addParameter("REST_ADAPTERTERM", "IO")

declare Iterator it!
it! = params!.entrySet().iterator()
while(it!.hasNext())
entry! = it!.next()
if(entry!.getValue() <> "") then
conf!.addParam(entry!.getKey(), entry!.getValue())
conf!.addParameter(entry!.getKey(), entry!.getValue())
endif
wend

Expand All @@ -191,33 +191,33 @@ class public RestBridgeConfigurator
endif

rem check that the mapping is not already used by another program
if(contextConfig!.getBBjspServletMappings().contains(mapping!)) then
if(contextConfig!.getBBxServletMappings().contains(mapping!)) then
a = msgbox("Mapping already exists!")
methodret
endif

declare File restBridgeFile!
restBridgeFile! = new File(#pluginDirectory!, "RestBridge.bbj")

declare BBjspServletConfiguration configuration!
declare BBxServlet configuration!

rem ClassName, Mapping, Source, Config(Optional)
rem http://documentation.basis.com/BASISHelp/WebHelp/gridmethods4/bbjjettycontextconfiguration_addbbjspservlet.htm
configuration! = contextConfig!.addBBjspServlet("RestBridge", mapping!, restBridgeFile!.getAbsolutePath())
configuration! = contextConfig!.addBBxServlet(mapping!, restBridgeFile!.getAbsolutePath(), "RestBridge", "service")

configuration!.setConfig(configFilePath!)
configuration!.setConfigFile(configFilePath!)

declare File adapterProgram!
adapterProgram! = new File(#pluginDirectory!, "RestBCAdapter.bbj")
configuration!.addParam("REST_ADAPTERPGM", adapterProgram!.getAbsolutePath())
configuration!.addParam("REST_ADAPTERTERM", "IO")
configuration!.addParameter("REST_ADAPTERPGM", adapterProgram!.getAbsolutePath())
configuration!.addParameter("REST_ADAPTERTERM", "IO")

declare Iterator it!
it! = params!.entrySet().iterator()
while(it!.hasNext())
entry! = it!.next()
if(entry!.getValue() <> "") then
configuration!.addParam(entry!.getKey(), entry!.getValue())
configuration!.addParameter(entry!.getKey(), entry!.getValue())
endif
wend

Expand Down Expand Up @@ -258,9 +258,9 @@ class public RestBridgeConfigurator
method public BBjVector getRestBridgeMappingsForContext(String contextName!)
declare Iterator it!
declare File sourceFile!
declare BBjVector bbjspServlets!
declare BBjVector bbxServlets!
declare BBjVector restBridgeMappings!
declare BBjspServletConfiguration conf!
declare BBxServlet conf!
declare BBjJettyContextConfiguration contextConfiguration!

rem get the custom context for the given context name
Expand All @@ -272,12 +272,12 @@ class public RestBridgeConfigurator
restBridgeMappings! = new BBjVector()

rem retrieve the BBJSP servlets for the custom context
bbjspServlets! = contextConfiguration!.getBBjspServlets()
bbxServlets! = contextConfiguration!.getBBxServlets()

it! = bbjspServlets!.iterator()
it! = bbxServlets!.iterator()
while(it!.hasNext())
conf! = cast(BBjspServletConfiguration, it!.next())
if(conf!.getClassName().equals("RestBridge") AND conf!.getSourceName().equals(sourceFile!.getAbsolutePath())) then
conf! = cast(BBxServlet, it!.next())
if(conf!.getClassName().equals("RestBridge") AND conf!.getSourceFile().equals(sourceFile!.getAbsolutePath())) then
restBridgeMappings!.addItem(conf!.getMapping())
endif
wend
Expand Down
Loading

0 comments on commit effbf26

Please sign in to comment.