aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes problem with proxy server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "problem with proxy server" Watch "problem with proxy server" New topic
Author

problem with proxy server

bhagavatula indu sekhar
Ranch Hand

Joined: Sep 17, 2006
Posts: 34
the following program works well at home but not in our college

import java.io.*;
import java.net.*;
import javax.swing.*;

public class URLdemo {
URL url_url;
public static void main(String[] args) {
new URLdemo();
}

public URLdemo(){
try{
url_url=new URL( JOptionPane.showInputDialog("Enter url"));

BufferedInputStream bis=new BufferedInputStream( url_url.openStream() );
String s="";
while( bis.available() != 0 ){
s+=(char) bis.read();
}

System.out.println(s);
}

catch(MalformedURLException mfurle){
System.out.println("URL Error");
}
catch(IOException ioe){
System.out.println("IOError!");
}
catch(Exception e){
System.out.println("Error Occurred");
}
}
}


in the college,the program works well for local resources but when http://www.google.com is given as input IOError is being raised.

the college provides us Internet facility through a proxy server.

i tried to bypass the proxy server using the statement:
System.setProperty("http.proxyHost", null);

this statement is raising some exception.


so help me to access the Internet through a Java program under these circumstatnces?

thank you
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8713
    
    6

Originally posted by bhagavatula indu sekhar:

this statement is raising some exception.


What is the exception? If you don't Tell The Details, we don't have a good picture of what is happening on your end.
In any case, if your college provides a proxy server for internet access, attempting to "bypass" it will result in you not getting access to the internet.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
bhagavatula indu sekhar
Ranch Hand

Joined: Sep 17, 2006
Posts: 34
the program is expected to get the content present the content in a web-page.

the content of the web-page thus obtained has to be processed further for any email ids and hyperlinks and they are to be displayed.

the message i am getting is "IOError!" and hence IOException is being raised.

the jdk kit on which we are working is jdk1.6 and we are working on WindowsXP servicepack 2 OS.

so how do i access Internet under these conditions using Java program?
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8713
    
    6

You should print out the exception message and possibly the stack trace. They will give you a better idea as to what is going wrong than simply printing out "IOError".
As for your proxy, I told you in your previous post that you had to configure the JVM to use a proxy. I don't see the configuration in your code so I'm not surprized to hear your code doesn't work.
bhagavatula indu sekhar
Ranch Hand

Joined: Sep 17, 2006
Posts: 34
the program has been modified

method 1)
proxy server's address is 132.200.13.2
it is set using setProperty method.
proxy server's port is 80

method 2)
passing arguement to "java" command

java -Dhttp.proxyHost=132.200.13.2 -Dhttp.proxyPort=80 URLdemo

when either of the one is used the message i am getting on the console is

132.200.13.2
IOError!



import java.net.*;
import java.io.*;
import javax.swing.*;

public class URLdemo {
URL url;
public static void main(String[] args) {
URLdemo ur=new URLdemo();
ur.getContent();
}


public void getContent(){

System.setProperty("http.proxyHost","132.200.13.2");
System.setProperty("http.proxyPort","80");
String sa=System.getProperty("http.proxyHost");
System.out.println(sa);


try{
url=new URL(JOptionPane.showInputDialog("Enter url"));
BufferedInputStream is=new BufferedInputStream(url.openStream());
String s="";
while( is.available() != 0 ){
s+=(char)is.read();
}
System.out.println(s);
}
catch( MalformedURLException murle){
System.out.println("URL error!");
System.exit(-1);
}
catch( IOException ioe){
System.out.println("IOError!");
System.exit(-1);
}
catch( Exception e){
System.out.println("Error!");
System.exit(-1);
}
}
}
bhagavatula indu sekhar
Ranch Hand

Joined: Sep 17, 2006
Posts: 34
the program has been modified

method 1)
proxy server's address is 132.200.13.2
it is set using setProperty method.
proxy server's port is 80

method 2)
passing arguement to "java" command

jav
bhagavatula indu sekhar
Ranch Hand

Joined: Sep 17, 2006
Posts: 34
the program has been modified

method 1)
proxy server's address is 132.200.13.2
it is set using setProperty method.
proxy server's port is 80

method 2)
passing arguement to "java" command

jav
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8713
    
    6

Originally posted by bhagavatula indu sekhar:

when either of the one is used the message i am getting on the console is

132.200.13.2
IOError!


Have a look at this short article on how to handle Java exceptions. You are missing out on some important information.
bhagavatula indu sekhar
Ranch Hand

Joined: Sep 17, 2006
Posts: 34
OUTPUT along with stack trace



132.200.13.2
java.net.SocketException: Unexpected end of file from server
at sun.net.www.http.HttpClient.parseHTTPHeader(Unknown Source)
at sun.net.www.http.HttpClient.parseHTTP%2
bhagavatula indu sekhar
Ranch Hand

Joined: Sep 17, 2006
Posts: 34
output along with stack trace

132.200.13.2
java.net.SocketException: Unexpected end of file from server
at sun.net.www.http.HttpClient.parseHTTPHeader(Unknown Source)
at sun.net.www.http.HttpClient.parseHTTP(Unknown Source)
at sun.net.www.http.HttpClient.parseHTTPHeader(Unknown Source)
at sun.net.www.http.HttpClient.parseHTTP(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at URLdemo.getContent(URLdemo.java:29)
at URLdemo.main(URLdemo.java:17)
IOError!
bhagavatula indu sekhar
Ranch Hand

Joined: Sep 17, 2006
Posts: 34
output along with stack trace

132.200.13.2
java.net.SocketException: Unexpected end of file from server
at sun.net.www.http.HttpClient.parseHTTPHeader(Unknown Source)
at sun.net.www.http.HttpClient.parseHTTP(Unknown Sou
bhagavatula indu sekhar
Ranch Hand

Joined: Sep 17, 2006
Posts: 34
output along with stack trace

132.200.13.2
java.net.SocketException: Unexpected end of file from server
at sun.net.www.http.HttpClient.parseHTTPHeader(Unknown Source)
at sun.net.www.http.HttpClient.parseHTTP(Unknown Sou
bhagavatula indu sekhar
Ranch Hand

Joined: Sep 17, 2006
Posts: 34
output along with stack trace

132.200.13.2
java.net.SocketException: Unexpected end of file from server
at sun.net.www.http.HttpClient.parseHTTPHeader(Unknown Source)
at sun.net.www.http.HttpClient.parseHTTP(Unknown Source)
at sun.net.www.http.HttpClient.parseHTTPHeader(Unknown Source)
at sun.net.www.http.HttpClient.parseHTTP(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at URLdemo.getContent(URLdemo.java:29)
at URLdemo.main(URLdemo.java:17)
IOError!
bhagavatula indu sekhar
Ranch Hand

Joined: Sep 17, 2006
Posts: 34
output along with stack trace

132.200.13.2
java.net.SocketException: Unexpected end of file from server
at sun.net.www.http.HttpClient.parseHTTPHeader(Unknown Source)
at sun.net.www.http.HttpClient.parseHTTP(Unknown Source)
at sun.net.www.http.HttpClient.parseHTTPHeader(Unknown Source)
at sun.net.www.http.HttpClient.parseHTTP(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at URLdemo.getContent(URLdemo.java:29)
at URLdemo.main(URLdemo.java:17)
IOError!
bhagavatula indu sekhar
Ranch Hand

Joined: Sep 17, 2006
Posts: 34
output along with stack trace

132.200.13.2
java.net.SocketException: Unexpected end of file from server
at sun.net.www.http.HttpClient.parseHTTPHeader(Unknown Source)
at sun.net.www.http.HttpClient.parseHTTP(Unknown Sou
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8713
    
    6

Originally posted by bhagavatula indu sekhar:

java.net.SocketException: Unexpected end of file from server


That sounds like you are connecting fine but the conversation between your machine and the server is broken. Can you view the same URL with a web browser?
bhagavatula indu sekhar
Ranch Hand

Joined: Sep 17, 2006
Posts: 34
yes i am able to view the page through web browser IE.
bhagavatula indu sekhar
Ranch Hand

Joined: Sep 17, 2006
Posts: 34
i am sorry Joe Ess.
i will not repeat this again.

i will continue the dialog under this post itself with you.
bhagavatula indu sekhar
Ranch Hand

Joined: Sep 17, 2006
Posts: 34
the problem is with proxy server connection.
by changing the proxy server connection, the problem is solved.

thank you very much for your guidance.
 
jQuery in Action, 2nd edition
 
subject: problem with proxy server
 
Similar Threads
Unable to get the content in URL
Unable to get the content in URL
Help need for client server program
Problem with InetAddress
Validate Domain Name