We recently moved our SAP to unicode and onto Linux. After the conversion and move to different IP address we had an issue where the new IP was not been set by the SAP JCO. After sometime we found a solution to the problem which is a better way to do the connection, hence a change to the original code I posted.
The original code has lines like this setting the properties -
Properties connectProperties = new Properties();
connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "xxx");
The problem is that the SAP JCO seems to create a property file on the file system which is initially set and then thereafter always read and not updated with any new values. To over come this problem the connection was changed to this -
public static void sapConnect(Document docConn) throws JCoException
{
System.out.println("sapConnect Start");
Properties connectProperties = new Properties();
if (docConn!=null){
try {
//Set values according to what is in the profile document
connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, docConn.getItemValueString("txtSAP_Server"));
connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, docConn.getItemValueString("txtSAP_SystemNo"));
connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, docConn.getItemValueString("txtSAP_Client"));
connectProperties.setProperty(DestinationDataProvider.JCO_USER, docConn.getItemValueString("txtSAP_UserID"));
connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, docConn.getItemValueString("txtSAP_Password"));
connectProperties.setProperty(DestinationDataProvider.JCO_LANG, docConn.getItemValueString("txtSAP_Language"));
connectProperties.setProperty(DestinationDataProvider.JCO_CODEPAGE,"4103");
createDestinationDataFile(ABAP_AS, connectProperties);
//These are only used if using Pool Connection
connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, "3");
connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT, "10");
} catch (NotesException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
destination = JCoDestinationManager.getDestination(ABAP_AS);
JCoAttributes attributes = destination.getAttributes();
System.out.println("Connection attributes:\n" +
"--------Connection attributes------\n" + attributes);
boolean is_backend_unicode = attributes.getPartnerCodepage().equals("4102") ||
attributes.getPartnerCodepage().equals("4103");
System.out.println("trace:\n" +
"--------Connection attributes-----\n" + attributes.getTrace());
System.out.println("sapConnect End");
}
/*
* Create the properties file for connection
*/
static void createDestinationDataFile(String destinationName, Properties connectProperties)
{
File destCfg = new File(destinationName+".jcoDestination");
try
{
FileOutputStream fos = new FileOutputStream(destCfg, false);
connectProperties.store(fos, "SAP JCo with Domino");
fos.close();
}
catch (Exception e)
{
throw new RuntimeException("Unable to create the destination files", e);
}
}
The (createDestinationDataFile) is where the file is created on the file system and the values always updated.
I hope this helps anyone out there.