Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

HTTPConnection - verbose error messages

Thread view: 
guyzdancin - 11 Jan 2006 21:06 GMT
I have a java application that polls an asp page for the purpose of
inserting to a data base.  I am interested in getting verbose (ie
unfriendly HTTP error messages) when there is an internal server error
(code 500).  Below is the code snippet that makes the application's web
connection and captures the response messages.

    String user = "";
    //String user = "Someone";

    try{//create url object
        urlWithQueryString =
"http://www.someaddress.com/lpt/lpt_login.asp?User=" + user +
"&FName=Alonzo&LName=Garbonzo&timeStamp=20060110_1106";
        System.err.println("urlWithQueryString ln 35: " +
urlWithQueryString);
        url = new URL(urlWithQueryString);
    }catch(MalformedURLException mURLE){
        System.err.println( "MalformedURLException thrown in WriteToWebDB: ln
41 " + mURLE.getMessage() );
        System.err.println("");
        return NetworkStatus.NETWORK_CONNECTION_PROBLEM;
    }

    try{//open connection. Write data succeeds or fails here
        connection = (HttpURLConnection)url.openConnection();
        inputStream = connection.getInputStream();
        connection.setInstanceFollowRedirects(true);
    }catch(IOException iOE1){
        try{
            System.err.println( "IOException caught in WriteToWebDB: ln 52");
            System.err.println("Connection response code ln 53: " +
connection.getResponseCode());
            System.err.println("Connection message ln 54: " +
connection.getResponseMessage());
            System.err.println("Exception message ln 55: " + iOE1.getMessage());
        }catch(IOException iOE){System.err.println("IOException caught ln 56"
+ iOE.getMessage());}
        return NetworkStatus.NETWORK_CONNECTION_PROBLEM;
    }

********************************************

Below are three examples of server output - two have defective
connection strings to force server error and one is a good connection
string that inserts to the data base.  Note that the defective string
passed from the application returns an error message without much
information while the defective string passed from a browser returns a
verbose and detailed error message. Can anyone help in discovering a
way to recover verbose detailed error messages in the java application?
Any help is greatly appreciated.

Guy Sussman

********************************************

Web server output to application connection when String user = ""

urlWithQueryString ln 35:
http://www.someaddress.com/lpt/lpt_login.asp?User=&FName=Alonzo&LName=Garbonzo&t
imeStamp=20060110_1106

IOException caught in WriteToWebDB: ln 52
Connection response code ln 53: 500
Connection message ln 54: Internal Server Error
Exception message ln 55: Server returned HTTP response code: 500 for
URL:
http://www.someaddress.com/lpt/lpt_login.asp?User=&FName=Alonzo&LName=Garbonzo&t
imeStamp=20060110_1106


********************************************

Web server output to browser connection when String user = ""

Microsoft OLE DB Provider for ODBC Drivers error '80004005'
[Microsoft][ODBC Microsoft Access Driver] Field 'tbl_test.Usr' cannot
be a zero-length string.
/lpt/lpt_login.asp, line 25

********************************************

Web server output to application connection when String user =
"Someone"

urlWithQueryString ln 35:
http://www.someaddress.com/lpt/lpt_login.asp?User=Someone&FName=Alonzo&LName=Gar
bonzo&timeStamp=20060110_1106

Http connection status (WriteToWebDB ln.69): OK ResponseCode = 200

********************************************
guyzdancin - 13 Jan 2006 16:30 GMT
Hello
Andrea Desole - 13 Jan 2006 17:02 GMT
> Hello

If I'm not wrong you should call the getErrorStream() method of
HttpURLConnection. This is used in case of error messages


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.