How to use softcoding in BSSV.

senthcs

Member
Hi,

I have been trying to fetch the username and password from Softcoding record.

I'm able to read the softcoding record. however when i invoke it, i'm getting a security invalid error.

I'm able to invoke the web service by hard coding the password key in my java program.

Could you please help.

Thanks,
Senthilkumar
 

[email protected]

Active Member
I can not guess whats going wrong in your code .
may below code help you !!!!!
I retrieved soft coding in below manner



String softCodingKey = new String("JC550001");
Element softCodingRecord;


try {
//retrieve from SoftCoding record
softCodingRecord =
(Element)SoftCodingRecordAccess.getSoftCodingRecord(context,
softCodingKey);
if (softCodingRecord != null) {


//1. WS URL
String url =
SoftCodingRecordAccess.getSoftcodingRecordFieldvalue(context,
"endpoint",
softCodingRecord);
//2. username
String softCodingUsername =
SoftCodingRecordAccess.getSoftcodingRecordFieldvalue(context,
"username",
softCodingRecord);
//3. password
String softCodingPassword =
SoftCodingRecordAccess.getSoftcodingRecordFieldvalue(context,
"password",
softCodingRecord);
QName serviceName =
new QName("MCSeFMSSecurityAPI", "MCSeFMSSecurityAPI");


SecurityAPIPortType SecurityAPIManager = null;


if (url != null &&
((softCodingUsername == null) && (softCodingPassword ==
null))) {
SBFLogger.getInstance().debug(context,
"Only Softcoding URL is set");
URL wsdlLocation = new URL(url);
MCSeFMSSecurityService =
new MCSeFMSSecurityAPI(wsdlLocation, serviceName);
SecurityAPIManager =
MCSeFMSSecurityService.getSecurityAPIPortType();
} else if (url != null && softCodingUsername != null &&
softCodingPassword != null) {
SBFLogger.getInstance().debug(context,
"Softcoding URL , Username & Password are set");
MCSeFMSSecurityService =
new MCSeFMSSecurityAPI(SecurityAPIPortTypeClient.class.getResource("MCSeFMSSecurityAPI.wsdl"),
serviceName);


/*
HeaderHandler hh = new HeaderHandler();
hh.setSoftCodingUsername(softCodingUsername);
hh.setSoftCodingPassword(softCodingPassword);
SBFLogger.getInstance().debug(context,
"Username & Password are set in HeaderHandler");
HeaderHandlerResolver handlerResolver =
new HeaderHandlerResolver(hh);
MCSeFMSSecurityService.setHandlerResolver(handlerResolver);
*/
SecurityAPIManager =
MCSeFMSSecurityService.getSecurityAPIPortType();
/*
Map<String, Object> reqContext =
((BindingProvider)SecurityAPIManager).getRequestContext();
reqContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
url);
reqContext.put(BindingProvider.USERNAME_PROPERTY,
softCodingUsername);
reqContext.put(BindingProvider.PASSWORD_PROPERTY,
softCodingPassword); */
} else {
SBFLogger.getInstance().debug(context, "No Softcoding");
MCSeFMSSecurityService = new MCSeFMSSecurityAPI();
SecurityAPIManager =
MCSeFMSSecurityService.getSecurityAPIPortType();
}
Regards
Pintya
 

senthcs

Member
Hi,

I have coded as below.


String endpAdd = null;
String username = null;
String password = null;
Element softCodingRecord;
String temp_pwd = null;
String url = null;
String SOFTCODING_KEY = null;
String policy = null;
String os = System.getProperty("os.name");


try {

/*Following part of the code is to generate security header which is exclusively required for Weblogic but not in Websphere*/
if (os.startsWith("Windows")) {
policy =
"C:\\e900\\DV900B\\java\\source\\oracle\\e1\\bssv\\J5942016\\WEB-INF\\Policies\\Wssp1.2-2007-Https-UsernameToken-Plain.xml";
} else {
policy =
"/opt/Oracle/Middleware/user_projects/domains/E1_Apps/Wssp1.2-2007-Https-UsernameToken-Plain.xml";
}
FileInputStream inbound = new FileInputStream(policy);


//softcoding
SOFTCODING_KEY = internalVO.getMerchantID().toUpperCase() + "WLS";
softCodingRecord =
SoftCodingRecordAccess.getSoftCodingRecord(context,
SOFTCODING_KEY);


if (softCodingRecord != null) {
url =
SoftCodingRecordAccess.getSoftcodingRecordFieldvalue(context,
"endpoint",
softCodingRecord);
// ADD WSDL to retrieve the WSDL
if (!url.contains("?wsdl")){
url = url + "?wsdl";
}
username =
SoftCodingRecordAccess.getSoftcodingRecordFieldvalue(context,
"username",
softCodingRecord);
password =
SoftCodingRecordAccess.getSoftcodingRecordFieldvalue(context,
"password",
softCodingRecord);
//to remove the equal symbol at the first position
// password = password.substring(1);



} else {
throw new InvalidSoftCodingRecordException("Unable to find Softcoding Record");
}

TransactionProcessor tranService = new TransactionProcessor_Impl(url);
ITransactionProcessor myPort =
tranService.getPortXML(inbound, true, false);
//Creating Stub
ITransactionProcessor_Stub TranProcStub =
(ITransactionProcessor_Stub)myPort;


//add username and password in XML header
ArrayList credentialproviders = new ArrayList();
CredentialProvider cp =
new ClientUNTCredentialProvider(username.getBytes(),
password.getBytes());
credentialproviders.add(cp);


TranProcStub._setProperty(WSSecurityContext.CREDENTIAL_PROVIDER_LIST,
credentialproviders);
endpAdd =
(String)TranProcStub._getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY);


}
 
Top