Dashboards

cancel
Showing results for 
Search instead for 
Did you mean: 

Exception is reported even though its caught within the context of business transaction

Highlighted
Creator

Exception is reported even though its caught within the context of business transaction

Have a simple method for connection,

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;

public class Connection {

    public boolean connect(URL url, String requestType) {
        HttpURLConnection connection = null;
        try {
            URLConnection urlConnection = url.openConnection();
            if (urlConnection instanceof HttpURLConnection) {
                connection = (HttpURLConnection) urlConnection;
                connection.setRequestMethod(requestType);
                connection.setRequestProperty("Authorization", getAuth()); //$NON-NLS-1$
            }

            if (connection == null) {
                return false;
            }
            connection.connect();
	    connection.getInputStream();

            return connection.getResponseCode() == HttpURLConnection.HTTP_OK;
        } catch (IOException e) {
            return false;
        }
    }
}

 

As the line connection.getInputStream(); is encountered there is a FileNotFoundException thrown for invalida URL, caught as IOException and false is returned, however AppDynamics reports it as a business transaction error.

 

Read this on the Appdynamics documentation “An exception that is thrown and caught within the context of the business transaction is not considered a transaction error and the exception is not captured in AppDynamics. “

 

Can someone explain on why is 'FileNotFoundException' being reported in AppDynamics as business transaction error even though its being caught. Thanks in advance.

Exception is reported even though its caught within the context of business transaction
2 REPLIES 2
Highlighted

Re: Exception is reported even though its caught within the context of business transaction

Are you sure you're not getting the FileNotFound when trying to do getInputStream on the connection later (or in your real code in case this is a simplified example)? Since HttpUrlConnection implements http protocol and 4xx codes are error codes trying to call getInputStream generates FNF. Instead you should call getErrorStream.

I ran your code (without the auth part) and I don't get any FilenotFoundException testing on url's that return 404.

So in this case HttpUrlConnection correctly implements the http protocol and appdynamics correctly catches the error.
I'm facing the same issue with jersey wrapping the FnF in a UniformResourceException but after some analyzing it's actually either jersey that should provide ways of checking the status code before returning output or correctly use httpurlconnection, and in our case - the webservice should not return 404 for requests that yields no found results but rather an empty collection.

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class Connection {

public boolean connect(URL url, String requestType) {
HttpURLConnection connection = null;
try {
URLConnection urlConnection = url.openConnection();
if (urlConnection instanceof HttpURLConnection) {
connection = (HttpURLConnection) urlConnection;
connection.setRequestMethod(requestType);
}
if (connection == null) {
return false;
}
connection.connect();
System.out.println(connection.getResponseCode());
return connection.getResponseCode() == HttpURLConnection.HTTP_OK;
} catch (IOException e) {
System.out.println("E" + e.getMessage());
return false;
}
}

public static void main(String args[])
{
Connection con = new Connection();
try{
con.connect(new URL("http://www.google.com/asdfasdfsd"), "GET");
} catch(MalformedURLException mfe)
{

}
}
}
Highlighted

Re: Exception is reported even though its caught within the context of business transaction

For some reason my answer was caught as spam.

 

So you can read it at https://stackoverflow.com/questions/50355471/appydynamic-reports-error-for-filenotfoundexception instead.