Part 1: OSLC CM with Jena Framework

Creation Date: 19.05.2012

Revised: 0.1

Version: 1

Autor: PH and StH


In the following steps we will look at the details “how to access work items with the help of Jena over the OSLC interface”. If your are unfumiliar with OSLC and RTC please look at

and Also the following document gives you an overview how RTC use RDF:

In Part1 we will see how to access the root services document with the help of Jena (create a Model/Graph, print the Model with a N3 notation).

1. Jena

Jena was invented  by HP and at the end it became Open Source. The reason for using Jena is simple…RTC use it internally.

Jena help you with the following common tasks:

  • read/write RDF documents
  • parse/navigate RDF Graph (Model)
  • query with SPARQL
  • OWL inference

Alternative you can use Sesame at

2. Using Jena with Eclipse

It is not necessary to download Jena when you installed the RTC SDK, because Jena is included inside the SDK.

Include the following Jar in your Eclipse classpath

3.Get the OSLC Examples

Download the OSLC Examples from

3. Access the root service document

Change the from the OSLC Workshop and insert:

 * Licensed Materials - Property of IBM
 * (c) Copyright IBM Corporation 2010, 2011. All Rights Reserved.
 * Note to U.S. Government Users Restricted Rights:  Use,
 * duplication or disclosure restricted by GSA ADP Schedule
 * Contract with IBM Corp.
package net.jazz.oslc.consumer.examples;


import net.jazz.oslc.utils.HttpUtils;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.NodeIterator;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.ResIterator;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.StmtIterator;

 * This first example describes how to access to the Root Services document
 * (https://localhost:9443/jazz/rootservices) using the Apache HttpClient APIs
 * A Jazz Team server must be started.
public class Example01 {

	public static void main(String[] args) {
		//============== Code to adapt to your own configuration =============//
		String server = "https://localhost:9443/ccm";		// Set the Public URI of your RTC server
		//============== -------------------------------------- =============//

		String rootServices = server + "/rootservices";
		System.out.println(">> Example01: Accessing Root Services document with HttpClient");
		System.out.println("	- Root Services URI: "+rootServices);

		// Setup the HttpClient
		HttpClient httpclient = new DefaultHttpClient();

		// Disabling SSL Certificate Validation

		// Setup the HTTP GET method
		HttpGet rootServiceDoc = new HttpGet(rootServices);
		rootServiceDoc.addHeader("Accept", "application/rdf+xml");
		rootServiceDoc.addHeader("OSLC-Core-Version", "2.0");

		HttpResponse response;
		try {
			// Execute the request
			response = httpclient.execute(rootServiceDoc);
			System.out.println(">> HTTP Status code:" + response.getStatusLine());

			if (response.getStatusLine().getStatusCode() == 200) {
				System.out.println(">> HTTP Response Headers: ");

				System.out.println(">> HTTP Response Body: ");

				HttpEntity entity = response.getEntity();
				if (entity == null) return;
				BufferedReader reader;
				try {
					//get the rootservice document
					reader = new BufferedReader(new InputStreamReader(entity.getContent()));

					//create Jena Model/Graph
					Model model = ModelFactory.createDefaultModel();, "https://localhost:9443/ccm");
					//Print RDF as N3
					//model.write(System.out, "N3");

					//model.setNsPrefix("oslc_cm", "");
					//NodeIterator objects2 = model.listObjectsOfProperty(model.createProperty(""));

					StmtIterator statements = model.listStatements((Resource)null,  model.createProperty(""), (RDFNode)null );

					//Get workitem catalog
						RDFNode object =;

				} catch (IllegalStateException e) {
				} catch (IOException e) {
			} else {
				// Release allocated resources
		} catch (ClientProtocolException e) {
		} catch (IOException e) {
		} finally {
			// Shutdown the HTTP connection


Useful links:
Introduction to Jena

, , , ,

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: