Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HttpConnection error only in devices (not emulators)

 
Diego Guidi
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ed Schepis
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Diego Guidi
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic