SAP / cloud-security-services-integration-library

Integration libraries and samples for authenticating users and clients bound to XSUAA authentication and authorization service or Identity authentication service.
Apache License 2.0
151 stars 135 forks source link

JCO_ERROR_COMMUNICATION: Initialization of repository destination failed: Opening connection to backend failed: There is no SAP Cloud Connector (SCC) connected to your subaccount matching the requested #1183

Closed yaohf777 closed 1 year ago

yaohf777 commented 1 year ago

Dear colleague,

Our application is a Cloud Foundry based SaaS application and we need to perform JCo call. I following SAP help - Calling JCo APIs from Newly Created Threads to call JCo in a new thread with code like below:

        String destinationName = "GXTCLNT200";

        // Get JCoDestination & JCoRepository in orginal thread for logging purpose
        JCoDestination destination = JCoDestinationManager.getDestination(destinationName);
        log.info("JCoDestination : {}", destination);
        JCoRepository repository = destination.getRepository();
        log.info("JCoRepository: {}", repository);

        Token token = SecurityContext.getToken();

        Thread runThread = new Thread(() -> {
            // set the information in the newly created thread
            SecurityContext.setToken(token);
            try {
                JCoDestination destination1 = JCoDestinationManager.getDestination(destinationName);
                log.info("JCoDestination : {}", destination1);
                JCoRepository repository2 = destination1.getRepository();
                log.info("JCoRepository: {}", repository);
            } catch (JCoException e) {
                log.error("JCoException", e);
            }
        });
        runThread.start();

The strange thing is that getting JCoDestination & JCoRepository in orginal thread works fine and also getting JCoDestination works also fine in the new thread. However getting JCoRepository throw below exception:

com.sap.conn.jco.JCoException: (102) JCO_ERROR_COMMUNICATION: Initialization of repository destination GXTCLNT200 failed: Opening connection to backend failed: 
There is no SAP Cloud Connector (SCC) connected to your subaccount matching the requested tunnel for subaccount "410ea1e5-8ca6-4f2b-b130-e99d83dd66a4" and SCC location ID, with default value, that is empty string or simply not configured. Check the configuration on SCC and cloud side.
    at com.sap.conn.jco.rt.RfcDestination.getSystemID(RfcDestination.java:1554)
    at com.sap.conn.jco.rt.RepositoryManager.getRepository(RepositoryManager.java:27)
    at com.sap.conn.jco.rt.RfcDestination.initRepository(RfcDestination.java:1458)
    at com.sap.conn.jco.rt.RfcDestination.getRepository(RfcDestination.java:1840)
    at com.sap.conn.jco.rt.RfcDestination.getRepository(RfcDestination.java:40)
    at com.sap.grc.iag.job.execution.accesscontrol.AccessControlBaseJob.prepareJCoDestination(AccessControlBaseJob.java:156)
    at com.sap.grc.iag.job.execution.accesscontrol.AccessControlBaseJob.runJob(AccessControlBaseJob.java:138)
    at com.sap.grc.iag.job.manager.JobRunWrapper.startJob(JobRunWrapper.java:31)
    at com.sap.grc.iag.job.manager.JobManager.lambda$startJob$1(JobManager.java:136)
    at com.sap.grc.iag.grcscheduler.client.multitenancy.TenantAwareExecutor.lambda$execute$0(TenantAwareExecutor.java:24)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:838)
Caused by: com.sap.conn.jco.JCoException: (102) JCO_ERROR_COMMUNICATION: Opening connection to backend failed: 
There is no SAP Cloud Connector (SCC) connected to your subaccount matching the requested tunnel for subaccount "410ea1e5-8ca6-4f2b-b130-e99d83dd66a4" and SCC location ID, with default value, that is empty string or simply not configured. Check the configuration on SCC and cloud side. (remote system is [<unknown>])
    at com.sap.conn.jco.rt.AbstractConnection.generateJCoException(AbstractConnection.java:623)
    at com.sap.conn.jco.rt.ClientConnection.connectInternal(ClientConnection.java:632)
    at com.sap.conn.jco.rt.ClientConnection.connect(ClientConnection.java:1186)
    at com.sap.conn.jco.rt.RepositoryConnection.connect(RepositoryConnection.java:183)
    at com.sap.conn.jco.rt.PoolingFactory.init(PoolingFactory.java:116)
    at com.sap.conn.jco.rt.ConnectionManager.createFactory(ConnectionManager.java:499)
    at com.sap.conn.jco.rt.ConnectionManager.getFactory(ConnectionManager.java:435)
    at com.sap.conn.jco.rt.RfcDestination.getSystemID(RfcDestination.java:1536)
    ... 12 more
Caused by: RfcException raised by system [<unknown>]:
    message: Opening connection to backend failed: There is no SAP Cloud Connector (SCC) connected to your subaccount matching the requested tunnel for subaccount "410ea1e5-8ca6-4f2b-b130-e99d83dd66a4" and SCC location ID, with default value, that is empty string or simply not configured. Check the configuration on SCC and cloud side.
    return code: RFC_FAILURE (RFC_FAILURE)
    error group: RFC_ERROR_COMMUNICATION
    at com.sap.conn.rfc.driver.NeoSocketDriver.open(NeoSocketDriver.java:210)
    at com.sap.conn.rfc.engine.RfcIoControl.ab_rfcopen(RfcIoControl.java:113)
    at com.sap.conn.rfc.api.RfcApi.RfcOpen(RfcApi.java:79)
    at com.sap.conn.jco.rt.ClientConnection.connectInternal(ClientConnection.java:619)
    ... 18 more

It looks the JCoDestination .getRepository() works differently with JCoDestinationManager.getDestination(destinationName). Need your support here. We can have a call if needed. Thanks.

Best regards, Haifeng Yao

yaohf777 commented 1 year ago

I just found the issue was resolved after updating my pom.xml. My guess is that there is something strange in neo-java-web-api.

Below dependency reports above issue:

    <dependency>
        <groupId>com.sap.cloud</groupId>
        <artifactId>neo-java-web-api</artifactId>
        <version>3.43.12</version>
        <scope>provided</scope>
    </dependency>

Below dependency reports no issue:

    <dependency>
        <groupId>com.sap.conn.jco</groupId>
        <artifactId>sapjco3</artifactId>
        <version>3.1.7</version>
        <scope>provided</scope>
    </dependency>
liga-oz commented 1 year ago

Hi @yaohf777, none of your mentioned dependencies nor class paths from stack traces belong to our library. I'm glad you solved the problem, but this was not the right repository for the issue anyway 😉