import com.ulcjava.container.servlet.client.ConnectorCommandException;
....
if ((reason instanceof ConnectorException) && (reason.getCause() instanceof ConnectorCommandException) ) {
ConnectorCommandException cause = (ConnectorCommandException) reason.getCause();
if (cause.getResponseInfo().getResponseCode() == 500) {
JOptionPane.showMessageDialog(getOwner(), "La sessione non è più attiva.","La sessione non è più attiva.", JOptionPane.ERROR_MESSAGE);
return;
}
}
-------------------- Con Reflection ----------------
Nota...senza import!!
try {
Class connector_command_exception = Class.forName(CONNECTOR_COMMAND_EXCEPTION);
if ((reason instanceof ConnectorException) && (connector_command_exception.isInstance(reason.getCause())) ) {
Object causeInstance = reason.getCause();
Method responseInfoMethod = causeInstance.getClass().getMethod("getResponseInfo");
Object responseCodeInstance = responseInfoMethod.invoke(causeInstance, new Object[]{});
Method responseCodeMethod = responseCodeInstance.getClass().getMethod("getResponseCode");
int cause=((Integer)responseCodeMethod.invoke(responseCodeInstance, new Object[]{})).intValue();
if (cause == 500) {
JOptionPane.showMessageDialog(getOwner(), "Sessione utente terminata.","La sessione utente è terminata.", JOptionPane.ERROR_MESSAGE);
return;
}
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
Nessun commento:
Posta un commento