on 01-13-2009 11:18 AM
Hi,
I am developing a Java Web Dynpro application which should send data through Customized Java Web Dynpro View
to SAP Master Data Manegemnt 5.5 Repository.
My approach will be to create a Web Dynpro View with the required fields to insert data.
Then, writing in the Implementation tab of the view, I will write the MDM Java API Code to connect with the MDM Repository.
Then, the records will be created using :
CreateRecordCommand createRecordCommand =
new CreateRecordCommand(connections);
connections will contain the connection to the actual MDM Server.
ConnectionPool connections = null;
connections = ConnectionPoolFactory.getInstance(serverName);
I will start using this approach and let you know as I am not a Java Programmer.
Regards
Neha Singh
Hi Neha,
I am sorry i thought you have already added them to built path of your project.
right click on your project name-> Properties->Java build path -> libraries->Add external jars-> select all the required jars now click on add button.
It will add all the jar files in your projects class path.
Hope this will help
Regards
Narendra
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I successfully added MDM with Java API.
Regards
Neha Singh
SAP MDM Consultant
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Neha,
Yes you can call a method which is there in component controller in View.
Use the below code in the goAction method
wdThis.wdGet<component controller name>.getRepositoryConnection();
Hope this will help
Regards
Narendra
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Neha,
Like java you can also print in webdynpro.
wdComponentAPI.getMessageManager().reportSuccess("table Id is "+tableId);
and for priting the exception messages use the belwo code
try{
//your code here
}
catch (Exception ex) {
wdComponentAPI.getMessageManager().reportException(ex.getMessage(),true); }
Hope this will help
Regards
Narendra
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Narendra,
Look at this code
try{
TableId mainTableId = new TableId("Main");
RecordFactory.createEmptyRecord(mainTableId);
RecordFactory.createEmptyRecord(mainTableId);
}
catch(Exception ce)
{
ce.printStackTrace();
}
I have created new TableId object mainTableId; I have passed Main as String parameter where Main is the table type.
TableId is instance of TableId.Type.
Regards
Neha Singh
Hi Narendra,
I need to give the port number say 40000 in the ServerName.
If we don't specify the port number, the servername is meaningless.
Also, in onActiongo(), I have implemented this logic which is doing nothing even if the
action event is triggered by the button.
public void onActionGo(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
{
//@@begin onActionGo(ServerEvent)
// wdThis.getRepositoryConnection("xx.xx.xx..xx","Kaushikb_Repo","Taton","taton@123");
if(wdEvent!=null)
{
wdThis.wdGetMDMCreateComponentController().getRepositoryConnection("kolan1.BSC.CORP.BSC.IN:50000","Kaushikb_Repo","Taton","taton@123");
}
else{
wdComponentAPI.getMessageManager().reportWarning("Failure");
}
//wdComponentAPI.getComponent().getContext().getController().getClass().getDeclaredMethods();
//@@end
}
Regards
Neha Singh
Hi Neha,
You can specify the server name both ways. i think one is mdm server machine name and other is IP address.
But since Ip address is not static so it changes with in weeks or so. So its better to use machine name or either clarify if you have static IP address.
I will try to debug your code and will provide you solution.
Regards
Narendra
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Narendra,
I can debug my code if the function module is written in
Component Controller, then I can use IWDMessageManager class.
But as I am implementing the whole code in View, I cannot use this class.
Now, how to know whether all variables are getting the correct values or not.
In Java programs, we can know the values by passing System.out.println();
and in servlets out.println();
IP is Ok.
Also, how to debug Java Web Dynpro programs.
Is it possible, to call getRepositoryConnection()
written in Component Contoller by adding the Component Controller
in View and goAction() calls this getRepositoryConnection?
Regards
Neha Singh
Edited by: Neha Singh on Jan 19, 2009 11:04 AM
Hi Neha,
the code TableId mainTableId = new TableId(1); creates the object of the TableId class and mainTableId is the object name(It can be anything like abc, table, maiTable etc depends upon yoyr choice.). Now you can use the object name to do anything on this the main table.
and by passing int 1 it will create object of your main table in mdm repository.
Here the code is given just to make connection to repository.
Regards
Narendra
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Nagendra,
Which of the commented code is appropriate?
//String serverName= "10.114.21.9";
//String serverName ="kolpoan1.BSC.CORP.BSC.IN";
Also please check this code added by me but it failing to create any emptyRecord in main table.
try{
TableId mainTableId = new TableId("Main");
RecordFactory.createEmptyRecord(mainTableId);
RecordFactory.createEmptyRecord(mainTableId);
}
catch(Exception ce)
{
ce.printStackTrace();
}
Regards
Neha Singh
Hi Neha,
Yes you are right the code i have given you only makes connection with the mdm repository now its up to you what you want to do with the repository like what to insert some data or modify etc.
and i have used hostName as the name of the machine where mdm server is installed and i was passing it from the place where i was calling this method.
hope this will clarify.
Regards
Narendra
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Nagendra,
This questions looks odd.
But I am not a Java Programmer.
I am also updating myself in Java.
Please check this code:
TableId mainTableId = new TableId(1);
This gives int value 1 to mainTableId.
But I don't have any field called mainTableId
so, this code does not do anything regarding my main table and repository.
But thanks for help....
Regards
Neha Singh
Hi Neha,
ya sure please let me knoe what you want to ask.
Regards
Narendra
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Nagendra,
Let's analyze your code.
You have entered java.lang.String hostName as parameter to getRepositoryConnection().
You are not using the hostName at all.
Now, hostName should be retrieved from the following change in code:
try{
serverName = connections.getHostname();
connections=ConnectionPoolFactory.getInstance(serverName);
}
catch(ConnectionException e)
{ e.printStackTrace();
return;
}
Also, this code sets userName and userPassword for a user session and also you have written
TableId mainTableId = new TableId(1);
Now, this code does not create any record in the repository.
I will create a record in Repository.
Creating New Records
There are two API commands for creating new record(s) in a repository:
● CreateRecordCommand
Creates a single record
Input = instance of Record
● CreateRecordsCommand
Creates a number of records
Input = an array of Record instances
You can create a new empty instance of Record using RecordFactory as
RecordFactory.createEmptyRecord(TableId)
You then populate with field and/or attribute values using the following methods:
● Record.setFieldValue(FieldId, MdmValue)
● Record.setAttributeValue(FieldId, AttributeId, MdmValue)
Let me do it and I will inform you later.
Regards
Neha Singh
Hi Nagendra,
I tried your code.
It did not give any runtime error.
I need to dicuss some part of your code.
Please reply back.
Regards Neha Singh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Nagendra,
I tried your code.
It did not give any runtime error.
I need to dicuss some part of your code.
Please reply back.
Regards Neha Singh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Neha,
below is the sample code of connectionpool using mdm java Apis
public void getRepositoryConnection( java.lang.String hostName, java.lang.String repositoryName, java.lang.String userId, java.lang.String passWord )
{
//@@begin getRepositoryConnection()
try {
// create connection pool to a MDM server
String serverName = "chdsez124604d";
ConnectionPool connections = null;
try {
connections = ConnectionPoolFactory.getInstance(serverName);
} catch (ConnectionException e) {
e.printStackTrace();
return;
}
// specify the repository to use
// alternatively, a repository identifier can be obtain from the GetMountedRepositoryListCommand
// String repositoryName = "Inbev_Spare_Part";
String dbmsName = "chdsez124604d";
RepositoryIdentifier reposId =
new RepositoryIdentifier(repositoryName, dbmsName, DBMSType.MS_SQL);
// get list of available regions for the repository
GetRepositoryRegionListCommand regionListCommand =
new GetRepositoryRegionListCommand(connections);
regionListCommand.setRepositoryIdentifier(reposId);
try {
regionListCommand.execute();
} catch (CommandException e) {
e.printStackTrace();
return;
}
RegionProperties[] regions = regionListCommand.getRegions();
// create a user session
CreateUserSessionCommand sessionCommand =
new CreateUserSessionCommand(connections);
sessionCommand.setRepositoryIdentifier(reposId);
sessionCommand.setDataRegion(regions[0]); // use the first region
try {
sessionCommand.execute();
} catch (CommandException e) {
e.printStackTrace();
return;
}
String sessionId = sessionCommand.getUserSession();
// authenticate the user session
String userName = "User1";
String userPassword = "jain";
AuthenticateUserSessionCommand authCommand =
new AuthenticateUserSessionCommand(connections);
authCommand.setSession(sessionId);
authCommand.setUserName(userName);
authCommand.setUserPassword(userPassword);
try {
authCommand.execute();
} catch (CommandException e) {
e.printStackTrace();
return;
}
// the main table, hard-coded
TableId mainTableId = new TableId(1);
please check... Its coding is different from mdm4j apis..
Regards
Narendra
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Neha,
Apart from adding the JAR files to the classpath, you need to specify the location to use the MDM APIs at runtime. Add the following refernece in Project Properties > References > Sharing Reference
add: sap.com/com.sap.mdm.tech.mdm4j
This will be used by project at runtime.
Hope this helps!!
Cheers,
Arafat
Hi Neha,
What type of project you have created Webdynpro project or Dc project.
If its webdynpro project then copy the jar files and paste them to lib folder.
If its a Dc project then you need to create deployable j2ee dc project as mdm jars does not have deployable parts and require some medium for deployment over portal.
please let me know i will help accordingly.
Regards
Narendra
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
It is a Web Dynpro Project.
I have copied the MDM jar files into the lib folder of the Created Web Dynpro Project
and Rebuild the Project but it is till not working.
But you are right, I missed this basic step.
The jar files should be kept in lib folder.
In MDM4J.jar, we have ConnectionPool.class file in com.a2i.xcat.internal.connections.ConnectionPool.class if we unzip the MDM4J.jar.
But it is not working.
Regards
Neha Singh
Hi Neha,
Error is in the import statements.
Please import these statements
import com.sap.mdm.net.ConnectionPool;
import com.sap.mdm.net.ConnectionPoolFactory;
Hope this will help
Regards
Narendra
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Neha,
Below are the jar files you need to use for using java apis
mdm-admin.jar
mdm-common.jar
mdm-core.jar
mdm-data.jar
mdm-protocol.jat
and the version of the jar should be the version of your mdm server which you can in mdm console by mounting the mdm server it will show the version on right hand side like Version 5.5 sp5(5.5.40.83)
for example 5.5.40.83 this should be the version of your jar files if above are the configuration of the mdm server.
If the jars are different than the version of mdm server you will get File Fail CRC check error
Hope this will help
Regards
Narendra
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I am getting an error.
Class File Editor
Source not found
The source attachment does not contain the source for the file ConnectionPool.class.
You can change the source attachment by clicking Change Attached Source below:
Change Attached Source...
public class sun.jdbc.odbc.ee.ConnectionPool extends sun.jdbc.odbc.ee.ObjectPool {
private sun.jdbc.odbc.ee.ConnectionEventListner cel;
java.util.Properties cp;
public sun.jdbc.odbc.ee.ConnectionPool(java.lang.String arg);
public void setConnectionDetails(Properties arg);
protected PooledObject create(Properties arg) throws java.sql.SQLException;
protected void destroyFromPool(PooledObject arg, Hashtable arg);
}
Regards
Neha Singh
Edited by: Neha Singh on Jan 13, 2009 1:15 PM
Hi Neha,
For using connectionpool you need to use mdm java apis jars instead of mdm4j.jar files.
Regards
Narendra
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Neha,
Below is the Link which will help you in understanding how to work with mdm java apis
If you require more info. i can help you out.
Regards
Narendra
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Neha,
Yes your approach is correct. Below is the code for connection to mdm tables.
public void getRepositoryConnection(
java.lang.String hostName,
java.lang.String repositoryName,
java.lang.String userId,
java.lang.String passWord) {
//@@begin getRepositoryConnection()
try {
if (simpleConnection == null) {
simpleConnection =
SimpleConnectionFactory.getInstance(hostName);
System.out.print("Successfull 1");
// Establish TCP Connection to the server
if (simpleConnection != null) {
// WorkflowId workflowId = new WorkflowId(99998);
// CreateWorkflowJobCommand createWorkflowJobCommand =
// new CreateWorkflowJobCommand(simpleConnection);
// createWorkflowJobCommand.setWorkflowId(workflowId);
// wdComponentAPI.getMessageManager().reportSuccess("Got Connected");
/** Establish a repository session with the respository */
//Set the region properties
RegionProperties dataRegion = new RegionProperties();
/** Set region code for the session */
dataRegion.setRegionCode("engUSA");
/** Set the locale on data region */
dataRegion.setLocale(new Locale("en", "US"));
/** Set the name of data region */
dataRegion.setName("US");
// Createa repository identifier
RepositoryIdentifier repositoryID =
new RepositoryIdentifier(
repositoryName,
hostName,
DBMSType.MS_SQL);
System.out.print("Successfull 2");
/** Create the User Session */
CreateUserSessionCommand createUserSessionCommand =
new CreateUserSessionCommand(simpleConnection);
/** Set the repository identifier (mandatory)*/
createUserSessionCommand.setRepositoryIdentifier(
repositoryID);
/** Set the region properties for the session (mandatory) */
createUserSessionCommand.setDataRegion(dataRegion);
System.out.print(
"Successfull 3" + repositoryID.getDBMSType());
createUserSessionCommand.execute();
System.out.print("Successfull 4");
/** Get the session identifier */
userSession = createUserSessionCommand.getUserSession();
System.out.print(
"Successfull.................." + userSession);
AuthenticateUserSessionCommand authenticateUserSessionCommand =
new AuthenticateUserSessionCommand(simpleConnection);
/** Set session identifier (mandatory)*/
authenticateUserSessionCommand.setSession(userSession);
/** Set id of repository user(mandatory) */
authenticateUserSessionCommand.setUserName(userId);
/** Set password (mandatory)*/
authenticateUserSessionCommand.setUserPassword(passWord);
System.out.print(
"Successfull.................."
+ authenticateUserSessionCommand.getUserName());
/** Establish the session */
authenticateUserSessionCommand.execute();
SetUnicodeNormalizationCommand unicodeNormalizationCommand =
new SetUnicodeNormalizationCommand(simpleConnection);
unicodeNormalizationCommand.setSession(userSession);
unicodeNormalizationCommand.setNormalizationType(
SetUnicodeNormalizationCommand.NORMALIZATION_COMPOSED);
unicodeNormalizationCommand.execute();
CreateRepositorySessionCommand repositorySessionCommand =
new CreateRepositorySessionCommand(simpleConnection);
/** Set the repository identifier */
repositorySessionCommand.setRepositoryIdentifier(
repositoryID);
/** Obtain repository session */
repositorySessionCommand.execute();
/** Store the session id into the variable repositorySession */
this.repositorySession =
repositorySessionCommand.getRepositorySession();
/** Authenticate the users session */
AuthenticateRepositorySessionCommand authenticatedRepositorySession =
new AuthenticateRepositorySessionCommand(simpleConnection);
/** set the session id */
authenticatedRepositorySession.setSession(
repositorySession);
/** set id of the repository user */
authenticatedRepositorySession.setUserName(userId);
/** set password */
authenticatedRepositorySession.setUserPassword(passWord);
authenticatedRepositorySession.execute();
/** Get the Repository schema */
GetRepositorySchemaCommand repositroySchemaCommand =
new GetRepositorySchemaCommand(simpleConnection);
repositroySchemaCommand.setSession(repositorySession);
repositroySchemaCommand.execute();
this.schema = repositroySchemaCommand.getRepositorySchema();
}
}
} catch (Exception e) {
e.printStackTrace();
}
//@@end
}
please revert if you require more info
Regards
Narendra
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Narendra,
Now,
I am using
com.sap.mdm.net.ConnectionPool
but this interface is not accessible.
I have already imported MDM4J.jar, ConnectorHelper.jar,ExtendedConnector.jar and connector.jar.
This jars are also installed in WAS J2E as com.sap.mdm.tech.mdm4j
Now, what could be the problem?
Regards
Neha Singh
Edited by: Neha Singh on Jan 13, 2009 12:28 PM
User | Count |
---|---|
85 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.