[mule-dev] Re: [mule-scm] [mule][25019] branches/mule-3.x: MULE-6470: As a user I want to be able to test a jms, jdbc or xmpp connector to ensure it's configured correctly and available.

0 views
Skip to first unread message

Daniel Feist

unread,
Nov 20, 2012, 5:11:11 PM11/20/12
to d...@mule.codehaus.org, s...@mule.codehaus.org
Are there no standard JDBC exception types that can be tested for?  Or a better more extensible way of mapping these descriptions?



On Nov 20, 2012, at 6:14 PM, cmo...@codehaus.org wrote:

Revision
25019
Author
cmordue
Date
2012-11-20 15:13:58 -0600 (Tue, 20 Nov 2012)

Log Message

MULE-6470: As a user I want to be able to test a jms, jdbc or xmpp connector to ensure it's configured correctly and available.

_Updated JdbcConnectors test method for TestResult interface changes in mule-common.
_Removed ConnectorTestResult because this is now DefaultTestResult in mule-common.

Modified Paths

Removed Paths

Diff

Deleted: branches/mule-3.x/core/src/main/java/org/mule/transport/ConnectorTestResult.java (25018 => 25019)


--- branches/mule-3.x/core/src/main/java/org/mule/transport/ConnectorTestResult.java	2012-11-20 17:36:17 UTC (rev 25018)
+++ branches/mule-3.x/core/src/main/java/org/mule/transport/ConnectorTestResult.java	2012-11-20 21:13:58 UTC (rev 25019)
@@ -1,44 +0,0 @@
-/*
- * $Id$
- * --------------------------------------------------------------------------------------
- * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
- *
- * The software in this package is published under the terms of the CPAL v1.0
- * license, a copy of which has been included with this distribution in the
- * LICENSE.txt file.
- */
-
-package org.mule.transport;
-
-import org.mule.common.TestResult;
-
-public class ConnectorTestResult implements TestResult
-{
-
-    private Status status;
-    private String message;
-
-    public ConnectorTestResult(TestResult.Status status)
-    {
-        this(status, "");
-    }
-
-    public ConnectorTestResult(TestResult.Status status, String message)
-    {
-        this.status = status;
-        this.message = message;
-    }
-
-    @Override
-    public String getMessage()
-    {
-        return message;
-    }
-
-    @Override
-    public Status getStatus()
-    {
-        return status;
-    }
-
-}

Modified: branches/mule-3.x/transports/jdbc/src/main/java/org/mule/transport/jdbc/JdbcConnector.java (25018 => 25019)


--- branches/mule-3.x/transports/jdbc/src/main/java/org/mule/transport/jdbc/JdbcConnector.java	2012-11-20 17:36:17 UTC (rev 25018)
+++ branches/mule-3.x/transports/jdbc/src/main/java/org/mule/transport/jdbc/JdbcConnector.java	2012-11-20 21:13:58 UTC (rev 25019)
@@ -24,6 +24,7 @@
 import org.mule.api.transaction.Transaction;
 import org.mule.api.transaction.TransactionException;
 import org.mule.api.transport.MessageReceiver;
+import org.mule.common.DefaultTestResult;
 import org.mule.common.TestResult;
 import org.mule.common.Testable;
 import org.mule.config.ExceptionHelper;
@@ -31,7 +32,6 @@
 import org.mule.transaction.TransactionCoordination;
 import org.mule.transport.AbstractConnector;
 import org.mule.transport.ConnectException;
-import org.mule.transport.ConnectorTestResult;
 import org.mule.transport.jdbc.sqlstrategy.DefaultSqlStatementStrategyFactory;
 import org.mule.transport.jdbc.sqlstrategy.SqlStatementStrategyFactory;
 import org.mule.transport.jdbc.xa.DataSourceWrapper;
@@ -593,17 +593,27 @@
     {
         if (isConnected())
         {
-            return new ConnectorTestResult(TestResult.Status.SUCCESS);
+            return new DefaultTestResult(TestResult.Status.SUCCESS);
         }
         Connection con = null;
         try
         {
             con = dataSource.getConnection();
-            return new ConnectorTestResult(TestResult.Status.SUCCESS);
+            return new DefaultTestResult(TestResult.Status.SUCCESS);
         }
         catch (Exception e)
         {
-            return new ConnectorTestResult(TestResult.Status.FAILURE, e.toString());
+        	// this surely doesn't cover all cases for all kinds of jdbc drivers but it is better than nothing
+        	TestResult.FailureType failureType = TestResult.FailureType.UNSPECIFIED;
+        	if (e.getMessage().contains("Communications link failure"))
+        	{
+        		failureType = TestResult.FailureType.CONNECTION_FAILURE;
+        	}
+        	else if (e.getMessage().contains("Access denied for user"))
+        	{
+        		failureType = TestResult.FailureType.INVALID_CREDENTIALS;
+        	}
+            return new DefaultTestResult(TestResult.Status.FAILURE, e.getMessage(), failureType, e);
         }
         finally
         {

To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email


Pablo Kraan

unread,
Nov 20, 2012, 5:25:37 PM11/20/12
to d...@mule.codehaus.org, s...@mule.codehaus.org
As long as I know, SQLException (which should be thrown in the satasource#getConnection) only contains an errorCode and is vendor specific.
Besides that, matching error using hardcoded strings is not a good idea. Error messages varies depending on driver implementation and language.

Pablo
Reply all
Reply to author
Forward
0 new messages