*
The moose likes Java Micro Edition and the fly likes HttpConnection error only in devices (not emulators) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "HttpConnection error only in devices (not emulators)" Watch "HttpConnection error only in devices (not emulators)" New topic
Author

HttpConnection error only in devices (not emulators)

Diego Guidi
Greenhorn

Joined: Sep 09, 2004
Posts: 4
I've developed a client application in j2me and nokia emulators:
this app get mapi "text/text" (simple ASCII document) informations by a server and shows this informations on screen.
My problem is: in emulators (any nokia emulator (6600, 7210, S40), most siemens and sonyericsson) the app works fine, but in my devices (nokia 3200 and nokia 7250i) i receive a connection error 502 (HTTP_BAD_GATEWAY).

I've developed a test method: this method works on emulators but not in devices...

This is the code:

public void testHttpReturnString()
{
String url = "http://" + serverName + ":" + portNumber + "/projectlist." + getRandomInt() + "?user=" + getUserName() + "&pwd=" + getPassword();
byte[] buffer = null;
HttpConnection conn = null;
String response = "";
try
{
conn = (HttpConnection)Connector.open(url, Connector.READ);
conn.setRequestMethod(HttpConnection.GET);
int responseCode = conn.getResponseCode();
if(responseCode != HttpConnection.HTTP_OK)
{
System.out.println("Response error: code " + responseCode);
response = "Response error: code " + responseCode;// in devices return code 502, in emulators returns HTTP_OK
conn.close();
}
else
{
InputStream is = conn.openInputStream();
System.out.println("Type: " + conn.getType());// returns "text/text" in emulators (correct)
int size = (int)conn.getLength();
buffer = new byte[size];
int ch;
int i = 0;
while((ch = is.read()) != -1)
{
buffer[i] = (byte)ch;
i++;
}
response = new String(buffer);
conn.close();
}
}
catch(IllegalArgumentException err)
{
err.printStackTrace();
response = "httpConnect IllegalArgumentException: " + err.toString();
}
catch(NullPointerException err)
{
err.printStackTrace();
response = "httpConnect NullPointerException: " + err.toString();
}
catch(IOException err)
{
err.printStackTrace();
response = "httpConnect IOException: " + err.toString();
}
finally
{
DebugTextBox form = new DebugTextBox("Debug Form", response, this);// Debug form for retrieve informations from device
display.setCurrent(form);
}
}

Any suggestions?

Thanks a lot
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Unfortunately, I don't have a suggestion for your code.

However, I have a suggestion for posting code.

We have a "CODE" tag, that can be created by clicking the CODE button, which is located under the "Add Reply" button, along with URL, BOLD, etc. buttons

This tag will enable you to keep your formatting for your code, like indentation, and makes your code readable. The way your code is posted makes it difficult to read, and therefore, more difficult for us to help you.

Thanks

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Ed Schepis
Greenhorn

Joined: Feb 06, 2004
Posts: 25
Often on devices you need to configure a web profile instead of a wap one. In fact some telco operators permit the network connections only if a web profile is used. Are you testing your application in Italy? (... I guess it from your name...). Let me know if you need more information on profiles to use in italian devices.
Ed


SCMAD 1.0 - SCEA - SCJA - [<a href="http://www.edschepis.net" target="_blank" rel="nofollow">My Weblog</a>]
Diego Guidi
Greenhorn

Joined: Sep 09, 2004
Posts: 4
Thanks for the information about <code> tag and thanks for replies...

I have locate the cause of the problem: i'ts a problem of configuration.

Vodafone and Wind mobile operators (italy) not allow to htp connections via wap configurations, but TIM operator allow this...

Result: program works crrectly with TIM operator, not with other operators.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HttpConnection error only in devices (not emulators)
 
Similar Threads
IOException on outputStream close on Nokia
J2me:Question about HttpConnection
encrption and decryption using cipher for Java ME
Problem reading the HttpConection response in some devices
servlet response