QR codes

I’m sure many of you have seen the new barcodes that are appearing on websites such as mobile YouTube and also people’s business cards. These are known as QR codes and are basically two dimensional barcodes. For more detailed information check the Wikipedia entry here: http://en.wikipedia.org/wiki/QR_Code. To create your own QR code, go to this link: http://zxing.appspot.com/generator/

One thing to keep in mind though is that this site belongs to Google and is tailored toward their products such as the Android platform. If you want to create a ‘generic’ code that will work with other devices e.g. Nokia phones you will have to use only a few of the input fields otherwise it will confuse the device. You may have to play around until you find the best fit. Here is the one I create for this blog using the zxing website:

Tagged with:
Posted in mCommerce

J2ME web services v. kSOAP2

When you are thinking about using web services with Java on mobile devices there are 2 main parsers you can use. These are:

A good explanation of the differences are explained here http://www.smalllinks.com/8D7. To summarise they are:

  • kSOAP supports DOM, XMLpull and SAX whereas JSR172 supports SAX only
  • kSOAP is document centric whereas JSR172 is Java centric
  • JSR172 supports SPI (see JSR172 URL above for more details)

What I will do in this tutorial is show the difference in the code for using these two technologies for creating mobile web service clients. For this tutorial I would not recommend using Oracle BPEL process manager to create your web services unless you have an idea of how to change the SOAP messaging format. For this tutorial I am using the Java Wireless Toolkit 2.5.2 for the mobile development and assume that you have some experience with creating MIDLets.

The first thing you will need to do is to create a simple HelloWorld web service in your chosen web service platform. This should have a method that takes a string field so that a user can enter their name as an input. The method should then append the “Hello ” and the persons name as an output.


1. Using JSR172

Setting up: The first thing you need to do is make sure your project is set up for using web services, I am going to use the Nokia NE51 as my test phone so I will use the MIDP2.0 and CLDC1.1 profiles so make sure these are checked under API selection in the settings tab. You must also make sure that JAXP XML Parser and Web Services API are checked.

Creating the stubs: Once you have done this you will need to create Stubs from the WSDL of the web service you have created. You must go the the ‘Stub generator’ which is under the ‘project’ menu. You will then need to navigate to your WSDL and give the output folder a name. Now if you look in your application folder under the ‘src’ folder you will find a new folder containing a package that contains all of the stubs. If you get the error: java.net.MalformedURLException when creating your stubs dont worry, this is because the wsdl document file path has a space in. Simply move it to your c: drive and it will create the stubs without a problem.

Creating the MIDlet: Now you need to create a simple client application MIDlet and you will need to import the the package with the stubs in. The next thing you must do is create a varible of the [service name]_portType_Stub. Once you have done this you can start calling the classes. Here is a code snippet that shows how to use the stubs:

try {
// create the stub
service = new HelloWorld_Stub();
service._setProperty(HelloWorld_Stub.SESSION_MAINTAIN_PROPERTY, new Boolean(true));

// call the method
returnString = service.sayHello(inputName.getString());

// display the response
outputForm.append(“JSR172 response: ” + returnString);
display.setCurrent(outputForm);

} catch (Exception exception) { …. }


Note: when calling the stubs there is a possibility that you may get an invalid element in response error. If this happens use the Network monitor to see if the SOAP message is coming back correctly. If this is the case there could be a namespace problem with a complex type if this is the case go to the stub and change the namespace URI to match what is returned in the message.

2. Using kSOAP

Setting up: When using kSOAP the first thing that you must do is to download kSOAP2 and then copy the core libary into the lib folder in the project. You will then need to import them into your MIDlet like this:

  • import org.ksoap2.SoapEnvelope;
  • import org.ksoap2.serialization.SoapObject;
  • import org.ksoap2.serialization.
  • SoapSerializationEnvelope;
  • import org.ksoap2.transport.HttpTransport;

Creating the MIDlet: Once you have done this you are then ready to start using kSOAP. It is actually quite simple. I have anotated the code I have used to call the web service:

try {
// set up the variables
String endPointURL = new String(“http://[host]/HelloWorld/services/HelloWorld”);
String nameSpace = new String(“http://hello”);
String soapAction = new String(“http://hello”);
String urn = new String(“urn:HelloService”);

// create the envelope
SoapObject soap = new SoapObject(urn, “sayHello”);
soap.addProperty(“name”, inputName.getString());

// serialize the envelope
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.bodyOut = soap;

// set up the transport
HttpTransport ht = new HttpTransport(endPointURL);

//make the call
ht.call(“”, envelope);

//get the response
Object soapIn = envelope.getResponse();
// Do something with the response
outputForm.append(“kSOAP response: ” + soapIn.toString());
display.setCurrent(outputForm);
} catch (Exception exception) {…}

When you create the SOAPObject the second argument is the method in the service that you wish to call. In this example its the sayHello method.

3. Device screenshots

The screenshots below show the MIDlet running on the device. The first screen lets you enter a name and then choose the parser type. The second screen is the JSR172 response and the third screen is the kSOAP response.

4. Final word

As you can see using both of these technologies is quite simple once you get over the main hurdle of knowing how to set them up. The mobile space is really interesting at the moment and I’m sure that web services will have a large role to play in the delivery of apps and content to mobile devices in the future.


Tagged with: , ,
Posted in Development

Using phone as radio control

This demonstration of using the Android platform in the G1 phone to control a blimp is really interesting and shows off what you can do with current mobile OSs :

Here is a link to the project:

http://code.google.com/p/srv1console/

I am getting really excited about the current mobile platforms and the things that people are doing with them because of their openness. Here is another example but with the iPhone:

Here is a link to their project page:

http://www.nerdkits.com/videos/rc_car/

The mobile space is really alive at the moment and hopefully will just keep on improving with the openness of the platforms and introduction of new sensors in the hardware, allowing innovators to accomplish more exciting things.

The real question is what is next?

Tagged with: , , ,
Posted in Android, iOS

Mobile web development

Read more ›

Posted in Mobile web

Augmented reality

Currently mobile technology is a very interesting space. With platforms becoming more open such as Android and Sybmian (now OS) and the introduction of different types of sensors on mobile devices there will be host of intersting new applications. One that I find really interesting is augmented reality.

Augmented reality adds information (words, images, links…) based on the position and direction the person is pointing their camera at. This would mean that if you were looking at a the front of a shop for example the phone would be able to give you information about that shop e.g. opening times. Other uses of this technology would be for tours or educational purposes. Here is an example from the Nokia MARA project:

Here is an application for Android, it is called Mobilizy:

Finally, there is the cross platform AR app called Layar which can be used on both the iPhone and Android

There could also be implications for advertising. For example you could be looking at nightclub and the device could recognise this and suggest a taxi firm number, which you could store in your device. You could then use this number when you come out of the club which would be more difficult if you were a little bit drunk! With this sort of technology you are only restricted by your creativity and look forward to seeing the new apps that come out in the future.

Tagged with: , , ,
Posted in Augmented reality

WSIF and BPEL Process manger

This is for people who like would like to use WSIF on Oracle BPEL Process manager but cannot find a step by step tutorial on how to do it. A lot of these steps are very manual and I am sure that there is probably an easier (automated) way to do this, which someone will post somewhere. For more information on WSIF please go to http://ws.apache.org/wsif/. This tutorial is based on:

  1. Matjaž B. Jurič, book chapter “Using WSIF for integration”: http://www.javaworld.com/javaworld/jw-12-2006/jw-1222-bpel.html
  2. 702. Bindings/JavaBindings in BPEL process manager tutorials folder: http://www.oracle.com/technology/products/ias/bpel/index.html

Step 1
The first thing to do is to create an empty business process called PersonProcess in JDeveloper and then create a new WSDL called PersonHelperService and save into the project BPEL folder. Make sure your definitions are the same as below:

The first thing you must put in the WSDL is the schema that you will be using for message passing. For this example I have create a basic schema which creates two types; a PersonType which consists of two strings and a PersonsType which is a PersonType. I’m sorry these aren’t very clear as they are based on my understanding of the Oracle tutorial.


Step2
The next thing to do is create the messages in the WSDL that will pass in a PersonsType from the schema and return the same type:

You then create the port type which defines an operation which has input and output of these message types:

Next you have the binding which states what binding you will use, the types that will be used and the methods that will be called in the Java class.

Next is the service definition:

And finally the partnerlink information for the business process:

Step 3

Once you have written the WSDL you must then create XML Facades from the schema which will be in the WSDL (see “Using WSIF for integration” for more details. To do this you open the Developer prompt for Oracle and navigate the BPEL folder in the business process project. You must then use the schemac command on the PersonHelperService.wsdl file you have created. This then creates java class files based on the schema from the WSDL file into the folder. This then creates java class files based on the schema from the WSDL file into the folder. One thing to note is that you must use complex types when using the schemac command.


To see what the methods are available see step 6 which shows how to generate javadoc documentation.

Step 4
The next thing to do is to create the business process that will use the PersonHelperService.wsdl file to create a partnerlink which will call a class that you will create later. For this example all I have done is create a simple process that:

  • Takes an input which is the same as the schema (see stage 4)
  • It then assigns the input as the input for the call (using a copy operation)
  • Makes a call to the partnerlink service
  • Performs a copy operation from the message received to the output variable
  • Makes the call back to the client

Here is the way in which I created the business process using JDeveloper:

1. Pulled across an assign from the component palette and put this under the recieveinput

2. Pulled across an invoke from the component palette and put this under the assign

3.Pulled across an assign from the component palette and put this under the invoke

4. Created a new partnerlink and located this under the project WSDL making sure that the partnerRole is chosen (only one should come up).


Now here it gets a bit messy (my understanding) – when you create a new business process it normally takes and returns a string but for this we need it take and return the same schema types as the ‘service’ that is defined by the PersonHelperService.wsdl. Therefore you need to change the WSDL file of the process itself. You need to open the process WSDL file and make the following addition to the types section:

I’m not sure why you need the extra elements but this is how the 702.Bindings WSDL is formed and it works. This should now reflect the types that the PersonHelperService.wsdl expects. You will also need to change the message type definitions to reflect these changes:

Finally, add: xmlns:types=http://services.otn.com/ to the definitions section.
5. Create the link between the invoke and PersonHelperService partnerlink making sure that you create the input and output variables.
6. Now you can must go into the first assign box and create a copy operation that takes the input payload (persons) and a copies this to the ‘service’ invoke variable payload (personsType). Make sure that the types in brackets are correct by checking the ‘show detailed node information’ checkbox.

7. You must then perform the same copy operation but from the ‘service’ call output variable to the process output variable. Again you should check the types to make sure they are correct.


Step 5 – create the class to be called
The first thing you need to do is create a folder called src in the main process folder (not BPEL folder) to put the java file in and then create the java file (PersonHelperService.java). It should have the same name as the binding section of the PersonHelperService.wsdl, in this case it is so the class is called: PersonHelperService. Here is the class:

package com.otn.services;
import com.otn.services.*;

public class PersonHelperService {

public PersonsType addPerson(PersonsType person) {
System.out.println(” Person = ” + person);
return person;
}
}

First you must say which package it will be in, here it is: com.otn.services. Also, everything is imported from this package which means that you have access to the façade classes you created previously (as they get compiled there later on).Then you must define the method which corresponds to the binding section of the WSDL in this case it is: so the method is called addperson. The binding section states that which means the method must take the PersonsType and also return a PersonsType. There is also a system.out.println method just to make sure everything has worked ok.

Step 6 – create the pre-build
Before you build the project you need to make sure that the java file you have created and the schema classes are compiled into the same directory where the process can see them.


This file needs to be saved as pre-build.xml under the main process folder along with the build.xml. Also notice that in the pre-build there is an attribute named doc that is followed by destination folder. This is useful as it documents the façade classes, letting you know what methods are available. Here is how your application structure should look in JDeveloper:


Step 7 – deploy
To ensure these are compiled into the correct directory you must create the following directory hierarchy under the process folder: $home/system/classes/com/otn/services. I haven’t used JDeveloper as I am having trouble with it but with the Developer prompt simply go to the folder where the build.xml file is and enter the word obant and this should do the work for. Assuming that everything is ok you should have a build with no errors.

Stage 8 – test
Below is the output from a call to the class from the business process:


You should also get some output on the BPEL server.

Conclusion
This is by no means a polished tutorial but is more of a guide for getting to grips with the WSIF on Oracle BPEL process manager. Please feel free to ask any questions or give advice where I have misunderstood anything. Hope this helps.

Tagged with: , , ,
Posted in Development

Switch to our mobile site