| | |  |
07-24-2008, 09:44 AM
|
#1 (permalink)
| | New Member
Join Date: Aug 2007 Model: 8100 PIN: N/A Carrier: 1
Posts: 14
Post Thanks: 0 Thanked 0 Times in 0 Posts
| HTTPConnection Through MDS Please Login to Remove! Hello,
I am a BB app. developer. i created an application to work on my BlackBerry 8100.
I use JDE 4.0.2 . I have created one button on screen. When i click that button HTTP request is send to corresponding URL("https://xxx.xxx.xxx") Then I never get the response from the sever. I run my app. in JDE simulator is not connecting the internet . Its take some of time to run my app. after that i get the timeout message '120000' What can i do ...
I tried my application some possible way
1)thro' TCP and WAp, but not works as my service provider is hesitating to give the APN username, password, WAPGatewayIP
My last try is ....
try {
HttpConnection httpConnection = (HttpConnection)Connector.open("https://xxx.xxx.xxx");
httpConnection.setRequestMethod(HttpConnection.POS T);
InputStream inputStream = httpConnection.openInputStream();
int len = (int)httpConnection.getLength();
if (len > 0) {
byte[] data = new byte[len];
int actual = inputStream.read(data);
//process(data);
}
else {
int ch;
while ((ch = inputStream.read()) != -1) {
//process((byte)ch);
}
}
}
catch(IOException e) {
Dialog.alert(e.toString());
}
execution stops at
inputStream.read(data)
Please tell me a solution.
Thanks!!!
__________________ CHEERIO, Paramasivan S. | | Offline
| |
07-24-2008, 10:42 AM
|
#2 (permalink)
| | BlackBerry Extraordinaire
Join Date: Jan 2006 Model: LEZ10 OS: 10.0.10 Carrier: Rogers CA
Posts: 1,700
Post Thanks: 19 Thanked 76 Times in 67 Posts
| Are you also running the MDS simulator? Without it you can't access the internet from the Blackberry. | | Offline
| |
07-24-2008, 10:49 AM
|
#3 (permalink)
| | New Member
Join Date: Aug 2007 Model: 8100 PIN: N/A Carrier: 1
Posts: 14
Post Thanks: 0 Thanked 0 Times in 0 Posts
| As i am using JDE4.0.2, it accompanies a MDS simulator. Before excecuting my application in device simulator, i run the MDS simulator and the command prompt window says at last......
<2008-07-24 21:14:57.812 IST>:[31]:<MDS_MDS>:<DEBUG>:<LAYER = MDS, Web Server Started>
But after running my application into device simulator, i can see no change on the command prompt of MDS simulaotor.
Please let me know, if you need any further details.
And advice me on this. And i am unable to use TCP, WAP methods.
So i can use only the MDS method.
I hope you would help me on this.
Thanks indeed for your quick reply.
__________________ CHEERIO, Paramasivan S. | | Offline
| |
07-24-2008, 01:56 PM
|
#4 (permalink)
| | BlackBerry Extraordinaire
Join Date: Jan 2006 Model: LEZ10 OS: 10.0.10 Carrier: Rogers CA
Posts: 1,700
Post Thanks: 19 Thanked 76 Times in 67 Posts
| Then it would seem that either the PC/MDS server can't look up the host name xxx.xxx.xxx or it can't connect to it once it has the IP address. Things to try:
Use your PC browser to browse to https://xxx.xxx.xxx
If that works, use the browser on the simulator to browse to https://xxx.xxx.xxx
If that works, then have a look at the logs on the web server.
If neither works, try again but replacing the host name with the IP address of the server. If this doesn't work, ie you can't connect to the server from your PC you need to sort that out before the simulator can have a hope. | | Offline
| |
07-24-2008, 02:37 PM
|
#5 (permalink)
| | New Member
Join Date: Aug 2007 Model: 8100 PIN: N/A Carrier: 1
Posts: 14
Post Thanks: 0 Thanked 0 Times in 0 Posts
| The url works fine in my PC.
And i am not testing this in my device simulator as it pops up an error "Could not find service book entry"
My device 8100 have enterprise service activated. So i tried on that.
The execution(at inputStream.read(data)) ends with an uncaught exception "The applcation connection example is is not responding. Process terminated."
Please let me know, how can i fix this.
Many thanks indeed for your reply.
__________________ CHEERIO, Paramasivan S. | | Offline
| |
07-24-2008, 03:18 PM
|
#6 (permalink)
| | Knows Where the Search Button Is
Join Date: Apr 2008 Location: New Cumberland, PA Model: 9530 OS: 5.0.0.732 Carrier: Verizon
Posts: 34
Post Thanks: 0 Thanked 0 Times in 0 Posts
| I have a program that reads information from the World of Warcraft Armory. Below is my connection thread. Maybe it'll help some. Code: class ServerConnection extends Thread {
// Declare variables
HttpConnection http = null;
InputStream httpInput = null;
DataOutputStream httpOutput = null;
String url = "http://cilraaz.thetimekillers.com/BlackBerry/WowArmory/WowArmory.php?r=";
String host = "cilraaz.thetimekillers.com";
String response = "";
String character;
String server;
String str1;
boolean mdsSetting;
WowArmoryScreen screen;
// Method called by submit button
public ServerConnection(String character, String server, boolean mds, WowArmoryScreen screen) {
str1 = server;
str1 = str1.replace(' ', '+');
mdsSetting = mds;
this.character = character;
this.server = str1;
this.screen = screen;
}
public void run() {
try {
byte[] data = character.getBytes();
int dataLength = data.length;
url += server;
url += "&c=";
url += character;
url += appendConnectionString();
if (url.indexOf("NOIPPP") > -1) {
screen.updateScreen("No IPPP Service Books found");
} else {
// Create connection
http = (HttpConnection) Connector.open(url);
http.setRequestMethod(HttpConnection.POST);
http.setRequestProperty("Content-Type", "text/plain; charset=utf-8");
http.setRequestProperty("Host", host);
http.setRequestProperty("Content-Length", Integer.toString(dataLength));
http.setRequestProperty("Expect", "100-continue");
// Output stream
httpOutput = http.openDataOutputStream();
httpOutput.write(data, 0, dataLength);
// Input stream
httpInput = http.openInputStream();
// Create buffer for information being received
StringBuffer buffer = new StringBuffer();
// Read until no data is left
int ch = 0;
while (ch != -1) {
ch = httpInput.read();
buffer.append((char) ch);
}
// Push information to the response screen
response = buffer.toString();
screen.updateScreen(response);
}
} catch (IOException ex) {
ex.printStackTrace();
screen.updateScreen(ex.toString());
}
}
String appendConnectionString() {
// Check to see if the useMDS box is checked
if (mdsSetting) {
// It is -- Use MDS
return ";deviceside=false";
} else {
// It isn't -- Use APN
return ";deviceside=true";
}
}
} | | Offline
| |
07-24-2008, 10:42 PM
|
#7 (permalink)
| | New Member
Join Date: Aug 2007 Model: 8100 PIN: N/A Carrier: 1
Posts: 14
Post Thanks: 0 Thanked 0 Times in 0 Posts
| HTTP connection thro' MDS Quote:
Originally Posted by Cilraaz I have a program that reads information from the World of Warcraft Armory. Below is my connection thread. Maybe it'll help some. Code: class ServerConnection extends Thread {
// Declare variables
HttpConnection http = null;
InputStream httpInput = null;
DataOutputStream httpOutput = null;
String url = "http://cilraaz.thetimekillers.com/BlackBerry/WowArmory/WowArmory.php?r=";
String host = "cilraaz.thetimekillers.com";
String response = "";
String character;
String server;
String str1;
boolean mdsSetting;
WowArmoryScreen screen;
// Method called by submit button
public ServerConnection(String character, String server, boolean mds, WowArmoryScreen screen) {
str1 = server;
str1 = str1.replace(' ', '+');
mdsSetting = mds;
this.character = character;
this.server = str1;
this.screen = screen;
}
public void run() {
try {
byte[] data = character.getBytes();
int dataLength = data.length;
url += server;
url += "&c=";
url += character;
url += appendConnectionString();
if (url.indexOf("NOIPPP") > -1) {
screen.updateScreen("No IPPP Service Books found");
} else {
// Create connection
http = (HttpConnection) Connector.open(url);
http.setRequestMethod(HttpConnection.POST);
http.setRequestProperty("Content-Type", "text/plain; charset=utf-8");
http.setRequestProperty("Host", host);
http.setRequestProperty("Content-Length", Integer.toString(dataLength));
http.setRequestProperty("Expect", "100-continue");
// Output stream
httpOutput = http.openDataOutputStream();
httpOutput.write(data, 0, dataLength);
// Input stream
httpInput = http.openInputStream();
// Create buffer for information being received
StringBuffer buffer = new StringBuffer();
// Read until no data is left
int ch = 0;
while (ch != -1) {
ch = httpInput.read();
buffer.append((char) ch);
}
// Push information to the response screen
response = buffer.toString();
screen.updateScreen(response);
}
} catch (IOException ex) {
ex.printStackTrace();
screen.updateScreen(ex.toString());
}
}
String appendConnectionString() {
// Check to see if the useMDS box is checked
if (mdsSetting) {
// It is -- Use MDS
return ";deviceside=false";
} else {
// It isn't -- Use APN
return ";deviceside=true";
}
}
} | May i know the sample arguments for the below constructor
public ServerConnection(String character, String server, boolean mds, WowArmoryScreen screen)
Thanks!!!
__________________ CHEERIO, Paramasivan S. | | Offline
| |
07-28-2008, 10:01 AM
|
#8 (permalink)
| | Knows Where the Search Button Is
Join Date: Apr 2008 Location: New Cumberland, PA Model: 9530 OS: 5.0.0.732 Carrier: Verizon
Posts: 34
Post Thanks: 0 Thanked 0 Times in 0 Posts
| Quote:
May i know the sample arguments for the below constructor
public ServerConnection(String character, String server, boolean mds, WowArmoryScreen screen)
Thanks!!!
| The arguments are passed from the main screen. They are pulled from fields on the screen. Here's the full code: Code: /*******************************************************************************
* Copyright (C) 2008
* Jeremy Complese
* Complese Technologies
* http://www.complesetech.com
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place - Suite 330, Boston, MA 02111-1307, USA.
******************************************************************************/
package com.wowarmory;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.String;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import net.rim.device.api.system.Application;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.UiApplication.*;
import net.rim.device.api.ui.component.BasicEditField;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.CheckboxField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.Menu;
import net.rim.device.api.ui.component.RichTextField;
import net.rim.device.api.ui.component.SeparatorField;
import net.rim.device.api.ui.container.MainScreen;
/**
* @author Jeremy Complese
*
*/
// Main class
public class WowArmory extends UiApplication {
// Starting point
public static void main(String[] args) {
WowArmory wowarmory = new WowArmory();
wowarmory.enterEventDispatcher();
}
// Calls initial screen
public WowArmory() {
pushScreen(new WowArmoryScreen());
}
}
class WowArmoryScreen extends MainScreen {
// Declare my initial variables
private ResultsScreen _resultsScreen;
BasicEditField charName = new BasicEditField("Character Name: ", "", 20, BasicEditField.FILTER_DEFAULT);
BasicEditField serverName = new BasicEditField("Server Name: ", "", 20, BasicEditField.FILTER_DEFAULT);
CheckboxField useMDS = new CheckboxField("Use MDS: ", false);
ButtonField submitButton = new ButtonField("Submit", ButtonField.CONSUME_CLICK);
WowArmoryScreen screen = this;
// Main screen, including entries for Character/Server names
public WowArmoryScreen() {
// Create Label for title for main screen
LabelField mainTitle = new LabelField("WoW Armory - Enemy Information", LabelField.ELLIPSIS
| LabelField.USE_ALL_WIDTH);
// Set title to above label
setTitle(mainTitle);
// Add other items to screen
add(charName);
add(serverName);
add(new SeparatorField());
add(useMDS);
add(submitButton);
// Create functionality of submit button
submitButton.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
Thread postnameThread = new Thread(new ServerConnection(charName.getText(), serverName.getText(), useMDS.getChecked(), screen));
postnameThread.start();
}
});
}
// Function for screen updates
// (used when receiving input from HttpInput stream or
// exception from ServerConnection)
public void updateScreen(String _message) {
final String message = _message;
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
UiApplication.getUiApplication().pushScreen(new ResultsScreen(message));
}
});
}
// Move application to background if "escape" is pressed
public boolean onClose() {
Application.getApplication().requestBackground();
return true;
}
// Force exit via menu
public boolean onExit() {
int response = Dialog.ask(Dialog.D_YES_NO, "Are you sure you wish to quit?");
if (Dialog.YES == response) {
System.exit(0);
} else {
return true;
}
return super.onClose();
}
// Menu option to clear entry fields
private MenuItem _clearFields = new MenuItem("Clear Fields", 110, 10) {
public void run() {
charName.setText("");
serverName.setText("");
}
};
// Menu option to exit application
private MenuItem _closeMenu = new MenuItem("Exit", 200000, 10) {
public void run() {
onExit();
}
};
// Make my menu!
protected void makeMenu( Menu menu, int instance ) {
menu.add(_clearFields);
menu.add(_closeMenu);
}
}
// Results screen
class ResultsScreen extends MainScreen {
RichTextField resultsField = new RichTextField("", Field.READONLY | Field.FOCUSABLE);
public ResultsScreen(String _results) {
final String results = _results;
LabelField resultsTitle = new LabelField("Enemy Information", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
setTitle(resultsTitle);
resultsField.setText(results);
add(resultsField);
}
}
// http connection class
class ServerConnection extends Thread {
// Declare variables
HttpConnection http = null;
InputStream httpInput = null;
DataOutputStream httpOutput = null;
String url = "http://cilraaz.thetimekillers.com/BlackBerry/WowArmory/WowArmory.php?r=";
String host = "cilraaz.thetimekillers.com";
String response = "";
String character;
String server;
String str1;
boolean mdsSetting;
WowArmoryScreen screen;
// Method called by submit button
public ServerConnection(String character, String server, boolean mds, WowArmoryScreen screen) {
str1 = server;
str1 = str1.replace(' ', '+');
mdsSetting = mds;
this.character = character;
this.server = str1;
this.screen = screen;
}
public void run() {
try {
byte[] data = character.getBytes();
int dataLength = data.length;
url += server;
url += "&c=";
url += character;
url += appendConnectionString();
if (url.indexOf("NOIPPP") > -1) {
screen.updateScreen("No IPPP Service Books found");
} else {
// Create connection
http = (HttpConnection) Connector.open(url);
http.setRequestMethod(HttpConnection.POST);
http.setRequestProperty("Content-Type", "text/plain; charset=utf-8");
http.setRequestProperty("Host", host);
http.setRequestProperty("Content-Length", Integer.toString(dataLength));
http.setRequestProperty("Expect", "100-continue");
// Output stream
httpOutput = http.openDataOutputStream();
httpOutput.write(data, 0, dataLength);
// Input stream
httpInput = http.openInputStream();
// Create buffer for information being received
StringBuffer buffer = new StringBuffer();
// Read until no data is left
int ch = 0;
while (ch != -1) {
ch = httpInput.read();
buffer.append((char) ch);
}
// Push information to the response screen
response = buffer.toString();
screen.updateScreen(response);
}
} catch (IOException ex) {
ex.printStackTrace();
screen.updateScreen(ex.toString());
}
}
String appendConnectionString() {
// Check to see if the useMDS box is checked
if (mdsSetting) {
// It is -- Use MDS
return ";deviceside=false";
} else {
// It isn't -- Use APN
return ";deviceside=true";
}
}
} | | Offline
| |
07-28-2008, 03:37 PM
|
#9 (permalink)
| | Thumbs Must Hurt
Join Date: Apr 2006 Location: Boston Model: 8900 Carrier: AT&T
Posts: 98
Post Thanks: 0 Thanked 0 Times in 0 Posts
| Hi!
One thing to keep in mind: HTTP connections should be encapsulated in a thread separate from the main event thread. Because network connectivity and activity and stuff takes a "relatively-significant" amount of time to process, certain networking calls will "block" (halt until data comes in, among other things), which means the OS is prevented from performing other device-event-based tasks/operations. Which the OS can get persnickety about. If the HTTP-connection/transmission/reception code is in a separate thread, it can go off into la-la-land and the OS isn't going to care. That may be why your uncaught exception error.
Other things to think about:
1. It's probably trivial, but you're usually better off compiling and building your BB app with a JDE version that is similar to the device OS version. Keep that in mind. So if your device is OS 4.0.2 (I'm assuming this is a mistype, because the 8100 shipped when OS 4.1 was latest-and-greatest), you would want to use JDE 4.0 or 4.1 - if your device is OS 4.2, you would want to use JDE 4.1 or 4.2 or 4.3.
2. The MDS simulator acts as a "gateway" between the device simulators and the network that the PC is connected to. If you're at home using a broadband internet connection, and you're not doing anything really interesting with your firewall/router, the MDS is probably good to go and should just act as a router for your device simulator. But if you're behind a corporate firewall and/or a proxy, your MDS will need to be configured to deal with that. As hrbuckley mentioned, try to connect to something, even "yahoo.com", using the browser on the simulator with the MDS running (just to be safe, launch the MDS simulator first, wait until it's settled down, then launch the device simulator). The simulator browser should display the yahoo page, AND you should see lots of print output on the command-line screen governing the MDS activity. If you don't get the yahoo page on the simulator browser, or if there's no activity on the MDS command-line screen, something is misbehaving. There's a file called "rimpublic.property" in the MDS config directory - it contains settings that the MDS simulator uses to find the network gateway and any proxy information that's needed to make HTTP connections (my employer requires every HTTP connection to go through a proxy server, and we had to configure MDS simulator to know about this, otherwise nothing would get through).
Good luck!
Cheers,
karl
__________________
Karl G. Kowalski
---------------
Owns a RAZR
Develops for BlackBerry
So next phone will be........an iPhone 3G!
| | Offline
| |
08-05-2008, 01:03 PM
|
#10 (permalink)
| | New Member
Join Date: Aug 2007 Model: 8100 PIN: N/A Carrier: 1
Posts: 14
Post Thanks: 0 Thanked 0 Times in 0 Posts
| Quote:
Originally Posted by Cilraaz The arguments are passed from the main screen. They are pulled from fields on the screen. Here's the full code: Code: /*******************************************************************************
* Copyright (C) 2008
* Jeremy Complese
* Complese Technologies
* http://www.complesetech.com
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place - Suite 330, Boston, MA 02111-1307, USA.
******************************************************************************/
package com.wowarmory;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.String;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import net.rim.device.api.system.Application;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.UiApplication.*;
import net.rim.device.api.ui.component.BasicEditField;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.CheckboxField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.Menu;
import net.rim.device.api.ui.component.RichTextField;
import net.rim.device.api.ui.component.SeparatorField;
import net.rim.device.api.ui.container.MainScreen;
/**
* @author Jeremy Complese
*
*/
// Main class
public class WowArmory extends UiApplication {
// Starting point
public static void main(String[] args) {
WowArmory wowarmory = new WowArmory();
wowarmory.enterEventDispatcher();
}
// Calls initial screen
public WowArmory() {
pushScreen(new WowArmoryScreen());
}
}
class WowArmoryScreen extends MainScreen {
// Declare my initial variables
private ResultsScreen _resultsScreen;
BasicEditField charName = new BasicEditField("Character Name: ", "", 20, BasicEditField.FILTER_DEFAULT);
BasicEditField serverName = new BasicEditField("Server Name: ", "", 20, BasicEditField.FILTER_DEFAULT);
CheckboxField useMDS = new CheckboxField("Use MDS: ", false);
ButtonField submitButton = new ButtonField("Submit", ButtonField.CONSUME_CLICK);
WowArmoryScreen screen = this;
// Main screen, including entries for Character/Server names
public WowArmoryScreen() {
// Create Label for title for main screen
LabelField mainTitle = new LabelField("WoW Armory - Enemy Information", LabelField.ELLIPSIS
| LabelField.USE_ALL_WIDTH);
// Set title to above label
setTitle(mainTitle);
// Add other items to screen
add(charName);
add(serverName);
add(new SeparatorField());
add(useMDS);
add(submitButton);
// Create functionality of submit button
submitButton.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
Thread postnameThread = new Thread(new ServerConnection(charName.getText(), serverName.getText(), useMDS.getChecked(), screen));
postnameThread.start();
}
});
}
// Function for screen updates
// (used when receiving input from HttpInput stream or
// exception from ServerConnection)
public void updateScreen(String _message) {
final String message = _message;
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
UiApplication.getUiApplication().pushScreen(new ResultsScreen(message));
}
});
}
// Move application to background if "escape" is pressed
public boolean onClose() {
Application.getApplication().requestBackground();
return true;
}
// Force exit via menu
public boolean onExit() {
int response = Dialog.ask(Dialog.D_YES_NO, "Are you sure you wish to quit?");
if (Dialog.YES == response) {
System.exit(0);
} else {
return true;
}
return super.onClose();
}
// Menu option to clear entry fields
private MenuItem _clearFields = new MenuItem("Clear Fields", 110, 10) {
public void run() {
charName.setText("");
serverName.setText("");
}
};
// Menu option to exit application
private MenuItem _closeMenu = new MenuItem("Exit", 200000, 10) {
public void run() {
onExit();
}
};
// Make my menu!
protected void makeMenu( Menu menu, int instance ) {
menu.add(_clearFields);
menu.add(_closeMenu);
}
}
// Results screen
class ResultsScreen extends MainScreen {
RichTextField resultsField = new RichTextField("", Field.READONLY | Field.FOCUSABLE);
public ResultsScreen(String _results) {
final String results = _results;
LabelField resultsTitle = new LabelField("Enemy Information", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
setTitle(resultsTitle);
resultsField.setText(results);
add(resultsField);
}
}
// http connection class
class ServerConnection extends Thread {
// Declare variables
HttpConnection http = null;
InputStream httpInput = null;
DataOutputStream httpOutput = null;
String url = "http://cilraaz.thetimekillers.com/BlackBerry/WowArmory/WowArmory.php?r=";
String host = "cilraaz.thetimekillers.com";
String response = "";
String character;
String server;
String str1;
boolean mdsSetting;
WowArmoryScreen screen;
// Method called by submit button
public ServerConnection(String character, String server, boolean mds, WowArmoryScreen screen) {
str1 = server;
str1 = str1.replace(' ', '+');
mdsSetting = mds;
this.character = character;
this.server = str1;
this.screen = screen;
}
public void run() {
try {
byte[] data = character.getBytes();
int dataLength = data.length;
url += server;
url += "&c=";
url += character;
url += appendConnectionString();
if (url.indexOf("NOIPPP") > -1) {
screen.updateScreen("No IPPP Service Books found");
} else {
// Create connection
http = (HttpConnection) Connector.open(url);
http.setRequestMethod(HttpConnection.POST);
http.setRequestProperty("Content-Type", "text/plain; charset=utf-8");
http.setRequestProperty("Host", host);
http.setRequestProperty("Content-Length", Integer.toString(dataLength));
http.setRequestProperty("Expect", "100-continue");
// Output stream
httpOutput = http.openDataOutputStream();
httpOutput.write(data, 0, dataLength);
// Input stream
httpInput = http.openInputStream();
// Create buffer for information being received
StringBuffer buffer = new StringBuffer();
// Read until no data is left
int ch = 0;
while (ch != -1) {
ch = httpInput.read();
buffer.append((char) ch);
}
// Push information to the response screen
response = buffer.toString();
screen.updateScreen(response);
}
} catch (IOException ex) {
ex.printStackTrace();
screen.updateScreen(ex.toString());
}
}
String appendConnectionString() {
// Check to see if the useMDS box is checked
if (mdsSetting) {
// It is -- Use MDS
return ";deviceside=false";
} else {
// It isn't -- Use APN
return ";deviceside=true";
}
}
} | The above code works perfectly for me in simulator, but not in my 8100.
Simula
When i run this in device, it gives me an error saying "Bad DNS Address"
with checking the "Use MDS" box, it gives me an error saying "Invalid URL parameter"
Please let me know, what i should do to fix this.
Many thanks buddy!!!
__________________ CHEERIO, Paramasivan S. | | Offline
| |
12-03-2008, 05:09 PM
|
#11 (permalink)
| | New Member
Join Date: Dec 2008 Model: Bold PIN: N/A Carrier: ATT
Posts: 7
Post Thanks: 0 Thanked 0 Times in 0 Posts
| Did you get this worked? Paramasivan,
did you get your code work? I see the same problem with my BB Bold.
The Connector.open(url) time out doesn't happen in the simulator,only on the hand held device. I tried deviceside=true and deviceside=false but no help.
I have the APN also set, I guess correctly.
-Guna Quote:
Originally Posted by paramasivan Hello,
I am a BB app. developer. i created an application to work on my BlackBerry 8100.
I use JDE 4.0.2 . I have created one button on screen. When i click that button HTTP request is send to corresponding URL("https://xxx.xxx.xxx") Then I never get the response from the sever. I run my app. in JDE simulator is not connecting the internet . Its take some of time to run my app. after that i get the timeout message '120000' What can i do ...
I tried my application some possible way
1)thro' TCP and WAp, but not works as my service provider is hesitating to give the APN username, password, WAPGatewayIP
My last try is ....
try {
HttpConnection httpConnection = (HttpConnection)Connector.open("https://xxx.xxx.xxx");
httpConnection.setRequestMethod(HttpConnection.POS T);
InputStream inputStream = httpConnection.openInputStream();
int len = (int)httpConnection.getLength();
if (len > 0) {
byte[] data = new byte[len];
int actual = inputStream.read(data);
//process(data);
}
else {
int ch;
while ((ch = inputStream.read()) != -1) {
//process((byte)ch);
}
}
}
catch(IOException e) {
Dialog.alert(e.toString());
}
execution stops at
inputStream.read(data)
Please tell me a solution.
Thanks!!! | | | Offline
| |
12-03-2008, 08:44 PM
|
#12 (permalink)
| | New Member
Join Date: Dec 2008 Model: Curve PIN: N/A Carrier: Verizon
Posts: 2
Post Thanks: 0 Thanked 0 Times in 0 Posts
| I wrote an HTTPClient recently that works. As stated previously in this post, make sure that you have the MDS server enabled. Check source code: Code: import java.io.InputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.StreamConnection;
public class HTTPClient {
public static String getPage(String url) {
String response = "";
try {
StreamConnection s = (StreamConnection)Connector.open(url);
InputStream input = s.openInputStream();
byte[] data = new byte[256];
int len = 0;
StringBuffer raw = new StringBuffer();
while( -1 != (len = input.read(data))) {
raw.append(new String(data, 0, len));
}
response = raw.toString();
input.close();
s.close();
} catch(Exception e) { }
return response;
}
}
Last edited by criccomini : 12-03-2008 at 08:45 PM.
Reason: Adding code block
| | Offline
| |
12-30-2008, 01:02 AM
|
#13 (permalink)
| | New Member
Join Date: Feb 2008 Model: 8100 PIN: N/A Carrier: Airtel
Posts: 2
Post Thanks: 0 Thanked 0 Times in 0 Posts
| HTTPConnection Through MDS Hi folks,
I am also getting the issue with the same,
I want to confirm that if i am using "Deviceside=false" in my Application, then am i need any signing or business with RIM to do this communication?
Regards,
Nagarajan. K | | Offline
| |
12-30-2008, 06:37 AM
|
#14 (permalink)
| | Talking BlackBerry Encyclopedia
Join Date: Oct 2006 Model: 7103 Carrier: Verizon
Posts: 259
Post Thanks: 0 Thanked 0 Times in 0 Posts
| according to the api the httpConnection class with which you would use a String url is not a class that requires signing.
Likely though, if you do almost anything more interesting than accessing data and displaying flat text, you will use a class that requires signing. That requires code signing keys available from RIM for 20$ u.s. | | Offline
| |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | |