2

I am running a simple JNI program using the Invocation API on z/os with C. The Java program has a simple sayHello() method like this-

public static String sayHello(){
    return "Hello World!!!";
}

the code that calls this method and prints the output is as follows-

jmethodID mid=(*env)->GetStaticMethodID(env,cls2,sHStr,sigVoidString);
 jstring j = (jstring)(*env)->CallStaticObjectMethod(env,cls2, mid);
 const char *str = (*env)->GetStringUTFChars(env, j, NULL);
 printf("%s", str);
 (*env)->ReleaseStringUTFChars(env,j,str);

The output is printed as follows-

..%%?..?.%....

Turning HEX on shows the following which indicates that it is indeed HelloWorld!!!-

46666256766222
85CCF07F2C4111

I have checked few SO posts about the same problems such as this and this and each suggests using GetStringUTFChars which I am using without any success. Is there anything specific to z/os going on here?

Community
  • 1
  • 1
User2709
  • 573
  • 5
  • 17
  • I don't understand how the hex representation could spell `Hello World!!!`. The observation that the 3rd and 4th characters (`ll`) differ indicates that it doesn't. Also, the last three characters should also be identical to each other (`!!!`). – Klas Lindbäck Nov 03 '15 at 11:16
  • http://www.asciitohex.com/ shows the conversion. For HelloWorld!!! the HEX equivalent is 48 65 6c 6c 6f 57 6f 72 6c 64 21 21 21 – User2709 Nov 03 '15 at 11:18
  • 2
    maybe your problem is related with this https://www-01.ibm.com/support/knowledgecenter/#!/SSLTBW_1.12.0/com.ibm.zos.r12.ceev100/mixedmodesupt.htm%23mixedmodesupt At the very end of the page there is this command conversion hellow 2 >&1 | iconv -f ISO8859-1 -t IBM-1047 – terence hill Nov 03 '15 at 11:21
  • That sounds like the problem. I would possibly use some API to convert from ASCII to EBCDIC. I will possibly try out the __atoe()... function listed here http://www-01.ibm.com/support/knowledgecenter/SSYKE2_7.0.0/com.ibm.java.zos.70.doc/user/usejni.html. Thank you. – User2709 Nov 03 '15 at 11:44

1 Answers1

0

The use of __atoe() function worked for me in the case.

User2709
  • 573
  • 5
  • 17
  • Two quick comments...If you do a lot of this, then look at the compiler option "CONVLIT". When set, the compiler automatically translate all your literals (such as your "Hello World" string) into a different codepage, saving you the overhead of doing this sort of thing at runtime. Second, be a bit careful with __atoe() as it just supports ISO8859 (standard ASCII). Technically, that string you're sending to Java is UTF-8. ICONV() would be a better solution than __atoe() if you have to deal with arbitrary strings. – Valerie R Nov 28 '15 at 12:25
  • How did it help? Could you possibly paste the solution? – ShellFish Jan 17 '17 at 19:09