Not a customer? Click the 'Start a free trial' link to begin a 30-day SaaS trial of our product and to join our community.
Existing Cisco AppDynamics customers should click the 'Sign In' button to authenticate to access the community
05-18-2018 08:04 AM
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.
02-27-2020 12:12 AM - edited 02-27-2020 12:14 AM
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)
{
}
}
}
02-27-2020 12:17 AM - last edited on 07-27-2020 08:48 AM by Ryan.Paredez
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.
^ Post edited by @Ryan.Paredez, Christopher's original reply that was flagged as spam has been unflagged and is live in this thread. It is the post that is right above this one.
User | Count |
---|---|
2 | |
1 | |
1 | |
1 | |
1 |
Thank you! Your submission has been received!
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form