The power of OData – Part 2 – Setting up the Environment
Content of this series:
The power of OData – Part 2 – Setting up the Environment (this part)
As already mentioned in the first part of this series (The power of OData – Part 1 – Introduction) I’d like to write about the usage of custom OData producers that can be combined with SAP Netweaver Gateway services or Sharepoint services to create even richer and better applications.
This post will deal with the initial setup of a development environment for developing own producers and services.As I wrote in another post about AIE (Trying new features and versions in Eclipse), I’m a fan of Eclipse. Therefore, I will use this as my basic IDE here to setup the needed tools. This also has the side-effect that I have all of my development tools in just one single IDE, as said within the mentioned blog post. You can for sure use other IDEs like Netbeans or just a plain text editor. So in the next lines, I will talk about choosing the needed Eclipse plugins, setting up a local web and database server and installing the OData producer SDK.
For this development example, I choose to use PHP. This is not a must; there exist SDK versions for Java, Python or .NET as well, but I feel that many organizations have their custom development, their web applications or services done in PHP in combination with MySQL.
Setting up a local webserver
My webserver of choice for local development is XAMPP available from ApacheFriends (https://www.apachefriends.org/de/index.html). The main advantage is that it comes with a ready to use Apache installation that includes the newest PHP, MySQL as well as Perl, FileZilla, Mercury and Tomcat, if anyone needs this, so that Java development and hosting would be possible. Another advantage is that this package is available for all major operating systems: Windows, Linux and OS X. As I use OS X at home, this enables me to develop wherever I am with the same solution.
The installation process is straight forward. After a successful installation, a control center is available that lets us start and stop the individual services as well as access the config files with one click:
If we navigate to localhost using our favorite browser, we should see the XAMPP start page, after we started the Apache service.
From this site, we can access PHP info, phpmyadmin for managing MySQL or J2EE specific things:
Lucky for us, XAMPP comes with a user-friendly configuration, so that not much has to be changed. There is one line that has to be added in Apache’s configuration, what will be shown in the next topic.
Installing the SDK
The OData Producer Library for PHP is available as an open source library from GitHub: https://github.com/MSOpenTech/odataphpprod
After downloading the contents of the package should be extracted to a newly created directory within the “htdocs” folder under the XAMPP installation directory, which normally is C:\xampp \htdocs\ (for Windows users).
For this test, I created a folder “customer_api” and placed the OData producer files in this location:
Now, your service root is accessible through a browser by calling the URL http://localhost/customer_api
Let’s look at the content.
We don’t actually need Docs and Tests here, so we can get rid of them. Web.config can be deleted as well, as this is specific for Microsofts IIS and we are using Apache here.
Finally, we have library and services. Within the library folder are the sources that create the services and provide the output we consume later on. Within services are the main services stored, that can be accessed. Index.php and Dispatcher.php are used to redirect request to the specific services. More about creating and routing services will come in the development part of this series.
There is one last thing we need here. As I wrote, Index.php and Dispatcher.php should redirect the requests. So we have to rewrite the requests by using Apache’s mod_rewrite module. To activate this module, we have to edit http.conf.
Open this file within your favorite text edit and search for this line:
#LoadModule rewrite_module modules/mod_rewrite.so
Remove the leading “#” to uncomment the line, save the config file and restart Apache.
Within the folder you created above, create a new file called “.htaccess”. This file will control access to the folder and will redirect every request that calls a <service.svc> to our Index.php that will handle the request.
Open the file in a text editor and insert the following content:
<IfModule mod_rewrite.c> RewriteEngine on RewriteRule (\.svc*) /customer_api/Index.php </IfModule> php_value include_path ".;C:\xampp\htdocs\customer_api\library"
This simply redirects all requests ending in .svc to Index.php.
The last line will define an include_path only relevant for the current application. As we don’t need it elsewhere, you can insert it in this .htaccess file without the need of editing your php.ini, as I suggested in the previous version of this post. If you then go to http://localhost/customer_api, you should see a string saying “No configuration info found for”
I’ve also added my service.config.xml as there seems to be some problems with this.
Let’s move on to Eclipse to complete the environmental setup.
Installing Eclipse plugins
Whenever I start setting up my environment, I download a new basic Eclipse instance. I would recommend getting the newest Java EE edition from their download page: http://www.eclipse.org/downloads/
In my case, this would be the following version:
Next would be the decision what languages we need and what we want to develop.
For this series, we will be developing PHP applications as well as UI5 applications. It might be worth thinking about integrating the ABAP development tools within our installation so that we have one single application ready for accessing different systems.
The update sites for SAP tools (ABAP dev tools and UI5 tools) is the following: https://tools.hana.ondemand.com/kepler
The site for Juno can be found at https://tools.hana.ondemand.com
From the options screen, choose these packages:
- ABAP Development Tools for SAP NetWeaver
- UI Development Toolkit for HTML5
PHP related plugins and add-ons can be found here http://p2-dev.pdt-extensions.org/ what also is the URL to be used as update site in Eclipse. Here, I would recommend installing the following:
- PDT Extensions
- PHP Development Tools (PDT)
The other plugins aren’t needed for this series, but may be worth some try, depending on the amount of PHP development that is done.
After the installation and restart of Eclipse, let’s import our OData project as a last step. Go to “FileàNewàProject” and choose “PHP Project”
On the next screen, enter a project name and choose “Create project at existing location (from existing source)”. Enter here the path to the created folder in htdocs.
Now click finish and your project is created. If you haven’t done yet, it is time to add the .htaccess file now. I think that Eclipse is better for editing this than a normal text editor.
Continue to read the next part about creating the data model and some sample data for the service: The power of OData – Part 3 – Creating a data Model