The SAP Java Connector (SAP JCo) is a development library that enables development of SAP compatible components in Java. It can be used to communicate with on-premise SAP systems via SAP's RFC protocol.
(Source: https://support.sap.com/en/product/connectors/jco.html)
package com.test.jco;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.sap.conn.jco.JCoDestination;
import com.sap.conn.jco.JCoDestinationManager;
import com.sap.conn.jco.JCoFunction;
import com.sap.conn.jco.JCoParameterList;
import com.sap.conn.jco.JCoRepository;
@WebServlet("/ConnectRFC/*")
public class ConnectRFC extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter responseWriter = response.getWriter();
try {
// access the RFC Destination "Test"
JCoDestination destination = JCoDestinationManager.getDestination("Test");
// make an invocation of STFC_CONNECTION in the backend
JCoRepository repo = destination.getRepository();
JCoFunction stfcConnection = repo.getFunction("STFC_CONNECTION");
JCoParameterList imports = stfcConnection.getImportParameterList();
imports.setValue("REQUTEXT", "JCO successful");
stfcConnection.execute(destination);
JCoParameterList exports = stfcConnection.getExportParameterList();
String echotext = exports.getString("ECHOTEXT");
String resptext = exports.getString("RESPTEXT");
responseWriter.println(echotext+":"+resptext);
} catch (Exception e) {
e.printStackTrace();
}
}
}
<dependencies>
<dependency>
<groupId>com.sap.cloud</groupId>
<artifactId>neo-java-web-api</artifactId>
<version>[3.71.8,4.0.0)</version>
<scope>provided</scope>
</dependency>
</dependencies>
{
"xsappname" : "connect-rfc",
"tenant-mode": "dedicated",
"scopes": [
{
"name": "$XSAPPNAME.all",
"description": "all"
}
]
}
---
applications:
- name: connect-rfc
buildpacks:
- sap_java_buildpack
env:
SAP_JWT_TRUST_ACL: '[{"clientid":"*","identityzone":"*"}]'
xsuaa_connectivity_instance_name: "jco_xs"
services:
- jco_xs
- jco_con
- jco_dest
---
applications:
- name: approuter-jco
path: ./
buildpacks:
- nodejs_buildpack
memory: 120M
env:
NODE_TLS_REJECT_UNAUTHORIZED: 0
destinations: >
[
{"name":"dest", "url" :"https://<your java application url>/ConnectRFC", "forwardAuthToken": true }
]
services:
- jco_xs
JCO successful:SAP R/3 Rel. 752 Sysid: XXX Date: 20200725 Time: 110012 Logon_Data: 100/XXXX/E
Note : In this tutorial, I used approuter for authentication purpose. You can use AppToAppSSO to propagate authentication token. Token is required for On-Premise connectivity.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
10 | |
9 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
5 | |
4 |