cancel
Showing results for 
Search instead for 
Did you mean: 

Error using the MDM Java Connector

Former Member
0 Kudos

Hi All,

I am developing a Web Dynpro type DC where I need to use MDM, I tried to reach MDM repository using the following code:

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.resource.ResourceException;

import a2i.common.A2iResultSet;
import a2i.common.CatalogData;
import a2i.common.ResultSetDefinition;
import a2i.search.Search;

import com.sapportals.connector.ConnectorException;
import com.sapportals.connector.connection.ConnectionFailedException;
import com.sapportals.connector.connection.IConnection;
import com.sapportals.connector.connection.IConnectionFactory;
import com.sapportals.connector.connection.IConnectionSpec;
import com.sapportals.connector.connection.INative;
import com.sapportals.connector.connection.InterfaceNotSupportedException;
import com.sapportals.connector.metadata.CapabilityNotSupportedException;


public class Mdmjconn{
	
	public /*IConnection*/ String conn()/*throws Exception*/{
		
		String s = null;
		String str = "start ";
		Context ctx = null;
		
		try{
			ctx = new InitialContext();
		}catch(NamingException nex){
			str = str + "[" + nex.getLocalizedMessage() + "]" + " NamingException - InitialContext| ";
		}
		
		IConnectionFactory connectionFactory = null;
		try{
			connectionFactory = (IConnectionFactory)ctx.lookup("deployedAdapters/MDM Factory/shareable/MDM Factory");
		}
		catch(NamingException nex){
			str = str + "[" + nex.getMessage() + "]" + " NamingException - lookup| ";
		}
		catch(ClassCastException ccex){
			str = str + "[" + ccex.getMessage() + "]" + " ClassCastException - lookup| ";
		}
		
		
		IConnectionSpec spec = null;
		CatalogData catalog = null;
		IConnection connection = null;
		
		try{
			spec = connectionFactory.getConnectionSpec();
			spec.setPropertyValue("UserName", "Admin");
			spec.setPropertyValue("Password", "Admin");
			spec.setPropertyValue("Server", "localhost");
			spec.setPropertyValue("Port", "2005");
			spec.setPropertyValue("RepositoryLanguage", "English [US]");
		}catch(ConnectorException cex){
			str = str + "[" + cex.getMessage() + "]" + " ConnectorException - getConnectionSpec| ";
		}catch(NullPointerException npex){
			str = str + "[" + npex.getMessage() + "]" + " NullPointerException - getConnectionSpec| ";
		}

		INative nativeInterface = null;

		try{
			connection = connectionFactory.getConnectionEx(spec);
		}catch(ConnectionFailedException cfex){
			str = str + "[" + cfex.getMessage() + "]" + " ConnectionFailedException - getConnectionEx| ";
		}catch(ConnectorException cex){
			str = str + "[" + cex.getMessage() + "]" + " ConnectorException - getConnectionEx| ";
		}catch(NullPointerException npex){
			str = str + "[" + npex.getMessage() + "]" + " NullPointerException - getConnectionEx| ";
		}
		try{
			nativeInterface = connection.retrieveNative();
		}catch(CapabilityNotSupportedException cnsex){
			str = str + "[" + cnsex.getMessage() + "]" + " CapabilityNotSupportedException - retrieveNative| ";
		}catch(NullPointerException npex){
			str = str + "[" + npex.getMessage() + "]" + " NullPointerException - retrieveNative| ";	
		}
		try{
			catalog = (CatalogData)nativeInterface.getNative(CatalogData.class.getName());
		}catch(InterfaceNotSupportedException insex){
			str = str + "[" + insex.getMessage() + "]" + " InterFaceNotSupportedException - getNative| ";
		}catch(ConnectorException cex){
			str = str + "[" + cex.getMessage() + "]" + " ConnectorException - getNative| ";
		}catch(NullPointerException npex){
			str = str + "[" + npex.getLocalizedMessage() + "]" + " NullPointerException - getNative| ";
		}
			
//TEST SEARCH BEGIN
  		A2iResultSet rs;
  		ResultSetDefinition resultdefinition = new ResultSetDefinition("MDM_BUSINESS_PARTNERS");
	 	resultdefinition.AddField("MDM_PARTNER_ID");
	 	resultdefinition.AddField("MDM_FIRST_NAME");
	 	resultdefinition.AddField("MDM_LAST_NAME");
	 	resultdefinition.AddField("M_CITY");
	 	resultdefinition.AddField("M_POSTAL_CODE");
	 	resultdefinition.AddField("M_STREET");
	 	resultdefinition.AddField("M_HOUSE_NUMBER");
	 	resultdefinition.AddField("M_COUNTRY");	
	 	resultdefinition.AddField("M_DUNS");
	 	resultdefinition.AddField("MDM_TAX_NUMBER_1");
	
		Search search = new Search(resultdefinition.GetTable());
	
		try {	
	  		rs = catalog.GetResultSet(search, resultdefinition, "MDM_PARTNER_ID", true, 0);
	  		int i=0;//1316;
	  		int idd = 0;

			i = 1327;
			idd = rs.GetValueAt(i, "MDM_PARTNER_ID").GetIntValue();
			String namef = rs.GetValueAt(i, "MDM_FIRST_NAME").TranslateToString();
			String namel = rs.GetValueAt(i, "MDM_LAST_NAME").TranslateToString();
			String city = rs.GetValueAt(i, "M_CITY").TranslateToString(); 
			String pc = rs.GetValueAt(i, "M_POSTAL_CODE").TranslateToString();
			String street = rs.GetValueAt(i, "M_STREET").TranslateToString();
			String hn = rs.GetValueAt(i, "M_HOUSE_NUMBER").TranslateToString();
			String country = rs.GetValueAt(i, "M_COUNTRY").TranslateToString();
			String duns = rs.GetValueAt(i, "M_DUNS").TranslateToString();
			String tax = rs.GetValueAt(i, "MDM_TAX_NUMBER_1").TranslateToString();
				
			str = namef + ", " + namel + ", " + city + ", " + pc + ", " + street + ", " + hn + ", "+ country + ", "+ duns + ", " + tax + "! ";
			
		
		  
	  	}catch (a2i.core.StringException e){
	  		e.A2iPrintError();	
	  		str = str + "Error at GetValueAt| ";
	  	}catch(NullPointerException npex){
	  		str = str + "[" + npex.getLocalizedMessage() + "]" + " NullPointerException - GetResultSet, GetValueAt| ";
	  	}
 			
//TEST SEARCH END			

		try{
			connection.close();
		}catch(ResourceException rex){
			str = str + "[" + rex.getMessage() + "]" + " ResourceException - close| ";
		}catch(NullPointerException npex){
			str = str + "[" + npex.getMessage() + "]" + " NullPointerException - close| ";
		}
		
		if(str == null){
			return "zero";
		}else
		return str; 
	}
	
}

I got the following result:

<i>start [null] ClassCastException - lookup| [null] NullPointerException - getConnectionSpec| [null] NullPointerException - getConnectionEx| [null] NullPointerException - retrieveNative| [null] NullPointerException - getNative| [null] NullPointerException - GetResultSet, GetValueAt| [null] NullPointerException - close| </i>

So the code throws ClassCastException at the <b>lookup</b> method call and causes the other NullPointerExceptions.

I checked the JNDI Registry in VA, the "deployedAdapters/MDM Factory/shareable/MDM Factory" path is right.

What can be the reason for this problem?

Thanks & regards,

Peter

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

My problem is solved!

The only needed Web Dynpro Library References were the following:

com.sap.mdm.tech.mdm4j

tcconnconnectorframework