30
Oct

The OSGI world of REST

Today, I’m speaking at EclipseConn in Germany about the OSGI world of REST.
For reference I’m pasting here the link to both the presentation and the code:

 

  1. Presentation link
  2. Sample code
16
Jul

Using Apache Sling with Jackson to output JSON/XML

Writing JSON using Sling’s built-in API is fun and fast, however there are alternatives that can make the coding smoother.

One interesting alternative is to use Jackson ( https://github.com/FasterXML ) libs.

First step is to install the following Jackson bundles into Sling ( v. 2.2.2 is the latest version at the time this tutorial has been written ):

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.2.2</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-annotations</artifactId>
    <version>2.2.2</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.2.2</version>
</dependency>

Then, to test the integration you can create 2 classes: a POJO and a Servlet exposing the POJO:

@XmlRootElement
public class User
{
    private String name = "hello jackson";
 
    public String getName()
    {
        return test;
    }
 
    public void setName(String test)
    {
        this.test = test;
    }
}

And the Apache Sling Servlet:

@Component
@Service(Servlet.class)
@Properties({ @Property(name="service.description", value="Jackson Test Servlet"),
    @Property(name="sling.servlet.paths", value="/bin/jackson-test")
})
public class TestJacksonOutputServlet  extends SlingSafeMethodsServlet
{
    @Override
    protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
            throws ServletException, IOException
    {
        User user = new User();
        ObjectMapper mapper = new ObjectMapper();
        String jsonOutput = mapper.writeValueAsString(user);
 
        response.getWriter().write(jsonOutput);
    }
}

That’s it and it’s really simple.

14
Jul

How to build a Flex Mobile App with Maven

Building applications that run on mobile is today’s trend. Everybody is thinking mobile and social and cloud.

To build a Flex application for Mobile is very easy, provided you use Flash Builder. When it comes to automating that build, things are not as easy. Because recently I’ve managed to overcome the obstacles that were preventing me to build a running Flex 4.5 app for mobile, I want to share the build.

I’ve taken the initial build from this thread. Marvin Froeder ( a.k.a VELO ) has been doing some hard work recently, creating the Enterprise version of Flex Mojos. This version seems pretty promising. I’m looking forward for its release. When you’re testing the build, make sure you register during the build, following the instructions. The process is fairly easy, but … rewarding. The maven build creates the final apk/air/exe/dmg…, which you can use to install the app on your device. It’s worth trying it.

To build the app, you need to execute

mvn3 clean install package

Prior to the build, you need to make sure you have Maven 3 installed, with the following environment variable:

MAVEN_OPTS="-Xmx1024m -Xms128m -XX:+DisableAttachMechanism"

Also, you need to have the mobile theme installed in a repository. As of today, the flex mojos repository doesn’t contain this theme, so you need to install it manually.

When the build ends, connect your device to the computer and execute:

adb install -r ./target/mobile-1.0-SNAPSHOT.apk

Then, go to your device and open “main” application.

If you see the following screen, it means that the application got compiled successfully.

Maven Mobile Screenshot

Screenshot showing the app built with Maven