Skip to content

Commit

Permalink
Added logs to trace rest request
Browse files Browse the repository at this point in the history
  • Loading branch information
AyanF committed Oct 9, 2024
1 parent 4795262 commit f2a7830
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ public <V> V getTool(@Nonnull String toolName, Class<V> instanceClass, Object...

@Override
public void initWebFacade(@Nonnull String webappMoquiName, @Nonnull HttpServletRequest request, @Nonnull HttpServletResponse response) {
logger.info("------------- ExecutionContextImpl.java , initializing web facade -----------------")
WebFacadeImpl wfi = new WebFacadeImpl(webappMoquiName, request, response, this);
webFacade = wfi;
webFacadeImpl = wfi;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,7 @@ class WebFacadeImpl implements WebFacade {
void handleServiceRestCall(List<String> extraPathNameList) {
ContextStack parmStack = (ContextStack) getParameters()

logger.info("====================== Service REst for post")
logger.info("Service REST for ${request.getMethod()} to ${request.getPathInfo()} headers ${request.headerNames.collect()} parameters ${getRequestParameters().keySet()}")

// check for login, etc error messages
Expand Down Expand Up @@ -1069,6 +1070,7 @@ class WebFacadeImpl implements WebFacade {
parmStack.putAll((Map) bodyListObj)
eci.contextStack.push(parmStack)

logger.info("---------------- calling rest api run with params =-----"+extraPathNameList.toString());
RestApi.RestResult restResult = eci.serviceFacade.restApi.run(extraPathNameList, eci)
responseList.add(restResult.responseObj ?: [:])

Expand All @@ -1088,6 +1090,7 @@ class WebFacadeImpl implements WebFacade {
}
} else {
eci.contextStack.push(parmStack)
logger.info("---------------- 2 calling rest api run with params =-----"+extraPathNameList.toString());
RestApi.RestResult restResult = eci.serviceFacade.restApi.run(extraPathNameList, eci)
eci.contextStack.pop()
response.addIntHeader('X-Run-Time-ms', (System.currentTimeMillis() - startTime) as int)
Expand All @@ -1102,6 +1105,7 @@ class WebFacadeImpl implements WebFacade {
// NOTE: This will always respond with 200 OK, consider using 201 Created (for successful POST, create PUT)
// and 204 No Content (for DELETE and other when no content is returned)
sendJsonResponse(restResult.responseObj)
logger.info("------------------- Sends rest result repsonse ")
}
}
} catch (AuthenticationRequiredException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ class ScreenRenderImpl implements ScreenRender {
@Override ScreenRender saveHistory(boolean sh) { this.saveHistory = sh; return this }

@Override
void render(HttpServletRequest request, HttpServletResponse response) {
void
render(HttpServletRequest request, HttpServletResponse response) {
logger.info("------------------------- ScreenRenerImpl.groovy, render(HttpServletRequest request, HttpServletResponse response) Rendering HTTP Request---------------------------");
if (rendering) throw new IllegalStateException("This screen render has already been used")
rendering = true
this.request = request
Expand Down Expand Up @@ -277,6 +279,7 @@ class ScreenRenderImpl implements ScreenRender {
}

protected void internalRender() {
logger.info("--------------- ScreenRenderImpl.groovy, Running Internal Render, this will call rest/s1 of rest.xml ------------------------------");
// make sure this (sri) is in the context before running actions or rendering screens
ec.contextStack.put("sri", this)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class RestApi {
RestResult run(List<String> pathList, ExecutionContextImpl ec) {
if (pathList == null || pathList.size() == 0) throw new ResourceNotFoundException("Cannot run REST service with no path")
String firstPath = pathList[0]
logger.info("------------- RestApi.groovy Getting Root Resource node for this path ---------------"+firstPath)
ResourceNode resourceNode = getRootResourceNode(firstPath)
return resourceNode.visit(pathList, 0, ec)
}
Expand Down Expand Up @@ -230,6 +231,7 @@ class RestApi {
serviceName = serviceNode.attribute("name")
}
RestResult run(List<String> pathList, ExecutionContext ec) {
logger.info("--------------------------- RestApi.groovy, static Class MethodService Running run method from method handler ------------------------");
if ((requireAuthentication == null || requireAuthentication.length() == 0 || "true".equals(requireAuthentication)) &&
!ec.getUser().getUsername()) {
throw new AuthenticationRequiredException("User must be logged in to call service ${serviceName}")
Expand All @@ -245,6 +247,7 @@ class RestApi {
}

try {
logger.info("--------------------- RestApi.groovy, static Class MethodService, calling ServiceCallSyncImpl.java call() which finally runs the service ---------------")
Map result = ec.getService().sync().name(serviceName).parameters(ec.context).call()
ServiceDefinition.nestedRemoveNullsFromResultMap(result)
return new RestResult(result, null)
Expand Down Expand Up @@ -679,6 +682,7 @@ class RestApi {
if (idNode != null && idNode.allowExtraPath && methodMap.get(getCurrentMethod(ec)) == null) {
return idNode.visit(pathList, nextPathIndex, ec)
}
logger.info("------------------- RestApi.groovy running runByMethod ------"+pathList);
return runByMethod(pathList, ec)
}
} finally {
Expand Down Expand Up @@ -754,7 +758,7 @@ class RestApi {
super(node, parent, ecfi, false)
}
RestResult visit(List<String> pathList, int pathIndex, ExecutionContextImpl ec) {
// logger.info("Visit resource ${name}")
logger.info("----------------------------------- RestApi.groovy Visit resource ${name} (keeps visiting until finds leaf node)")
// visit child or run here
return visitChildOrRun(pathList, pathIndex, ec)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class ServiceCallSyncImpl extends ServiceCallImpl implements ServiceCallS

@Override
public Map<String, Object> call() {
logger.info("--------------------------------------- Service CAll Sync IMPL =------------------------------");
ExecutionContextFactoryImpl ecfi = sfi.ecfi;
ExecutionContextImpl eci = ecfi.getEci();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class MoquiServlet extends HttpServlet {

@Override
void service(HttpServletRequest request, HttpServletResponse response) {
logger.info("------------- Running void service() from MoquiServlet.groovy, triggered by Http Request on Jetty Server ----------")
ExecutionContextFactoryImpl ecfi = (ExecutionContextFactoryImpl) getServletContext().getAttribute("executionContextFactory")
String webappName = getInitParameter("moqui-name") ?: getServletContext().getInitParameter("moqui-name")

Expand Down Expand Up @@ -101,7 +102,7 @@ class MoquiServlet extends HttpServlet {
}
// get a new ExecutionContext
ExecutionContextImpl ec = ecfi.getEci()

logger.info("------------- Running void service() from MoquiServlet.groovy, Creating new execution context ----------")
/** NOTE to set render settings manually do something like this, but it is not necessary to set these things
* for a web page render because if we call render(request, response) it can figure all of this out as defaults
*
Expand All @@ -111,10 +112,13 @@ class MoquiServlet extends HttpServlet {

ScreenRenderImpl sri = null
try {
logger.info("------------- Running void service() from MoquiServlet.groovy, Calling intiWebFacade ----------")
ec.initWebFacade(webappName, request, response)
ec.web.requestAttributes.put("moquiRequestStartTime", startTime)

logger.info("------------- Running void service() from MoquiServlet.groovy, creating object of Screen Render ----------")
sri = (ScreenRenderImpl) ec.screenFacade.makeRender().saveHistory(true)
logger.info("------------- Running void service() from MoquiServlet.groovy, Calling ScreenRenderImpl render(HttpServletRequest request, HttpServletResponse response) ----------")
sri.render(request, response)
} catch (AuthenticationRequiredException e) {
logger.warn("Web Unauthorized (no authc): " + e.message)
Expand Down

0 comments on commit f2a7830

Please sign in to comment.