Hi,
I am trying the following code in a javascript rule file:
function rule()
{
java.lang.System.out.println("num parts: " + XQMessage.getPartCount());
java.lang.String sContentType = XQMessage.getPart(0).getContentType();
return null;
}
I keep getting "JavaScript Error: Internal Error: SyntaxError: missing ;
before statement (line 4)". I cannot see anything wrong with getPart(0)
as getPartCount() returns 1. Am I missing something here?
You appear to be mixing javascript and java.
This is a javascript function definition:
function rule()...
This is a java function call
java.lang.System.out.println...
which language are you trying to use?
Yes, these are java calls, but they should work.
If I remove the statement:
"java.lang.String sContentType = XQMessage.getPart(0).getContentType();"
there is no error and I see output from "java.lang.System.out.println(...".
One comment --- you can certainly use Java objects from inside JavaScript -- and you seem to be doing that correctly (i.e. you preface the method with the explicit class), so this is perfectly fine.
function rule()
{
java.lang.System.out.println("Testing calls to Java in Javascript" );
return null;}
Looking at your code it seems fine -- but the real interpreter is probably seeing something I can't. I might remove the java.lang.String from line 3, and just use JavaScripts automatic type converion. You definitely don't need that, however, I do not think that is the issue.
All I can recomment is removing all the lines and starting from scratch adding them in one-by-one.
I am guessing this works
function rule()
{
java.lang.System.out.println("num parts: " + XQMessage.getPartCount());
return null;
}
// So try adding:
sContentType = XQMessage;
// and then:
sContentType = XQMessage.getPart(0);
// and then:
sContentType = XQMessage.getPart(0).getContentType();
Of course. This is Javascript and does not need class specification.
Removing java.lang.String. did the trick.
Thanks!
Glad it worked. In thinking about it, the casting of objects definitely is the problem. You can refer to Java static objects and classes using the fully qualified packages, so that is why you need java.lang.System.out.println ("something") but you don't use the typing for assignments.