SAP HANA Cloud Platform
SAP HANA Cloud Platform
Documentation
Developing Applications
You can develop
applications for SAP HANA Cloud just like for any application server. SAP HANA
Cloud applications are based on the Java EE Web application model. You can use
programming logic that is well-known to you, and benefit from the advantages of
Java EE, which defines the application frontend. Inside, you can embed the
usage of the services provided by the platform.
Development Environment
SAP HANA Cloud
development environment is designed and built to optimize the process of
development and deployment.
It includes the SAP
HANA Cloud Tools for Java, which integrate the standard capabilities of Eclipse
IDE with some extended features that allow you to deploy on the cloud. You can
choose between two types of SAP HANA Cloud SDK for Java applications:
- SAP HANA Cloud SDK for Java Web - provides support for
some of the standard Java EE APIs (Servlet, JSP, JSTL, EL) - SAP HANA Cloud SDK for Java EE 6 Web Profile -
certified to support Java EE 6 Web Profile APIs - Authentication
- by default, SAP HANA Cloud is configured to use SAP ID service as
identity provider (IdP), as specified in SAML 2.0. You can configure trust
to your custom IdP, to provide access to the cloud using your own user
database. - SAPUI5
- use the platform's official UI framework. - Persistence Service - provide relational persistence with JPA and JDBC via
our persistence service. - Connectivity Service - use it to connect Web applications to Internet, make
on-demand to on-premise connections to Java and ABAP on-premise systems
and configure destinations to send and fetch e-mail. - Document Service
- use the service to store unstructured or semistructured data in your
application. - Logging -
implement a logging API if you want to have logs produced at runtime. - Tutorials: Familiarize yourself with the JPA and JDBC
technologies on SAP
HANA Cloud by completing the tutorials. - Basic conceptual information: Particular aspects about
working with JPA and JDBC that were introduced in the tutorials are
explained in more detail. - Database switch: For test purposes, replace the local
database provided as standard with a database of your choice. - SQL trace: Activate the SQL trace to include SQL
details in the standard trace files. - EclipseLink weaving: Enable static weaving in Eclipse.
- Remote database access (beta version): Remotely access
your Web application's database schema and tables in the cloud. - Links to more information about the JPA and JDBC APIs
- Frequently asked questions (FAQ) about the persistence
service - HTTP Destinations
- RFC Destinations
- Mail Destinations
- Application developers - develop the SAP HANA Cloud application. They create
a connectivity-enabled application by using SAP HANA Cloud connectivity
API. - Application operators - access SAP HANA Cloud Cockpit and are responsible
for productive deployment and operation of an application. They are also
responsible for configuring the remote connections that an application
might need. - IT administrators - set up the connectivity to SAP HANA Cloud in the customer's on-premise network, using the SAP
HANA Cloud connector. - Making Internet connections between Web applications
and external servers via HTTP protocol: Tutorial: Using Internet Services in Cloud Applications - Making connections between Web applications and
on-premise backend services via HTTP protocol: Tutorial: Using On-Premise Back-End Services in Cloud
Applications - Making connections between Web applications and
on-premise backend services via RFC protocol: Tutorial: Invoking ABAP Function Modules in On-Premise ABAP
Systems - Establishing connections from on-premise systems to SAP
HANA Cloud, using SAP HANA Cloud Connector: Using the Cloud Connector - Sending and fetching e-mail via mail protocols: Sending and Fetching E-Mail
- You have
downloaded and configured the SAP Eclipse platform. For more information,
see Setting Up the
Tools and SDK linked below. - You have created
a HelloWorld Web application as described in the Creating a HelloWorld Application
tutorial linked below. - You have
downloaded the SDK used for local development. - You have
installed MongoDB as described in Getting
Prepared for Local Development.
For more information,
see Development Environment
Create a basic application
In the Eclipse IDE,
create a simple HelloWorld application with basic functional logic wrapped in a
Dynamic Web Project and a Servlet. You can do this with both SDKs.
For more information,
see Creating a HelloWorld Application
Use Java EE 6 Web Profile
SAP HANA Cloud is Java
EE 6 Web Profile certified so you can extend the basic functionality of your
application with Java EE 6 Web Profile technologies. If you are working with
the SDK for Java EE 6 Web Profile, you can equip the basic application with
additional Java EE functionalities, such as EJB, CDI, JTA.
For more information,
see Using Java EE 6 Web Profile
Use services and utilities
Create a fully-fledged
application benefiting from the capabilities and services provided by SAP HANA
Cloud. In your application, you can choose to use:
Deploy
First, deploy and test
the ready application on the local runtime and then make it available on SAP
HANA Cloud.
For more information,
see Deploying Applications
Manage
Manage all
applications deployed in your account from a single dedicated user interface -
SAP HANA Cloud cockpit.
For more information,
see SAP HANA Cloud Cockpit
Monitor
Configure checks and
monitor the state of your applications.
For more information,
see Monitoring Applications
Consuming the Persistence Service
Overview
The SAP HANA Cloud persistence service provides persistence in a
relational database for applications that are hosted on SAP HANA Cloud. This section introduces the key concepts of
the persistence service and shows how you can use JPA and JDBC to manage
relational data in your applications:
Related Information
Tutorials
Programming with JPA
Using Plain JDBC
Creating SAP HANA Column-Store Tables
Changing the Local Database
Using the SQL Trace
EclipseLink Weaving
Remote Database Access
JPA and JDBC APIs
Frequently Asked Questions
Consuming the Connectivity Service
Overview
In this section, you
will learn how to use SAP HANA Cloud connectivity service to connect Web
applications to Internet, make on-demand to on-premise connections to Java and
ABAP on-premise systems and configure destinations to send and fetch e-mail. To
do all these tasks, you need to create and configure destinations, according to
the relevant protocol type. For more information, see: Using Destinations
To learn more how to
configure a destination from a particular type, see:
Who Can Use It
The following user
groups are involved in the end-to-end use of SAP HANA Cloud connectivity
service:
Scenarios
Troubleshooting
If you encounter
connectivity problems, you can check the available solutions related to general
connectivity issues or specific on-demand to on-premise cases.
For more information,
see Connectivity Troubleshooting Guide.
Securing Applications
SAML 2.0 Authentication
SAP HANA Cloud uses
the Security Assertion Markup Language (SAML) 2.0 protocol for authentication
and single sign-on.
By default, SAP HANA
Cloud is configured to use SAP ID service as identity provider (IdP), as
specified in SAML 2.0. You can configure trust to your custom IdP, to provide
access to the cloud using your own user database.
Java EE Identity and Access Management
SAP ID Service
provides Identity and Access Management for Java EE Web applications hosted on
SAP HANA Cloud through the mechanisms described in Java EE Servlet
specification and through dedicated APIs.
Protecting Applications from Cross-Site Scripting (XSS)
Cross-site Scripting
(XSS) is one of the most common types of malicious attacks to Web applications.
In order to help protecting against this type of attacks, SAP HANA Cloud
provides a common output encoding library to be used from applications.
Protecting from Cross-Site Request Forgery (CSRF)
Cross-Site Request
Forgery (CSRF) is another common type of attack to Web applications. You can
protect applications running on SAP HANA Cloud from CSRF, based on the Tomcat
Prevention Filter.
Related Information
ID Federation with the Corporate Identity Provider
Test Security on the
Cloud (with Local Identity Provider)
Assigning Roles
Enforcing Authentication
Protecting from Cross-Site Scripting (XSS)
Protecting from Cross-Site Request Forgery (CSRF)
Using the Document Service in a Web Application
Prerequisites
Context
This tutorial describes how to
extend the HelloWorld Web application to use the SAP HANA Cloud document
service to manage unstructured content in your application. You test and run
the Web application on your local server and the SAP HANA Cloud.
Procedure
1. Connect the HelloWorld Web
application to the document service. The document service client
library is used to connect to the document service. It connects to the local or
central document service and returns an authenticated OpenCMIS session. If you
are running your application locally in Eclipse IDE, the document service
client library connects to a local document service of the SAP HANA Cloud SDK
that is connected to your local MongoDB. If your application is deployed on SAP
HANA Cloud, the document service client library connects to the document
service that belongs to the corresponding system landscape.
2. Configure your Web application
in the following way to enable user authentication if your application needs
authenticated users and these users should be automatically propagated to the
document service:
a. Expand the
HelloWorld/WebContent/WEB-INF node.
b. Select the web.xml file and,
from the context menu, choose Open.
c. Enable authentication for your
application.
For more information on authentication see User Authentication
linked below.
3. Connect to the document service
and create a folder and a document.
a. Expand the HelloWorld/Java
Resources/src/hello node.
b. Select the
HelloWorldServlet.java file and, from the context menu, choose Open.
c. Add the following code to
HelloWorldServlet.java:
d. package hello;e.
f. import java.io.ByteArrayInputStream;
g. import java.io.IOException;
h. import java.io.InputStream;
i. import java.util.HashMap;
j. import java.util.Map;
k.
l. import javax.servlet.ServletException;
m. import javax.servlet.http.HttpServlet;
n. import javax.servlet.http.HttpServletRequest;
o. import javax.servlet.http.HttpServletResponse;
p.
q. import org.apache.chemistry.opencmis.client.api.CmisObject;
r. import org.apache.chemistry.opencmis.client.api.Document;
s. import org.apache.chemistry.opencmis.client.api.Folder;
t. import org.apache.chemistry.opencmis.client.api.ItemIterable;
u. import org.apache.chemistry.opencmis.client.api.Session;
v. import org.apache.chemistry.opencmis.commons.PropertyIds;
w. import org.apache.chemistry.opencmis.commons.data.ContentStream;
x. import org.apache.chemistry.opencmis.commons.enums.VersioningState;
y. import org.apache.chemistry.opencmis.commons.exceptions.CmisNameConstraintViolationException;
z. import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException;
aa.
bb.import com.sap.ecm.api.RepositoryOptions;
cc.import com.sap.ecm.api.RepositoryOptions.Visibility;
dd.import com.sap.ecm.api.EcmService;
ee.import javax.naming.InitialContext;
ff.
gg./**
hh. * Servlet implementation class HelloWorldServlet
ii. */
jj.public class HelloWorldServlet extends HttpServlet {
kk. private static final long serialVersionUID = 1L;
ll.
mm. /**
nn. * @see HttpServlet#HttpServlet()
oo. */
pp. public HelloWorldServlet() {
qq. super();
rr. }
ss.
tt. /**
uu. * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
vv. * response)
ww. */
xx. protected void doGet(HttpServletRequest request,
yy. HttpServletResponse response) throws ServletException, IOException {
zz. response.getWriter().println("<html><body>");
aaa. try {
bbb. // Use a unique name with package semantics e.g. com.foo.MyRepository
ccc. String uniqueName = "com.foo.MyRepository";
ddd. // Use a secret key only known to your application (min. 10 chars)
eee. String secretKey = "my_super_secret_key_123";
fff. Session openCmisSession = null;
ggg. InitialContext ctx = new InitialContext();
hhh. String lookupName = "java:comp/env/" + "EcmService";
iii. EcmService ecmSvc = (EcmService) ctx.lookup(lookupName);
jjj. try {
kkk. // connect to my repository
lll. openCmisSession = ecmSvc.connect(uniqueName, secretKey);
mmm. }
nnn. catch (CmisObjectNotFoundException e) {
ooo. // repository does not exist, so try to create it
ppp. RepositoryOptions options = new RepositoryOptions();
qqq. options.setUniqueName(uniqueName);
rrr. options.setRepositoryKey(secretKey);
sss. options.setVisibility(Visibility.PROTECTED);
ttt. ecmSvc.createRepository(options);
uuu. // should be created now, so connect to it
vvv. openCmisSession = ecmSvc.connect(uniqueName, secretKey);
www. }
xxx. response.getWriter().println(
yyy. "<h3>You are now connected to the Repository with Id "
zzz. + openCmisSession.getRepositoryInfo().getId()
aaaa. + "</h3>");
bbbb.
cccc. // access the root folder of the repository
dddd. Folder root = openCmisSession.getRootFolder();
eeee.
ffff. // create a new folder
gggg. Map<String, String> newFolderProps = new HashMap<String, String>();
hhhh. newFolderProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
iiii. newFolderProps.put(PropertyIds.NAME, "SapHANANeo");
jjjj. try {
kkkk. root.createFolder(newFolderProps);
llll. } catch (CmisNameConstraintViolationException e) {
mmmm. // Folder exists already, nothing to do
nnnn. }
oooo.
pppp. // create a new file in the root folder
qqqq. Map<String, Object> properties = new HashMap<String, Object>();
rrrr. properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
ssss. properties.put(PropertyIds.NAME, "HelloWorld.txt");
tttt. byte[] helloContent = "Hello World!".getBytes("UTF-8");
uuuu. InputStream stream = new ByteArrayInputStream(helloContent);
vvvv. ContentStream contentStream = openCmisSession.getObjectFactory()
wwww. .createContentStream("HelloWorld.txt",
xxxx. helloContent.length, "text/plain; charset=UTF-8", stream);
yyyy. try {
zzzz. root.createDocument(properties, contentStream, VersioningState.NONE);
aaaaa. } catch (CmisNameConstraintViolationException e) {
bbbbb. // Document exists already, nothing to do
ccccc. }
ddddd.
eeeee. // Display the root folder's children objects
fffff. ItemIterable<CmisObject> children = root.getChildren();
ggggg. response.getWriter().println("The root folder of the repository with id " + root.getId()
hhhhh. + " contains the following objects:<ul>");
iiiii. for (CmisObject o : children) {
jjjjj. response.getWriter().print("<li>" + o.getName());
kkkkk. if (o instanceof Folder) {
lllll. response.getWriter().println(" createdBy: " + o.getCreatedBy() + "</li>");
mmmmm. } else {
nnnnn. Document doc = (Document) o;
ooooo. response.getWriter().println(" createdBy: " + o.getCreatedBy() + " filesize: "
ppppp. + doc.getContentStreamLength() + " bytes"
qqqqq. + "</li>");
rrrrr. }
sssss. }
ttttt. response.getWriter().println("</ul>");
uuuuu. } catch (Exception e) {
vvvvv. throw new ServletException(e);
wwwww. } finally {
xxxxx. response.getWriter().println("</body></html>");
yyyyy. }
zzzzz. }
aaaaaa.
bbbbbb. /**
cccccc. * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
dddddd. * response)
eeeeee. */
ffffff. protected void doPost(HttpServletRequest request,
gggggg. HttpServletResponse response) throws ServletException, IOException {
hhhhhh. // TODO Auto-generated method stub
iiiiii. }
jjjjjj.
kkkkkk. }
llllll.
- For more information about using the OpenCMIS API, see the
Apache Chemistry documentation linked below. During execution, this servlet
does the following:
Connects to a repository and creates the repository if it does
not yet exist
Creates a subfolder
Creates a document
Displays the children of the root folder
Add the resource reference
description to the web.xml file.
In the Project Explorer view,
expand the HelloWorld/WebContent/WEB-INF node.
Select the web.xml file and
from the context menu choose Open WithText Editor.
Insert the following content
after the <servlet-mapping> elements:
<resource-ref> - Test the Web application
locally or in the SAP HANA Cloud. For testing, proceed as described in Deploying
from the Eclipse IDE linked below.
Sending and Fetching E-Mail
The e-mail
connectivity functionality allows you to send electronic mail messages from
your Web applications using e-mail providers that are accessible on the
Internet, such as Google Mail (Gmail). It also allows you to retrieve e-mails
from the mailbox of your e-mail account.
To send and fetch
e-mail, you need to do the following:7. <res-ref-name>EcmService</res-ref-name>
8. <res-type>com.sap.ecm.api.EcmService</res-type>
</resource-ref>
- Obtain a mail session resource using resource injection
or, alternatively, using a JNDI lookup. - Configure the mail session resource by specifying the
protocol settings of your mail server as a mail destination configuration.
SMTP is supported for sending e-mail, and POP3 and IMAP for retrieving
messages from a mailbox account. - In your Web application, use the JavaMail API (javax.mail) to create and send a MimeMessage object or retrieve e-mails from a message store
- Passing the parameter inside the message String
- Passing the parameter as an argument to the respective
methods (info, error, and so on): - Customer and partner accounts: https://account.hana.ondemand.com
- Developer accounts: https://account.hanatrial.ondemand.com
Navigation
The object on which
you are currently focused is shown in the object area in the upper left section
of the screen. At the highest level it is an account and, as you drill down to
lower levels, an application or application process. The main areas of the
cockpit screen are outlined below, showing the object area (upper left), the
navigation options (lower left), and the content area (on the right), which in
this example consists of just one panel (Applications):
Each level determines
which navigation options are available and the information that is displayed.
You can navigate upwards in the hierarchy using the links in the object area
and switch to other objects by clicking the triangular selector, as shown in
the example below:Auto Refresh
By default, auto
refresh is deactivated. You can trigger the auto-refresh function using the Auto-Refresh button located above a panel. Note that auto
refresh is only available for panels that may occasionally require automatic
updates to track progress or see trends, while other panels allow manual
refresh or do not have a refresh function at all. Auto refresh, when activated,
runs for a maximum of 30 minutes. Certain actions also trigger auto refresh, such
as when you start or stop an application
Logging in Applications
Overview
If you want to have
logs produced at runtime, which you can use for analysis and troubleshooting,
you have to use a logging API in your SAP HANA Cloud application.
For SAP HANA Cloud applications, we recommend that you use the
Simple Logging Facade for Java (SLF4J). The API is built upon using Logger
class. All logs are put in the default trace file of the server and are
visualized at runtime in the Cockpit.
Prerequisites
You have created an
application for SAP HANA Cloud.
For more information,
see Creating a HelloWorld Application.
Implementing the SLF4J API in your application
Follow the guidelines
in the SLF4J User Manual.
SAP HANA Cloud
applications can access SLF4J API directly without adding any references or
packaging the library in the application archive.
Example
You can add an error
log in your application with the following code:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class YourClass {
public static void
main(String[] args){
Logger logger =
LoggerFactory.getLogger(YourClass.class);
logger.error("message");
}
}
To construct a
parameterized message, you can use one of the following ways:
You also need to add a
log level check here - this will help you avoid creating too many String
objects which could lead to performance issues of your application.
if (logger.isInfoEnabled()) {
logger.info("Message logged for name " + name + " with
level info");
}
logger.info("Message logged for name {} with level
info", name);
For more tips and
tricks, check the SLF4J FAQ.
Log severity mapping
SLF4J uses the
following log severity levels:
SLF4J
Description
DEBUG
This level designates fine-grained informational events that
are most useful to debug an application.
INFO
This level designates informational messages that highlight
the progress of the application at coarse-grained level.
WARN
This level designates potentially harmful situations.
ERROR
This level designates error events that might still allow the
application to continue running.
Deploying Applications
After you have created
your application, you need to deploy and run it on SAP HANA Cloud. We recommend that you first deploy and test
your application on the local runtime before deploying it on the cloud.
Applications can be
deployed on the production landscape or the trial landscape depending on your
account type.
Eclipse IDE
If you have developed
your application using the Eclipse IDE and SAP HANA Cloud Tools, you can deploy
the application from inside the Eclipse IDE.
Deploying Locally from
Eclipse IDE
Deploying on the Cloud
from Eclipse IDE
SAP HANA Cloud console client
If you want to deploy
existing or developed with another development environment applications, use SAP HANA Cloud console client. With this tool, you can
deploy applications in the form of WAR files.
Deploying Locally with
the Console Client
Deploying on the Cloud
with the Console Client
SAP HANA Cloud Cockpit
Overview
The cockpit is the
central point for managing all activities associated with your account and for
accessing key information about your applications. It allows you to manage all
applications deployed in your account from a single dedicated user interface. You
retain an overview of the current status of the individual applications and the
overall application deployment status in your account, while at the same time
being able to drill down quickly to review logging and monitoring information
and initiate actions at application and process level.
Accounts
The cockpit provides
integrated access to all accounts you operate on the production landscape, hana.ondemand.com. Bear in mind that the accounts are totally
independent of each other.
A separate cockpit for
developer accounts is available on the trial landscape, hanatrial.ondemand.com.
Login
You can log into the
cockpit from the landing page, which is available at the following URLs: - Obtain a mail session resource using resource injection