Using Clockwork with Codenvy

Use Codenvy Factory to instantly start working with a sample Clockwork API project:

This tutorial will explain the details of integrating the Clockwork API into Codenvy. Clockwork API provides your application the ability to send SMS to any numbers. The explanation has been done with a very basic Java servlet project that makes use of the Clockwork API to explain some basic features provided by the API.

Register With Clockwork

Before proceeding to the creation of the Java project, please register at with your email id and a mobile number that will receive a activation code to generate the API key which will be used for the integration:

On registering the application, you can see your keys at

You can get more information about the Clockwork API at

Create a Project

Now, login to your Codenvy workspace and create a WAR project named as ‘ClockworkSample’. This will have the following structure:

Create pom.xml File

To make use of the Clockwork API through HttpClient as a servlet, please update the pom.xml to include the HttpClient and Java EE Web API jars and the servletapi jar into your project as Maven dependencies:

      <name>Maven Repository Switchboard</name>

This will include these jars in your project as follows:

Create Java Class

Now create a Java servlet class named that will talk to the Clockwork API with the Http request URL to send a SMS to a number and then get a Http response back with the response header and the response body which will be then displayed on the browser through a JSP. The response body will contain the message Id if the delivery has been successful. All this is done inside the method doGet() in the sample source Java class.

   protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

        StringBuffer sb = null;
        try {
            String getURL = "";

            HttpGet req = new HttpGet(getURL);
            req.addHeader("X-Originating-Ip", "");
            HttpResponse res = client.execute(req);
            HttpEntity entity = res.getEntity();
            String responseString = new BasicResponseHandler().handleResponse(res);
            if (entity != null) {

            sb = new StringBuffer("<br/>Simple GET request to url : "+ getURL +"<br/><br/>");
            sb.append("*** Request headers ***").append("<br/>");
            Header[] requestHeaders = req.getAllHeaders();
            for (Header header : requestHeaders) {

            sb.append("*** Response headers ***").append("<br/>");
            Header[] headers = res.getAllHeaders();
            for (Header header : headers) {

            sb.append("*** Response Body ***").append("<br/>");

        } catch (Exception ex) {
            sb = new StringBuffer(ex.toString());

        request.setAttribute("data", sb.toString());
        RequestDispatcher rd = request.getRequestDispatcher("/success.jsp");
        rd.forward(request, response);

Create index.jsp File

Your Codenvy project will have an index.jsp which will invoke the Servlet class -


Create success.jsp File

Your Codenvy project will have a success.jsp which will be invoked from the ClockworkServlet class to display the response on the browser -

      <p>Data : <br/><%=request.getAttribute("data") %></p>

Create web.xml File

The servlet mapping ‘/hello’ is defined in the web.xml as follows –

  <display-name>Clockwork Servlet App</display-name>


Now you build and run your Codenvy project and the Http response with the message Id will be displayed in the browser: