Thursday May 10, 2007

Howto win a Helicopter

How to win a helicopter @ JavaONE

BT had a booth at JavaONE for their Web21C SDK.  The SDK, among other things, allows you to write software that invokes a WebService hosted by BT to place a phone call between 2 parties.  You simply need to provide 2 phone numbers and BT calls both parties and connects the two.  They provide a limited amount of usage for free, and for a small fee you can use their service more, here's a link to their pricing.  The Web21C SDK opens up the door to many possibilities, however, that's outside the scope of this blog.

BT was offering a challenge at their booth: Use their SDK to place a phone call and win a remote controlled helicopter.  My son is 5 and would love to crash the helicopter, and it sounded like any easy task for GlassFish + JSFTemplating... so I got to work!

Here's what I had to do:

1) I started with the JSFTemplating demo application. (Note: I used the version from CVS so that I would already have a build environment setup which uses APT.)

2) I added the Web21C jar files to my WEB-INF/lib directory of the demo app.  They gave me a memory stick with these, but I think you can find them here.

3) I had problems w/ some of their jar files because many of them are already part of GlassFish and were not needed.  Also some of the versions may not have been compatible.  I ended up turning off classloader delegation by adding this to my sun-web.xml file:

  <class-loader delegate="false"/>

4) I registered my application.  BT requires you to register your application.  This was a necessary, but the most painful part of the process.  It required me to download the Web21C-Certificate-Tool, patch the JDK with the unlimited strength policy files, run their certificate tool, place the generated file in the WEB-INF/classes directory of the demo app, and create / place a security.properties file in the WEB-INF/classes directory that pointed to the generated file.

5) With the environment finally setup, I was ready to write the app!  I created the following JSFTemplating page:


call.jsf

<sun:page>
<sun:html>
<sun:head />
<sun:body>
<sun:form>
<sun:messageGroup />
<sun:propertySheet>
<sun:propertySheetSection label="Web21 Phone Dialer">
<sun:property>
<sun:textField required="true" label="Call From:" value="#{requestScope.from}" />
</sun:property>
<sun:property>
<sun:textField required="true" label="Call To:" value="#{requestScope.to}" />
</sun:property>
<sun:property>
<sun:button text="Make Call">
<!command
Web21.call(from="#{requestScope.from}", to="#{requestScope.to}");
navigate("calling.jsf");
/>
</sun:button>
</sun:property>
</sun:propertySheetSection>
</sun:propertySheet>
</sun:form>
</sun:body>
</sun:html>
</sun:page>



6) I created the following handler in a new java file called Web21Handlers.java (see above call.jsf page where the button is invoking this handler):

Web21Handlers.java

package org.example.handlers;

import com.sun.jsftemplating.annotation.Handler;
import com.sun.jsftemplating.annotation.HandlerInput;
import com.sun.jsftemplating.annotation.HandlerOutput;
import com.sun.jsftemplating.layout.descriptors.handler.HandlerContext;


/\*\*
\* <p> This class is written to demonstrate how to write a
\* <code>Handler</code>.</p>
\*/
public class Web21CHandlers {

/\*\*
\* <p> This is a handler makes phone calls.</p>
\*
\* @param context The <code>HandlerContext</code>.
\*/
@Handler(id="Web21.call",
input={
@HandlerInput(name="to", type=String.class, required=true),
@HandlerInput(name="from", type=String.class, required=true)
})
public static void calculateResponse(HandlerContext context) {
// Get the input.
String to = (String) context.getInputValue("to");
if (!to.startsWith("tel:+")) {
to = "tel:+" + to;
}
String from = (String) context.getInputValue("from");
if (!from.startsWith("tel:+")) {
from = "tel:+" + from;
}

com.bt.sdk.thirdpartycall.ThirdPartyCall tpc = new com.bt.sdk.thirdpartycall.ThirdPartyCall(to, from);
tpc.startCall();
}
}



7) I compiled the app (just typed "ant" on the command line, the demo application already has the build environment setup), started the server and went to http://localhost:8080/demo/call.jsf where I saw:

Screenshot 

After typing in the 2 phone numbers and clicking the "Make Call" button... the 2 phones rang! 

8) Finally... I showed this to the Web21C people and they gave me a helicopter!

Ken and Senthil 

(I'm in the blue Sun shirt.  You can also see this on flickr.)

That's how to get a helicopter using JSFTemplating + Web21C + GlassFish at JavaONE.


About

paulsen

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today