on 2007 Feb 02 10:57 PM
Hi,
am trying to call a portal service from portal application.
2 scenarios:
SCENARIO 1:
componnent and the service in the same project.
in the KEY filed of ImyService. when I provide the value as Parfilename|servicename, it works
when i change the KEY field to name of the classfile, i.e. com.mycomp.myService [ implemention class of that interface], it doesnt work. throwing exception "could not instatiate the implementation class".
SCENARIO 2:
SERVICE and the usage component is in different projects and I provided the value of service to sharingreference in the portalapp.xml file
it doesnt work when the KEY is "Parfilename|servicename" or when it is set to the class file name, i.e. "com.mycomp.myService".
BTW, the portal service is started.
any ideas are highly appreciated.
Hi Yogi,
The Steps below Describes how to call a Portal Service from a Portal Application.
<b>Add Sharing Reference Value in the Deployment Descriptor.</b>
<application-config>
<property name=SharingReference value=<ApplicationName or ApplicationAlias>/>
<property name=SharingReference value=com.sap.portal.navigation.api_service/>
</application-config>
<b>Add Libraries of the Portal Service (xxxapi.jar)</b>
<b>Write code to access the Portal Service</b>
Import Package of the Portal Service
Get Instance of the Portal Service
Call Methos of the Portal Service.
<b>Here is an Example:</b>
<b>PORTAL SERVICE</b>
/********************** Service Interface : IServiceOne.java ************************/
package com.abc.def;
import com.sapportals.portal.prt.service.IService;
public interface IServiceOne extends IService
{
public static final String KEY = "ServiceProject.ServiceOne";
//PARFilename.Servicename
public String display();
}
/**************** Service Source File : ServiceOne.java ***************************/
// Implement the display() Method
public String display() {
// TODO Auto-generated method stub
return "Welocme To My Service Project. Thank you for accessing my service.";
}
/*******************portalapp.xml*********************/
<application>
<application-config/>
<components/>
<services>
<service name="ServiceOne">
<service-config>
<property name="className" value="com.abc.def.ServiceOne"/>
</service-config>
</service>
</services>
</application>
<b>After Creating Your Service , Deploy it on the Server.</b>
<b>PORTAL APPLICATION</b>
package com.sample;
import com.abc.def.*;
import com.sapportals.portal.prt.component.*;
import com.sapportals.portal.prt.runtime.*;
public class AccessOne extends AbstractPortalComponent
{
public void doContent(IPortalComponentRequest request, IPortalComponentResponse response)
{
IServiceOne myService =(IServiceOne)PortalRuntime.getRuntimeResources().getService(IServiceOne.KEY);
String s = myService.display();
response.write(s);
}
}
/********************** Portalapp.xml ***********************/
<application>
<application-config>
<property name="SharingReference" value="ServiceProject"/>
</application-config>
<components>
<component name="AccessOne">
<component-config>
<property name="ClassName" value="com.sample.AccessOne"/>
</component-config>
<component-profile/>
</component>
</components>
<services/>
</application>
<b>Right Click on the Portal Application --->Properties -> Java Build Path-> click on Libraries Tab on the Top and Click Add External Jars Tab on the Right ---> Add Your Portal Service PAR File</b> .
Now Deploy the Application.<i></i><u></u><i></i>
Reward Points if u find this useful.
Regards,
Eben.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Yogi,
When calling a service, It does not make any difference if it is in same project or in other project. <b>So there is only one Scenario, accessing a service</b>
It is ofcourse your Service.KEY that is very important for external components to access it. So let us see, how to define a KEY.
KEY can never be a class file name, as from logic this class can even be present in some other project/application which will create a conflict situation.
So the right KEY should be:
1. <b>ApplicationName</b>.<b>ServiceName</b>
2. <b>ApplicationAliasName.ServiceName</b>
ApplicationName = Parfilename
ApplicationAliasName = You can define application alias in portalapp.xml
So it should be Parfilename.servicename and not Parfilename|servicename
Greetings,
Praveen Gudapati
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The line
<property name="SharingReference" value="serviceproject" /> fixed my problem in the calling application. If i am correct, it must be the name of the PAR file.. thats all.. you need not specify service name, alias etc.. in the sharingreference property.
Thanks for your help.
Yogi
P.S: Points granted
User | Count |
---|---|
66 | |
10 | |
10 | |
10 | |
10 | |
8 | |
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.