cancel
Showing results for 
Search instead for 
Did you mean: 

The new MDM APIs and connection using Portal System

Former Member
0 Kudos

Dear experts,

As of SP06 Patch 3 there is an error that prevents us from using the old APIs (A2i - MDM4J.jar) but we still have the requirement to establish the Portal to MDM connection using the Portal System.

After the portal system is established the standard iViews work just fine with SP06, but our custom code with old APIs fails. Therefore, we need to find a way to use the new APIs and establish a connection using the Portal System (already configured). I am having troubles to find examples on how to do that. All I found was the example to use the old APIs. All the connection examples with new APIs I find are using a fixed username and password and that's not what we need.

If you have that part sorted and working, please send some sample code that might help.

Thanks for your help in advance,

Boris

Edited by: Boris Todorov on Nov 28, 2008 4:31 PM

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Greg,

Do you have some code example on how to extract the Mapped System user and password? This will help us in the future when we move to 7.1

Thanks for your help so far, I appreciate it!

Boris

Greg_Austin
Active Participant
0 Kudos

Hey Boris sorry for the delay I had to track down the code. Here is an example that reads the logged in users user name and password for the hard coded portal system object. Hope this helps.



private String[] getUserMapping()
		throws
			MDMSystemObjectNotFound,
			NoLogonDataAvailableException,
			ExceptionInImplementationException,
			GuestUserException {

		String[] retArray = null;
		ArrayList systemLandscapes = UMFactory.getSystemLandscapeWrappers();

		try {
			ISystemLandscapeWrapper systemLandscape =
				(ISystemLandscapeWrapper)systemLandscapes.get(0);
			IUserMapping userMapping = UMFactory.getUserMapping();
			IAuthentication a = UMFactory.getAuthenticator();
			IUser user = a.getLoggedInUser();
			if (user.getUniqueName().equals("Guest")) {
				throw new GuestUserException();
			}
			ISystemLandscapeObject MDMSystem = null;
                        //the portal system name goes here
			MDMSystem = systemLandscape.getSystemByAlias("MDMSystem");

			if (MDMSystem == null) {
				throw new MDMSystemObjectNotFound();
			}

			IUserMappingData mappingData =
				userMapping.getUserMappingData(MDMSystem, user);

			//read the user mapping
			HashMap hash = new HashMap();
			try {
				mappingData.enrich(hash);
			} catch (NoLogonDataAvailableException e1) {
				throw e1;
			}
			//read the user name and password from the mapping
			String userString, passString;
			if (hash.get(IUserMappingData.UMAP_USER) != null) {
				userString = hash.get(IUserMappingData.UMAP_USER).toString();
			} else {
				throw new NoLogonDataAvailableException();
			}
			if (hash.get(IUserMappingData.UMAP_PASSWORD) != null) {
				passString =
					hash.get(IUserMappingData.UMAP_PASSWORD).toString();
			} else {
				throw new NoLogonDataAvailableException();
			}

			//return the user and password in a String array
			retArray = new String[2];
			retArray[0] = userString;
			retArray[1] = passString;

		} catch (ExceptionInImplementationException e) {
			throw e;
		}

		return retArray;

	}



Former Member
0 Kudos

Hey Greg,

Thanks, that's a great example... and exactly what I needed.

Problem solved

Regards,

Boris

Former Member
0 Kudos

Hi Greg,

Have you defined these two exceptions yourself?

MDMSystemObjectNotFound,

GuestUserException

Please let me know if you did and there is something specific about them.

Thanks,

Boris

Greg_Austin
Active Participant
0 Kudos

Yes they were custom exceptions. Nothing too special I just used them to determine why the user mapping was not retrieved successfully so the calling methods could determine how to handle the exceptions. In my case if the MDMSystemObjectNotFound exception was thrown the user wasn't setup correctly so a message told them to contact the help desk. If the user was "Guest" we had temporary hard coded user name and password the calling methods would use.

-Greg

Answers (2)

Answers (2)

Former Member
0 Kudos

We've decided to use the old APIs for that and not go through the hastle of reading the password from the Mapped System.

Thanks,

Boris

Greg_Austin
Active Participant
0 Kudos

This would work fine for now, but I believe the old APIs are not supported with MDM 7.1 so you will have issues when you upgrade. If you are still coding I would push for only using the new APIs.

-Greg

Former Member
0 Kudos

Hi Boris,

Inorder to work with MDM JAVA API SP6 , you need to have latest jars and you can download jars with some Code Examples from sap link - http://service.sap.com/installMDM .

anyway here i mentioned few lines of description for you.

// Get Connection----


When MDM Server is up and running, it listens for network connection calls on port 20005 and this port is by default except changed by the user. In order to communicate with Server, TCP Connection should be established for the server port. All This implementation details are taken care by MDM JAVA API internally .And API Developer part is just to deal with one of Connection Accessors which are provided by API.

When ever making call to Server using API for execution of commands and notifications, Connection is needed.

There are three types of Connection Accessors provided by JAVA API.

The following are ConnectionAccessor interfaces.

1 ConnectionPool: - Pool of MDM Server Connections will be created at a time and picks one of them based on the necessity. It can be obtained through the ConnectionPoolFactoryClass. This type of connection is recommended for stand-alone, (especially multi-thread), Java applications.

2 SimpleConnection: - This way of connection is suitable when the application requires only one connection. It can be obtained through the SimpleConnectionFactory class. This type of connection is recommended for multi-user J2EE applications deployed on the application server. This is not suitable for multithreaded applications.

3 JCAConnectionAccessor: - It deals with MDM Connector Resource Adapter which is deployed on WAS (Web Application Server). This way of getting connections supplies available connections to Resource Adapter. This type of connection is recommended for multi-user J2EE applications deployed on the application server.

ex:- take Connection Pool

ConnectionPool connPool = ConnectionPoolFactory.getInstance (connectionTag); // ConnectionTag String is a host name

// Get Session----


There are Three Sessions available.

A Server Session: -

A Server Session is used for Server Administration. It is needed when dealing with the server level operations such as Creating Repository, Stopping MDM Server, Mounting Repository and UnArchiving Repository.

A Repository Session: -

A Server Repository Session is used for Repository Administration. It requires a mounted repository to get a session on particular repository i.e. Repository on which the Session is to be obtained must not be unmounted. Repository Session is aimed mainly to deal with two kinds of operations Administrative Part Operations and Data Modeling Operations. For example to deal with the operations such as Creation, Deletion, Modification of Users, Roles, Tables, and Fields.

A User Session: -

A User Session is used for Content Management such as Creation, Updating and Deletion of records, attributes. In other words when client call is dealing with Data Manager Operations, User Session is mandatory.

// Authenticate Session

Once you have executed , appropriate Session Command , Authenticate it by using appropriate Authenticate commands.

// Execute Any command based on your requirement.

look at the following link where you find few examples

http://help.sap.com/javadocs/MDM/SP06/com/sap/mdm/examples/package-summary.html

if you still face some problem , let me know please.

regards

Rajasekhar K

Former Member
0 Kudos

Hello Rajasekhar,

Your answer is really good and the supporting example links are very useful.

This would help me in the future to learn some of the best approaches on how to achieve different type of connection. Unfortunately, that doesn't give me the answer to my question.

Perhaps I couldn't explain very well my requirement.

What I need to achieve is to establish a User Session, but not by providing a username and password and hardcoding it or having it in a config file. What I need is to be able to use the already defined Portal System and user mapping in the System Administration -> System Configuration module of the Portal.

Using the old APIs I was able to achieve this using the IConnection, IUser, and MDM4J

Unfortunately, I don't know how to do this using the new APIs.

Here is the code that I used before, and it works fine also with SP06. There is a little trick to enable it in the System properties when you configure it though. By default there is a property "Use MDM4J" that is set to "No". Once you change this property, you are able to establish the connection using the old APIs.

Here is the code that I currently use to get the connection from the System Alias of the Portal.

IUser user;

user = this.getCurrentUser();

Locale locale = null;

// System Alias that is configured in the portal System Administration -> System Configuration

String systemAlias = "MDM_Customer_System";

try {

locale = WDClientUser.getCurrentUser().getLocale();

} catch (WDUMException ex) {

msgMgr.reportException(ex.getMessage(),false);

}

ConnectionProperties prop = null;

try {

IConnectorGatewayService cgService = (IConnectorGatewayService) WDPortalUtils.getServiceReference(IConnectorService.KEY);

try {

prop = new ConnectionProperties(locale, user);

} catch (Exception e) {

msgMgr.reportException(e.getMessage(),false);

}

try {

connection = cgService.getConnection(systemAlias, prop);

} catch (ConnectorException e) {

msgMgr.reportException(e.getMessage(),false);

}

} catch (Exception e) {

msgMgr.reportException(e.getMessage(),false);

}

try {

INative nativeInterface = connection.retrieveNative();

catalogData = (CatalogData) nativeInterface.getNative(CatalogData.class.getName());

result = true;

} catch (Exception e) {

msgMgr.reportException(e.getMessage(),false);

}

Let me know if you have something similar to utilize the new APIs, not the CatalogData.

Thanks,

Boris

Greg_Austin
Active Participant
0 Kudos

Hi Boris,

At my clients we have achieved this by having an MDM portal system object and mapping each portal user to an MDM user in the portal's UME. In our application code we find the user running the applicaiton and read the user name and password mapped to the MDM portal system object. We use this user name and password with the Java APIs. I know there are some posts about this in the forums, there are also some posts in the other forums that have to do with finding the current user and reading user and password for mapped systems.

-Greg