Skip to Content
0
Former Member
Jan 17, 2012 at 01:00 PM

Class Cast Exception - Implementing Custom Portal Service

76 Views

Hi You all,

We are struggling for a solution about this issue.

We firstly implemented a Custom Portal Service which is successfully accessed and used by an Abstract Portal Component through standard access way.

Assuming that IMYService is the service interface which extends IService and MYService is the class which implements IMYService, we can easily access it by:

IPortalRuntimeResources runtimeRes = PortalRuntime.getRuntimeResources();
  IService service = runtimeRes.getService(IMYService.KEY);
  IMYService myService = (IMYService) service;
  Object obj = myService.myMethod();

PortalApp.xml as follow:

<?xml version="1.0" encoding="UTF-8"?>
<application>
<application-config>
 <property name="SharingReference" value="MYService"/>
</application-config>
  <components>
    <component name="MYServiceComponent">
      <component-config>
        <property name="ClassName" value="mypackage.MYServiceComponent"/>
      </component-config>
      <component-profile/>
    </component>
  </components>
  <services>
 <service name="MYService">
  <service-config>
   <property name="className" value="mypackage.service.MYService"/>
  </service-config>
 </service>
  </services>
</application>
 

After that, we implemented a J2EE Application (WAR inside an EAR Application) which contains an HttpServlet in order to access our Custom Portal Service through JNDI mechanism as suggested in many other topics, like this:

EAR Project includes the references to Custom Service Project.

1)

Hashtable env = new Hashtable();
   env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sapportals.portal.prt.registry.PortalRegistryFactory");
   InitialContext context = new InitialContext(env);
 IService s = (IService)context.lookup("/broker/services/" + IMYService.KEY);
 IMYService myserv = (IMYService) s;
//exception raised (ClassCastException .......  mypackage.IMYService incompatible with mypackage.IMYService 

2)

Hashtable environment = new Hashtable();
environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sapportals.portal.prt.registry.PortalRegistryFactory");
 			try
			.....
				InitialContext ic = new InitialContext(environment);
				Context context = (Context) ic.lookup("broker/services");
				for (NamingEnumeration serviceNames = context.listBindings(""); serviceNames.hasMore();) 
                                       .......
					Binding binding = (Binding) serviceNames.next();
					if(binding.getName().equalsIgnoreCase(IMYService.KEY))
					//               here we  find our interface name correcty  
................ 

neither first nor second approach work correctly,

while trying to get Custom Service Interface by downcasting to IMYService (2 approach), the application raises the following exception

com.sapportals.portal.prt.core.broker.PortalServiceItem incompatible with com.sapportals.portal.prt.core.broker.PortalServiceItem

in general, every object we try to reach by JNDI mechanism throws a ClassCastException, for example:

mypackage.IMYService incompatible with mypackage.IMYService

We also checked that no different ClassLoaders are used.

We obviously can use our implemented class MYService using reflection and Our Service is correctly shown in JNDI browser list.

Environment : SAP-JEE 7.01 SP7 (1000.7.01.7.0.20100612175953)

Points to any suggestions,

Regards,

MB.