Create Integrated Configuration objects using Directory API – Part 2 of 2
This blog is in continuation to Part 1 where we have discussed an example and informal logic to consume Directory API.
For working and consuming Webservice api in Java, one should understand JAXB.
Java Architecture for XML Binding (JAXB) allows Java developers to map Java classes to XML representations
JAXB is different from DOM or SAX.The Java DOM and SAX parsing APIs are lower-level APIs to parse XML documents, while JAXB (Java API for XML Binding) is a higher-level API for converting XML elements and attributes to a Java object hierarchy (and vice versa).
Now coming to development of standalone NWDS project.
For initial setup part please refer these 3 comprehensive blogs by William Li are good reference :
Directory API Development – Part 1 of 3
Directory API Development – Part 2 of 3
Directory API Development – Part 3 of 3
After import of API WSDL and Generate client step, classes specific to XML Schema are generated.
We can find types and getter and setter functions for each XML element(courtesy JAXB ๐ ).
Using these elements and get set methods one can traverse all API data.
As discussed in prev blog,
ICO-create() for Sender component : Change in MessageHeaderId & InboundProcessing .
ICO-change() for Receiver Component: Change in Receivers, ReceiverInterrfaces & OutboundProcessing.
Below is code for the NWDS project fo Create ICO Class.
NWDS Project Code:
mainClass
public static void main(String[] args)
{
String csvFilePath = new String (<DataFile>);
String[] bsList = readExcel(csvFilePath);
CreateIntegratedConfiguration obj = new CreateIntegratedConfiguration(user,password,hostPort,bsList);
obj.createICO();
}
Class
CreateIntegratedConfiguration
//Function createICO()
public void createICO()
{
IntegratedConfigurationCreateChangeIn
createIn=new IntegratedConfigurationCreateChangeIn();
createIn.setChangeListID(createChangeListId());
try{
List<RestrictedIntegratedConfiguration>
listCreateICO = createIn.getIntegratedConfiguration();
listCreateICO.addAll(readICO(queryICO()));
//Create Configuration Object
ConfigurationObjectModifyOut createOut
= port.create(createIn);
}
catch (Exception e) {
e.printStackTrace();
rejectChangeListId(createIn.getChangeListID().toString());
System.exit(0);
}
}
// Function queryICO()
public
List<MessageHeaderID> queryICO() {
IntegratedConfigurationQueryIn
queryIn = new IntegratedConfigurationQueryIn();
MessageHeaderID msgHdr = new
MessageHeaderID();
msgHdr.setSenderComponentID(getSourceBS());
queryIn.setIntegratedConfigurationID(msgHdr);
IntegratedConfigurationQueryOut
queryOut = port.query(queryIn);
List<MessageHeaderID>
lMsgHdr = queryOut.getIntegratedConfigurationID();
return lMsgHdr;
}
@SuppressWarnings("finally")
public
List<RestrictedIntegratedConfiguration>
readICO(List<MessageHeaderID> msgHdrList)
{
List<RestrictedIntegratedConfiguration>
createICOlist= new ArrayList<RestrictedIntegratedConfiguration>();
try {
IntegratedConfigurationReadIn
readIn =new IntegratedConfigurationReadIn();
readIn.getIntegratedConfigurationID().addAll(msgHdrList);
readIn.setReadContext(ReadContextCode.ACTIVE);
IntegratedConfigurationReadOut
readOut = port.read(readIn);
List<IntegratedConfiguration>
listreadOut = readOut.getIntegratedConfiguration();
for(int
i=0;i<listreadOut.size();i++)
{
RestrictedIntegratedConfiguration
resICO = new RestrictedIntegratedConfiguration();
resICO.setMasterLanguage(listreadOut.get(i).getMasterLanguage());
// Get Description
resICO.getDescription().addAll(listreadOut.get(i).getDescription());
//Get Set
MessageHeaderId/IntegratedCOnfiguration ID
resICO.setIntegratedConfigurationID(listreadOut.get(i).getIntegratedConfigurationID());
resICO.getIntegratedConfigurationID().setSenderComponentID(getTargetBS());
//Get Set
MessageHeaderId/IntegratedCOnfiguration ID
//Get Set InboundProcessing
resICO.setInboundProcessing(listreadOut.get(i).getInboundProcessing());
resICO.getInboundProcessing().getCommunicationChannel().setComponentID(getTargetBS());
//Get Set InboundProcessing
//Get Receivers
resICO.setReceivers(listreadOut.get(i).getReceivers());
//Get Receiver Interfaces
resICO.getReceiverInterfaces().addAll(listreadOut.get(i).getReceiverInterfaces());
//Get Outbound
Processing
resICO.getOutboundProcessing().addAll(listreadOut.get(i).getOutboundProcessing());
createICOlist.add(resICO);
}
}
catch (Exception e) {
e.printStackTrace();
}
finally{
return createICOlist;
}
}
Nice Blog Arpil.
Ravi raika
Hi Arpil,
Nice blog, liked it... ๐
I tried to create java project in NWDS to create ICO - to change source business system to target one and kept rest of the ICO objects same.
IntegratedConfigurationCreateChangeIn createIn=new IntegratedConfigurationCreateChangeIn();
List<RestrictedIntegratedConfiguration>
listCreateICO = createIn.getIntegratedConfiguration();
I tried to read above ICO list object "listCreateICO" as well, after modifying ICOs matching as per source system and replacing with target system as sender component. And above object is perfectly updated with ICO list.
Almost used your above code, but I can see empty change list in ID,however still I am getting empty change list id in ID.
--Any hints.. please...
Divyesh
Hi Divyesh,
Summarizing psuedo-code for you:
List<RestrictedIntegratedConfiguration> listCreateICO = createIn.getIntegratedConfiguration();
listCreateICO.addAll(readICO(queryICO()));
if(listCreateICO.size()>0)
{
ConfigurationObjectModifyOut createOut = getICOPort().create(createIn);
}
// In queryICO() read all the ICO MessageHeaderID
// In readICO() read all ICO data and create new ICO list(with Changed Sender Business System): List<RestrictedIntegratedConfiguration>
In your case since changelist is not getting created, its most possibly due to exception.
I suggest try to capture xml in sysout or file and checking the same in wsnavigator.
Regards
Arpil
Hi Arpil,
Thank you for quick reply ๐
Actually issue is that java program is not reporting any exception and also change list is created everytime, but it is empty one.
I checked the size of filled List object of type and it is always filled with modifned new ICO values.
List<RestrictedIntegratedConfiguration> listCreateICO = createIn.getIntegratedConfiguration();
listCreateICO.addAll(readICO(queryICO()));
listCreateICO.size() is > 0
I also tried to parse LogMessageCollection out of "ConfigurationObjectModifyOut" but I do not see any errors, severitycode within "LogMessageCollection".
Basically issue is : empty changelist is created and it is not filled with new ICOs even though I set the same changelistID and add new modified ICOs to the object of IntegratedConfigurationCreateChangeIn "createIn".
Divyesh
Hi Divyesh,
Changelist will get created from api even if no object is added. That is fine.
I think there is some mandatory field which is missing from ICO structure. Best and easiest way is to get xml of the ICO-tree and test in wsnavigator.
Regards
Arpil
Hi April,
We are working on editing communication channel attributes say Directory path.Could able to fetch communication channel details using query and read operation ,but struggling for implementing change and changelist operations for the above requirement .Could you please share your code for change over mail.
Regards
Venkat
Hi Arpil,
I have customized code to create whole ICO. However, I have questions regarding the code.
For
CreateIntegratedConfiguration obj = new CreateIntegratedConfiguration(user,password,hostPort,bsList);
What type is user, password, hostPort? Are they string? What is hostPort? Where do we configure user and password?
And:
ConfigurationObjectModifyOut createOut = port.create(createIn);
What class is port? I can't find class which has .create, it says it cannot be resolved.
Also:
I get error The method setChangeListID(String) in the type IntegratedConfigurationCreateChangeIn is not applicable for the arguments ()
on
createIn.setChangeListID();
Many thanks,
Raye
Hi Raye,
hostPort is String variable, should contain value like <host>:<port>.
I am reading it from an csv file, it your choice how you are setting it.
Also port is of type IntegratedConfigurationIn. To get port value, please use this code:
private IntegratedConfigurationIn getICOPort() {
IntegratedConfigurationIn port = null;
try {
IntegratedConfigurationInService service = new IntegratedConfigurationInService();
port = service.getIntegratedConfigurationIn_Port();
BindingProvider bp = (BindingProvider)port;
bp.getRequestContext().put("javax.xml.ws.security.auth.username", this.user);
bp.getRequestContext().put("javax.xml.ws.security.auth.password", this.password);
if (this.ICOapiURL.length() != 0)
bp.getRequestContext().put("javax.xml.ws.service.endpoint.address", this.ICOapiURL);
}
catch (Exception ex) {
System.out.println("Exception in getICOPort");
ex.printStackTrace();
}
return port;
}
Hi, thank you Arpil!
What is ICOapiURL?
Regards,
Raye
ICOapiURL = "http://" + hostPort + "/IntegratedConfigurationInService/IntegratedConfigurationInImplBean?wsdl=binding&mode=ws_policy";
Hi Arpil, I am almost done thank you.
However, I am getting error when I get value of port.
IntegratedConfigurationInService service = new IntegratedConfigurationInService();
Cannot instantiate the type IntegratedConfigurationInService
Edit: Since I cannot instantiate an interface, I instantiate it with class.
IntegratedConfigurationInService service = new ntegratedConfigurationInServiceLocator();
port = service.getIntegratedConfigurationInPort();
BindingProvider bp = (BindingProvider)port;
However, I get exception :
com.sap.xi.BASIS.IntegratedConfigurationInBindingStub cannot be cast to javax.xml.ws.BindingProvider
Regards,
Raye
Hi Arpil!
I have problems setting up bindingport and provider. I have created question in this thread:
Integrated Configuration WS - API Development - Setting BindingPort and BindingProvider
Thanks and regards,
Raye
Hi Arpil!
I have resolved my problem. Now, I can access the port. However, when my program runs, it does not create under the change list.
public void createICO()
{
port = getICOPort();
{
Token a = new Token();
a.setValue("ICO TEST");
createIn.setChangeListID(a);
try{
senderDetails(); //sets MessageHeader
senderComChannel(); //sets Outbound Processing
Rcvrs(); //sets Receivers, Receiver Interface, Inbound Processing
createIn.setIntegratedConfiguration(CreateICO);
ConfigurationObjectModifyOut createOut = port.create(createIn);
System.out.println("CREATED");
}catch (Exception e)
{
e.printStackTrace();
//changeList.revert("ICO TEST");
}
System.exit(0);
}
}
All parts of the ICO are set up already. But it does not create
createIn.setIntegratedConfiguration(CreateICO);
ConfigurationObjectModifyOut createOut = port.create(createIn);
Help please,
Thanks and regards,
Raye
Hello Everyone,
I have followed the given steps and tried to execute the given program but It's giving me an error statingย "Exception in thread "main" java.lang.NoClassDefFoundError: com/sap/security/hardener/nw/facade/HardenerFacade". I tried to search for possible solution but I am not able to solve this issue. Please help me out with this issue.
Refer the error thread snap attached below.
It'll be really helpful if you provide your expertise to solve this issue.
Thanks