Archive for April, 2012

REST Services in GateIn / eXoPlatform : add your own !

Mulitple REST services are available out of the box in GateIn / eXoPlatform. They allow to easily interact with the platform’s features and data.

Here we will see how to quickly add your own REST services (valid for eXoPlatform 3.0 or 3.5).

Java REST class

Firstly, we create the Java class which will expose the REST service :

package org.exoplatform.samples.rest;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;

import org.exoplatform.services.rest.resource.ResourceContainer;

@Path("/user/")
public class MyRESTService implements ResourceContainer {

    @Path("/name/{name}/")
    @GET
    public Response getName(@PathParam("name") String name) throws Exception {
        return Response.ok("Hello " + name + " !").build();
    }

}

As you can see, this class uses standard JAX-RS annotations to expose its services (javax.ws.rs.*). The only thing to add is the org.exoplatform.services.rest.resource.ResourceContainer interface. This interface is a marker to define this class as a REST services class.

If you use Maven, the org.exoplatform.services.rest.resource.ResourceContainer class is available with the following dependency :

<dependency>
  <groupId>org.exoplatform.ws</groupId>
  <artifactId>exo.ws.rest.core</artifactId>
  <version>2.2.6-GA</version>
  <scope>provided</scope>
</dependency>

Adjust the dependency version according to your Gatein / eXoPlatform version.

Declare your REST service

The second and last thing to do is to declare the REST service. To achieve this, declare your class in the GateIn / eXoPlatform configuration :

<component>
  <type>org.exoplatform.samples.rest.MyRESTService</type>
</component>

This configuration can be put either in the jar containing the java class (in conf/portal/configuration.xml), or in an extension, or even in the external configuration.

Now you just have to deploy your class and your configuration (for example, put the jar containing the class and the configuration in the tomcat’s libs), and restart the server.
Your service is now available at http://<host&gt;:<port>/portal/rest/user/name/<yourname> :

Up to you now to implement your custom REST service !

Advertisements

2 Comments

Remove the Categories’ items from the menu in WordPress

By default, WordPress displays the categories in the menu bar. If you don’t want them, you can’t just remove all the categories. At least one category should be present. And a post has to be categorized.

The solution is to hide the categories’ items of the menu bar with the following steps :

  • go to your WordPress dashboard
  • in the left menu, go to Appearance> Theme Options
  • expand the Navigation panel
  • check Hide all categories
  • save changes

Now your categories does not appear anymore in the menu.

Leave a comment

Request parameters from a portlet in eXo/GateIn

Portlet specs does not provide a standard way to read a parameter from the request within a portlet, for example to get the myparameter parameter in http://localhost/portal?myparameter=myvalue.

request.getParameter() within a portlet does not help since the request object is a PortletRequest, not the HttpRequest.

An easy solution in eXo/GateIn is to use the getRealRequest method of the concrete implementation of PortletRequest of GateIn. So, in order to retrieve the myparameter param from the request in the render phase, you can do :

((org.gatein.pc.portlet.impl.jsr168.api.RenderRequestImpl) request).getRealRequest().getParameter("myparameter")

, ,

2 Comments