src-main.org.awakefw.sql.jdbc.http.JdbcHttpTransferUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of awake-sql Show documentation
Show all versions of awake-sql Show documentation
Awake SQL is an open source framework that allows remote and secure JDBC access through HTTP.
/*
* This file is part of Awake SQL.
* Awake SQL: Remote JDBC access over HTTP.
* Copyright (C) 2013, KawanSoft SAS
* (http://www.kawansoft.com). All rights reserved.
*
* Awake SQL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* Awake SQL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see .
*
* If you develop commercial activities using Awake SQL, you must:
* a) disclose and distribute all source code of your own product,
* b) license your own product under the GNU General Public License.
*
* You can be released from the requirements of the license by
* purchasing a commercial license. Buying such a license will allow you
* to ship Awake SQL with your closed source products without disclosing
* the source code.
*
* For more information, please contact KawanSoft SAS at this
* address: [email protected]
*
* Any modifications to this file must keep this entire header
* intact.
*/
package org.awakefw.sql.jdbc.http;
import java.io.IOException;
import java.net.ConnectException;
import java.net.MalformedURLException;
import java.net.UnknownHostException;
import java.sql.SQLException;
import org.awakefw.commons.api.client.InvalidLoginException;
import org.awakefw.commons.api.client.RemoteException;
import org.awakefw.sql.api.client.InvalidatedSessionException;
import org.awakefw.sql.util.SqlReturnCode;
/**
* Utility methods for JdbcHttpTransfer
*
* @author Nicolas de Pomereu
*/
public class JdbcHttpTransferUtil {
/**
* Protected constructor, not callable
*/
protected JdbcHttpTransferUtil() {
}
/**
* Throws back the trapped Exception throw by HttpTransfer as SQLException
*
* @param e
* the Exception thrown by HttpTransfer call
*
* @throws SQLException
* the wrapped thrown Exception:
*/
public static void wrapExceptionAsSQLException(Exception e)
throws SQLException {
/*
* UnknownHostException, ConnectException, AwakeRemoteException,
* SecurityException, IOException,
*/
if (e instanceof UnknownHostException) {
UnknownHostException wrappedException = (UnknownHostException) e;
throw new SQLException(wrappedException.getMessage(),
wrappedException);
} else if (e instanceof ConnectException) {
ConnectException wrappedException = (ConnectException) e;
throw new SQLException(wrappedException.getMessage(),
wrappedException);
} else if (e instanceof MalformedURLException) {
MalformedURLException wrappedException = (MalformedURLException) e;
throw new SQLException(wrappedException.getMessage(),
wrappedException);
} else if (e instanceof InvalidLoginException) {
throw new SQLException(e);
} else if (e instanceof RemoteException) // Must be done before
// IOException
{
RemoteException wrappedException = (RemoteException) e;
// Special case if message is SESSION_INVALIDATED
if (wrappedException.getMessage() != null
&& wrappedException.getMessage().trim()
.equals(SqlReturnCode.SESSION_INVALIDATED)) {
throw new SQLException(new InvalidatedSessionException());
} else {
throw new SQLException(wrappedException.getMessage(),
wrappedException);
}
}
else if (e instanceof SecurityException) {
SecurityException wrappedException = (SecurityException) e;
throw new SQLException(wrappedException.getMessage(),
wrappedException);
// SecurityException wrappedException = (SecurityException) e;
// throw wrappedException;
}
else if (e instanceof IOException) // IOException thrown by local code
{
IOException wrappedException = (IOException) e;
if (wrappedException.getCause() != null
&& wrappedException.getCause() instanceof InterruptedException) {
throw new SQLException(wrappedException.getCause());
}
throw new SQLException(wrappedException.getMessage(),
wrappedException);
} else {
IOException wrappedException = new IOException(e);
throw new SQLException(wrappedException.getMessage(),
wrappedException);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy