DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Building REST API Backend Easily With Ballerina Language
  • Reactive Elasticsearch With Quarkus
  • How To REST With Rails and ActiveResource: Part Three
  • Spring Boot - How To Use Native SQL Queries | Restful Web Services

Trending

  • Event-Driven Architectures: Designing Scalable and Resilient Cloud Solutions
  • The Human Side of Logs: What Unstructured Data Is Trying to Tell You
  • Automating Data Pipelines: Generating PySpark and SQL Jobs With LLMs in Cloudera
  • The Cypress Edge: Next-Level Testing Strategies for React Developers
  1. DZone
  2. Data Engineering
  3. Databases
  4. Hybris Multi-Tenant System Using REST Webservices

Hybris Multi-Tenant System Using REST Webservices

Take a look at this is about the Integration of Hybris multi tenant with REST API.

By 
Chaitanya Kapure user avatar
Chaitanya Kapure
·
Updated May. 28, 20 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
16.7K Views

Join the DZone community and get the full member experience.

Join For Free

Introduction

The purpose of this document is to demonstrate how to achieve multitenancy using web services. Before starting, we need to understand the basic concept of the multi-tenant system in SAP Hybris and REST web services.

Multi-tenancy means an individual set of data across one database. The Hybris e-commerce suite provides one single codebase that can be run over multiple set of data. A multi-tenant system:  

  1. Provides isolation between a set of data (tenant).
  2. Provides the option of using separate databases.
  3. Provides individual time zone and locale settings.

 

Single tenant vs. multi tenantIn a multi-tenant architecture, multiple instances of an application operate in a shared environment. This architecture is able to work because each tenant is integrated physically, but logically separated; meaning that a single instance of the software will run on one server and then serve multiple tenants. In this way, a software application in a multi-tenant architecture can share a dedicated instance of configurations, data, user management, and other properties.

Multi-tenancy applications can share the same users, displays, rules although users can customize these to an extent and database schemas, which tenants can also customize.

Types of Multi-Tenant Architecture

There are three main multi-tenancy model types, all with varying levels of complexity and costs. A single, shared database schema is a multi-tenancy model with a multi-tenant database. This is the simplest form out of the three and is a relatively low cost for tenants because of the use of shared resources. This form uses a single application and database instance to host tenants and store data. Using a single, shared database schema allows for easier scaling; however, operational costs can be higher.

Multi tenant with REST call

REST Web Services

Hybris provides a great way to expose all of its functionality via web services, We can provide all the data available in the Hybris database (products, promotions, vouchers, wish list) to third-party applications which are not built using Hybris.

Some web services are exposed via HTTP and 9001 ports, whereas others, where Spring security is applied, are exposed via HTTPS and 9002 port.

Most of the features are provided by Hybris Out-Of-The-Box (OOTB). In the case of customization, we only have to fetch data either by Flexible Search Query or from services, add them to a list, and return the list to the calling application. Everything else will be taken care of by Hybris automatically.

Follow these steps to configure the new tenant with web service extension:

  1. You will need to add the new tenant, that we'll call “mytenant,” to the list of installed tenants in your local properties file.

Like this:

             installed.tenants=mytenant 

Use this property for mytenant working with other slave tenants:

             installed.tenants=mytenant, junit 

 

2. We need to create a new module inside the custom module, and under that, you can create new extensions such as “mytenantwebservices” for managing web services for new tenant using ywebservice or ycommercewebservice template. After creation, you need to add this extension to your localextensions.xml file like this:

 <extension dir="${HYBRIS_BIN_DIR}/custom/mytenant/mytenantwebservices" /> 


3. Hybris allows us to have different “.properties” file to each slave tenant. You don't necessarily need to have them in order to install a slave tenant. But in our case, we have to override some properties from the master tenant. Every property that is not present on slave tenant’s “.properties” file will inherit the values from the master tenant. So create a file named local_tenant_mytenant.properties inside your Hybris config folder.

Put these properties inside it:

Properties files
 




xxxxxxxxxx
1
81


 
1
task.engine.loadonstartup=true
2

          
3
# Add your Database details
4

          
5
db.url=jdbc:sqlserver://localhost:1433;databaseName=mytenant;responseBuffering=adaptive;loginTimeout=10
6

          
7
db.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
8

          
9
db.username=hybris
10

          
11
db.password=newPassword
12

          
13
db.tableprefix=es_
14

          
15
mysql.optional.tabledefs=CHARSET=utf8 COLLATE=utf8_bin
16

          
17
mysql.tabletype=InnoDB
18

          
19
 
20

          
21
hmc.webroot=/hmc_mytenant
22

          
23
hac.webroot=/hac_mytenant
24

          
25
 
26

          
27
platformwebservices.webroot=/ws410_mytenant
28

          
29
oauth2.webroot=/authorizationserver_mytenant
30

          
31
mytenantwebservices.rootcontext=/mytenantwebservices
32

          
33
 
34

          
35
solrserver.instances.default.autostart=true
36

          
37
hmc.language=en
38

          
39
cockpit.default.useTestIds=true
40

          
41
cmscockpit.default.login=cmsmanager
42

          
43
cmscockpit.default.password=1234
44

          
45
 
46

          
47
productcockpit.default.login=productmanager
48

          
49
productcockpit.default.password=1234
50

          
51
 
52

          
53
hmc.default.login=admin
54

          
55
hmc.default.password=nimda
56

          
57
 
58

          
59
commerceservices.orderCode.keyGenerator=orderCodeGenerator
60

          
61
 
62

          
63
// you can add extensions from master tenant in below property
64

          
65
forbidden.extensions= 
66

          
67
 
68

          
69
# Added New for Tenant switch and accessing web context
70

          
71
mytenantwebservices.webroot=/mytenant
72

          
73
 
74

          
75
cache.shared=true
76

          
77
 
78

          
79
core.application-context=core-spring.xml,core-media-spring.xml,persistence-spring.xml,core-profiling-spring.xml,core-jmx-spring.xml,core-filter-spring.xml,servicelayer-spring.xml,user-spring.xml,security-spring.xml,media-spring.xml,i18n-spring.xml,interceptor-spring.xml,event-spring.xml
80

          
81
processing.application-context=processing-spring.xml,cronjob-spring.xml,task-spring.xml,processengine-spring.xml,processing-jmx-spring.xml,processing-distributed-spring.xml



Make the modifications to the properties related to database connectivity according to your local database. As mentioned above property create database mytenant. You can have any name to database but make sure it is correctly mentioned in above tenant properties.

4. Go to the extensioninfo.xml file of the newly created extension -> mytenantwebservices.

Here this line is very important:

<webmodule jspcompile="false" webroot="/mytenantwebservices"/> 

You will be calling your web services with the root as /mytenantwebservices. Here you can give any name you want to give but you need to use the same name mentioned in this file for calling your web services.

5. For testing your setup: 

  1. Compile your code (ant clean all) and start hybris server.
  2. Once it's up. In master tenant, go to /hac → platform tab → tenants. 
  3. You should see your “mytenant” tenant within the tenants list.
  4. Click on the activate button. 
  5. Check if you were redirected to your tenant /hac endpoint. In our case "hac_mytenant"
  6. Go to platform → initialization. 
  7. Check on the project list if you have only the needed extensions within this list. Other master tenant’s extensions should not be present here.
  8. Click to initialize.
  9. If the initialization is finished with success you should be able to start using your new mytenant tenant. 

6. Time to check the sample webservice:

Now open Rest-Client and execute the following sample webservice request to retrieves all user from Hybris.

 The URL is found here. http://localhost:9001/mytenant/mytenantwebservices/sample/users

Method: GET

You can able see the response in the body of the REST client.

Note: If you don’t want to customize webservice and use the default webservices provided use /rest instead of your custom name /mytenantwebservice.

Example:

URL - http://localhost:9001/mytenant/rest/sample/users

References

  • https://help.sap.com/viewer/d0224eca81e249cb821f2cdf45a82ace/1905/en-US/8c14e7ae866910148e59ebf4a2685857.html?q=Multi%20tenant
  • https://www.guru99.com/restful-web-services.html
REST Web Protocols Hybris (software) Web Service Database Property (programming) application

Opinions expressed by DZone contributors are their own.

Related

  • Building REST API Backend Easily With Ballerina Language
  • Reactive Elasticsearch With Quarkus
  • How To REST With Rails and ActiveResource: Part Three
  • Spring Boot - How To Use Native SQL Queries | Restful Web Services

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: