I used the following code (see this SO post) to read a userId and password stored as a JC2 Alias on my WAS 7 server.
Map<String, String> map = new HashMap<String, String>();
map.put(Constants.MAPPING_ALIAS, MDM_JC2_ALIAS);
CallbackHandler callbackHandler = WSMappingCallbackHandlerFactory.getInstance().getCallbackHandler(map, null);
LoginContext loginContext = new LoginContext(DEFAULT_PRINCIPAL_MAPPING, callbackHandler);
loginContext.login();
Subject subject = loginContext.getSubject();
Set<Object> credentials = subject.getPrivateCredentials();
PasswordCredential passwordCredential = (PasswordCredential) credentials.iterator().next();
userId = passwordCredential.getUserName();
password = new String(passwordCredential.getPassword());
The code works fine. But now I am trying to use it in a batch process. To test the batch process I have to use Run->Debug As in Rad 8.5. (I configure the process using Run->Debug As->Debug configurations). I am getting the error "java.lang.NullPointerException: WSMappingCallbackHandlerFactory not initialized". I have stepped through the code that works and can't see any difference in the values from the code which doesn't work. I suspect I may need to modify the build path in my debug configuration but I don't know what to change.
EDIT:
I don't think I have explained the situation very well. The code works inside of a web service running on WAS 7. We have completely different project which has some code which is called as a batch job as follows:
-classpath D:\WebSphere\AppServer\profiles\AppSrv01\Apps\Cell01\SSS.ear\PlanningEJB.jar;
D:\WebSphere\AppServer\profiles\AppSrv01\Apps\Cell01\SSS.ear\Planning.war\WEB-INF\classes;
D:\Progra~1\IBM\SQLLIB\java\db2jcc.jar -Dlog4j.configuration=file:/d:/apps/websphere/SSS/properties/log4J.properties
url.planning.batch.AppName D:\\apps\\websphere\\SSS\\properties\\sss.properties
I want to add the code to read the userId and Password to the code which is called as a batch job. Normally to debug the code called as a batch job we use Debug Configuration and the server does not have to be running. I can set breakpoints and step through the code and it works until I get to the callbackHandler
line.