web stats
Real debugging for mirth javaScript channel code - Page 2 - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #11  
Old 01-28-2014, 10:59 AM
rastababy rastababy is offline
OBX.2 Kenobi
 
Join Date: Mar 2008
Posts: 72
rastababy
Default Working!

Quote:
Originally Posted by rastababy View Post
Trying to get this functioning in v3 with no success so far. Can anyone share how to get hte "global scope" in main.java?

I see javaScriptScopeUtil class, but the "getDeployScope" method takes a "logger". not sure how to get the scope to send the debugger.
Used the following to get it working:

Scriptable scope = JavaScriptScopeUtil.getDeployScope("testlogger");

Way easier to debug channel code !!
Reply With Quote
  #12  
Old 01-28-2014, 11:00 AM
rastababy rastababy is offline
OBX.2 Kenobi
 
Join Date: Mar 2008
Posts: 72
rastababy
Default Working in v3.01

Used the following:

Scriptable scope = JavaScriptScopeUtil.getDeployScope("testlogger");


Much easier to debug channel code !!
Reply With Quote
  #13  
Old 03-06-2014, 03:40 AM
sibmat sibmat is offline
Mirth Newb
 
Join Date: Jan 2014
Posts: 20
sibmat is on a distinguished road
Default

Hello rastababy,

I have followed each step as mentioned above, i am able to launch rhino debugger when server is started, but when i redeploy all the channels and run them, debugger is not catching any thing. Nothing is displayed in debugger at all.

In 'Scriptable scope = JavaScriptScopeUtil.getDeployScope("testlogger");'

what is 'testlogger'?

Thanks.
Reply With Quote
  #14  
Old 05-12-2014, 01:41 PM
jessethouin jessethouin is offline
What's HL7?
 
Join Date: Apr 2014
Posts: 5
jessethouin is on a distinguished road
Default Debugger working in 3.0

After 3 days of head banging and looking for documentation that doesn't exist, I was able to get the debugger working in Mirth 3.0.2. I haven't tried this solution in other 3.x versions, but I imagine it's not too different, if at all.

Basically, you don't need a separate Main class to launch mirth, becasue the new architecture of the scope objects requires that the context and scope be created after Mirth is launched; so launching the debugger before you instantiate Mirth does no good.

The trick is to modify com.mirth.connect.server.util.javascript.JavaScrip tScopeUtil. Add this import:

Code:
import org.mozilla.javascript.tools.debugger.Main;
Add this static variable:

Code:
private static Main debugger = null;
In method "protected static Context getContext()", just before the return statement, add the following lines:

Code:
if (debugger == null) {
    debugger = Main.mainEmbedded(ContextFactory.getGlobal(), getScope(context), "Mirth debugger");
}
Here's the entire new method for reference:

Code:
    protected static Context getContext() {
        initialize();
        Context context = ContextFactory.getGlobal().enterContext();
        context.setOptimizationLevel(rhinoOptimizationLevel);

        if (sealedSharedScope == null) {
            sealedSharedScope = new ImporterTopLevel(context);
            Script script = JavaScriptUtil.getCompiledGlobalSealedScript(context);
            script.exec(context, sealedSharedScope);
            sealedSharedScope.sealObject();
        }

        if (debugger == null) {
            debugger = Main.mainEmbedded(ContextFactory.getGlobal(), getScope(context), "Mirth debugger");
        }

        return context;
    }
Hope that helps anyone looking for a solution!
Reply With Quote
  #15  
Old 07-06-2016, 12:38 PM
mastersb mastersb is offline
Mirth Newb
 
Join Date: Aug 2012
Posts: 7
mastersb is on a distinguished road
Default

Quote:
Originally Posted by jessethouin View Post
Hope that helps anyone looking for a solution!
This actually worked great when I was debugging 3.0.x versions. I'm trying to get this setup again for version 3.4.1.8057 and not having much success at the moment.

Have you (or anyone else) managed to get javascript debugging working in a newer version?
Reply With Quote
  #16  
Old 07-11-2016, 11:52 AM
jessethouin jessethouin is offline
What's HL7?
 
Join Date: Apr 2014
Posts: 5
jessethouin is on a distinguished road
Default

I have this working through 3.2.2, but I haven't tried it on 3.4.x. I'll fire up that version and see what's what.
Reply With Quote
  #17  
Old 11-30-2016, 03:23 PM
ppazos ppazos is offline
OBX.2 Kenobi
 
Join Date: May 2008
Posts: 76
ppazos
Default

Are there any news about this issues? The developers keep delaying it's inclusion since 2012, and today it is marked to be solved in 3.6 with current being 3.4.x
Reply With Quote
  #18  
Old 04-23-2018, 06:27 AM
Andrea Pravato Andrea Pravato is offline
What's HL7?
 
Join Date: Apr 2018
Posts: 1
Andrea Pravato is on a distinguished road
Default Are there any news about debugging

Hi! I have compiled Mirth 3.5.2 source using Ant and I am trying now to make real debugging of javascript code work in Mirth; I do not find most of the classes referenced in previous posts; are there news about the procedure to follow to get debugger to work? Thanks
Reply With Quote
  #19  
Old 04-25-2018, 09:26 AM
mitch_nchin mitch_nchin is offline
Mirth Newb
 
Join Date: Nov 2015
Posts: 17
mitch_nchin is on a distinguished road
Default Rhino Debugger

I've found that removing the "headless" argument from the run configuration is important to getting the Rhino debugger window to show up.

Modifying JavaScriptFilterTransformer.java such that FilterTransformerTask's doCall method starts the debugger kinda sorta works off the trunk, but seems to invoke shutdown code in the current release's branch.

Running the server in Eclipse on Windows, this seems to cause the debugger window to appear but perhaps only once after the transformer has been modified... at least that's been my confusing experience.

The variable dbg in the code below is declared private static Main dbg in the FilterTransformer class, and the file imports org.mozilla.javascript.tools.debugger.Main (and org.mozilla.javascript.Scriptable, .Script, .RhinoException, and .Context).

This may well fall in the "a little knowledge is a dangerous thing" category.

HTML Code:
      @Override
        public FilterTransformerResult doCall() throws Exception {
        	System.out.println("In doCall of JavaScriptFilterTransformer.");
            Logger scriptLogger = Logger.getLogger("filter");
            // Use an array to store the phase, otherwise java and javascript end up referencing two different objects.
            String[] phase = { new String() };

            // get the script from the cache and execute it
            Script compiledScript = compiledScriptCache.getCompiledScript(scriptId);

            if (compiledScript == null) {
                logger.debug("Could not find script " + scriptId + " in cache.");
                throw new FilterTransformerException("Could not find script " + scriptId + " in cache.", null, ErrorMessageBuilder.buildErrorMessage("Filter/Transformer", "Could not find script " + scriptId + " in cache.", null));
            } else {
                try {
                	System.out.println("In doCall/else/try of JavaScriptFilterTransformer.");
                    // TODO: Get rid of template and phase
                    Scriptable scope = JavaScriptScopeUtil.getFilterTransformerScope(getContextFactory(), scriptLogger, new ImmutableConnectorMessage(message, true, connector.getDestinationIdMap()), template, phase);
                    if (dbg == null){
                    	System.out.println("In doCall/else/try of JavaScriptFilterTransformer, creating dbg.");
                    	dbg = Main.mainEmbedded(getContextFactory(),scope,"Mirth SVN HEAD at NCHIIN");
                       	System.out.println("In doCall/else/try of JavaScriptFilterTransformer, created dbg.");
                    }
                    dbg.attachTo(getContextFactory());

                    Object result = executeScript(compiledScript, scope);

                    String transformedData = JavaScriptScopeUtil.getTransformedDataFromScope(scope, StringUtils.isNotBlank(template));

                    return new FilterTransformerResult(!(Boolean) Context.jsToJava(result, java.lang.Boolean.class), transformedData);
                } catch (Throwable t) {
                    if (t instanceof RhinoException) {
                        try {
                            String script = CompiledScriptCache.getInstance().getSourceScript(scriptId);
                            int linenumber = ((RhinoException) t).lineNumber();
                            String errorReport = JavaScriptUtil.getSourceCode(script, linenumber, 0);
                            t = new MirthJavascriptTransformerException((RhinoException) t, connector.getChannelId(), connectorName, 0, phase[0].toUpperCase(), errorReport);
                        } catch (Exception ee) {
                            t = new MirthJavascriptTransformerException((RhinoException) t, connector.getChannelId(), connectorName, 0, phase[0].toUpperCase(), null);
                        }
                    }

                    if (phase[0].equals("filter")) {
                        eventController.dispatchEvent(new ErrorEvent(message.getChannelId(), message.getMetaDataId(), message.getMessageId(), ErrorEventType.FILTER, connectorName, null, "Error evaluating filter", t));
                        throw new FilterTransformerException(t.getMessage(), t, ErrorMessageBuilder.buildErrorMessage(ErrorEventType.FILTER.toString(), "Error evaluating filter", t));
                    } else {
                        eventController.dispatchEvent(new ErrorEvent(message.getChannelId(), message.getMetaDataId(), message.getMessageId(), ErrorEventType.TRANSFORMER, connectorName, null, "Error evaluating transformer", t));
                        throw new FilterTransformerException(t.getMessage(), t, ErrorMessageBuilder.buildErrorMessage(ErrorEventType.TRANSFORMER.toString(), "Error evaluating transformer", t));
                    }
                } finally {
                    Context.exit();
                }
            }
        }
    }

Last edited by mitch_nchin; 04-25-2018 at 09:32 AM.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 05:01 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation