Question

I'm creating DataSource in the jython in wsadmin console in the following way:

First I search for JDBC provider by name:

for provider in AdminConfig.list('JDBCProvider').split('\r\n'):
  if AdminConfig.showAttribute(provider, 'name') == providerName:
    print 'Found JDBC provider: '+provider
    db2provider = provider

The JDBC provider is found. Now I create DataSource using this provider:

dsAttrs = [['name', 'myDS1'], ['jndiName','jdbc/MY/DS1']]    
newDs = AdminConfig.create('DataSource', db2provider, dsAttrs)

but I get an exception:

WASX7015E: Exception running command: "newDs = AdminConfig.create('DataSource', db2provider, dsAttrs)"; exception inform ation: com.ibm.websphere.management.exception.ConfigServiceException java.lang.NullPointerException: java.lang.NullPointerException

What is wrong in that code? I'm following the IBM documentation and the examples from internet.

I'm using WebSphere 8.5

Était-ce utile?

La solution

My guess is that you've developed your script on Windows, then you run it on UNIX/Linux. Hence, .split('\r\n') which works fine on Windows, doesn't split lines. With .splitlines() your script would be more portable, you don't have to bother with '\n' vs '\r\n' then.

BTW: There's a quicker way of finding the right provider via AdminConfig.getid:

# getid will return only JDBCProviders with specified name
# then splitlines will return an array of matched objects
# finally [0] will get the first item
db2provider = AdminConfig.getid('/JDBCProvider:%s/' % providerName).splitlines()[0]
if db2provider:
    dsAttrs = [['name', 'myDS1'], ['jndiName','jdbc/MY/DS1']]    
    newDs = AdminConfig.create('DataSource', db2provider, dsAttrs)
else:
    print 'JDBCProvider not found'

Same script with WDR library (http://wdr.github.io/WDR/):

# getid1 will return single JDBCProvider1 or fail
db2provider = getid1('/JDBCProvider:%s/' % providerName)
newDs = db2provider.create('DataSource', name = 'myDS1', jndiName = 'jdbc/MY/DS1')

Or even better (idempotent):

# getid1 will return single JDBCProvider1 or fail
db2provider = getid1('/JDBCProvider:%s/' % providerName)
ds = db2provider.assure('DataSource', {'name': 'myDS1'}, jndiName = 'jdbc/MY/DS1')

Confession: I'm one of WDR contributors.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top