Try to access the on-premise system from SAP Cloud Platform --Java App Edition

1.First of all

I tried accessing the system on-premises from an SAP Cloud Platform application.

Create a simple JAVA application to check the functionality and try to access the on-premise ABAP system from SAP Cloud Platform.

2. The application to be created this time

I will briefly introduce the operation of the application.

2.1. Authentication screen

This is the SAP Cloud Platform authentication screen. image.png

2.2. First screen

Enter any text and press the submit button to call the function module STFC_CONNECTION. The character string entered in Input Text is passed to the parameter REQUTEXT when calling. image.png

2.3. Second screen

The value returned by the function module STFC_CONNECTION is displayed. RESPTEXT shows the release of SAP Netweaver, the current date and time, and information about the user who used the access. image.png

3. How to access ABAP

To connect with JCo, pass the destination name set in SAP Cloud Platform to the argument of JCoDestinationManager # getDestination and get the JCoDestination object. You can connect to the on-premises ABAP server from this object via the SAP Cloud Connector.

The following is an example when the destination name set in SAP Cloud Platform can be obtained with p.getProperty (JCO_DESTINATION).

  return JCoDestinationManager.getDestination(p.getProperty(JCO_DESTINATION));

Specifically, it was implemented in the following form. Actually, it should be easier to use if you create Interface and inherit it, but I will omit it because it is a trial.

StfcConnection.java


public class StfcConnection {
	public static final String PRAM_REQUTEXT = "REQUTEXT";
	public static final String PRAM_ECHOTEXT = "ECHOTEXT";
	public static final String PRAM_RESPTEXT = "RESPTEXT";
	private static final String FUNCTION_NAME = "STFC_CONNECTION";
	private static final String JCO_DESTINATION = "jco.destination";
	private static final String JCO_PROPERTIES = "jco.properties";

	private String propFilePath;
	private String requText;
	private String echoText;
	private String respText;


	public StfcConnection(String propDirPath, String requText) {
		this.propFilePath = Paths.get(propDirPath, JCO_PROPERTIES).toString();

		this.requText = requText;
	}

	public void execute() throws JCoException, FileNotFoundException, IOException {
		JCoDestination d = getDestiation();
		JCoFunction f = d.getRepository().getFunction(FUNCTION_NAME);

		//Function module call parameter setting
		f.getImportParameterList().setValue(PRAM_REQUTEXT, requText);

		//General-purpose module execution
		f.execute(d);

		//Acquisition of function module execution result
		JCoParameterList exports = f.getExportParameterList();
		echoText = exports.getString(PRAM_ECHOTEXT);
		respText = exports.getString(PRAM_RESPTEXT);
	}


	private JCoDestination getDestiation() throws FileNotFoundException, IOException, JCoException {

		InputStream is = new FileInputStream(propFilePath);
		Properties p = new Properties();

		// load jco destination name
		p.load(is);
		is.close();

		return JCoDestinationManager.getDestination(p.getProperty(JCO_DESTINATION));
	}

	public String getEchoText() {
		return echoText;
	}

	public String getRespText() {
		return respText;
	}
}

4. Summary

I was able to successfully access the on-premise ABAP system from SAP Cloud Platform via the SAP Cloud Connector. I felt that the implementation on the JAVA side, including authentication, has become easy.

Digression: Authentication

I implemented programmatic authentication by referring to the following help page.

For implementation, we prepared a dedicated class and called it from each Servlet.

Authenication.java


public class Authenication {

  private final static Logger logger = LoggerFactory.getLogger(Authenication.class);

  protected static void login(String user) throws LoginException {
    if (user == null) {

      logger.debug("User is not logged in.");

      //authenticate the User
      LoginContext loginContext = LoginContextFactory.createLoginContext("FORM");
      loginContext.login();
    }
  }

  protected static void logout(String user) throws LoginException {
    if (user != null) {

      logger.debug("User is logged in.");

      //logout
      LoginContext loginContext = LoginContextFactory.createLoginContext("FORM");
      loginContext.logout();
    }
  }

  protected static boolean isLoggedin(HttpServletRequest request) {
    if (request.getRemoteUser() == null) {
      return false;
    } else {
      return true;
    }
  }
}

The source code has been uploaded to GitHub. For your reference. GitHub - ScpJcoTest1

Recommended Posts

Try to access the on-premise system from SAP Cloud Platform --Java App Edition
[JDBC] I tried to access the SQLite3 database from Java.
The road from JavaScript to Java
Try passing values from Java Servlet to iPhone app using JSON
Deploy Java programs on SAP Cloud Platform
Try calling Watson NLU that seems to support Japanese from the Java SDK
Try calling the CORBA service from Spring (Java)
Try accessing the dataset from Java using JZOS
Setting up SAP Cloud Platform Tools for Java
[Java] Try to solve the Fizz Buzz problem
3. Create a database to access from the web module
[Java] I want to calculate the difference from the date
[Java] How to extract the file name from the path
Try calling IBM Watson Assistant 2018-07-10 from the Java SDK.
Kotlin may take the world from App to Web
Access API.AI from Java
From Java to Ruby !!
How to transition from the [Swift5] app to the iPhone settings screen
Try switching from the RHEL environment to the Ubuntu environment Server installation
Get to the abbreviations from 5 examples of iterating Java lists
[Xcode 12.3] Introduction to Apple Platform App Development-Object Edition- [Swift UI]
Android app to select and display images from the gallery
[Java] Deploy the Spring Boot application to Azure App Service
Learn how to customize the Navigation Bar from the sample app
[Docker] How to access the host from inside the container. http://host.docker.internal:
[Code Pipeline x Elastic Beanstalk] Update the runtime version from Java 8 to Corretto 11 on the Java SE platform
Read the data of Shizuoka point cloud DB with Java and try to detect the tree height.