BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 06-03-2008, 10:09 AM   #1
incal
New Member
 
Join Date: Jun 2008
Model: 8100
PIN: N/A
Carrier: vodafone
Posts: 10
Default HTTP Connection problem

Please Login to Remove!

Hallo,
I am new of this forum, my name is Maurizio I am a developer in one small society, I'm sorry for my English.
I am developing an application for mobile device on a
BlackBerry Pearl8100, with the standard sun api.I have problem to connect my midlet with a web server. The code is like this:
........................
try {
http = (HttpConnection) Connector.open(url);
http.setRequestMethod(HttpConnection.GET);

if (http.getResponseCode() == HttpConnection.HTTP_OK) {
.......

every time occurr a "java.io.IOException, Unable to Open Connection"; considering that the BlackBerry asks me it asks the consent for the hit the network.
Any suggestion?, thanks in advance,
Maurizio
Offline  
Old 06-03-2008, 10:45 AM   #2
simon.hain
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Default

do you use the simulator? if yes, did you start the MDS simulator, too?
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 06-03-2008, 12:33 PM   #3
incal
New Member
 
Join Date: Jun 2008
Model: 8100
PIN: N/A
Carrier: vodafone
Posts: 10
Default

I don't use the simulator
Offline  
Old 06-03-2008, 03:43 PM   #4
incal
New Member
 
Join Date: Jun 2008
Model: 8100
PIN: N/A
Carrier: vodafone
Posts: 10
Default

I have try the code on simulator and all work fine, what I must do on the device?
Offline  
Old 06-05-2008, 04:46 AM   #5
incal
New Member
 
Join Date: Jun 2008
Model: 8100
PIN: N/A
Carrier: vodafone
Posts: 10
Default

please don't live me alone...
Offline  
Old 06-05-2008, 09:13 AM   #6
EmilieL
Thumbs Must Hurt
 
Join Date: Apr 2008
Model: 7100T
PIN: N/A
Carrier: idk
Posts: 84
Default

What kind of URL are you trying to open?
__________________
Stop telling me what it can do...
Show me how to make it do it!!!!
Offline  
Old 06-05-2008, 11:30 AM   #7
incal
New Member
 
Join Date: Jun 2008
Model: 8100
PIN: N/A
Carrier: vodafone
Posts: 10
Default

A http url like this: "http://www.hostname.it/gps/RegisterData.php5?".
The applications installed on my BB like Opera, googlemaps, maps alls work fine.
the code:
Code:
try {
			
			http = (HttpConnection) Connector.open(url,Connector.READ_WRITE,true);
			// open the connection and extract the data
			if (http == null)
				midlet.updateStatus("Unable to create connection");
			
			s = (StreamConnection) Connector.open(url);
			http = (HttpConnection) s;
			midlet.updateStatus("Connesso con:" + http.getHost());			
			// 1) Send request method
			http.setRequestMethod(HttpConnection.GET);
			// 2) Send header information - none
			// 3) Send body/data - data is at the end of URL			
			midlet.updateStatus("request method set");
			//set the content length of the message that you want to send

			http.setRequestProperty("Content-Length", Integer.toString(dati.length()));

			// obtain DataOutputStream for sending the request string

			java.io.DataOutputStream dos = http.openDataOutputStream();

			midlet.updateStatus("open output stream");
			midlet.updateStatus("length:" + dati.length());
			// send request string to server
			//send the message through the dataoutputstream
			dos.write(dati.getBytes());

			midlet.updateStatus("sending to server the string:" + dati); 
			
			if (http.getResponseCode() == HttpConnection.HTTP_OK) {
				 //is this html?
                String ctype = http.getHeaderField(HEADER_CONTENTTYPE);
                midlet.updateStatus("Content type:" + ctype);
                boolean htmlContent = (ctype != null && ctype.equals(CONTENTTYPE_TEXTHTML));				
				// dichiariamo un array di byte vuoto
				byte servletData[] = null;
				
				input = http.openInputStream();
				// Cerchiamo di ottenere la lunghezza in byte della response
				int length = (int) http.getLength();
				// Se la lunghezza della response e nota:
				if (length > 0) {
					
					servletData = new byte[length];
					// Effettuiamo la lettura dei dati dall'InputStream
					// sull'array
					input.read(servletData);
					// Appendiamo al form i dati di output
					midlet.updateStatus("\nRisposta del SERVER\n"
							+ new String(servletData));

					// Se la response e'® nulla:
				} else if (length == 0) {
					midlet
							.updateStatus("\nLettura risposta del SERVER fallita");
					// Se la lunghezza non e'® nota:
				} else {
					// Istanziamo un oggetto ByteArrayOutputStream
					ByteArrayOutputStream output = new ByteArrayOutputStream();
					/***********************************************************
					 * Leggiamo l'InputStream e inseriamo il contenuto nel
					 * ByteArrayOutputStream con il metodo write() /
					 **********************************************************/
					int ch;
					while ((ch = input.read()) != -1)
						output.write(ch);
					// Valorizziamo l'array di bytes
					servletData = output.toByteArray();
					// Appendiamo al form i dati di output
					midlet.updateStatus("\nRisposta del SERVER\n"
							+ new String(servletData));
					// Chiudiamo il ByteArrayOutputStream
					output.close();
				}
			} else {
				// Gestione dei vari http status code diversi da 200
				midlet.updateStatus("Http exit code: " + http.getResponseCode()
						+ "\n");
			}

			http.close();
			input.close();
		} catch (Exception e) {
			// Gestione degli errori di connessione
			midlet.updateStatus("Errore di rete:\n");
			midlet.updateStatus("Type: " + e);
			midlet.updateStatus("Messaggio: " + e.getMessage());
		} finally {
			// Chiudiamo le risorse allocate.
			if (input != null)
				input.close();
			if (http != null)
				http.close();

		}
i have attemp with and without 'deviceside=true', the problem result unchanged.
Thank's for help
Offline  
Old 06-05-2008, 11:47 AM   #8
EmilieL
Thumbs Must Hurt
 
Join Date: Apr 2008
Model: 7100T
PIN: N/A
Carrier: idk
Posts: 84
Default

The code looks good to me...
Have you tried to modify the security permissions of the application?
Might wanna try that!

On the handheld, go to options->advanced option-> applications
and select your application
click edit default permissions and allow everything (if you can)
__________________
Stop telling me what it can do...
Show me how to make it do it!!!!
Offline  
Old 06-05-2008, 01:20 PM   #9
incal
New Member
 
Join Date: Jun 2008
Model: 8100
PIN: N/A
Carrier: vodafone
Posts: 10
Default

i have checked the permission for my application are everything is allowed......
I am very confused and I don't know if I must to set up other things
Offline  
Old 06-06-2008, 06:02 PM   #10
mateo666
New Member
 
Join Date: May 2008
Model: 8830
PIN: N/A
Carrier: bell
Posts: 11
Default

Hi i'm doing this with post and it is working fine. i'm just sending some headers though. Glad to share what i have with you.

try {
_conn = (HttpConnection) Connector.open(_url);
_conn.setRequestMethod(HttpConnection.POST);
_conn.setRequestProperty("Content-Type", "text/plain; charset=utf-8");
_conn.setRequestProperty("Expect", "100-continue");
_conn.setRequestProperty("GpsCoordinate", Double.toString(sendingPoint.getQualifiedCoordinat es().getLatitude()) + "," + Double.toString(sendingPoint.getQualifiedCoordinat es().getLongitude()));
_conn.setRequestProperty("GpsUser", Integer.toHexString(DeviceInfo.getDeviceId()));

responseCode = _conn.getResponseCode();
if (responseCode != HttpConnection.HTTP_OK) {
throw new IOException("Not able to send.");
}
sendingPoint=null;
} catch (IOException e) {
} finally {
try {
if(_out!=null)
_out.close();
if(_conn!=null)
_conn.close();
} catch (IOException ioe) {
//no-op - we don't care on close
}
}

If you know a good javascript code to get the coordinates in a web form i would be glad to have a look on it as i'm trying to force a refresh of the coordinates in the browser and its not working:(

Hope this helps
mateo
Offline  
Old 06-09-2008, 05:20 AM   #11
incal
New Member
 
Join Date: Jun 2008
Model: 8100
PIN: N/A
Carrier: vodafone
Posts: 10
Default

Thanks very much for reply, i will try your code, I hope can help me even if think that I have a connection problem....
Offline  
Old 06-09-2008, 12:19 PM   #12
bestenator
New Member
 
Join Date: Jun 2008
Model: 8100
PIN: N/A
Carrier: telcel
Posts: 1
Default Hola amigo

Creo que tu habla es hispana asi que... sorry for the english speakers... jaja

Mira tu problema es que no tienes configuarada la APN en la Blackberry, que esto está en:

Options/Advanced Options/ TCP

Necesitas llenar los datos de la operadora, PERO OJO!! estos datos son para salir directo por internet, esto es, no usar la BIS-B (Tarifa plana) y se traduce en un costo por kb transferido.

Configurando tu APN seguro estableceras la conexión, pero para salir por la tarifa plana necesitas comunicarte directamente con personal de Research In Motion (Solo en inglés) y hacer una alianza para que tu aplicación salga por la tarifa plana...

Offline  
Old 06-10-2008, 10:11 AM   #13
jeromeng
Knows Where the Search Button Is
 
Join Date: Jun 2008
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 26
Cool HTTP connection problem

Hello Simon,
I had a similar problem but solved it by putting my carrier specific APN, username and password in Options -> Advanced Options -> TCP.

How were u able to connect to the internet via ur simulator? Mine is showing lowercase edge/grps, the simulator browser gave the error below:

"Unable to connect to the selected Mobile Data Service, please try again later. If the problem persists please contact your administrator."

The application gave this error:

"java.io.InterruptedIOException: Local connection timed out after ~ 120000"

My web proxy server requires authentication, this may be the problem but I'm not very sure. Pls assist.
Offline  
Old 06-10-2008, 01:06 PM   #14
roryf
New Member
 
Join Date: May 2008
Model: 8130
PIN: N/A
Carrier: T-Mobile
Posts: 9
Default

Do you have the MDS simulator running in the background? this is required for data access on the device simulators.
Offline  
Old 06-11-2008, 03:00 AM   #15
jeromeng
Knows Where the Search Button Is
 
Join Date: Jun 2008
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 26
Cool HTTP Connection problem

Quote:
Originally Posted by roryf View Post
Do you have the MDS simulator running in the background? this is required for data access on the device simulators.

Yes roryf, I always run the MDS black screen before running the simulator. Below is the last few lines of output from the MDS when I try to use the browser to access the internet. Pls let me know where i am making a mistake.

<2008-06-11 08:52:01.301 BST>:[112]:<MDS-CS_MDS>:<DEBUG>:<LAYER = SCM, EVENT = A
vailable threads in DefaultJobPool = 9 running JobRunner: DefaultJobRunner-4>
<2008-06-11 08:52:01.304 BST>:[113]:<MDS-CS_MDS>:<DEBUG>:<LAYER = IPPP, HANDLER
= BSM, DEVICEPIN = 2100000a, Successful Connect>
<2008-06-11 08:52:01.307 BST>:[114]:<MDS-CS_MDS>:<DEBUG>:<LAYER = SCM, EVENT = F
inished JobRunner: DefaultJobRunner-4, available threads in DefaultJobPool = 10,
time spent = 3ms>
<2008-06-11 08:52:01.321 BST>:[115]:<MDS-CS_MDS>:<DEBUG>:<LAYER = IPPP, EVENT =
QueueSize, DEVICEPIN = 2100000a, SendingQueueSize = 4>
<2008-06-11 08:52:01.325 BST>:[118]:<MDS-CS_MDS>:<DEBUG>:<LAYER = IPPP, EVENT =
Sending, TAG = 984940548, DEVICEPIN = 2100000a, VERSION = 16, CONNECTIONID = 164
1838676, SEQUENCE = 0, TYPE = DISCONNECT-ORDER, SIZE = 19>
<2008-06-11 08:52:01.337 BST>:[119]:<MDS-CS_MDS>:<DEBUG>:<LAYER = SCM, EVENT = D
evice connections: AVG latency (msecs)16>
<2008-06-11 08:52:01.342 BST>:[120]:<MDS-CS_MDS>:<DEBUG>:<LAYER = IPPP, EVENT =
RemovedReceivingQueue, DEVICEPIN:CONNECTIONID = 2100000a:1641838676, ReceivingQu
eueSize = 0>
<2008-06-11 08:52:41.415 BST>:[121]:<MDS-CS_MDS>:<DEBUG>:<LAYER = IPPP, EVENT =
Receiving, TAG = -462740068, DEVICEPIN = 2100000a, VERSION = 16, CONNECTIONID =
1641838676, SEQUENCE = 0, TYPE = CONNECTION-REQUEST, CONNECTIONHANDLER = bsm, PR
OTOCOL = TCP, PARAMETERS = [bsmhandler:0], SIZE = 251>
<2008-06-11 08:55:36.657 BST>:[124]:<MDS-CS_MDS>:<DEBUG>:<LAYER = IPPP, EVENT =
CreatedReceivingQueue, DEVICEPIN:CONNECTIONID = 2100000a:1641838676, ReceivingQu
eueSize = 1>
<2008-06-11 08:55:36.662 BST>:[125]:<MDS-CS_MDS>:<DEBUG>:<LAYER = IPPP, EVENT =
StartExecuting, TAG = -462740068, DEVICEPIN = 2100000a, VERSION = 16, CONNECTION
ID = 1641838676, SEQUENCE = 0, TYPE = CONNECTION-REQUEST, CONNECTIONHANDLER = bs
m, PROTOCOL = TCP, PARAMETERS = [bsmhandler:0], SIZE = 251>
<2008-06-11 08:55:36.678 BST>:[126]:<MDS-CS_MDS>:<DEBUG>:<LAYER = IPPP, EVENT =
EndExecuting, TAG = -462740068, DEVICEPIN = 2100000a, VERSION = 16, CONNECTIONID
= 1641838676, SEQUENCE = 0, TYPE = CONNECTION-REQUEST, CONNECTIONHANDLER = bsm,
PROTOCOL = TCP, PARAMETERS = [bsmhandler:0], SIZE = 251>
<2008-06-11 08:55:23.044 BST>:[123]:<MDS-CS_MDS>:<DEBUG>:<LAYER = SCM, EVENT = S
tatistics save task started>
<2008-06-11 08:55:03.082 BST>:[122]:<MDS-CS_MDS>:<DEBUG>:<LAYER = SCM, EVENT = E
xpire records from device storage that are expired or older than 0 hours; 6>
<2008-06-11 08:55:36.689 BST>:[127]:<MDS-CS_MDS>:<DEBUG>:<LAYER = SCM, EVENT = A
vailable threads in DefaultJobPool = 9 running JobRunner: DefaultJobRunner-5>
<2008-06-11 08:55:36.720 BST>:[128]:<MDS-CS_MDS>:<DEBUG>:<LAYER = SCM, EVENT = E
xpire records process ended; 6>
<2008-06-11 08:55:36.724 BST>:[129]:<MDS-CS_MDS>:<DEBUG>:<LAYER = IPPP, HANDLER
= BSM, DEVICEPIN = 2100000a, Successful Connect>
<2008-06-11 08:55:36.729 BST>:[130]:<MDS-CS_MDS>:<DEBUG>:<LAYER = SCM, EVENT = F
inished JobRunner: DefaultJobRunner-5, available threads in DefaultJobPool = 10,
time spent = 18ms>
<2008-06-11 08:55:36.739 BST>:[131]:<MDS-CS_MDS>:<DEBUG>:<LAYER = IPPP, EVENT =
QueueSize, DEVICEPIN = 2100000a, SendingQueueSize = 5>
<2008-06-11 08:55:36.754 BST>:[134]:<MDS-CS_MDS>:<DEBUG>:<LAYER = SCM, EVENT = D
evice connections: AVG latency (msecs)16>
<2008-06-11 08:55:36.759 BST>:[135]:<MDS-CS_MDS>:<DEBUG>:<LAYER = IPPP, EVENT =
RemovedReceivingQueue, DEVICEPIN:CONNECTIONID = 2100000a:1641838676, ReceivingQu
eueSize = 0>
<2008-06-11 08:55:36.746 BST>:[132]:<MDS-CS_MDS>:<DEBUG>:<LAYER = SCM, EVENT = S
tatistics save task finished -- number of rows inserted:5>
Offline  
Old 06-11-2008, 04:15 AM   #16
jeromeng
Knows Where the Search Button Is
 
Join Date: Jun 2008
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 26
Default

I edited the rimpublic.property file in MDS/config/ with the information in the link below; this allows MDS to work behind a proxy server but it did not have any effect on my simulator. The error msg i keep getting on the browser indicates that the simulator can not connect to the MDS: "Unable to connect to the selected Mobile Data Service, please try again later."

Livelink - Redirection
Offline  
Old 06-11-2008, 04:20 AM   #17
incal
New Member
 
Join Date: Jun 2008
Model: 8100
PIN: N/A
Carrier: vodafone
Posts: 10
Default

Espanol:
Hola bestenator, tu dices que tengo che configurar la APN en la Blackberry, pero come va a ser que googlemaps y opera minibrowser se pudan connectar?

English:
Hi bestenator, you say me to set up the apn in the Blackberry but as it is possible that googlemaps an ioera mini browser they can be connected?

Last edited by incal; 06-11-2008 at 04:23 AM..
Offline  
Old 06-11-2008, 06:03 AM   #18
jeromeng
Knows Where the Search Button Is
 
Join Date: Jun 2008
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 26
Default

I created a JAVA_HOME environmental variable using the path to my jdk1.6 directory and can now access the web from the browser and my application on the default simulator (8120 pearl) that came with JDE 4.3 but still can not connect if I change the simulator on the JDE to any of the ones I downloaded and installed separately (8300 series).

Running the simulators externally to the JDE also did not work.

The app I am developing is meant to run on a curve 8310 handheld and I would prefer to simulate on it instead of the default pearl simulator.

Any ideas?
Offline  
Old 06-11-2008, 06:22 AM   #19
jeromeng
Knows Where the Search Button Is
 
Join Date: Jun 2008
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 26
Default

ITS IS WORKING NOW!!!!

This is what I did

1.Open the rimpublic.property file. The rimpublic.property file can be found at:

\Program Files\Research In Motion\BlackBerry JDE #.#.#\MDS\config

Then add or edit these http handlers

[HTTP HANDLER]
application.handler.http.proxyEnabled = true
application.handler.http.proxyHost= your_proxy_name_or_ip
application.handler.http.proxyPort=your_proxy_port
application.handler.http.proxyUser=your_username
application.handler.http.proxyPass=your_password

A more comprehensive procedure can be found at Livelink - Redirection

Note: You may ignore the last 2 entries but this means u will have to supply your username or password everytime the simulator wants to connect via the proxy server.



2. Make sure the APN in Options -> Advanced Options -> TCP is set to rim.net.gprs

3. Create a JAVA_HOME environmental variable and put the path of your java jdk, mine is C:\Program Files\Java\jdk1.6.0_04
Offline  
Old 06-12-2008, 03:44 AM   #20
incal
New Member
 
Join Date: Jun 2008
Model: 8100
PIN: N/A
Carrier: vodafone
Posts: 10
Default

Hi, I think that the target of the discussion has changed, I haven't problem to run a midlet on simulator but I have problem to connect to a remote server from device.
Offline  
Closed Thread



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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


MSA ALTAIR 4XR picture

MSA ALTAIR 4XR

$700.00



MSA altair 4X multi gas meter Monitor detector, O2,H2S,CO,LEL Charger calibrated picture

MSA altair 4X multi gas meter Monitor detector, O2,H2S,CO,LEL Charger calibrated

$340.00



MSA Altair 5 Gas Detector  picture

MSA Altair 5 Gas Detector

$98.99



MSA Altair 5X Gas Detector Meter *Recently Calibrated and 30 Day Warranty* picture

MSA Altair 5X Gas Detector Meter *Recently Calibrated and 30 Day Warranty*

$795.00



MSA 10042621 Altair 5X Sampling Probe Straight Air-Line 1' Color Black (E2) picture

MSA 10042621 Altair 5X Sampling Probe Straight Air-Line 1' Color Black (E2)

$295.00



Msa Altair 4XR picture

Msa Altair 4XR

$372.60







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