BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 03-06-2007, 04:09 AM   #1 (permalink)
Knows Where the Search Button Is
 
Join Date: Mar 2007
Model: 8700v
Carrier: VodaFone
Posts: 16
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default NetBeans, a Blackberry and some Web Services

Please Login to Remove!

Hi,
I have used NetBeans to create a VERY simple Web Service that connects to a database and retrieves a piece of data related to the record input by the user. i.e. (Select column2 from table1 where column2 = :userInput)

Has anyone developed a Blackberry app, in NetBeans, to access a Web Service like this? If so, any pointers or sample code would be appreciated

Cheers
Jon L
Offline  
Old 03-06-2007, 05:21 AM   #2 (permalink)
CrackBerry Addict
 
Join Date: Jun 2005
Location: Manchester, UK
Model: BOLD
Carrier: t-mobile
Posts: 714
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

i used ksoap for the webservice transaction then sax to parse the results, using this plugin for netbeans to create the class:

>>>netbeans 5.5 blackberry template

the code generated by the soap/sax template is:

package jhfisher.bclient;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import net.rim.device.api.xml.parsers.SAXParser;
import net.rim.device.api.xml.parsers.SAXParserFactory;
import org.ksoap.SoapFault;
import org.ksoap.SoapObject;
import org.ksoap.transport.HttpTransport;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

/*
* testSoapSaxClass.java
*
* Created on March 6, 2007, 10:21 AM
* RIM Blackberry kSoap/Sax Class
*
* @author jfisher
*/


class testSoapSaxClass extends Thread{

String url = "";
String serverResponse = "";

public void run() {
try {
SoapObject RPC = new SoapObject("http://webservices.mycompany.net/module", "webservicename");
RPC.addProperty("parameterName", "");
serverResponse = "" + new HttpTransport(url, "http://webservices.mycompany.net/module/webservicename").call(RPC);
}catch (SoapFault sf){

}catch(Exception e){

}

try{
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
InputStream in = new ByteArrayInputStream(serverResponse.getBytes());
InputSource inputSource = new InputSource(in);
saxParser.parse(in, new testSoapSaxClassHandler());
}catch(Exception ex){

}
}

static class testSoapSaxClassHandler extends DefaultHandler {
String builder;
String temp;

public void startDocument() throws SAXException {
}

public void startElement(String uri, String name, String qName, Attributes atts){
if ("".equals(uri)){
System.out.println("Start element: " + qName);
}
temp = "";
}

public void endElement(String uri, String name, String qName){
if ("".equals(uri)){
System.out.println("End element: " + qName);
}
}

public void characters(char buf[],int offset,int len) throws SAXException {
temp="";
String temp2;
temp2 = new String(buf, offset, len).trim();
if (!temp2.equals("") || !temp2.equals(" ")){
temp = temp2;
}else{
temp = "";
}
}

public void endDocument() throws SAXException {

}
}
}
__________________
new job doesn't allow a public profile - please do not contact this user with questions, you will not get a response. good luck!
Offline  
Old 03-06-2007, 06:14 AM   #3 (permalink)
Knows Where the Search Button Is
 
Join Date: Mar 2007
Model: 8700v
Carrier: VodaFone
Posts: 16
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Jonathan,
Any chance you could post the code that uses this class? I am struggling to see how it is used.
Offline  
Old 03-06-2007, 06:37 AM   #4 (permalink)
CrackBerry Addict
 
Join Date: Jun 2005
Location: Manchester, UK
Model: BOLD
Carrier: t-mobile
Posts: 714
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

i've not got any little apps available that use it so no, but some info:

- call this class from wherever, it's a thread so it'd be something like:

testSoapSaxClass tssc = new testSoapSaxClass();
tssc.start();

- the ksoap library handles the connection itself but you need to tell the class what the url is (edit the String url = ""; line), then edit the SoapObject with your web service namespace and and the service you're accessing.

- once ksoap has made the soap transaction the sax parser then parses the returned xml message, in endElement just catch the node that holds your info:

public void endElement(String uri, String name, String qName){
if(name.equals("SUCCESS")){
Status.show("Success = " + temp);
}
}

- once the class reached endDocument you can do whatever you want as the transaction is finished
__________________
new job doesn't allow a public profile - please do not contact this user with questions, you will not get a response. good luck!
Offline  
Old 03-07-2007, 08:58 AM   #5 (permalink)
Knows Where the Search Button Is
 
Join Date: Mar 2007
Model: 8700v
Carrier: VodaFone
Posts: 16
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Jonathan,
Hopefully you have dealt with idiots before...


I have a web service called DBWS, with an operation called getDescription.
This web service is deployed to a Sun Java Application server residing on a machine called expxxxxxx.
I can test the service by browsing to "expxxxxxx:8080/DBWSService/DBWS?Tester" and it works.

In the SoapSax class would you expect the following:

String url = "://expxxxxxx:4848/DBWSService";
String serverResponse = "";

public void run() {
try {
SoapObject RPC = new SoapObject("://expxxxxxx:8080/DBWSService", "DBWS")
RPC.addProperty("parameterName", "getDescription");
serverResponse = "" + new HttpTransport(url, "://expxxxxxx:8080/DBWSService/DBWS")).call(RPC);

Followed by:

public void endElement(String uri, String name, String qName){
if ("getDescription".equals(uri)){
System.out.println("End element: " + qName);
}
}

In my screen class I am calling
newBlackberrySoapSaxClass tssc = new newBlackberrySoapSaxClass();
tssc.start();


If all the above looks ok, I doubt it but hey, how would I show the output of the getDescription method in my screen class.

Sorry for all the questions.
Jon L.
Offline  
Old 03-07-2007, 10:09 AM   #6 (permalink)
CrackBerry Addict
 
Join Date: Jun 2005
Location: Manchester, UK
Model: BOLD
Carrier: t-mobile
Posts: 714
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

i've only ever done blackberry to a .net web service so i might be missing something but:

- the url needs the http:// prefix

- the url should be the webservice, you pass the web service the web method you want to access in the soap object - looks like you're doing this correctly but i'd expect the url to target a file? (for .net the web service sits in a .aspx file, not sure how other platforms operate)

- when catching the return message i use:

if(name.equals("xmlnode")){
System.out.println(temp);
}

ie. this would print out whatever text is between <xmlnode> and </xmlnode>

- you're adding your property incorrectly in the soap object, if my webmethod expects a parameter called 'username' i'd add it to the rpc like so:

RPC.addProperty("username", "sysadmin");

hope this helps!
__________________
new job doesn't allow a public profile - please do not contact this user with questions, you will not get a response. good luck!
Offline  
Old 03-07-2007, 10:58 AM   #7 (permalink)
Knows Where the Search Button Is
 
Join Date: Mar 2007
Model: 8700v
Carrier: VodaFone
Posts: 16
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Jonathan,
Sorry about the missing hxxp:// prefix. I was getting posting errors when I had it in the message (SOmething about the need to post ten messages before it would allow me to post a url)
Offline  
Old 03-07-2007, 11:52 AM   #8 (permalink)
CrackBerry Addict
 
Join Date: Jun 2005
Location: Manchester, UK
Model: BOLD
Carrier: t-mobile
Posts: 714
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

aaaaahhhh!

haha. if you're still struggling i'd suggest looking online for the many examples that usually use the google or yahoo web services as examples. ksoap is pretty old but does the job perfectly and you can strip out everything you dont use from it. i'm no expert but using ksoap with sax as descripbed above has proved to be very convenient and easy to maintain (our app uses several webservices).
__________________
new job doesn't allow a public profile - please do not contact this user with questions, you will not get a response. good luck!
Offline  
Old 03-09-2007, 04:13 AM   #9 (permalink)
Knows Where the Search Button Is
 
Join Date: Mar 2007
Model: 8700v
Carrier: VodaFone
Posts: 16
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

What's really annoying is that I can get this working no problem from MDS Studio. Using the wizrds in studion, I just selected my service, created the app and bingo, everything works.
I just cannot seem to get the correct data into the url, SoapObject and HttpTransport objects.

Grrr.
Offline  
Old 03-13-2007, 03:53 PM   #10 (permalink)
Thumbs Must Hurt
 
Join Date: Jul 2006
Location: Atlanta
Model: 8703e
Carrier: Sprint
Posts: 58
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is another sample if you need but this one calls a java weblogic 8.1 webservice. My app calls a webservice with a vector as a param, you can specify almost any object type, you just have to describe it to ksoap. Of course using primitive types is even easier. I used version 1 of ksoap btw. Let me know if you need help on how to describe custom data types to ksoap. "storeForm" is my webservice function

Code:
       //Set up the class Mapping
       ClassMap classMap = new ClassMap();
       classMap.addMapping("java:language_builtins.util", "Vector", new Vector().getClass());
       
       //Set up the HTTP Transport
       final HttpTransport transport = new HttpTransport(WEBSERVICE_URL, "#storeForm");
       transport.setClassMap(classMap);
       transport.debug = true;
       
       //Set up the Soap Request
       SoapObject request = new SoapObject(WEBSERVICE_NAMESPACE, "storeForm");
       request.addProperty("vector", SOME_VECTOR_REF);
       Object obj = null;
       obj = transport.call(request); //Calls the webservice functions and Blocks while waiting for response
       
       //Then simply cast obj to whatever type it is as defined by the WS
__________________
Cingular BB 7290 and Sprint BB 8703e.

Last edited by donricouga : 03-13-2007 at 03:57 PM.
Offline  
Old 03-14-2007, 11:42 AM   #11 (permalink)
Knows Where the Search Button Is
 
Join Date: Mar 2007
Model: 8700v
Carrier: VodaFone
Posts: 16
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am getting closer all the time.
I can get a midlet working using the J2MW Wireless Toolkit (kToolBar). This is accessing my web service and is returning data.
When I copy the same SOAPObject and httpTransport fields to my NetBeans app I get an exception (Local connection timed out after ~ 120000
).

Grrr
Offline  
Old 03-14-2007, 11:49 AM   #12 (permalink)
CrackBerry Addict
 
Join Date: Jun 2005
Location: Manchester, UK
Model: BOLD
Carrier: t-mobile
Posts: 714
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

have you got the mds simulator running?
__________________
new job doesn't allow a public profile - please do not contact this user with questions, you will not get a response. good luck!
Offline  
Old 03-14-2007, 11:58 AM   #13 (permalink)
Knows Where the Search Button Is
 
Join Date: Mar 2007
Model: 8700v
Carrier: VodaFone
Posts: 16
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I've got "BlackBerry Controller" and "BlackBerry MDS Services - Apache Tomcat Service" services running on my pc. Is that what you mean?
Sorry for the stupidity.
Offline  
Old 03-15-2007, 05:12 AM   #14 (permalink)
Knows Where the Search Button Is
 
Join Date: Mar 2007
Model: 8700v
Carrier: VodaFone
Posts: 16
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Whoop, Yoopa Doop Doop.
It's working.
Finally got the little bugger to do as it was told. I now have a working simulation connecting to our database and retrieving data. My next problem lies in getting the application signed coz it will not run on an actual device due to a signing error. I understand that RIM require some money to let this happen, so as long as I can get the BigBoys to release some funds it should be ok.

Thanks for all the help I have received.
Jon L.
Offline  
Old 03-15-2007, 05:46 AM   #15 (permalink)
CrackBerry Addict
 
Join Date: Jun 2005
Location: Manchester, UK
Model: BOLD
Carrier: t-mobile
Posts: 714
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

good news

the thing about stuff like this is you only have to get it working once - then you just copy what you did for evermore and concentrate on the fun stuff of actually writing your app.

the code-signing is only 100 dollars and they send you the keys within a day (i think), rather than a money making scheme it's just an added bit of insurance so they can potentially locate the developer responsible should a virus appear in the wild.

more details here: BlackBerry
__________________
new job doesn't allow a public profile - please do not contact this user with questions, you will not get a response. good luck!
Offline  
Old 03-20-2007, 10:57 AM   #16 (permalink)
Knows Where the Search Button Is
 
Join Date: Mar 2007
Model: 8700v
Carrier: VodaFone
Posts: 16
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

The web form for signing demands a pos (Just below country)
Anyone know what a pos is?
Offline  
Old 03-20-2007, 12:19 PM   #17 (permalink)
CrackBerry Addict
 
Join Date: Jun 2005
Location: Manchester, UK
Model: BOLD
Carrier: t-mobile
Posts: 714
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

probably postcode, zip code in the us?
__________________
new job doesn't allow a public profile - please do not contact this user with questions, you will not get a response. good luck!
Offline  
Old 03-20-2007, 12:42 PM   #18 (permalink)
Knows Where the Search Button Is
 
Join Date: Mar 2007
Model: 8700v
Carrier: VodaFone
Posts: 16
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'll give that a go. It semes strange fro them to call it pos, rather than zip.
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.