|
Prerequisites
To use the Net Caboodle plugin, you
require
- NetBeans version 5.x and NetBeans
5.x Mobility Pack
- JDK 1.5
Please make sure you have the required software
before proceeding with the Net Caboodle installation.
You can run NetBeans with a Java 1.4 or 1.6 JDK,
however, JDK 1.5 is required by the plugin and can be set in the
gateway's preferences
Installation & Upgrading
The Net Caboodle plugin for NetBeans
is installed via the NetBeans "Tools->Update Center"
menu option as "Manually installed" module.
- Download
the Net Caboodle v4.2.6 plugin - 2 MB
ZIP file containing plugin, simple messenger example with a PDF
user guide.
version 4.2.6 - free 60 day trial
- In NetBeans select "Tools->Update Center"
- Select "Install Manually Downloaded Modules"
- Click the "Next button" and the "Add"
button
- Select the downloaded module (contained in the
ZIP) called com-nc-plugin-nb.nbm
Please note that if you are upgrading to a newer version of
the Net Caboodle plugin, then you may need to regenerate your mobile stubs to
stay compatible with any changes to the gateway transports.
Plugin
configuration
Having successfully installed the Net
Caboodle plugin, you need to configure the plugin to use the Java
Development Kit 1.5.
Use the "Tools ->Net Caboodle
Gateway->Gateway Configuration.." menu option (shown below)
to make sure that you have selected a Java Development Kit (JDK)
1.5 not just the JRE.

|
Gateway Properties
- Host
This property is automatically set to your computer's IP
address
- Port
This is the port used by the mobile stubs to communicate
with the Gateway.
- Bind port
This is the RMI registry port used by the gateway to run
the Hello RMI server example.
Additional libraries
- Use
this section to add any JAR depenencies that your POJO/Bean
services require.
Runtime Properties
- JDK 1.5
This is the JDK used by the plugin to start the
Gateway
- License file [optional after
30 day trial]
|
 |
If you skip the above configuration setup the plugin
will issue warning messages.
Net Caboodle plugin menus
The Net Caboodle plugin has three main
menu options, which are available from the "Tools" menu
in NetBeans.

- Net Caboodle Business 2 Mobile
- Net
Caboodle Gateway
- Gateway Configuration
- Start Gateway
- Stop Gateway
- Net
Caboodle Gateway Deployment
- Deploy Bean to Gateway
- Deploy MIDlet to Gateway
- Deploy Gateway
Getting started
with the Net Caboodle plugin
The Net Caboodle platform and NetBeans
Mobility Pack make it quick and easy to write and deploy mobile
applications
|
Included with the Business 2 Mobile
plugin download is a simple POJO (Plan Old Java Object) service
that allows MIDP clients to post and read messages on a simple
message board via the Internet and the Net Caboodle gateway.
Extract the project in the zip file
and then open the two projects in NetBeans as shown below.

|

|
|
Start the Net Caboodle Gateway
Having opened both the Message Board
Bean and MIDPMessage client projects in NetBeans,
the next step is to start the Net Caboodle Gateway as shown
below.

You can check that the Gateway has started
correctly by looking at the Net Caboodle: console

Creating the MIDP stubs
To allow the mobile client to communicate
with the Message Board Bean, you need to generate the
mobile stubs.
Select the MIDP project and the use
the "Tools | Net Caboodle Business 2 Mobile | New connector..."
menu option.

Having selected the above menu option
you will presented with the "New Connector" dialog
as shown below.
 |
- Select
the "Bean connector" tab
- Use
the browser button and select the "Message_board_bean.jar"
from the "dist" sub-directory of the Message
Board Bean project directory.
- Select
the class "com.nc.example.MessageBoardBean"
from the classes list
- Click
OK to generate the mobile stubs
- Check the Gateway console
for any errors.

|
Testing the Mobile client
If you have successfully followed the
steps above, you can now try out the mobile client, by right-clicking
on the MIDP project and selecting "Run Project"

Select "Run project" 2 times,
so you have 2 emulators running at the same time, so you can
to send messages from one emulator to the other.
Using the emulator
NetBeans will now start-up the MIDP
emulator as shown below. Select the application and you will
be prompted "Is it OK to use airtime?"
|

If you are wondering why the emulator
is prompting you with this question, it is because it
is emulating what happens on a real device.
There's no need to worry about
this with the emulator, the only connection being made
is to the Gateway running in NetBeans on your local
computer.
The mobile application has two
menu options and a ticker across the top.
|

Select "Yes"
|
|
1: Select
"Post message" by pressing the select key
on the emulator

|
2: Enter
a nickname and a message to post to the message board,
then select "Send"

|
|
3: Your
message will appear in the ticker and the Message
text field will be cleared

|
4: Use
the "Back" button to return to the main menu
and select "Read messages"
|
Please note, that when using the 30
day evaluation of this plugin, the gateway is limited to only
5 concurrent connections. To use more connections you must
purchase a developer license from Net Caboodle.
RMI Example
|
|
Having successfully run the simple
Message Board example included with the Net Caboodle distribution,
let's now take a look at another type of service - an RMI
(Remote Method Invocation) service.
When you use the Caboodle "Start
gateway" menu option, the plugin will also start up the
example RMI "Hello" service for you bound on the
RMI registry port you entered using the Gateway Configuration
option described above. ( the default is port 6060 ).
|
|
Follow the steps below to use
the Caboodle plugin to generate the code you need to access
the example "Hello" RMI service from a MIDP device.
Once you are familiar with the steps
involved, then it will be easy for you to start writing MIPD
code for your existing services.
To test with the "Hello RMI"
example and import the service into a MIDP project you must
first use the "start gateway" option.
|
Starting the Gateway
Start the Net Caboodle gateway by using
the "Tools->Net Caboodle Gateway->Start Gateway"
menu option.

When the gateway starts up it creates
a new Output window in NetBeans as shown below. All output from
the plugin is directed to this window.

Having started the Gateway let's proceed with
the Hello example, by first creating a new MIDP project with the
NetBeans Mobility Pack
Creating a new NetBeans Mobility Pack Project
Use the "File-> New project"
option in NetBeans and then select a "Mobile Application"
project as shown in the figure below.

Click the "Next" button and call
your project "Hello RMI" followed by the "Finish"
button. You new project will appear in the IDE as shown below.

Business 2 Mobile
Connectors
The "New Connector" menu option
allows you to connect to a running RMI service (or
other service types) so the Caboodle plugin can generate the
MIDP stubs and connector code required for your MIDlet to use the
RMI service via the Net Caboodle gateway.
This option is only enabled when the gateway is
running, and you have selected your mobile project's root icon.

When you select the "New connector"
menu option you will be presented with the dialog box as shown below.
The "host" and "port" parameters will default
to your computer's IP address and the default RMI registry port
(1099).
 |
RMI Connector
You need
to change these fields to the correct values to match the
RMI URL of your running services.
For the "Hello RMI"
example you need to enter the default port, which is 6060
There are three text fields you
need to either modify or complete to construct an RMI lookup
URL, for example, rmi://myhost:1099/MyService
- Host
This is the IP address or host name of the computer where
the RMI service is running. By default this is set to your
local host's IP address.
- Port
This is the port the RMI registry is running on. By default
this is set to 1099
- Lookup name
This is the name you have registered with the RMI registry
when you started the service
|
Connect button
Having entered the three lookup parameters,
click the "Connect" button.
Make sure your RMI server has a correctly
configured and exported codebase - see
our FAQ pages for more details if you don't
know what this means.
You should now see the interface used
to the Hello RMI example listed in the dialog box, as shown below.

If network/connection problems are encountered
these will be displayed in the Net Caboodle console.
Select the interface you want to use
and then click the OK button.
The Net Caboodle plugin will then attempt
to generate the stubs required for the MIDP client, as shown in
the figure below.

The Net Caboodle console will issue
you with warnings for methods/classes that are not compatible for
MIDP 1.0 conversion. See the section
below on MIDP compatibility.
When conversion is complete, take a look in
the Caboodle console window for the basic code required to use the
converted service.

On successful completion of the above
process, the Net Caboodle plugin will automatically add the generated
stubs JAR file to your project's classpath.
Your project should
be ready so you can start using the generated mobile stubs to invoke
methods on the example Hello RMI service running in the Gateway.
Using the NetBeans Mobility Pack
In this section we
will explain the basic steps to use the NetBeans Mobility Pack's
designer to add the code to invoke methods on the Hello RMI service.
First rename the default Form created by NetBeans
to "helloOutput" as shown below.

Next click on "Source" tab in the
editor to view the generated code and add the code highlighted in
yellow below.
- Add the import statement (that was shown
in the Net Caboodle console) for the service.
- Add a private field for the Hello service
Next scroll down until you find the "get_helloOutput()"
method as shown below.

In the "Insert Post-Init User Code here"
section add the code as shown below

Here's the code to
insert, that is shown in the screenshot above
// Insert post-init code here
try{
String message=service.sayHello();
helloOutput.append(message);
}catch(Exception ex){
helloOutput.append(""+ex);
}
The following sections
describe how to use the code generated by the Net Caboodle mobile
stub generator, but for now let's complete the Hello example by
running the MIDP emulator.
Right click on the
project icon and select "Run Project", which will launch
the MIDP emulator.
Next select the MIDlet
and you should be prompted with the "Is it OK to use airtime"
alert. This message appears, because the mobile stubs are trying
to contact the Net Caboodle Gateway, running in NetBeans. There
are no external calls being made by the stubs.
Select "Yes"
and then you should see the output from the Hello RMI service, as
shown below.

Code
generation patterns & rules
Net Caboodle converts RMI (and other
Java service types) using the following rules/patterns.
Generated code library
Earlier we mentioned that the code code
required to use a converted service will be displayed in the Caboodle
console. In the case of the Hello example, here's what you need
to do; add the import statement, plus a field that holds the MIDP
service's proxy instance.

The Hello example illustrates three
types of service methods.
- Service returning a primitive/Java
type (String)
- Service returning a user-defined
type ( called ServiceInfo )
- Service receiving the user-defined
type ServiceInfo
The figure below show the basic code
to test the Hello example

MIDP lookup
of services
For each converted service Net Caboodle
will generate a lookup factory using the following naming conventions.
<service_package><service_interface>Factory
e.g com.nc.exmple.HelloFactory
To access the MIDP service proxy there are
two overloaded methods
<service_interface>Factory.getService();
<service_interface>Factory.getService(String gatewayHost,int gatewayPort);
e.g
//use default gateway
Hello service=HelloFactory.getService();
//explicitly use the gateway "janeway:8080"
Hello service=HelloFactory.getService("janeway",8080);
//Use the runtime properties set by the Gateway or add these to your JAD
String host = getAppProperty("gatewayHost");
String port = getAppProperty("gatewayPort");
if(host!=null){
service=HelloFactory.getService(host,Integer.parseInt(port);
}
POJO (bean) Connectors
The Net Caboodle plugin for NetBeans
allows you to select a remote service, either via lookup or by directly
selecting the JAR file that contains your business service's interface.
The plugin then creates a JAR file containing all the connector
code and stubs, for you to link into your NetBeans MIDP project.
As you add/remove methods from you business services, the plugin
can be used to regenerate the JAR file.
Version 4.0 of the Net Caboodle plugin
for NetBeans supports the following service types.
- User-defined beans (POJO)
- RMI
- Jini
To work with Jini (Apache River) services
rather than RMI-based services, download the Inca X Jini
plugn for NetBeans
User-defined beans or POJOs (Plain Old Java Objects)
can also be used to write your own bridging code, for example, you might have
service implementations other than RMI or Jini, such as CORBA or JMS. By creating
a Java interface/adapter for these applications or services the Caboodle server
can then make them available as services for your MIDP clients.
User-defined beans can also be used
to write "adapters" for existing services, which have
methods and parameters that are incompatible with CLDC 1.0.
The Net Caboodle gateway acts as a container for
user-define connector beans and dynamically provisions them, the first time
a mobile client tries to access the connector. A user-defined connector bean
must have a public no-args constructor with public methods defined for the functionality
you want to expose to your mobile clients.
Another POJO example
In many cases it
is much easier just to write a POJO (Plain Old Java Object) connector
as we have seen with the Message
Board example.
Earlier you saw how to use the Net Caboodle
plugin to connect to the example Hello RMI service, below
is a simple Hello POJO connector.
public class HelloPOJO{
//required constructor
public HelloPOJO(){}
//say hello method
public String sayHello(){
return "Hello from a POJO";
}
}
To use a POJO connector bean, simply create
a JAR file containing the required class files and the use the "Bean
connector" tab in the new connector dialog as described earlier
for the RMI service.
Jini Service connectors and User-defined
beans
Both Jini service and user-defined beans can
be imported by selecting the JAR file that contains the service's
interface class as shown below. Having selected a JAR file the import
dialog will display a list of interface classes (or beans) contained
in the JAR file.
Having selected a JAR file the Jini or Beans
import dialog will display a list of interface or bean classes contained
in the JAR file.
Select the service or bean interface and then
click the OK button. The Net Caboodle plugin will generate all the
connector code, just as it does for a RMI service import.
CLDC 1.0 compatible
types
Due to the restrictions of the Connected
Limited Device Configuration (CLDC), not all services are candidates
for being accessed from a MIDP device. However, by using Net Caboodle
it is possible to create POJOs to act as mediators between existing
services and MIDP clients.
CLDC 1.0 types supported by Net Caboodle.
- Primitives types, excluding double
and float
- Number wrapper classes excluding
Double and Float
- java.lang.String
- java.util.Date and java.util.Calendar
- java.util.Vector
Note that ONLY single
and two dimension arrays are supported for primitive types and String
in this release -- Use
Vectors instead of arrays for user-defined types
User-defined classes that are used as
parameters or return types MUST have a public no-args constructor
and provide matching field accessors in the form of "getters"
and "setters".
User-defined classes embedded as fields are
NOT supported this version of the software.
Class pattern matching and conversion
The selected service interface class
name and package are maintained during conversion, for example,
if we take the RMI Hello example interface
com.nc.example.Hello
The generated MIDP code will have the
same fully qualified class name.
Any user-defined class types used by
the service interface class, will also be converted into the same
package. For example, if we had a class called com.nc.service.ServiceInfo,
which was returned from the "Hello" service, the converted
class, would be placed in the sample package as the MIDP service
interface (e.g, com.nc.example).
Gateway
deployment
The gateway deployment options allow you to
develop and build your Net Caboodle gateway instance within NetBeans
and then export the gateway configuration directly to the file system.
Having exported the Gateway instance, you can then run the gateway
outside of NetBeans.
When using the 30 day
evaluation of this plugin, the gateway is limited to only 5 concurrent
connections. To use more connections you must purchase a developer
license from Net Caboodle.
To configure the gateway, use the Deploy MIDlet
and Gateway Configuration dialog.

Deployment options
- Deploy Bean to Gateway
Use this option to update the gateway with any POJO/Bean services
that have been updated. Please note that if you change the methods
in your POJOs, then you will need to re-generate the mobile stubs,
which also updates the the Gateway.
- Deploy MIDlet to Gateway
Use this option to deploy a MIDlet to the Gateway. Having been
deployed your MIDlet it will be configured for OTA provisioning
by the Gateway.
- Deploy Gateway
Exports the current Gateway configuration to the file system,
so you can run the Gateway independently of NetBeans.
Before exporting (deploying) the gateway you will need to
1. Make sure you have included the MIDlet code to read
the "gatewayHost" and "gatewayPort" parameters,
as follows
String host = getAppProperty("gatewayHost"); String port = getAppProperty("gatewayPort"); if(host!=null){ service=MyServiceFactory.getService(host,Integer.parseInt(port);
}
2. Makes ure you have tested and deployed your MIDlets
to the Gateway.
3. Configure the gateway to use your exteneral Intenet
address or hostname-- this is the address that you will
enter on your phone to download your MIDlets Over the Air (OTA).
To do this, open the gateway's configuration dialog from the "Net
Caboodle Gateway" menu and change the Gateway Host value
to either your exteneral Internet IP address or hostname.
4. Change the default Gateway Port from 8205
to a different port which is available and either accessible through
your firewall or can be accessed via your router's configuration.
5. Save the configuration changes and STOP the
gateway from NetBeans if it is running.
6. Use the "Deploy Gateway" menu option
and select the directory to deploy the gateway to.
Having configured, exported and started the gateway, you should
next test that you can access the Gateway from your mobile phone
- to do this use one of the OTA provisioning URL from the gateway
console. If you phone cannot connect to the gateway, check
your firewall and router settings.
Developer
license & Gateway license
|
The Net Caboodle Business 2 Mobile plugin
for Net Beans is available as a free 30 trial.
When your trial expires you can purchase a developer license
to reactivate the software.
Please note: A developer license permits
you to write and test your services and mobile applications
using the Business 2 Mobile plugin and exported gateway instances,
which are restricted to a maximum of 5 concurrent connections.
A Developer License does not permit
you to use the Net Caboodle gateway for any other purposes
other than developing and testing. To deploy the Net Caboodle
Gateway for any other purpose requires a separate Gateway
license, details of which can be obtained by contacting
sales.
|
If you have any questions
or comments about using the Net Caboodle Business 2 Mobile plugin
for NetBeans, then please
contact us
Different
packs and Plugable servers
With Net Caboodle Professional, you
can install and use additional server and client-side development
packs to hook in your own authentication
code and to interact with the Net Caboodle
Transaction Manager.

Contact us for more information.
More code examples
 |
In this article we explain how to create
a mobile (MIDP) messaging client that reads and stores messages
to/from a relational database.
Click
here to read this article and download the example code
for NetBeans
This article fills in some of the technical
detail outlined in the article Taking
Service-Oriented Architectures Mobile, Part 1
The screen shot on the left is from
a live version of a system that provides a secure and private
messaging service.
|
Other code examples
|