In Part 1 I showed how to set up the CDT environment in RTC 3.0.1. If you haven't gone through the steps in Part 1 you should do so before doing this part. You should be able to build simple code now.
In this part you will import an OSLC client written in C++ (see my post on OSLC). In order to do so we need to introduce some libraries into our environment to be able to make HTTP requests (libcurl) and parse the returning XML (libxml2).
You'll need the following:
(Latest as of publishing)
1. libcurl: curl-7.21.7-devel-mingw32.zip 2. libxml2: libxml2-2.7.8.win32.zip
3. libiconv: iconv-1.9.2.win32.zip
4. RTC OSLC C++ Project: OSLC Consumer.zip
Configure and Install:
1. First lets download some dependencies into prep our MinGW environment. Open up a command prompt and type the following commands:
mingw-get install zlib
mingw-get install libiconv
2. Unzip the curl-7.21.7-devel-mingw32.zip. Ensure that the contents of bin,include,lib, etc. are extracted into the corresponding directories in the MinGW home (usually C:\MinGW)mingw-get install libiconv
3. Now unzip the libxml2-2.7.8.win32.zip. Again, Ensure that the contents of bin,include,lib, etc. are extracted into the corresponding directories in the MinGW home (usually C:\MinGW).
As libxml2 is a generic win32 package, we need to prep it from MinGW. Open a command prompt and type:
cd C:\mingw\bin (or wherever you MinGW home is)
pexports libxml2.dll > libxml2.def
dlltool --dllname libxml2.dll --def libxml2.def --output-lib ../lib/libxml2.a
pexports libxml2.dll > libxml2.def
dlltool --dllname libxml2.dll --def libxml2.def --output-lib ../lib/libxml2.a
5. Now we are going to import the sample project into RTC.
-Launch RTC Client
-File->Import
-General->Existing Projects Into Workspace
-Click Next
-Select Archive File: Browse for the OSLC Consumer.zip file downloaded earlier
-Click Finish
You can to build and run the project at this point by right clicking on the newly imported project and selecting "Build Project". It should build without errors or warnings. Unless you have exactly the same host,port,username and password you will get some kind of connect error if you try to run it using the run button (

If you take a look at the source code the first thing you will notice is that this is neither proper C nor C++ code. As this is just a code sample to convey the general idea, it was written up in a very simple linear fashion with no classes or many parameters.
In order for the code to connect to your Jazz Server you will need to change the hostname, port and username/password in the OSLCPAFetch.h file.
const std::string server = "https://localhost:9443/ccm"; <-your Jazz server
const std::string login = "username"; <-your user name
const std::string password = "password"; <- your password
This code demonstrates a few things:
1. A set up build environment that has extra libraries (take a look at the project properties for the linking, C/C++ Build->Settings->MinGW C++ Linker->General)
2. How to create OSLC requests (note the header parsing).
3. How to do form based authentication with Jazz
4. How to fetch Project areas using the xml2 XPath functionality.
If you need to have more in depth information about how this code functionality works I suggest to take a look at the OSLC workshop as this code sample is loosely based on it. Enjoy!
Next up (part 3)... creating an automated build environment for our new code using RTC SCM and automated builds!
Boris, could you please put a license on your code (preferably MIT or EDL), please?
ReplyDelete