J2ME, HttpConnection and Proxy

From: Marko (marko.horvat_at_hznet.hr)
Date: 10/11/04


Date: 11 Oct 2004 04:46:47 -0700

I'm having big trouble with a small J2ME app. In a nutshell.. MIDlet
just doesn't want to pass HTTP requests through a proxy.

Needless to say I've set up correctly all proxy's parameters in the
Toolkit's preferences. As a matter of fact, I'm using the same proxy
to post this message.

I'm using standard J2ME code for sending HTTP GET and POST requests.
Nothing fancy. Also, my proxy doesn't require authentication.

To make the matters worse, the same small J2ME app. won't work on my
Siemens S55 either. I've defined correctly Telecom's proxy parameters
in my mobile phone. For example, phone's WAP browser works perfectly
while MIDlet can't send a simple HTTP request.

This is the code I'm using:

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import java.io.*;

...

private void loadText(String sURL) {

HttpConnection c;
DataInputStream s;
            
String strMethodName = "loadText().";
            
try {
c = (HttpConnection)Connector.open(sURL, Connector.READ);
} catch (Exception ex) {
System.out.println("Error: " + strMethodName + "1");
System.out.println(ex.toString());
return;
}
                
try {
c.setRequestProperty("Content-Type","text/html"); // not neccessary
c.setRequestProperty("Content-Language", "en-US"); // not neccessary
c.setRequestProperty("Accept", "*/*"); // not neccessary
c.setRequestMethod(HttpConnection.GET);
} catch (Exception ex) {
System.out.println("Error: " + strMethodName + "2");
System.out.println(ex.toString());
return;
}
                
try {
s = new DataInputStream(c.openDataInputStream());
} catch (Exception ex) {
System.out.println("Error: " + strMethodName + "3");
System.out.println(ex.toString());
return;
}

try {
s.close();
c.close();
}
catch (Exception ex) {
System.out.println("Error: " + strMethodName + "4");
System.out.println(ex.toString());
return;
}

}

I know the code is OK because when I'm using direct connection to the
Internet, without proxy, J2ME HTTP request works just fine. I can send
GET and POST requests without any problems.

Error always occurs in:
s = new DataInputStream(c.openDataInputStream());

The error description is:
Exception: java/lang/ClassNotFoundException
Initializing class: 'com/sun/cldc/io/NetworkConnectionBase'
Initializing class: 'com/sun/cldc/io/j2me/socket/Protocol'
Exception: java/lang/ClassNotFoundException
Exception: java/io/IOException
Exception: java/io/IOException
Error: loadText().3
java.io.IOException: Error initializing HTTP tunnel connection:
HTTP/1.0 403 Forbidden
Server: squid/2.5.STABLE1
Mime-Version: 1.0
Date: Mon, 11 Oct 2004 11:13:21 GMT
Content-Type: text/html
Content-Length: 1053
Expires: Mon, 11 Oct 2004 11:13:21 GMT
X-Squid-Error: ERR_ACCESS_DENIED 0
X-Cache: MISS from wonderland.hznet.hr
X-Cache-Lookup: NONE from wonderland.hznet.hr:8001
Proxy-Connection: close
http://www.google.com/index.html

I've browsed through Google groups several times but I haven't found
any meaningful answers to this conundrum.

Please help!

Marko



Relevant Pages

  • Re: Exception: "WebServiceBindingAttribute is required on proxy classes"
    ... required on proxy classes". ... the exception may still be thrown even if you have decorated ... the proxy class inherits from ... > WebServiceBindingAttribute is required on proxy classes. ...
    (microsoft.public.dotnet.framework.webservices.enhancements)
  • problem of input field size in the GPO for the Proxy settings
    ... The problem is I can't enter as much information as I want in the exception ... I tried to not enter any info and unchek the proxy settings, ... pretty, but worked damned well) but it doesn't work: every gpo refresh, the ...
    (microsoft.public.windows.inetexplorer.ie6.ieak)
  • Re: IE 6 proxy settings
    ... specialty web server on a Windows 2000 server on ... I have bypass proxy for local computers set on ... If I add an exception for the server in IE 6 ...
    (microsoft.public.windows.server.sbs)
  • =?iso-8859-1?B?UmU6IFtMQU5HXSBNZXRob2RlbiD8YmVyZ2ViZW4=?=
    ... Baue einen Proxy mit dem Interface I, der alle passenden Empfaenger repraesentiert und dem ... public Object invoke(Object proxy, Method method, Objectargs) throws Throwable { ... Die erste Exception fliegt hier durch und bricht alles ab; ... Runnable proxy = broadCaster; // Wildcard erlaubt hier auch List ...
    (de.comp.lang.java)
  • Re: BizTalk Deployment Wizard and HTTP ports
    ... although I guess this has nothing to do with the proxy ... but rather with the credentialset when doing the actual HTTP request. ... > the SSO refers to the secure storage rather then a mapping between ... Ideally I'd like to use anonymous authentication and SSO for the proxy ...
    (microsoft.public.biztalk.general)