Problem with Proxy.Type.HTTP and Socket class

J

Jean-Paul

Hi everyone,

I am currently writing a Jabber client for some specific purposes.
Basically the Jabber client, instead of being used as a chat client
will be sending some specific data encapsulated in the Jabber
protocols. Now, users might decide to use the client by connecting
directly or if in a corporate environment (university, office, and so
on) they might be forced to pass through a proxy. So I wrote my code in
such a way that depending on what is in the XML configuration file, a
direct connection is made or the connection is made through a Proxy
server, be it HTTP or SOCKS. So far, I have had no luck with SOCKS but
at least I do not get the same Exception that I get when I use
Proxy.Type.HTTP. Here's a sample code:

// check whether the connection should occur through a proxy. If so,
get the settings and get
// the proxy's connection
InetSocketAddress proxyAddr = null;
Proxy proxy = null;

try {
if(configurator.useProxy()) {
proxyAddr = new InetSocketAddress(configurator.getProxyURI(),
Integer.parseInt(configurator.getProxyPort()));
if(configurator.getProxyType().equals("SOCKS")) {
proxy = new Proxy(Proxy.Type.SOCKS, proxyAddr);
} else if(configurator.getProxyType().equals("HTTP")) {
proxy = new Proxy(Proxy.Type.HTTP, proxyAddr);
}
}

socket = new Socket(proxy);

socket.connect(new InetSocketAddress(jabberHost, jabberHostPort));
} catch(UnknownHostException e) {
System.out.println("The following host " + jabberHost.toUpperCase()
+ " could not be found!");
e.printStackTrace();
return false;
} catch(Exception e) {
System.out.println("An IO error occured while trying to open a
socket to host " + jabberHost.toUpperCase() + " !");
e.printStackTrace();
return false;
}

When in the configuration file, the proxy is set as HTTP, at the line
that says "socket = new Socket(proxy), I get a
java.lang.IllegalArgumentException: Invalid Proxy. Which obviously is
not true as I am connecting via that same proxy right now. And no, it
is not a proxy that requires a username and a password. So far, I could
not get any clue form my Internet search. Any help would be more than
welcome.

Thank you very much indeed.
 
R

Roedy Green

I am currently writing a Jabber client for some specific purposes.
Basically the Jabber client,

I looked into Jabber a few years ago and decided it would be a
nightmare for deployment since it used its own protocol and port
numbers. That meant you would end up on the phone eternally solving
client firewall tunneling problems.
 
J

Jean-Paul

Possibly. But if you look at the code, a simple configuration to my XML
configuration file and I can actually connect to an HTTP server on port
80. However, this will still not happen if I cannot get the Proxy class
to work properly. This means that even if I forgot abou Jabber and
decided to do anything else, which I wont, I still won't get the code
to properly work. So, can I get a real answer to my problem?

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top