Skip to Content
author's profile photo Former Member
Former Member

JCO.Server appends null character to string

I am a complete SAP and JCO newbie so I'll try making as much since as I can, given the fact that I'm not familiar with SAP terminology and technology. I've been lent as a developer to another group which needs a legacy application rewritten. The application processes a RFC and decrypts the RFC encrypted payload and returns it along with a status code.

I have made progress - I'm able to register my server with the SAP runtime and using the SAP GUI application and the help of a SAP developer, I'm able to make an RFC call to my application. I'm able to read the parameters sent from SAP and write parameters back.

The problem is that one of the parameters I'm writing back (java.lang.String) appears to have and extra character on SAP side. On the GUI it appears as a '#' (pound) sign. The SAP developer told me the string is terminated with a null character which I know is a C/C++ thing but not a Java thing. I don't think it is a Unicode issue. The Java server is not running in Unicode mode and any attempt to set the jco.server.unicode property (I may have forgotten the exact name) to a value of 1 causes the RFC to fail.

I think the issue is likely to be the manner in which I defined the function parameters or the manner in which I write them. The following are code snippets:

Defining the function:

JCO.MetaData metadata = new JCO.MetaData(Constants.FUNCTION_DECRYPT);

metadata.addInfo(Constants.PARAMETER_SCHEME, JCO.TYPE_INT, 255, 0, 0, JCO.IMPORT_PARAMETER, null);

metadata.addInfo(Constants.PARAMETER_ENCRYPTED, JCO.TYPE_STRING, 255, 0, 0, JCO.IMPORT_PARAMETER, null);

metadata.addInfo(Constants.PARAMETER_DECRYPTED, JCO.TYPE_STRING, 255, 0, 0, JCO.EXPORT_PARAMETER, null);

metadata.addInfo(Constants.PARAMETER_RETURN_CODE, JCO.TYPE_INT, 255, 0, 0, JCO.EXPORT_PARAMETER, null);

Server request handling code:

protected void handleRequest(JCO.Function function)

{

// Obtaining import/export parameter lists.

JCO.ParameterList input = function.getImportParameterList();

JCO.ParameterList output = function.getExportParameterList();

// Getting scheme and encrypted text parameters.

int scheme = input.getInt(Constants.PARAMETER_SCHEME);

String encrypted = input.getString(Constants.PARAMETER_ENCRYPTED);

// Decoding base 64 string.

byte[] bytes = Base64.decode(encrypted);

// Obtaining cipher by scheme and decrypting the text.

AppCipher cipher = ApplicationConfiguration.getDecryptor(scheme);

if(cipher == null)

{

logger.error("Unable to get cipher due to an unknown encryption scheme: " + scheme);

}

else

{

byte[] decrypted = cipher.decrypt(bytes);

String plainText = new String(decrypted);

// Setting decrypted value information and return code.

output.setValue(plainText, Constants.PARAMETER_DECRYPTED);

output.setValue(Constants.RETURN_CODE_SUCCESS, Constants.PARAMETER_RETURN_CODE);

}

}

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on Aug 18, 2011 at 06:52 PM

    I seem to have made progress. If I define the parameter type as JCO.TYPE_CHAR instead of JCO.TYPE_STRING, it works:

    metadata.addInfo(Constants.PARAMETER_DECRYPTED, JCO.TYPE_CHAR, 255, 0, 0, JCO.EXPORT_PARAMETER, null);

    That is the only change I made. I'm still setting the parameter value as java.lang.String. I hope this won't cause issues elsewhere. I was also able to change the field definition and set it as a byte array. However, that had the problem of having to define the exact length of the byte array in the field metadata otherwise the remaining bytes would appear as null bytes on SAP side.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.