Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
base repository: wildfly/wildfly
Choose a Base Repository
wildfly/wildfly
2002simon01/jboss-as
ALRubinger/wildfly
ErikWRasmussen/jboss-as
KurtStam/jboss-as
Lerm/jboss-as
LinuxEvangelist/jboss-as
Mogztter/wildfly
OndraZizka/jboss-as
PayU-EMEA/jboss-as
aaronwalker/jboss-as
agibsonccc/jboss-as
akalachm/jboss-as
alesj/jboss-as
alns/jboss-as
aloubyansky/wildfly
aminorex/jboss-as
andersnorgaard/jboss-as
andredemathe/jboss-as
andytaylor/wildfly
aprilhu0/jboss-as
ashields/jboss-as
aslakknutsen/jboss-as
asoldano/wildfly
awirayaksa/jboss-as
bershath/jboss-as
bgeorges/jboss-as
blue61/jboss-as
bosschaert/jboss-as
bstansberry/wildfly
btison/jboss-as
cbue/jboss-as
charleswmiller/jboss-as
chikin/jboss-as
chriskriel/jboss-as
coberle/jboss-as
colmsean/jboss-as
ctomc/wildfly
dandreadis/wildfly
darranl/wildfly
dcaillia/jboss-as
denuno/jboss-as
deruelle/jboss-as
dhollandAtWex/dh-old-forks-jboss-as
dmlloyd/wildfly
dobozysaurus/jboss-as
dpospisil/wildfly
edbean/jboss-as
emannuel/jboss-as
emerile1/jboss-as
emuckenhuber/wildfly
esantana/jboss-as
fbricon/jboss-as
fedora-jboss-as/wildfly
fei-yin/jboss-as
fharms/wildfly
fregaham/jboss-as
fxlambda-twickly5/wildfly
garcimouche/jboss-as
goldmann/jboss-as
gonne/jboss-as
gvagenas/jboss-as
hamanju/jboss-as
hamming229/jboss-as
heiko-braun/wildfly
hgkmiracle/jboss-as
hunter-thom/jboss-as
ikaro/jboss-as
istudens/wildfly
jaikiran/wildfly
jamezp/wildfly
janpiel/jboss-as
java-coder/jboss-as
jayhowell/jboss-as
jbossejb3/jboss-as
jdmr/jboss-as
jdpgrailsdev/jboss-as
jeenapeter/jboss-as
jeffzhang/jboss-as
jeremiahshirk/jboss-as
jiwils/jboss-as
jlindesmith/jboss-as
jmartisk/wildfly
jocstar/jboss-as
joseph2000/jboss-as
jrwhitley/jboss-as
jswordfish/jboss-as
jtoerber/jboss-as
julianzhu/jboss-as
jwulf/jboss-as
kabir/wildfly
kbys/jboss-as
koledzhikov/jboss-as
kpiwko/wildfly
kylape/wildfly
ldevrie/jboss-as
lingling788/jboss-as
liweinan/jboss-as
luksa/wildfly
lydonchandra/jboss-as
maasvdberg/wildfly
madhumita/jboss-as
madhumita12/jboss-as
maerqiang/jboss-as
maeste/jboss-as
mageshbk/jboss-as
markmc/jboss-as
markyour/jboss-as
maschmid/jboss-as
matejonnet/jboss-as
mathieuancelin/jboss-as
mathieufortin01/jboss-as
mattdrees/jboss-as
maxandersen/jboss-as
maximilienw/jboss-as
mbogoevici/jboss-as
mbrasier/jboss-as
mdemerath/jboss-as
mgencur/jboss-as
michaelschuetz/jboss-as
miclark/jboss-as
migue/wildfly
mikebrock/jboss-as
mkiman/jboss-as
mlinhard/jboss-as
mmoyses/jboss-as
mojavelinux/jboss-as
mschwartzman/jboss-as
mstruk/jboss-as
nikkack/jboss-as
nookala/jboss-as
npfr/jboss-as
nscavell/jboss-as
ochaloup/wildfly
patmcdonough/jboss-as
pbielicki/jboss-as
pentarou/jboss-as
pepite/jboss-as
petbac/jboss-as
pferraro/wildfly
pmf8/jboss-as
pmuir/jboss-as
porobd/jboss-as
prabugp/jboss-as
pragnesh/jboss-as
prasad-deshpande/jboss-as
prcg66/jboss-as
pskopek/wildfly
pslegr/jboss-as
rachmatowicz/wildfly
rachmatowicz2/jboss-as
randythomas/jboss-as
rhusar/wildfly
richmidwinter/jboss-as
richsharples/jboss-as
ringerc/jboss-as
robertpanzer/jboss-as
robstryker/jboss-as
rsvoboda/wildfly
rzimmermann/jboss-as
sacdroid/jboss-as
samuelo/jboss-as
sasgww/jboss-as
scottmarlow/wildfly
sebersole/jboss-as
seeburger-ag/jboss-as
seko2000/jboss-as
sgilda/wildfly
shadangi/jboss-as
shuawest/jboss-as
sjancke/jboss-as
skoussou/jboss-as
smcgowan/wildfly
spreadline/jboss-as
ssilvert/wildfly
starksm64/jboss-as
starksmjboss/jboss-as
stliu/jboss-as
stuartwdouglas/wildfly
sujaybawaskar/jboss-as
tdiesler/wildfly
tfennelly/jboss-as
thammoud/jboss-as
thanhvc/jboss-as
thauser/jboss-as
thomasnymand/jboss-as
thunderlei/jboss-as
tomathome/jboss-as
tomwells/jboss-as
tristantarrant/wildfly
tyasuma/jboss-as
undertow-io/jboss-as
vladimirralev/jboss-as
vmariusvv/jboss-as
vratsel/jboss-as
weld/wildfly
wfink/wildfly
wolfc/jboss-as
zhigunovs/jboss-as
zhleonix/jboss-as
Nothing to show
base: ade505a
head repository: wildfly/wildfly
Choose a Head Repository
wildfly/wildfly
2002simon01/jboss-as
ALRubinger/wildfly
ErikWRasmussen/jboss-as
KurtStam/jboss-as
Lerm/jboss-as
LinuxEvangelist/jboss-as
Mogztter/wildfly
OndraZizka/jboss-as
PayU-EMEA/jboss-as
aaronwalker/jboss-as
agibsonccc/jboss-as
akalachm/jboss-as
alesj/jboss-as
alns/jboss-as
aloubyansky/wildfly
aminorex/jboss-as
andersnorgaard/jboss-as
andredemathe/jboss-as
andytaylor/wildfly
aprilhu0/jboss-as
ashields/jboss-as
aslakknutsen/jboss-as
asoldano/wildfly
awirayaksa/jboss-as
bershath/jboss-as
bgeorges/jboss-as
blue61/jboss-as
bosschaert/jboss-as
bstansberry/wildfly
btison/jboss-as
cbue/jboss-as
charleswmiller/jboss-as
chikin/jboss-as
chriskriel/jboss-as
coberle/jboss-as
colmsean/jboss-as
ctomc/wildfly
dandreadis/wildfly
darranl/wildfly
dcaillia/jboss-as
denuno/jboss-as
deruelle/jboss-as
dhollandAtWex/dh-old-forks-jboss-as
dmlloyd/wildfly
dobozysaurus/jboss-as
dpospisil/wildfly
edbean/jboss-as
emannuel/jboss-as
emerile1/jboss-as
emuckenhuber/wildfly
esantana/jboss-as
fbricon/jboss-as
fedora-jboss-as/wildfly
fei-yin/jboss-as
fharms/wildfly
fregaham/jboss-as
fxlambda-twickly5/wildfly
garcimouche/jboss-as
goldmann/jboss-as
gonne/jboss-as
gvagenas/jboss-as
hamanju/jboss-as
hamming229/jboss-as
heiko-braun/wildfly
hgkmiracle/jboss-as
hunter-thom/jboss-as
ikaro/jboss-as
istudens/wildfly
jaikiran/wildfly
jamezp/wildfly
janpiel/jboss-as
java-coder/jboss-as
jayhowell/jboss-as
jbossejb3/jboss-as
jdmr/jboss-as
jdpgrailsdev/jboss-as
jeenapeter/jboss-as
jeffzhang/jboss-as
jeremiahshirk/jboss-as
jiwils/jboss-as
jlindesmith/jboss-as
jmartisk/wildfly
jocstar/jboss-as
joseph2000/jboss-as
jrwhitley/jboss-as
jswordfish/jboss-as
jtoerber/jboss-as
julianzhu/jboss-as
jwulf/jboss-as
kabir/wildfly
kbys/jboss-as
koledzhikov/jboss-as
kpiwko/wildfly
kylape/wildfly
ldevrie/jboss-as
lingling788/jboss-as
liweinan/jboss-as
luksa/wildfly
lydonchandra/jboss-as
maasvdberg/wildfly
madhumita/jboss-as
madhumita12/jboss-as
maerqiang/jboss-as
maeste/jboss-as
mageshbk/jboss-as
markmc/jboss-as
markyour/jboss-as
maschmid/jboss-as
matejonnet/jboss-as
mathieuancelin/jboss-as
mathieufortin01/jboss-as
mattdrees/jboss-as
maxandersen/jboss-as
maximilienw/jboss-as
mbogoevici/jboss-as
mbrasier/jboss-as
mdemerath/jboss-as
mgencur/jboss-as
michaelschuetz/jboss-as
miclark/jboss-as
migue/wildfly
mikebrock/jboss-as
mkiman/jboss-as
mlinhard/jboss-as
mmoyses/jboss-as
mojavelinux/jboss-as
mschwartzman/jboss-as
mstruk/jboss-as
nikkack/jboss-as
nookala/jboss-as
npfr/jboss-as
nscavell/jboss-as
ochaloup/wildfly
patmcdonough/jboss-as
pbielicki/jboss-as
pentarou/jboss-as
pepite/jboss-as
petbac/jboss-as
pferraro/wildfly
pmf8/jboss-as
pmuir/jboss-as
porobd/jboss-as
prabugp/jboss-as
pragnesh/jboss-as
prasad-deshpande/jboss-as
prcg66/jboss-as
pskopek/wildfly
pslegr/jboss-as
rachmatowicz/wildfly
rachmatowicz2/jboss-as
randythomas/jboss-as
rhusar/wildfly
richmidwinter/jboss-as
richsharples/jboss-as
ringerc/jboss-as
robertpanzer/jboss-as
robstryker/jboss-as
rsvoboda/wildfly
rzimmermann/jboss-as
sacdroid/jboss-as
samuelo/jboss-as
sasgww/jboss-as
scottmarlow/wildfly
sebersole/jboss-as
seeburger-ag/jboss-as
seko2000/jboss-as
sgilda/wildfly
shadangi/jboss-as
shuawest/jboss-as
sjancke/jboss-as
skoussou/jboss-as
smcgowan/wildfly
spreadline/jboss-as
ssilvert/wildfly
starksm64/jboss-as
starksmjboss/jboss-as
stliu/jboss-as
stuartwdouglas/wildfly
sujaybawaskar/jboss-as
tdiesler/wildfly
tfennelly/jboss-as
thammoud/jboss-as
thanhvc/jboss-as
thauser/jboss-as
thomasnymand/jboss-as
thunderlei/jboss-as
tomathome/jboss-as
tomwells/jboss-as
tristantarrant/wildfly
tyasuma/jboss-as
undertow-io/jboss-as
vladimirralev/jboss-as
vmariusvv/jboss-as
vratsel/jboss-as
weld/wildfly
wfink/wildfly
wolfc/jboss-as
zhigunovs/jboss-as
zhleonix/jboss-as
Nothing to show
compare: 948d860
  • 3 commits
  • 10 files changed
  • 0 commit comments
  • 2 contributors
Commits on Apr 28, 2019
 [WFLY-10798] Setting correct TCCL for Datasource constructor
@@ -133,22 +133,35 @@ protected void performRuntime(OperationContext context, ModelNode operation, Mod
final ServiceLoader<Driver> serviceLoader = module.loadService(Driver.class);
boolean driverLoaded = false;
if (serviceLoader != null) {
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(module.getClassLoader());
try {
for (Driver driver : serviceLoader) {
startDriverServices(target, moduleId, driver, driverName, majorVersion, minorVersion, dataSourceClassName, xaDataSourceClassName);
driverLoaded = true;
//just consider first definition and create service for this. User can use different implementation only
// w/ explicit declaration of driver-class attribute
break;
}
} finally {
Thread.currentThread().setContextClassLoader(tccl);
}
}
if (!driverLoaded)
SUBSYSTEM_DATASOURCES_LOGGER.cannotFindDriverClassName(driverName);
} else {
try {
final Class<? extends Driver> driverClass = module.getClassLoader().loadClass(driverClassName)
.asSubclass(Driver.class);
final Constructor<? extends Driver> constructor = driverClass.getConstructor();
final Driver driver = constructor.newInstance();
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
Driver driver = null;
try {
Thread.currentThread().setContextClassLoader(module.getClassLoader());
final Constructor<? extends Driver> constructor = driverClass.getConstructor();
driver = constructor.newInstance();
} finally {
Thread.currentThread().setContextClassLoader(tccl);
}
startDriverServices(target, moduleId, driver, driverName, majorVersion, minorVersion, dataSourceClassName, xaDataSourceClassName);
} catch (Exception e) {
SUBSYSTEM_DATASOURCES_LOGGER.cannotInstantiateDriverClass(driverClassName, e);
@@ -0,0 +1,216 @@
package org.jboss.as.test.integration.jca.classloading;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.as.arquillian.api.ServerSetupTask;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.test.integration.jca.datasource.Datasource;
import org.jboss.as.test.shared.ServerReload;
import org.jboss.as.test.shared.ServerSnapshot;
import org.jboss.dmr.ModelNode;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.exporter.ZipExporter;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;

import javax.annotation.Resource;
import javax.sql.DataSource;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.ResultSet;
import java.sql.Statement;

import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;

public abstract class AbstractDataSourceClassloadingTestCase {

public static JavaArchive getDeployment() {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "driver.jar");
jar.addClass(ClassloadingDataSource.class);
jar.addClass(ClassloadingDriver.class);
jar.addClass(TestConnection.class);
jar.addClass(ClassloadingXADataSource.class);
jar.addClass(TestXAConnection.class);
jar.addAsServiceProvider(Driver.class, ClassloadingDriver.class);
return jar;
}

@Deployment
public static JavaArchive getTesterDeployment() {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "tester.jar");
jar.addClass(AbstractDataSourceClassloadingTestCase.class);
jar.addClass(DataSourceTcclDatasourceClassTestCase.class);
return jar;
}

@Resource(mappedName = "java:jboss/datasources/TestDS")
private DataSource ds;

public static class Setup implements ServerSetupTask {

private AutoCloseable snapshot;
private String classNamePropertyName;
private String driverClass;

protected Setup(String classNamePropertyName, String driverClass) {
this.classNamePropertyName = classNamePropertyName;
this.driverClass = driverClass;
}

@Override
public void setup(ManagementClient managementClient, String s) throws Exception {
snapshot = ServerSnapshot.takeSnapshot(managementClient);

setupModule();
setupDriver(managementClient, classNamePropertyName, driverClass);
setupDs(managementClient, "TestDS", false);
ServerReload.executeReloadAndWaitForCompletion(managementClient.getControllerClient(), 50000);
}

@Override
public void tearDown(ManagementClient managementClient, String s) throws Exception {
snapshot.close();
File testModuleRoot = new File(getModulePath(), "org/jboss/test/testDriver");
if (testModuleRoot.exists()) {
deleteRecursively(testModuleRoot);
}
ServerReload.executeReloadAndWaitForCompletion(managementClient.getControllerClient(), 50000);
}

private void setupModule() throws IOException {
File testModuleRoot = new File(getModulePath(), "org/jboss/test/testDriver");
File file = new File(testModuleRoot, "main");
if (file.exists()) {
deleteRecursively(file);
}
if (!file.mkdirs()) {
// TODO handle
}

try(FileOutputStream jarFile = new FileOutputStream(new File(file, "module.xml"));
PrintWriter pw = new PrintWriter(jarFile)) {
pw.println("<module name=\"org.jboss.test.testDriver\" xmlns=\"urn:jboss:module:1.8\">\n" +
" <resources>\n" +
" <resource-root path=\"testDriver.jar\"/>\n" +
" </resources>\n" +
"\n" +
" <dependencies>\n" +
" <module name=\"javax.sql.api\"/>\n" +
" <module name=\"sun.jdk\"/>\n" +
" <module name=\"javax.orb.api\"/>\n" +
" <module name=\"java.logging\"/>\n" +
" </dependencies>\n" +
"</module>");
}


JavaArchive deployment = getDeployment();
try(FileOutputStream jarFile = new FileOutputStream(new File(file, "testDriver.jar"))) {
deployment.as(ZipExporter.class).exportTo(jarFile);
jarFile.flush();
}
}

private static void deleteRecursively(File file) {
if (file.exists()) {
if (file.isDirectory()) {
for (String name : file.list()) {
deleteRecursively(new File(file, name));
}
}
file.delete();
}
}

private static File getModulePath() {
String modulePath = System.getProperty("module.path", null);
if (modulePath == null) {
String jbossHome = System.getProperty("jboss.home", null);
if (jbossHome == null) {
throw new IllegalStateException("Neither -Dmodule.path nor -Djboss.home were set");
}
modulePath = jbossHome + File.separatorChar + "modules";
} else {
modulePath = modulePath.split(File.pathSeparator)[0];
}
File moduleDir = new File(modulePath);
if (!moduleDir.exists()) {
throw new IllegalStateException("Determined module path does not exist");
}
if (!moduleDir.isDirectory()) {
throw new IllegalStateException("Determined module path is not a dir");
}
return moduleDir;
}

private void setupDriver(ManagementClient managementClient, String classNamePropertyName, String driverClass) throws Exception {
ModelNode address = new ModelNode();
address.add("subsystem", "datasources");
address.add("jdbc-driver", "test");

ModelNode operation = new ModelNode();
operation.get(OP).set(ADD);
operation.get(OP_ADDR).set(address);
operation.get("driver-module-name").set("org.jboss.test.testDriver");
operation.get("driver-name").set("test");
operation.get("driver-datasource-class-name").set("org.jboss.as.test.integration.jca.classloading.ClassloadingDataSource");
operation.get(classNamePropertyName).set(driverClass);
managementClient.getControllerClient().execute(operation);
}

protected void setupDs(ManagementClient managementClient, String dsName, boolean jta) throws Exception {
Datasource ds = Datasource.Builder(dsName).build();
ModelNode address = new ModelNode();
address.add("subsystem", "datasources");
address.add("data-source", dsName);

ModelNode operation = new ModelNode();
operation.get(OP).set(ADD);
operation.get(OP_ADDR).set(address);
operation.get("jndi-name").set(ds.getJndiName());
operation.get("use-java-context").set("true");
operation.get("driver-name").set("test");
operation.get("enabled").set("true");
operation.get("user-name").set(ds.getUserName());
operation.get("password").set(ds.getPassword());
operation.get("jta").set(jta);
operation.get("use-ccm").set("true");
operation.get("connection-url").set("jdbc:foo:bar");
managementClient.getControllerClient().execute(operation);
}
}

@Test
public void testGetConnection() throws Exception {
Assert.assertNotNull(ds);
ds.getConnection();
ds.getConnection("", "");
}

@Test
public void testCreateStatement() throws Exception {
Connection connection = ds.getConnection();
connection.createStatement();
connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
}

@Test
public void testPrepareStatement() throws Exception {
Connection connection = ds.getConnection();
connection.prepareStatement("");
connection.prepareStatement("", new int[]{});
connection.prepareStatement("", new String[]{});
connection.prepareStatement("", Statement.RETURN_GENERATED_KEYS);
connection.prepareStatement("", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
connection.prepareStatement("", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
}


}
@@ -0,0 +1,69 @@
package org.jboss.as.test.integration.jca.classloading;

import javax.sql.DataSource;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.logging.Logger;

public class ClassloadingDataSource implements DataSource {

public ClassloadingDataSource() {
try {
Class.forName(TestConnection.class.getName(), true, Thread.currentThread().getContextClassLoader());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}

@Override
public Connection getConnection() throws SQLException {
try {
Class.forName(TestConnection.class.getName(), true, Thread.currentThread().getContextClassLoader());
} catch (ClassNotFoundException e) {
throw new SQLException(e);
}
return new TestConnection();
}

@Override
public Connection getConnection(String username, String password) throws SQLException {
return getConnection();
}

@Override
public <T> T unwrap(Class<T> iface) throws SQLException {
return null;
}

@Override
public boolean isWrapperFor(Class<?> iface) throws SQLException {
return false;
}

@Override
public PrintWriter getLogWriter() throws SQLException {
return null;
}

@Override
public void setLogWriter(PrintWriter out) throws SQLException {

}

@Override
public void setLoginTimeout(int seconds) throws SQLException {

}

@Override
public int getLoginTimeout() throws SQLException {
return 0;
}

@Override
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
return null;
}
}
@@ -0,0 +1,62 @@
package org.jboss.as.test.integration.jca.classloading;

import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverPropertyInfo;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.Properties;
import java.util.logging.Logger;

public class ClassloadingDriver implements Driver {

public ClassloadingDriver() {
try {
Class.forName(TestConnection.class.getName(), true, Thread.currentThread().getContextClassLoader());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}

@Override
public Connection connect(String url, Properties info) throws SQLException {

try {
Class.forName(TestConnection.class.getName(), true, Thread.currentThread().getContextClassLoader());
} catch (ClassNotFoundException e) {
throw new SQLException(e);
}

return new TestConnection();
}

@Override
public boolean acceptsURL(String url) throws SQLException {
return true;
}

@Override
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
return new DriverPropertyInfo[0];
}

@Override
public int getMajorVersion() {
return 0;
}

@Override
public int getMinorVersion() {
return 0;
}

@Override
public boolean jdbcCompliant() {
return false;
}

@Override
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
return null;
}
}

No commit comments for this range

You can’t perform that action at this time.