Skip to main content
Jump to: navigation, search


< Lyo
Revision as of 10:09, 28 September 2012 by (Talk | contribs) (Getting started with OSLC4J)


What is OSLC4J?

OSLC4J is a Java toolkit for building Open Services for Lifecycle Collaboration providers and consumers. It includes:

  • annotations to decorate Java objects with OSLC attributes
  • annotations to assist with resource preview UIs (compact rendering)
  • built-in support for service provider and resource shape documents
  • libraries to simplify service provider and consumer development
  • sample applications, including an OSLC Registry (catalog) application and a Change Management provider implementation
  • Tests for the sample applications to complement the Lyo OSLC Test Suite


  • OSLC4J - The core component providing OSLC annotation and model support (org.eclipse.lyo.oslc4j.core / oslc4j-core)
  • Apache Jena Provider - A library to assist with serialization/de-serialization of OSLC-annotated Java objects to/from RDF XML (org.eclipse.lyo.oslc4j.core / oslc4j-jena-provider).
  • Apache Wink Json4J Provider - A library to assist with serialization/de-serialization of OSLC-annotated Java objects to/from JSON (org.eclipse.lyo.oslc4j.core / oslc4j-json4j-provider).
  • Apache Wink JAX-RS Provider - Utility classes, including an OSLC REST Client, to facilitate development using the Apache Wink JAX-RS implementation.

The Apache Jena[1] and Apache Wink[2] components are the built-in providers for RDF, RDF XML, JSON and JAX-RS. Additional providers could be implemented using technologies such as OpenRDF and Jersey.

Sample code

Annotation sample

    //sample simple string attribute (dcterms:description, as in
    @OslcDescription("Descriptive text (reference: Dublin Core) about resource represented as rich text in XHTML content.")
    @OslcPropertyDefinition(OslcConstants.DCTERMS_NAMESPACE + "description")
    public String getDescription()
        return description;
    //sample relationship attribute (oslc_cm:affectsTestResult, as in
    @OslcDescription("Associated QM resource that is affected by this Change Request.")
    @OslcPropertyDefinition(Constants.CHANGE_MANAGEMENT_NAMESPACE + "affectsTestResult")
    @OslcTitle("Affects Test Results")
    public URI[] getAffectsTestResults()
        return affectsTestResults.toArray(new URI[affectsTestResults.size()]);

JAX-RS method sample

This illustrates implementation of an OSLC-CM (REST) server/provider

    //support GET for a specific OSLC ChangeRequest
    @Produces({OslcMediaType.APPLICATION_RDF_XML, OslcMediaType.APPLICATION_XML, OslcMediaType.APPLICATION_JSON})
    public ChangeRequest getChangeRequest(@Context                      final HttpServletResponse httpServletResponse,
                                          @PathParam("changeRequestId") final String              changeRequestId)
        final ChangeRequest changeRequest = Persistence.getChangeRequest(changeRequestId);
        if (changeRequest != null)
            setETagHeader(getETagFromChangeRequest(changeRequest), httpServletResponse);
            return changeRequest;
        throw new WebApplicationException(Status.NOT_FOUND);
    //support POST to create a new ChangeRequest
    @Consumes({OslcMediaType.APPLICATION_RDF_XML, OslcMediaType.APPLICATION_XML, OslcMediaType.APPLICATION_JSON})
    @Produces({OslcMediaType.APPLICATION_RDF_XML, OslcMediaType.APPLICATION_XML, OslcMediaType.APPLICATION_JSON})
    public Response addChangeRequest(@Context final HttpServletRequest  httpServletRequest,
    		                         @Context final HttpServletResponse httpServletResponse,
                                              final ChangeRequest       changeRequest)
           throws URISyntaxException
        final long identifier = Persistence.getNextIdentifier();
        final URI about = new URI(httpServletRequest.getScheme(),
                                  httpServletRequest.getContextPath() + "/changeRequests/" + identifier,
        final Date date = new Date();
        setETagHeader(getETagFromChangeRequest(changeRequest), httpServletResponse);
        return Response.created(about).entity(changeRequest).build();

Getting started with OSLC4J

See also

Cite error: <ref> tags exist, but no <references/> tag was found

Back to the top