Technical Articles
Exploring CPI’s filesystem’s content
While I was doing more in-depth research on how CPI works, I became curious about the content of its own filesystem. In this post, I’ll tell you a little about its content and how you can explore it yourself.
One of the peculiarities of CPI, is that it is very flexible when it comes to establishing an HTTP communication. In this way, it is possible to imitate a web server by modifying some headers and the body of an “exchange”. Ultimately, a web server mainly serves GETs and POSTs requests. Using this technique, and including a couple of lines of groovy script, you can create a file explorer emulator. Logically, due to access privileges, it is not possible to browse all directories. Still, it is possible to get very interesting information and files of CPI. A lot of low hanging fruits.
As a word of warning, check first that you are not breaking any rules and keep in mind that there could be risks involved. I cannot be held responsible for how you use the information offered in this post. Also, beware that the explorer I am presenting is basic, rustic and buggy. Feel free to improve it and share your snippets. 🙂
Creating the Iflow
Short way: you can download the example from this url.
Normal way: we need to create a very simple iflow, with two independent communication channels and running groovy scripts. One channel will be in charge of reviewing the contents of the directories and the other will be responsible for downloading the files.
In my own iflow I have used the following configurations:
Iflow
Channels
Script
import com.sap.gateway.ip.core.customdev.util.Message
import java.util.HashMap
def Message browse(Message message) {
def mapHeaders = message.getHeaders()
String mainDir = mapHeaders.get("CamelHttpPath")
String mainUrl = mapHeaders.get("CamelHttpUrl")
String mainSrv = mapHeaders.get("CamelServletContextPath")
String srvUrl = mainUrl.minus(mainDir)
String urlDown = srvUrl.minus(mainSrv)+"/amba/cpifilesystemdownload"
File dir = new File(mainDir)
StringBuilder strBuilder = new StringBuilder()
strBuilder << '<meta charset="UTF-8"></br>'
if (dir.parent != null){strBuilder << "<a href='${srvUrl}${dir.parent}'>📁 ..</a></br>"}
dir.eachDir {strBuilder << "<a href='${mainUrl}/${it.name}'>📁 ${it.name}</a></br>"}
dir.eachFile {if (it.isFile()) {strBuilder << "<a href='${urlDown}/${mainDir}/${it.name}'>${it.name}</a></br>" }}
message.setBody(strBuilder.toString())
mapHeaders = ['content-type':'text/html']
message.setHeaders(mapHeaders)
return message
}
def Message download(Message message) {
def mapHeaders = message.getHeaders()
String filePath = mapHeaders.get("CamelHttpPath")
StringBuilder strBuilder = new StringBuilder()
File file = new File(filePath);byte[] fileContent = file.bytes
strBuilder << fileContent.encodeBase64().toString()
message.setBody(strBuilder.toString());
mapHeaders = ['Content-Transfer-Encoding':'base64',
'Content-Disposition':'attachment; filename=${file.getName()}']
return message
}
What directories can you explore?
It’s hard to give an answer, as I haven’t found a way to get available folders to explore. However, by analysing CPÃŽ’s environment variables, I have found the following directories with interesting information. Please, share your findings!
Folder | Comments |
/usr/sap/ljs/ | CPI’s home? |
/usr/lib/jvm | SAP’s Java Virtual Machine |
/usr/sap/ljs/configuration | OSGI configuration area |
/usr/sap/ljs/configuration/org.eclipse.osgi/bundles | Â Iflows Contents |
/usr/sap/ljs/plugins | CPI’s jar files |
/tmp | Standard Linux temporary folder |
/proc    ? (not ‘real’ files) | Process Information |
How to use
Once you load the iflow, copy the endpoint that will give you the channel that scans the directories. Paste that address into your internet browser. At the end of the url, include the folder you want to explore. (Not all routes can be explored as already mentioned)
Example:
Please share your findings!
Ariel Bravo Ayala
That is pretty cool and useful. You can even find the error logs that way.
Just a small modification to make it a little easier to navigate so you can get a table view and get size and last modified of the files.
You can find many things. Even some leftovers from the SAP developers :-S
Have you find something useful for daily usage?
Thanks for the snippet improvement!
Ariel
Really useful and great stuff... Thank you for sharing..
Regards,
Srinivas
You are welcome!
Thanks for Sharing this!! , Its Really Helpful.
Thanks
--Siva
You are welcome Siva!
Hello Guys,
Great stuff.
Please share if you found anymore useful folders which we can use.
Regards,
Rajath Kodandaramu
Hello,
very nice blog! Thanks for sharing this.
kind regards
I am getting the following error
Hi Balaji
try http/amba/cpifilesystem//usr/sap/ljs
I’m also on the same boat as Balaji…I downloaded and deployed the iFlow straight from Github.Â
Ariel Bravo Ayala – do you have any suggestions please?
Thanks,
Anirban
What url are you using?
Br, Ariel
Can’t find /usr/ SAP/LJS /plugins, can you send relevant JAR package, com.sap.script.customs-development liuw@sbtjt.com
Â
Hi, is this method still supported? I have downloaded the iFlow but am receiving the error message "com.sap.it.rt.adapter.http.api.exception.HttpResponseException: An internal server error occured: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.processData() is applicable for argument types: (com.sap.gateway.ip.core.customdev.processor.MessageImpl) values: [com.sap.gateway.ip.core.customdev.processor.MessageImpl@48ec27a4]. The MPL ID for the failed message is : AGCr_MIXzDkzgJWbd5pNvNnhK3_V For more details please check tail log." when accessing the URL at ,<tenant>/http/amba/cpifilesystem//usr/sap/ljs.
I would like to be able to access some of the information (i.e. CPU, memory, disk space, etc.) that this claims to provide, but so far have not been able to.
Thanks
Hi Matt,
I wrote this long ago, I am not sure if this is still valid. If so, a few points to consider:
1.- The snippet implements the functions "browse" and "download". Your error implies you haven't changed the function names in the Groovy Script steps. (The default is processData)
2.- This works(ed) in Neo. I did not test this in CF.
3.- If your goal is to access the information like CPU, memory, etc, you have other alternatives, like using the operation APIs. This explorer will give you the info of the worker node that executes the request exclusively, but your tenant is likely to have multiple worker/management nodes.
The operations APIs you could use are:
https://{{{operationsURL}}}/com.sap.it.op.srv.commands.dashboard.ParticipantListCommand (Basic info of your account)
https://{{{operationsURL}}}/com.sap.it.nm.commands.node.GetNodesCommand (Get the node IDs)
https://{{{operationsURL}}}/com.sap.it.op.srv.commands.dashboard.NodeProcessStatisticCommand (Get the statistics of the nodes)
I hope this helps.
Ariel
Hi Ariel,
Thank you for your response. You were exactly right with your diagnosis of the error. Once I added the script function it seems to be working as you showed in your original post. I'll also check out a blog post I see from you on the operations APIs to get more info on those. Thanks so much for your help and this great information!
Best Regards,
Matthew
Hello,
It seems that for this iFlow to work in Cloud Foundry CPI we need to adjust the URL and script.
The issue is that URL should not contain "//"
After this deploy and open like