The Source for Java Technology Collaboration

Home » java.net Forums » Phone ME » phoneME Feature software

Thread: Http proxy issue

Welcome, Guest Help
Login Login
Guest Settings Guest Settings
This question is answered. Helpful answers available: 2. Correct answers available: 1.

Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 4 - Last Post: Jul 4, 2009 3:56 AM by: amak Threads: [ Previous | Next ]
tusharj9

Posts: 58
Http proxy issue
Posted: Dec 19, 2007 5:07 AM
 
  Click to reply to this thread Reply

Hi,
I able to successfully connect to any http server inside local network using phoneme MIDlets. But if I try to access external http server from behind the proxy, I'm getting error "111".
I have compiled pcsl library for using bsd/generic sockets, and testing phoneme inside scratchbox. Also tried to set http_proxy environment variable, but that too didn't help.

Any code change require to handle proxy at native layer ?

Regards,
Tushar

tusharj9

Posts: 58
Re: Http proxy issue
Posted: Dec 20, 2007 3:27 AM   in response to: tusharj9
 
  Click to reply to this thread Reply

Got this proxy issue resolved.
If you are behind the proxy then you need to modify midp/src/configuration/configuration_xml/share/properties.xml and set com.sun.midp.io.http.proxy to the address of your proxy.
Recompile and then your midlet should be able to connect to servers of outside network.

Regards,
Tushar

babaroga84

Posts: 1
Re: Http proxy issue
Posted: Jan 12, 2008 4:54 AM   in response to: tusharj9
 
  Click to reply to this thread Reply

Hello
I have sort of a same problem. I have a MIDlet application on one side and Apache proxy server on the other side. When I debug my application thorough Sun emulator everything works fine. When I port my app to my mobile device in 1 of 7 (proximately) attempts I successfully obtain a connection through Apache proxy. Basically, sometimes it works sometimes it doesn't. When it doesn't work I receive NullPointerException. Now, I see you managed to solve your problem. Could you tell me where to find that properties.xml file you referred to. It is really confusing because sometimes on my mobile device app works and sometimes it doesn't and that's driving me crazy!

Thanks for you reply in advance,
Sava

jannewmarch

Posts: 1
Re: Http proxy issue
Posted: Sep 2, 2008 10:31 PM   in response to: tusharj9
 
  Click to reply to this thread Reply

Setting the property com.sun.midp.io.http.proxy only works with certain proxies configured in certain ways. The usual way of talking to proxy is to open a TCP connection and then issue commands such as "GET url HTTP/1.1" where the url is the resource you really want to access. The proxy is expected to forward the request to the desired host and relay the response.

MIDP uses proxy tunneling instead (expired internet draft "Tunneling TCP based protocols through Web proxy servers"). It sends "CONNECT remote-host" to the proxy which should then open a stream to the remote host. If successful, the proxy returns "200 Okay" and the client can then send HTTP requests (or anything) over the stream. It does this so it can support HTTPS.

Many proxies refuse to handle CONNECT requests. e.g. my work proxy will only handle them for port 443, the normal HTTPS port. Solutions like "use another proxy" or "reconfigure the proxy" are not an option in our work environment.

Solution? Write your own HTTP client which can talk to proxies using the normal mechanism. It's not TOO hard to write a basic HTTP client, but it starts to get messy if you need to handle HTTP redirects, chunked documents, etc, etc. All the code to do that is already in MIDP and it wouldn't take much to support proxies as in the JDK. Sigh :-(

Here is some naive code, use at your own risk:

public InputStream getInputStreamFromURL(String url) {
InputStream is = null;
try {
// Are we using a proxy?
httpProxy = System.getProperty("com.sun.midp.io.http.proxy");
if (httpProxy == null) {
// No proxy, connect directly
HttpConnection conn = (HttpConnection)
Connector.open("http://" + url);
return conn.openInputStream();

} else {
/*
* we need to talk over TCP to the proxy and send HTTP requests to it
*/
SocketConnection conn = (SocketConnection)
Connector.open("socket://" + httpProxy);


OutputStream os = conn.openOutputStream();
DataOutputStream out = new DataOutputStream(os);

// send an HTTP 1.0 request so we get a simple reply
String request = "GET " + url + " HTTP/1.0\r\n\r\n";

byte[] b = request.getBytes();
for (int n = 0; n < b.length; n++)
out.writeByte(b[n]);

is = conn.openInputStream();
int ch;
//

amak

Posts: 1
Re: Http proxy issue
Posted: Jul 4, 2009 3:56 AM   in response to: tusharj9
 
  Click to reply to this thread Reply

Hi,

You may be interested in this database of open source HTTP proxies written in Java.

http://proxies.xhaus.com/java/

There's also a list of open source HTTP proxies written in python.

http://proxies.xhaus.com/python/

Regards,

Alan.




 XML java.net RSS