Announcement

Collapse
No announcement yet.

TransformerException: Java constructor replace matching JavaScript argument types is ambiguous

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • TransformerException: Java constructor replace matching JavaScript argument types is ambiguous

    Any help to resolve this error would be appreciated.

    Thanks in advance!
    ===============

    Mirth 1.3.1

    ==============
    Transformer: JavaScript Code
    // =========================================
    // Get the encrypted document from the database
    // =========================================
    var dbConn = DatabaseConnectionFactory.createDatabaseConnection ('net.sourceforge.jtds.jdbc.Driver', 'jdbc:jtds:sqlserver://TestServer:1433/DocumentDB', 'sa', 'test'
    var expression = 'SELECT DocumentText FROM DocumentList WHERE DocumentID = 1';
    var result = dbConn.executeCachedQuery(expression);

    result.next();
    var cl = result.getClob(1);
    var strOut = new java.lang.StringBuffer();
    var aux = new java.lang.String();

    // We access to stream, as this way we don't have to use the CLOB.length() which is slower...
    var br = new java.io.BufferedReader(cl.getCharacterStream());

    while ((aux = br.readLine())!= null)
    strOut.append(aux);
    // DocumentText is encrypted
    var input = strOut.toString();

    // Begin - Decrypt document to plain text

    var output = "";
    var chr1, chr2, chr3;
    var enc1, enc2, enc3, enc4;
    var i = 0;

    // The replace method below is causing exception
    // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
    input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

    do {
    enc1 = keyStr.indexOf(input.charAt(i++));
    enc2 = keyStr.indexOf(input.charAt(i++));
    enc3 = keyStr.indexOf(input.charAt(i++));
    enc4 = keyStr.indexOf(input.charAt(i++));

    chr1 = (enc1 << 2) | (enc2 >> 4);
    chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
    chr3 = ((enc3 & 3) << 6) | enc4;

    output = output + String.fromCharCode(chr1);

    if (enc3 != 64) {
    output = output + String.fromCharCode(chr2);
    }
    if (enc4 != 64) {
    output = output + String.fromCharCode(chr3);
    }
    } while (i < input.length);

    // End - Decrypt

    var plainTextOutput = output;

    globalMap.put(&#039;gDocInPlainText&#039;, plainTextOutput);

    ==============


    ERROR 2007-01-12 18:40:27,282 [739c7d6b-6e70-4d35-b766-fa217de48b85_destination_1_connector.dispatcher.1] org.mule.providers.file.FileMessageDispatcher: Error at tranformerorg.mule.umo.transformer.TransformerExce ption: The choice of Java constructor replace matching JavaScript argument types (function,string) is ambiguous; candidate constructors are:
    class java.lang.String replace(java.lang.CharSequence,java.lang.CharSeque nce)
    class java.lang.String replace(char,char) (5853e445-f53f-495f-b7c5-3856f7a58ca0#27) (org.mozilla.javascript.EvaluatorException)

    ERROR 2007-01-12 18:40:27,322 [739c7d6b-6e70-4d35-b766-fa217de48b85_destination_1_connector.dispatcher.1] org.mule.impl.DefaultComponentExceptionStrategy: Caught exception in Exception Strategy for: 739c7d6b-6e70-4d35-b766-fa217de48b85: org.mule.umo.transformer.TransformerException: The choice of Java constructor replace matching JavaScript argument types (function,string) is ambiguous; candidate constructors are:
    class java.lang.String replace(java.lang.CharSequence,java.lang.CharSeque nce)
    class java.lang.String replace(char,char) (5853e445-f53f-495f-b7c5-3856f7a58ca0#27) (org.mozilla.javascript.EvaluatorException)
    org.mule.umo.transformer.TransformerException: The choice of Java constructor replace matching JavaScript argument types (function,string) is ambiguous; candidate constructors are:
    class java.lang.String replace(java.lang.CharSequence,java.lang.CharSeque nce)
    class java.lang.String replace(char,char) (5853e445-f53f-495f-b7c5-3856f7a58ca0#27) (org.mozilla.javascript.EvaluatorException)
    at com.webreach.mirth.server.mule.transformers.JavaSc riptTransformer.evaluateOutboundTransformerScript( JavaScriptTransformer.java:332)
    at com.webreach.mirth.server.mule.transformers.JavaSc riptTransformer.doTransform(JavaScriptTransformer. java:174)
    at org.mule.transformers.AbstractTransformer.transfor m(AbstractTransformer.java:197)
    at org.mule.impl.MuleEvent.getTransformedMessage(Mule Event.java:251)
    at org.mule.providers.file.FileMessageDispatcher.doDi spatch(FileMessageDispatcher.java:74)
    at org.mule.providers.AbstractMessageDispatcher$Worke r.run(AbstractMessageDispatcher.java:257)
    at org.mule.impl.work.WorkerContext.run(WorkerContext .java:290)
    at edu.emory.mathcs.backport.java.util.concurrent.Thr eadPoolExecutor$Worker.runTask(ThreadPoolExecutor. java:650)
    at edu.emory.mathcs.backport.java.util.concurrent.Thr eadPoolExecutor$Worker.run(ThreadPoolExecutor.java :675)
    at java.lang.Thread.run(Unknown Source)
    Caused by: org.mozilla.javascript.EvaluatorException: The choice of Java constructor replace matching JavaScript argument types (function,string) is ambiguous; candidate constructors are:
    class java.lang.String replace(java.lang.CharSequence,java.lang.CharSeque nce)
    class java.lang.String replace(char,char) (5853e445-f53f-495f-b7c5-3856f7a58ca0#27)
    at org.mozilla.javascript.DefaultErrorReporter.runtim eError(DefaultErrorReporter.java:95)
    at org.mozilla.javascript.Context.reportRuntimeError( Context.java:966)
    at org.mozilla.javascript.Context.reportRuntimeError( Context.java:1022)
    at org.mozilla.javascript.Context.reportRuntimeError3 (Context.java:1000)
    at org.mozilla.javascript.NativeJavaMethod.findFuncti on(NativeJavaMethod.java:382)
    at org.mozilla.javascript.NativeJavaMethod.call(Nativ eJavaMethod.java:153)
    at org.mozilla.javascript.optimizer.OptRuntime.call2( OptRuntime.java:74)
    at org.mozilla.javascript.gen.c116._c2(5853e445-f53f-495f-b7c5-3856f7a58ca0:27)
    at org.mozilla.javascript.gen.c116.call(5853e445-f53f-495f-b7c5-3856f7a58ca0)
    at org.mozilla.javascript.optimizer.OptRuntime.callNa me0(OptRuntime.java:106)
    at org.mozilla.javascript.gen.c116._c0(5853e445-f53f-495f-b7c5-3856f7a58ca0:52)
    at org.mozilla.javascript.gen.c116.call(5853e445-f53f-495f-b7c5-3856f7a58ca0)
    at org.mozilla.javascript.ContextFactory.doTopCall(Co ntextFactory.java:337)
    at org.mozilla.javascript.ScriptRuntime.doTopCall(Scr iptRuntime.java:2755)
    at org.mozilla.javascript.gen.c116.call(5853e445-f53f-495f-b7c5-3856f7a58ca0)
    at org.mozilla.javascript.gen.c116.exec(5853e445-f53f-495f-b7c5-3856f7a58ca0)
    at com.webreach.mirth.server.mule.transformers.JavaSc riptTransformer.evaluateOutboundTransformerScript( JavaScriptTransformer.java:307)
    ... 9 more

  • #2
    Re: TransformerException: Java constructor replace matching JavaScript argument types is ambiguous

    This is a tricky quirk of Javascript in Java. Since strOut is a Java object, var input = strOut.toString(); means that "input" is also a Java string, not a Javascript string. Javascript strings have a replace that takes a regex function (/regex/) as a parameter, however Java strings take two string parameters in the replaceAll method:

    Code:
    input = input.replaceAll("[^A-Za-z0-9\+\/\=]", "");
    You might have to modify the regex a bit as I&#039;m not sure that Javascript and Java share the same regex structure.

    -Chris

    (Just a note - I used replaceAll vs replace. Replace is a valid function, but it only operates on characters, not strings. ReplaceAll will take a string that CAN be a regex. See: http://java.sun.com/j2se/1.5.0/docs/...ng/String.html for more info)
    Chris Lang

    Comment


    • #3
      Re: TransformerException: Java constructor replace

      Problem: Java, Javascript String replace
      I am trying to replace all instances of ' with ''.

      In the preprocessor, JavaScript replace with regular expression works fine.

      However, when I try to do the same in Destinations tab, Database Writer,and Javascript, it doesn't like it. It says suggested constructor(char, char) etc - error mentioned in the thread (above).

      If I try with value.toString().replaceAll("is", "are"), replaceAll is not recognized.
      Error message below:

      [2008-10-06 15:44:36,864] ERROR (org.mule.impl.DefaultComponentExceptionStrategy:9 5): Caught exception in Exception Strategy for: 505150d3-0b9f-4ef8-bc55-83cf0f25f5fa: org.mozilla.javascript.EcmaError: TypeError: Cannot find function replaceAll. (a1267cb7-8b1e-4447-b725-35a6c972d32a#1138)
      org.mozilla.javascript.EcmaError: TypeError: Cannot find function replaceAll. (a1267cb7-8b1e-4447-b725-35a6c972d32a#1138

      I can do simple replace, but that will replace only the first instance. I am confused as to which method Mirth is looking for. If I try replaceAll (java) it doesn't recognize the funtion. If i just do replace with regular expression (javascript), it insists on using java.lang.String.

      I'd appreciate your help.

      Thanks.

      Comment


      • #4
        I'm in the same situation... Trying to replace single quotes (') with non-obstructive characters (´):

        Code:
        $('c16').replace(/\'/g, "´")
        But getting this error:

        Code:
        ERROR MESSAGE:	Error writing to database: 
        org.mozilla.javascript.EvaluatorException: The choice of Java constructor replace matching JavaScript argument types (function,string) is ambiguous; candidate constructors are: 
            class java.lang.String replace(char,char)
            class java.lang.String replace(java.lang.CharSequence,java.lang.CharSequence) (bf36fa83-590f-4365-929f-c222598fafab#168)
        Last edited by Dimas; 06-17-2009, 12:08 AM.

        Comment


        • #5
          Just wanted to share. I had a the same issue and figured this out if you want to use the '.replace' the way you where trying too cast the java string into a javascript string:

          instead of:
          Code:
          var input = strOut.toString();
          use:
          Code:
          var input = new String(strOut);
          The .toString() is primarily for e4x to take an XML node and print its value.

          Hope this helps you or anyone in the future.

          Comment


          • #6
            Originally posted by crobbins View Post
            Just wanted to share. I had a the same issue and figured this out if you want to use the '.replace' the way you where trying too cast the java string into a javascript string:

            instead of:
            Code:
            var input = strOut.toString();
            use:
            Code:
            var input = new String(strOut);
            The .toString() is primarily for e4x to take an XML node and print its value.

            Hope this helps you or anyone in the future.
            oohh, im trying to see an xml elemnt with tostring and am having troubles.
            Last edited by FlamingRacer; 04-04-2010, 05:30 PM.

            Comment


            • #7
              @peisima

              We do replacement of all charaters like this:

              We have an array with the characters to be replaced called repArray.

              var myMessage = message.toString();

              for ( i = 0; i < repArray.length; i++ ) {
              var idx = myMessage.indexOf( repArray[i][0] );

              while ( idx > -1 ) {
              myMessage = myMessage.replace( repArray[i][0], repArray[i][1] );
              idx = myMessage.indexOf( repArray[i][0] );
              }

              }

              message = myMessage;
              JJ Mouris
              FFE Luxembourg
              IT-Department

              Comment


              • #8
                Originally posted by FlamingRacer View Post
                oohh, im trying to see an xml elemnt with tostring and am having troubles.
                If you do a .toString() on an xml element it will return the value of the element. If the value is XML it will return the xml in string form

                Comment

                Working...
                X
                😀
                🥰
                🤢
                😎
                😡
                👍
                👎