You Are Here:

Community: Developer Discussion Boards

#1 Old HTTP connection to Tomcat Server - 2003-04-11, 22:31

Join Date: Mar 2003
Posts: 17
chrisnsx
Offline
Registered User
Hi,

Following is some basic code I use to connect to a Tomcat server from a MIDlet(Excuse the lack of tab layout, its not been copied correctly):

public SyncLogic2(String userName, String Password) throws Exception
{
password = Password;
try
{
System.out.println("Attempting to open syncfile:"+userName+".txt. Using password: "+password);
//conn = (StreamConnection)Connector.open("http://localhost:8080/smartorg/"+userName);
conn = (StreamConnection)Connector.open("http://62.255.76.7:8080/smartorg/"+userName+".txt");
if (conn==null)
{
System.out.println("Conn is null");
throw new Exception("SyncLogic2 constructor(): Conn is null");
}
in = conn.openDataInputStream();
if (in==null)
{
System.out.println("IN is null");
throw new Exception("SyncLogic2 constructor(): In is null");
}
}

catch(IOException e)
{
System.out.println("SyncLogic2 constructor(): EXCEPTION: could not open HTTP connection: "+e.getMessage());
throw new Exception("SyncLogic2 constructor(): EXCEPTION: could not open HTTP connection: "+e.getMessage());
}
}

*******************************************

Notice the two string containing the URL. The first one is REMMED out and contains "localhost" written for the emulator which runs fine.
The active line contains the IP address of the Tomcat Server. This also runs fine on the emulator. However when the system is packaged and transferred to the phone, when this class is accessed via a function in th GUI, the phone simply ignores the function. When I EXIT my application, THEN the I see the phone attempting to make a data call, which always fails after 12 seconds.

Anyone who can help me??? I have no idea whats causing it.

Please help!

chris
Last edited by chrisnsx : 2003-04-11 at 22:36.
Reply With Quote

#2 Old 2003-04-12, 04:21

Join Date: Mar 2003
Posts: 4
arfff
Offline
Registered User
There's not attempt to read the resulting input stream. Have you tried the same with an:

in.read ();

in there somewhere?

--lee
Reply With Quote

#3 Old 2003-04-13, 02:10

Join Date: Mar 2003
Posts: 17
chrisnsx
Offline
Registered User
Sorry, I didnt include all my code. You can see from the method blocks that most of the variables and objects(including "in") were initialised outside the method block(as shown below). Hence their scope persists so that the following methods (below) can access them. The above method is located in the following class.
startSyncNow() starts the thread that actually reads the text file from the http connection. This makes calls to getNextLine() which returns a line from the file at a time.

As I said it works fine in the emulator, reading and decoding the file. Thanks for the input anyway, maybe you can help me further?

prety plz with sugar on top?


class SyncLogic2
{
StreamConnection conn = null;
DataInputStream in = null;
//Reader in = null;
StringBuffer data = new StringBuffer();
int ch;
String currentLine;
SyncLogic syncLogic = new SyncLogic();
String password;

private String getNextLine()
{
try
{

while ((ch = in.read()) != -1) //While inputstream has not reached end of file
{
if (ch != '\n') //If inputstream has not encountered a carriage return
{
data.append((char)ch);
}
else //Else return the line of data, ch = /n
{
String returnString = data.toString();
data = new StringBuffer(); //Clear the Stringbuffer
return returnString;
}
}
}
catch(IOException e)
{
System.out.println("SyncLogic2.getNextLine(): EXCEPTION: Error obtaining next line of syncfile: "+e.getMessage());
}
return null;
}

public LastSyncObject startSyncNow() throws Exception
{
System.out.println("Waypoint 11");
String currentLine = "";
String date = "";
String time = "";
int numMemos = 0;
int numTodos = 0;
int numContacts = 0;
int numSchedules =0;
Vector vecNewMemos = new Vector();
Vector vecNewTodos = new Vector();
Vector vecNewContacts = new Vector();
Vector vecNewSchedules = new Vector();
DBControl db;
System.out.println("Waypoint 12");

currentLine = getNextLine();
System.out.println("Waypoint 13");
if (currentLine==null) System.out.println("currentLine is null.");

if (!currentLine.startsWith(password, 0)) throw new Exception("Password Incorrect");
getNextLine();
currentLine = getNextLine();

while (!currentLine.startsWith("endoffile", 0))
{
System.out.println("currentLine = "+currentLine);

//System.out.println("SyncLogic2: Inside 1st while loop, retrieved line as:"+currentLine+".");
if (currentLine.startsWith("memos",0))
{
System.out.println("SyncLogic2: Entered memo section by detecting string memos as:"+currentLine);


etc etc etc etc
Last edited by chrisnsx : 2003-04-14 at 00:49.
Reply With Quote

#4 Old Same Problme - 2004-01-10, 17:15

Join Date: Mar 2003
Posts: 25
tuttas
Offline
Registered User
Hi, have you solved your problem. It looks like I have nearly the same !?!?!

best regrads

Joerg
Reply With Quote

#5 Old 2004-02-23, 08:18

Join Date: Sep 2003
Posts: 22
sujoydas
Offline
Registered User
hey dude,i think u got it wrong.
as u r using GET method so u have to send the value along with the variable
eg:
conn=http://localhost:8080/servlet?"username="usrname+"password="passwd;
now the servlet will take care of the values that u r passing using
HttpResponse
There will be no problem in that.
in case of any problem u can mail me at sujoydas1981@hotmail.com
best of luck.
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
[IMG] code is Off
HTML code is Off
Forum Jump

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia