Skip to Content
0
Former Member
Apr 14, 2010 at 06:27 AM

How to use a Portal Service in a JSPDynpro?

34 Views

Hi, everyone:

I have a big problem. I had develop a Portal Service insert the data to MySQL. When I build a JSPDynpro to use the Portal Service, the EP tell me "Caused by: java.lang.ClassCastException". help me !

Xiaoming Liu

-


error message:

Exception ID:02:17_14/04/10_0008_3852351 
[EXCEPTION]
 com.sapportals.portal.prt.component.PortalComponentException: Error in service call of Portal Component
Component : pcd:portal_content/lxm_test/insertInputData
Component class : inserttest.InsertInputData
User : mdm_liuxm
	at com.sapportals.portal.prt.core.PortalRequestManager.handlePortalComponentException(PortalRequestManager.java:973)
	at com.sapportals.portal.prt.core.PortalRequestManager.callPortalComponent(PortalRequestManager.java:343)
	at com.sapportals.portal.prt.core.PortalRequestManager.dispatchRequest(PortalRequestManager.java:136)
	at com.sapportals.portal.prt.core.PortalRequestManager.dispatchRequest(PortalRequestManager.java:189)
	at com.sapportals.portal.prt.component.PortalComponentResponse.include(PortalComponentResponse.java:215)
	at com.sapportals.portal.prt.pom.PortalNode.service(PortalNode.java:645)
	at com.sapportals.portal.prt.core.PortalRequestManager.callPortalComponent(PortalRequestManager.java:328)
	at com.sapportals.portal.prt.core.PortalRequestManager.dispatchRequest(PortalRequestManager.java:136)
	at com.sapportals.portal.prt.core.PortalRequestManager.dispatchRequest(PortalRequestManager.java:189)
	at com.sapportals.portal.prt.core.PortalRequestManager.runRequestCycle(PortalRequestManager.java:753)
	at com.sapportals.portal.prt.connection.ServletConnection.handleRequest(ServletConnection.java:240)
	at com.sapportals.portal.prt.dispatcher.Dispatcher$doService.run(Dispatcher.java:524)
	at java.security.AccessController.doPrivileged(Native Method)
	at com.sapportals.portal.prt.dispatcher.Dispatcher.service(Dispatcher.java:407)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
	at com.sap.engine.services.servlets_jsp.server.servlet.InvokerServlet.service(InvokerServlet.java:156)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
	at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:401)
	at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:266)
	at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:386)
	at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:364)
	at com.sap.engine.services.httpserver.server.RequestAnalizer.invokeWebContainer(RequestAnalizer.java:1039)
	at com.sap.engine.services.httpserver.server.RequestAnalizer.handle(RequestAnalizer.java:265)
	at com.sap.engine.services.httpserver.server.Client.handle(Client.java:95)
	at com.sap.engine.services.httpserver.server.Processor.request(Processor.java:175)
	at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:33)
	at com.sap.engine.core.cluster.impl6.session.MessageRunner.run(MessageRunner.java:41)
	at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
	at java.security.AccessController.doPrivileged(Native Method)
	at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:104)
	at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:176)
Caused by: com.sapportals.portal.prt.component.PortalComponentException: Exception during PageProcessorComponent.doContent()
	at com.sapportals.portal.htmlb.page.PageProcessorComponent.doContent(PageProcessorComponent.java:139)
	at com.sapportals.portal.prt.component.AbstractPortalComponent.doPreview(AbstractPortalComponent.java:240)
	at com.sapportals.portal.prt.component.AbstractPortalComponent.serviceDeprecated(AbstractPortalComponent.java:168)
	at com.sapportals.portal.prt.component.AbstractPortalComponent.service(AbstractPortalComponent.java:114)
	at com.sapportals.portal.prt.core.PortalRequestManager.callPortalComponent(PortalRequestManager.java:328)
	... 29 more
Caused by: java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:324)
	at com.sapportals.htmlb.page.DynPage.doProcessCurrentEvent(DynPage.java:173)
	at com.sapportals.htmlb.page.PageProcessor.handleRequest(PageProcessor.java:119)
	at com.sapportals.portal.htmlb.page.PageProcessorComponent.doContent(PageProcessorComponent.java:134)
	... 33 more
Caused by: java.lang.ClassCastException
	at inserttest.InsertInputData$InsertInputDataDynPage.onInsertDataButton(InsertInputData.java:56)
	... 40 more

-


Class:

package inserttest;
import insert.IInsertData;

import com.sapportals.htmlb.*;
import com.sapportals.htmlb.event.*;
import com.sapportals.htmlb.page.*;
import com.sapportals.portal.htmlb.page.*;
import com.sapportals.portal.prt.component.*;
import com.sapportals.portal.prt.runtime.IPortalRuntimeResources;
import com.sapportals.portal.prt.runtime.PortalRuntime;
import com.sapportals.portal.prt.service.IService;

public class InsertInputData extends PageProcessorComponent
{
	public DynPage getPage()
	{
		return new InsertInputDataDynPage();
	}
	public static class InsertInputDataDynPage extends JSPDynPage
	{
		private IPortalComponentRequest request;
		private IPortalComponentContext context;
		private IPortalComponentResponse response;
		private IPortalComponentProfile profile;
		private boolean isOK = false;
		public void doInitialization()
		{
			request = (IPortalComponentRequest) this.getRequest();
			response = (IPortalComponentResponse) this.getResponse();
			context = request.getComponentContext();
		}
		public void doProcessAfterInput() throws PageException
		{
			request = (IPortalComponentRequest) this.getRequest();
			response = (IPortalComponentResponse) this.getResponse();
			context = request.getComponentContext();
		}
		public void doProcessBeforeOutput() throws PageException
		{
			request.getComponentSession().putValue(
				"isOK",
				isOK ? "success" : "failure");
			this.setJspName("InsertInputDataPage.jsp");
		}
		public void onInsertDataButton(Event event)
		{
			InputField usernameInput =
				(InputField) this.getComponentByName("UsernameInput");
			InputField messageInput =
				(InputField) this.getComponentByName("MessageInput");
			String username = usernameInput.getValue().toString();
			String message = messageInput.getValue().toString();
			IPortalRuntimeResources runtimeResources =
				PortalRuntime.getRuntimeResources();
			IService aService = runtimeResources.getService(IInsertData.KEY);
			IInsertData myService = (IInsertData) aService;
			isOK = myService.insertData(username, message);
		}
	}
}

-


portalapp.xml:

<?xml version="1.0" encoding="utf-8"?>
<application>
  <application-config>
    <property name="SharingReference" value="06-CustomPortalServiceLXM"/>
    <property name="SharingReference" value="com.sap.portal.htmlb,com.sap.portal.ivs.connectorservice"/>
  	<property name="SharingReference" value="htmlb"/>
  </application-config>
  <components>
    <component name="InsertInputData">
      <component-config>
        <property name="ClassName" value="inserttest.InsertInputData"/>
        <property name="JSP" value="pagelet/InsertInputDataPage.jsp"/>
      </component-config>
      <component-profile>
		 <property name="tagLib" value="/SERVICE/htmlb/taglib/htmlb.tld"/>
     </component-profile>
    </component>
  </components>
  <services/>
</application>