What you wanna do is technically not supported: You want to invoke a BAPI from your localhost via the transport protocol RFC using the JCo library (used behind the scenes via the SAP Cloud SDK). The usage of JCo requires to run your app on SAP Cloud Platform.
when deploying locally you must add a dependency to Neo SDK (which also contains the JCO libraries).
cf create-route <space name> cfapps.eu10.hana.ondemand.com --hostname <host name of App Router>
cf create-route <space name> cfapps.eu10.hana.ondemand.com --hostname <host name of Java App>
mvn archetype:generate "-DarchetypeGroupId=com.sap.cloud.sdk.archetypes" "-DarchetypeArtifactId=scp-cf-tomee" "-DarchetypeVersion=RELEASE"
---
applications:
- name: test-rfc
memory: 1024M
timeout: 300
routers:
- route: https://<route host name>.<route domain name>
random-route: false
path: application/target/test-rfc-application.war
buildpacks:
- sap_java_buildpack
env:
TARGET_RUNTIME: tomee7
SET_LOGGING_LEVEL: '{ROOT: INFO, com.sap.cloud.sdk: INFO}'
JBP_CONFIG_SAPJVM_MEMORY_SIZES: 'metaspace:128m..'
services:
# - my-application-logs
- <destination name>
# - my-connectivity
<plugin>
<groupId>com.sap.cloud.sdk.plugins</groupId>
<artifactId>usage-analytics-maven-plugin</artifactId>
<!-- changed from 3.19.1 to 3.18.0 -->
<version>3.18.0</version>
<executions>
<execution>
<goals>
<goal>usage-analytics</goal>
</goals>
<configuration>
<!-- changed from false to true -->
<skipUsageAnalytics>true</skipUsageAnalytics>
<generateSalt>true</generateSalt>
<!--
Note: A random salt is auto-generated once the project is built for the first time.
Please keep the generated salt in the POM file, for example, when pushing to git.
To learn more, visit: https://blogs.sap.com/2018/10/23/usage-analytics-s4sdk/
-->
<salt>55578c0d7b7bff985020ad9ce2e033dbb9bd6425acb24eb8d4b40dcc1ba0f9b0</salt>
</configuration>
</execution>
</executions>
</plugin>
mvn clean package && cf push
$ curl https://test-rfc.cfapps.eu10.hana.ondemand.com/hello
Hello World!
$ sap-cloud-sdk add-approuter
No 'manifest.yml' found.
Enter project name as maintained in Cloud Foundry: test-rfc
✔ Creating files
✅ Successfully added approuter to your project.
Generated files might need customization. Documentation available here:
- xs-security.json (for help check https://help.sap.com/viewer/4505d0bdaf4948449b7f7379d24d0f0d/2.0.02/en-US/e6fc90df44464a29952e1c2c36...
- xs-app.json (for help check https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/c103fb414988447ead2023f7680...
- mainfest.yml (for help check https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/ba527058dc4d423a9e0a69ecc67...
{
"xsappname": "test-rfc",
"tenant-mode": "dedicated"
}
cf create-service xsuaa application <xsuaa name> -c xs-security.json
cf bind-service test-rfc <xsuaa name>
applications:
- name: test-rfc-approuter
routes:
- route: >-
https://<App Router Route host name><App Router Route domain>
path: .
memory: 128M
buildpacks:
- nodejs_buildpack
env:
# TENANT_HOST_PATTERN: >-
# "test-rfc-(.*).cfapps.sap.hana.ondemand.com"
destinations: >-
[{"name":"test-rfc","url":"https://<Java Route host name>.<Java Route domain>","forwardAuthToken":true}]
services:
- <xsuaa name>
cf push
cf create-service connectivity lite <connectivity name>
---
applications:
- name: test-rfc
memory: 1024M
timeout: 300
random-route: false
routers:
- route: https://test-rfc-java.cfapps.eu10.hana.ondemand.com
path: application/target/test-rfc-application.war
buildpacks:
- sap_java_buildpack
env:
TARGET_RUNTIME: tomee7
SET_LOGGING_LEVEL: '{ROOT: INFO, com.sap.cloud.sdk: INFO}'
JBP_CONFIG_SAPJVM_MEMORY_SIZES: 'metaspace:128m..'
xsuaa_connectivity_instance_name: "<xsuaa name>"
services:
- <destination name>
- <xsuaa name>
- <connectivity name>
package com.sap.cloud.sdk;
import com.google.gson.Gson;
import com.sap.cloud.sdk.cloudplatform.connectivity.Destination;
import com.sap.cloud.sdk.cloudplatform.connectivity.DestinationAccessor;
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("/rfc")
public class RfcServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private static final Logger logger = LoggerFactory.getLogger(RfcServlet.class);
private static final Destination destinationRfc =
DestinationAccessor.getDestination("<destination name>");
@Override
protected void doGet(final HttpServletRequest request, final HttpServletResponse response)
throws IOException {
logger.info("Start get method: " + request.getRequestURI());
String parameter = request.getParameter("name");
logger.info("Get parameter 'name': " + parameter);
if (parameter == null) {
parameter = "RFCPING";
}
Iterable names = destinationRfc.getPropertyNames();
logger.info(new Gson().toJson(names));
try {
final RfmRequestResult rfmTest = new RfmRequest(parameter, false) //false is for non-commit
.execute(destinationRfc);
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(new Gson().toJson(rfmTest));
} catch (RequestExecutionException e) {
e.printStackTrace();
}
}
}
# from application directory
mvn clean package && cd .. && cf push
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
24 | |
9 | |
8 | |
7 | |
7 | |
6 | |
6 | |
6 | |
6 | |
6 |