Skip to Content
1
Mar 27, 2020 at 09:18 AM

ClassNotFoundException when calling Function Module with SAP Cloud SDK for JAVA

1874 Views Last edit Mar 27, 2020 at 09:19 AM 2 rev

Dear Experts,

When I tried to call Remote Function Module on S/4 HANA using SAP Cloud SDK for Java, following exception occurs.

java.lang.ClassNotFoundException: com.sap.conn.jco.JCoException

The application is deployed on SAP Cloud Platform CF application run time.

Does anybody know how to deal with this issue?

The code is as following.

package com.sap.cloud.sdk;

import com.google.gson.Gson;

import com.sap.cloud.sdk.cloudplatform.connectivity.*;
import com.sap.cloud.sdk.s4hana.connectivity.exception.RequestExecutionException;
import com.sap.cloud.sdk.s4hana.connectivity.rfc.RfmRequest;
import com.sap.cloud.sdk.s4hana.connectivity.rfc.RfmRequestResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/bapi")
public class BapiServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    private static final Logger logger = LoggerFactory.getLogger(BapiServlet.class);
    private static final Destination destinationRfc =
            DestinationAccessor.getDestination("Erp1809rfc");

    @Override
    protected void doGet(final HttpServletRequest request, final HttpServletResponse response)
            throws IOException {

        logger.info("Start get method: " + request.getRequestURI());
        Iterable names = destinationRfc.getPropertyNames();
        logger.info(new Gson().toJson(names));

        try {
            final RfmRequestResult rfmTest = new RfmRequest("RFCPING")
                    .execute(destinationRfc);
            response.setContentType("application/json");
            response.setCharacterEncoding("UTF-8");
            response.getWriter().write(new Gson().toJson(rfmTest));
            } catch (RequestExecutionException e) {
            e.printStackTrace();
        }
    }
}

The log is as following.

   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT [CONTAINER] a].[localhost].[/].[com.sap.cloud.sdk.BapiServlet] SEVERE  Servlet.service() for servlet [com.sap.cloud.sdk.BapiServlet] in context with path [] threw exception
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT com.sap.cloud.sdk.cloudplatform.exception.ShouldNotHappenException: com.sap.cloud.sdk.cloudplatform.thread.exception.ThreadContextExecutionException: javax.servlet.ServletException: Servlet execution threw an exception
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at com.sap.cloud.sdk.cloudplatform.servlet.RequestAccessorFilter.doFilter(RequestAccessorFilter.java:74)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at com.sap.cloud.sdk.cloudplatform.security.servlet.HttpCachingHeaderFilter.doFilter(HttpCachingHeaderFilter.java:83)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at com.sap.cloud.sdk.cloudplatform.security.servlet.HttpSecurityHeadersFilter.doFilter(HttpSecurityHeadersFilter.java:41)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at org.apache.catalina.filters.RestCsrfPreventionFilter.doFilter(RestCsrfPreventionFilter.java:116)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at org.cloudfoundry.router.ClientCertificateMapper.doFilter(ClientCertificateMapper.java:79)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:526)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:678)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:747)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:861)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1579)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at java.lang.Thread.run(Thread.java:748)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT Caused by: com.sap.cloud.sdk.cloudplatform.thread.exception.ThreadContextExecutionException: javax.servlet.ServletException: Servlet execution threw an exception
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at com.sap.cloud.sdk.cloudplatform.thread.AbstractThreadContextExecutor.execute(AbstractThreadContextExecutor.java:325)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at com.sap.cloud.sdk.cloudplatform.servlet.RequestAccessorFilter.doFilter(RequestAccessorFilter.java:71)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     ... 32 more
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT Caused by: javax.servlet.ServletException: Servlet execution threw an exception
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:238)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at com.sap.cloud.sdk.cloudplatform.servlet.RequestAccessorFilter.lambda$doFilter$1(RequestAccessorFilter.java:71)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at com.sap.cloud.sdk.cloudplatform.thread.AbstractThreadContextExecutor.lambda$execute$0(AbstractThreadContextExecutor.java:317)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at com.sap.cloud.sdk.cloudplatform.thread.ThreadContextCallable.call(ThreadContextCallable.java:247)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at com.sap.cloud.sdk.cloudplatform.thread.AbstractThreadContextExecutor.execute(AbstractThreadContextExecutor.java:319)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     ... 33 more
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT Caused by: java.lang.NoClassDefFoundError: com/sap/conn/jco/JCoException
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at com.sap.cloud.sdk.s4hana.connectivity.rfc.RfmTransactionFactory.createJCoTransaction(RfmTransactionFactory.java:32)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at com.sap.cloud.sdk.s4hana.connectivity.rfc.AbstractTransactionFactory.createTransaction(AbstractTransactionFactory.java:39)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at com.sap.cloud.sdk.s4hana.connectivity.rfc.RemoteFunctionRequestExecutor.execute(RemoteFunctionRequestExecutor.java:41)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at com.sap.cloud.sdk.s4hana.connectivity.rfc.RfmRequest.execute(RfmRequest.java:102)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at com.sap.cloud.sdk.BapiServlet.doGet(BapiServlet.java:47)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     ... 41 more
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT Caused by: java.lang.ClassNotFoundException: com.sap.conn.jco.JCoException
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1365)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1188)
   2020-03-27T17:40:00.72+0900 [APP/PROC/WEB/0] OUT     ... 49 more

Regards,

Yohei