repo
stringlengths
1
191
file
stringlengths
23
351
code
stringlengths
0
5.32M
file_length
int64
0
5.32M
avg_line_length
float64
0
2.9k
max_line_length
int64
0
288k
extension_type
stringclasses
1 value
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/structure/jar/InSameModule.java
package org.jboss.as.test.integration.deployment.structure.jar; /** * @author Stuart Douglas */ public class InSameModule { }
129
15.25
63
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/structure/ear/ToBeIgnored.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.structure.ear; /** * User: jpai */ public class ToBeIgnored { }
1,140
37.033333
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/structure/ear/ClassLoadingEJB.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.structure.ear; import jakarta.annotation.Resource; import jakarta.ejb.Stateless; import javax.naming.InitialContext; import javax.naming.NamingException; /** * User: jpai */ @Stateless public class ClassLoadingEJB { @Resource(lookup = "java:module/ModuleName") private String moduleName; @Resource(lookup = "java:app/AppName") private String appName; public Class<?> loadClass(String className) throws ClassNotFoundException { if (className == null || className.trim().isEmpty()) { throw new RuntimeException("Classname parameter cannot be null or empty"); } return this.getClass().getClassLoader().loadClass(className); } public boolean hasResource(String resource) { return this.getClass().getResource(resource) != null; } public String query(String name) throws NamingException { return new InitialContext().lookup(name).toString(); } public String getResourceModuleName() { return moduleName; } public String getResourceAppName() { return appName; } }
2,164
32.307692
86
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/structure/ear/Available.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.structure.ear; /** * User: jpai */ public class Available { }
1,138
36.966667
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/structure/ear/Available2.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.structure.ear; /** * test class for WFCORE-3670 */ public class Available2 { }
1,156
37.566667
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/structure/ear/EarJBossDeploymentStructureTestCase.java
package org.jboss.as.test.integration.deployment.structure.ear; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; import static org.junit.Assert.assertEquals; import jakarta.ejb.EJB; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.logging.Logger; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * Tests parsing of jboss-deployment-structure.xml file in a deployment * <p/> * User: Jaikiran Pai */ @RunWith(Arquillian.class) public class EarJBossDeploymentStructureTestCase { private static final Logger logger = Logger.getLogger(EarJBossDeploymentStructureTestCase.class); @EJB(mappedName = "java:module/ClassLoadingEJB") private ClassLoadingEJB ejb; public static final String TO_BE_FOUND_CLASS_NAME = "org.jboss.as.test.integration.deployment.structure.ear.Available"; public static final String TO_BE_FOUND_CLASS_NAME_2 = "org.jboss.as.test.integration.deployment.structure.ear.Available2"; public static final String TO_BE_MISSSING_CLASS_NAME = "org.jboss.as.test.integration.deployment.structure.ear.ToBeIgnored"; public static final String METAINF_RESOURCE_TXT = "aa/metainf-resource.txt"; /** * .ear * | * |--- META-INF * | | * | |--- jboss-deployment-structure.xml * | * |--- ejb.jar * | * |--- available.jar * | * |--- available2.jar (test case for WFCORE-3670) * | * |--- ignored.jar * * @return */ @Deployment public static Archive<?> createDeployment() { final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "deployment-structure.ear"); ear.addAsManifestResource(EarJBossDeploymentStructureTestCase.class.getPackage(), "jboss-deployment-structure.xml", "jboss-deployment-structure.xml"); final JavaArchive jarOne = ShrinkWrap.create(JavaArchive.class, "available.jar"); jarOne.addClass(Available.class); jarOne.addAsManifestResource(new StringAsset("test resource"), METAINF_RESOURCE_TXT); final JavaArchive jarTwo = ShrinkWrap.create(JavaArchive.class, "available2.jar"); jarTwo.addClass(Available2.class); jarTwo.addAsManifestResource(new StringAsset("test resource"), METAINF_RESOURCE_TXT); final JavaArchive ignoredJar = ShrinkWrap.create(JavaArchive.class, "ignored.jar"); ignoredJar.addClass(ToBeIgnored.class); final JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, "ejb.jar"); ejbJar.addClasses(ClassLoadingEJB.class, EarJBossDeploymentStructureTestCase.class); // grant necessary permissions ejbJar.addAsResource(createPermissionsXmlAsset(new RuntimePermission("getProtectionDomain")), "META-INF/jboss-permissions.xml"); ear.addAsModule(jarOne); ear.addAsModule(jarTwo); ear.addAsModule(ignoredJar); ear.addAsModule(ejbJar); return ear; } /** * Make sure the <filter> element in jboss-deployment-structure.xml is processed correctly and the * exclude/include is honoured * * @throws Exception */ @Test public void testDeploymentStructureFilters() throws Exception { this.ejb.loadClass(TO_BE_FOUND_CLASS_NAME); this.ejb.loadClass(TO_BE_FOUND_CLASS_NAME_2); try { this.ejb.loadClass(TO_BE_MISSSING_CLASS_NAME); Assert.fail("Unexpectedly found class " + TO_BE_MISSSING_CLASS_NAME); } catch (ClassNotFoundException cnfe) { // expected } } @Test public void testUsePhysicalCodeSource() throws ClassNotFoundException { Class<?> clazz = this.ejb.loadClass(TO_BE_FOUND_CLASS_NAME); Assert.assertTrue(clazz.getProtectionDomain().getCodeSource().getLocation().getProtocol().equals("jar")); Class<?> clazzTwo = this.ejb.loadClass(TO_BE_FOUND_CLASS_NAME_2); Assert.assertTrue(clazzTwo.getProtectionDomain().getCodeSource().getLocation().getProtocol().equals("jar")); Assert.assertTrue(ClassLoadingEJB.class.getProtectionDomain().getCodeSource().getLocation().getProtocol().equals("jar")); } @Test public void testMetaInfResourceImported() { Assert.assertTrue(this.ejb.hasResource("/META-INF/" + METAINF_RESOURCE_TXT)); } /** * EE.5.15, part of testsuite migration AS6->AS7 (jbas7556) */ @Test public void testModuleName() throws Exception { String result = ejb.query("java:module/ModuleName"); assertEquals("ejb", result); result = ejb.getResourceModuleName(); assertEquals("ejb", result); } @Test public void testAppName() throws Exception { String result = ejb.query("java:app/AppName"); assertEquals("deployment-structure", result); result = ejb.getResourceAppName(); assertEquals("deployment-structure", result); } }
5,273
37.49635
158
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/structure/war/WarJBossDeploymentStructureTestCase.java
package org.jboss.as.test.integration.deployment.structure.war; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.logging.Logger; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.exporter.ZipExporter; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import jakarta.ejb.EJB; import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; import static org.junit.Assert.assertEquals; /** * Tests parsing of jboss-deployment-structure.xml file in a deployment * <p/> * User: Jaikiran Pai */ @RunWith(Arquillian.class) public class WarJBossDeploymentStructureTestCase { private static final Logger logger = Logger.getLogger(WarJBossDeploymentStructureTestCase.class); @EJB(mappedName = "java:module/ClassLoadingEJB") private ClassLoadingEJB ejb; public static final String TO_BE_FOUND_CLASS_NAME = "org.jboss.as.test.integration.deployment.structure.war.Available"; public static final String TO_BE_MISSSING_CLASS_NAME = "org.jboss.as.test.integration.deployment.structure.war.ToBeIgnored"; @Deployment public static Archive<?> createDeployment() { final WebArchive war = ShrinkWrap.create(WebArchive.class, "deployment-structure.war"); war.addAsManifestResource(WarJBossDeploymentStructureTestCase.class.getPackage(), "jboss-all.xml", "jboss-all.xml"); final JavaArchive jarOne = ShrinkWrap.create(JavaArchive.class, "available.jar"); jarOne.addClass(Available.class); final JavaArchive ignoredJar = ShrinkWrap.create(JavaArchive.class, "ignored.jar"); ignoredJar.addClass(ToBeIgnored.class); war.addClasses(ClassLoadingEJB.class, WarJBossDeploymentStructureTestCase.class); war.add(jarOne, "a", ZipExporter.class); war.add(ignoredJar, "i", ZipExporter.class); war.addAsWebResource(new StringAsset("Root file"), "root-file.txt"); war.addAsManifestResource(createPermissionsXmlAsset( new RuntimePermission("getClassLoader"), new RuntimePermission("getProtectionDomain")), "permissions.xml"); return war; } /** * Make sure the <filter> element in jboss-deployment-structure.xml is processed correctly and the * exclude/include is honoured * * @throws Exception */ @Test public void testDeploymentStructureFilters() throws Exception { this.ejb.loadClass(TO_BE_FOUND_CLASS_NAME); try { this.ejb.loadClass(TO_BE_MISSSING_CLASS_NAME); Assert.fail("Unexpectedly found class " + TO_BE_MISSSING_CLASS_NAME); } catch (ClassNotFoundException cnfe) { // expected } } @Test public void testUsePhysicalCodeSource() throws ClassNotFoundException { Class<?> clazz = this.ejb.loadClass(TO_BE_FOUND_CLASS_NAME); Assert.assertTrue(clazz.getProtectionDomain().getCodeSource().getLocation().getProtocol().equals("jar")); Assert.assertTrue(ClassLoadingEJB.class.getProtectionDomain().getCodeSource().getLocation().getProtocol().equals("file")); } /** * EE.5.15, part of testsuite migration AS6->AS7 (jbas7556) */ @Test public void testModuleName() throws Exception { String result = ejb.query("java:module/ModuleName"); assertEquals("deployment-structure", result); result = ejb.getResourceModuleName(); assertEquals("deployment-structure", result); } @Test public void testAppName() throws Exception { String result = ejb.query("java:app/AppName"); assertEquals("deployment-structure", result); result = ejb.getResourceAppName(); assertEquals("deployment-structure", result); } @Test public void testAddingRootResource() throws ClassNotFoundException, IOException { InputStream clazz = getClass().getClassLoader().getResourceAsStream("root-file.txt"); try { byte[] data = new byte[100]; int res; StringBuilder sb = new StringBuilder(); while ((res = clazz.read(data)) > 0) { sb.append(new String(data, 0, res, StandardCharsets.UTF_8)); } Assert.assertEquals("Root file", sb.toString()); } finally { clazz.close(); } } }
4,754
36.148438
130
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/structure/war/ToBeIgnored.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.structure.war; /** * User: jpai */ public class ToBeIgnored { }
1,140
37.033333
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/structure/war/ClassLoadingEJB.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.structure.war; import jakarta.annotation.Resource; import jakarta.ejb.Stateless; import javax.naming.InitialContext; import javax.naming.NamingException; /** * User: jpai */ @Stateless public class ClassLoadingEJB { @Resource(lookup = "java:module/ModuleName") private String moduleName; @Resource(lookup = "java:app/AppName") private String appName; public Class<?> loadClass(String className) throws ClassNotFoundException { if (className == null || className.trim().isEmpty()) { throw new RuntimeException("Classname parameter cannot be null or empty"); } return this.getClass().getClassLoader().loadClass(className); } public String query(String name) throws NamingException { return new InitialContext().lookup(name).toString(); } public String getResourceModuleName() { return moduleName; } public String getResourceAppName() { return appName; } }
2,045
32.540984
86
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/structure/war/Available.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.structure.war; /** * User: jpai */ public class Available { }
1,138
36.966667
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/structure/war/symboliclink/SymlinkingUnitTestCase.java
package org.jboss.as.test.integration.deployment.structure.war.symboliclink; import java.io.File; import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; import org.junit.Assert; import org.junit.Assume; import org.apache.commons.lang3.SystemUtils; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.client.ModelControllerClient; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.as.controller.operations.common.Util; import org.jboss.as.test.shared.TestSuiteEnvironment; import org.jboss.dmr.ModelNode; import org.jboss.logging.Logger; import org.junit.After; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; /** * Unit test to make sure that the symbolic linking feature on the web subsystem is enabled properly. * Corresponding JIRA: AS7-3414. * * @author navssurtani */ @RunWith(Arquillian.class) @RunAsClient public class SymlinkingUnitTestCase { private static final Logger logger = Logger.getLogger(SymlinkingUnitTestCase.class); private static final String WAR_NAME = "explodedDeployment.war"; private static File warDeployment = null; private static File symbolic = null; private static ModelControllerClient controllerClient = TestSuiteEnvironment.getModelControllerClient(); @BeforeClass public static void beforeClass() throws IOException, InterruptedException { Assume.assumeFalse(SystemUtils.IS_OS_WINDOWS); // We are going to check whether or not the war deployment actually exists. Assert.assertTrue(checkForDeployment()); // Now create the symlink. createSymlink(); } @AfterClass public static void afterClass() throws IOException { if (SystemUtils.IS_OS_WINDOWS) { // skip windows; } else { // Delete the symlink symbolic.delete(); controllerClient.close(); controllerClient = null; } } @After public void tearDown() throws IOException { ModelNode removeSystemProperty = Util.createRemoveOperation(PathAddress.pathAddress(systemPropertyAddress())); // Define the content. ModelNode content = new ModelNode(); content.get(0).get(ModelDescriptionConstants.ARCHIVE).set(false); content.get(0).get(ModelDescriptionConstants.PATH).set(warDeployment.getAbsolutePath()); // Undeploy operation. ModelNode undeployOperation = Util.getEmptyOperation(ModelDescriptionConstants.UNDEPLOY, new ModelNode().add(ModelDescriptionConstants.DEPLOYMENT, WAR_NAME)); undeployOperation.get(ModelDescriptionConstants.CONTENT).set(ModelDescriptionConstants.CONTENT); undeployOperation.get(ModelDescriptionConstants.ENABLE).set(true); // Remove operation. ModelNode removeOperation = Util.getEmptyOperation(ModelDescriptionConstants.REMOVE, new ModelNode().add(ModelDescriptionConstants.DEPLOYMENT, WAR_NAME)); removeOperation.get(ModelDescriptionConstants.CONTENT).set(ModelDescriptionConstants.CONTENT); removeOperation.get(ModelDescriptionConstants.ENABLE).set(true); // Composite operation. ModelNode compositeOperation = Util.getEmptyOperation(ModelDescriptionConstants.COMPOSITE, new ModelNode()); ModelNode steps = compositeOperation.get(ModelDescriptionConstants.STEPS); steps.add(undeployOperation); steps.add(removeOperation); steps.add(removeSystemProperty); ModelNode compositeResult = controllerClient.execute(compositeOperation); Assert.assertEquals(ModelDescriptionConstants.SUCCESS, compositeResult.get(ModelDescriptionConstants.OUTCOME).asString()); } @Test public void testEnabled() throws IOException { // By default we should not be able to browse to the symlinked page. Assert.assertTrue(getURLcode("symbolic") == 404); setup(true); // First make sure that we can browse to index.html. This should work in the enabled or disabled version. Assert.assertTrue(getURLcode("index") == 200); // Now with symbolic.html. Assert.assertTrue(getURLcode("symbolic") == 200); } @Test public void testDisabled() throws IOException { // By default we should not be able to browse to the symlinked page. Assert.assertTrue(getURLcode("symbolic") == 404); setup(false); // First make sure that we can browse to index.html. This should work in the enabled or disabled version. Assert.assertTrue(getURLcode("index") == 200); // Now with symbolic.html. Assert.assertTrue(getURLcode("symbolic") == 404); } private void setup(boolean symlinkingEnabled) throws IOException { ModelNode addSysProperty = Util.createAddOperation(PathAddress.pathAddress(systemPropertyAddress())); addSysProperty.get(ModelDescriptionConstants.VALUE).set(Boolean.toString(symlinkingEnabled)); ModelNode result = controllerClient.execute(addSysProperty); Assert.assertEquals(ModelDescriptionConstants.SUCCESS, result.get(ModelDescriptionConstants.OUTCOME).asString()); // Define the content. ModelNode content = new ModelNode(); content.get(0).get(ModelDescriptionConstants.ARCHIVE).set(false); content.get(0).get(ModelDescriptionConstants.PATH).set(warDeployment.getAbsolutePath()); // Add operation. ModelNode addOperation = Util.getEmptyOperation(ModelDescriptionConstants.ADD, new ModelNode().add(ModelDescriptionConstants.DEPLOYMENT, WAR_NAME)); addOperation.get(ModelDescriptionConstants.CONTENT).set(content); addOperation.get(ModelDescriptionConstants.ENABLE).set(true); result = controllerClient.execute(addOperation); Assert.assertEquals(ModelDescriptionConstants.SUCCESS, result.get(ModelDescriptionConstants.OUTCOME).asString()); // Deployment operation. ModelNode deploymentOperation = Util.getEmptyOperation(ModelDescriptionConstants.DEPLOY, new ModelNode().add(ModelDescriptionConstants.DEPLOYMENT, WAR_NAME)); deploymentOperation.get(ModelDescriptionConstants.CONTENT).set(content); deploymentOperation.get(ModelDescriptionConstants.ENABLE).set(true); result = controllerClient.execute(deploymentOperation); Assert.assertEquals(ModelDescriptionConstants.SUCCESS, result.get(ModelDescriptionConstants.OUTCOME).asString()); } private int getURLcode(String htmlPage) { int code = 0; try { String url = "http://" + TestSuiteEnvironment.getServerAddress() + ":8080/explodedDeployment/" + htmlPage + ".html"; HttpURLConnection urlConnection = (HttpURLConnection) new URL(url).openConnection(); urlConnection.setRequestMethod("GET"); urlConnection.connect(); code = urlConnection.getResponseCode(); } catch (Exception e) { logger.errorf(e, "Exception of type: %s caught", e.getClass()); Assert.fail("Failed to get the URL code: " + e.getLocalizedMessage()); } return code; } private ModelNode systemPropertyAddress() { ModelNode address = new ModelNode(); address.add("system-property", "symbolic-linking-enabled"); address.protect(); return address; } private static boolean checkForDeployment() { String warLocation = getWarLocation(); warDeployment = new File(warLocation); return warDeployment.exists(); } private static String getWarLocation() { return SymlinkingUnitTestCase.class.getResource(WAR_NAME).getPath(); } private static void createSymlink() throws IOException, InterruptedException { // TODO: navssurtani: once AS7 is on a minimum of Java 7 then we can change the approach used to create the symlink. File index = new File(warDeployment, "index.html"); Assert.assertTrue(index.exists()); // Now set up the information to create the symlink. String toExecute; if (SystemUtils.IS_OS_WINDOWS) { toExecute = "mklink \\D " + index.getAbsolutePath() + " " + warDeployment.getAbsolutePath() + "\\symbolic.html"; } else { toExecute = "ln -s " + index.getAbsolutePath() + " " + warDeployment.getAbsolutePath() + "/symbolic.html"; } logger.debugf("String to be executed is: %s", toExecute); Runtime.getRuntime().exec(toExecute).waitFor(); symbolic = new File(warDeployment.getAbsolutePath(), "symbolic.html"); logger.debugf("Absolute path of symbolic file is located at %s. Checking to see if the file really exists.", symbolic.getAbsolutePath()); Assert.assertTrue(symbolic.exists()); } }
9,036
42.868932
166
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/moduleslisting/DeploymentModulesListTestCase.java
/* * Copyright 2019 Red Hat, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.as.test.integration.deployment.moduleslisting; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.LIST_MODULES; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RESULT; import static org.jboss.as.domain.management.ModelDescriptionConstants.VERBOSE; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.arquillian.api.ContainerResource; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.client.helpers.Operations; import org.jboss.dmr.ModelNode; import org.jboss.dmr.Property; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; /** * List modules which are on deployment’s classpath * /deployment=application_war_ear_name:list-modules(verbose=false|true) * @author <a href="mailto:[email protected]">Sultan Zhantemirov</a> (c) 2019 Red Hat, inc. */ @RunWith(Arquillian.class) @ServerSetup(UserModuleSetupTask.class) @RunAsClient public class DeploymentModulesListTestCase { private static final String NODE_TYPE = "deployment"; private static final String INNER_JAR_ARCHIVE_NAME = "inner-jar-lib.jar"; private static final String EXAMPLE_MODULE_TO_EXCLUDE = "org.slf4j.impl"; private static final String INNER_WAR_ARCHIVE_NAME = "list-modules.war"; private static final String EAR_DEPLOYMENT_NAME = "list-modules-ear-test.ear"; public static final String TEST_MODULE = "org.testModule"; @ContainerResource private static ManagementClient managementClient; @Deployment public static Archive<?> deploy() { EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, EAR_DEPLOYMENT_NAME); JavaArchive earLib = ShrinkWrap.create(JavaArchive.class); earLib.addClass(DeploymentModulesListTestCase.class); earLib.addAsManifestResource(EmptyAsset.INSTANCE, "emptyJarLibResource.properties"); earLib.addAsManifestResource(EmptyAsset.INSTANCE, "properties/nestedJarLib.properties"); ear.addAsLibraries(earLib); WebArchive war = ShrinkWrap.create(WebArchive.class, INNER_WAR_ARCHIVE_NAME); war.addClass(DeploymentModulesListTestCase.class); war.add(EmptyAsset.INSTANCE, "META-INF/example.txt"); war.add(EmptyAsset.INSTANCE, "META-INF/properties/nested.properties"); JavaArchive libJar = ShrinkWrap.create(JavaArchive.class, INNER_JAR_ARCHIVE_NAME); libJar.addClass(DeploymentModulesListTestCase.class); war.addAsLibraries(libJar); ear.addAsModules(libJar, war); ear.add(new StringAsset(prepareJBossEarDeploymentStructure()),"/META-INF/jboss-deployment-structure.xml"); ear.addAsResource(EmptyAsset.INSTANCE, "emptyEarResource"); return ear; } @Test public void listEarModulesNonVerbose() throws Throwable { this.listEarModules(false); } @Test public void listEarModulesVerbose() throws Throwable { this.listEarModules(true); } private void listEarModules(boolean verbose) throws Throwable { final ModelNode operation = new ModelNode(); operation.get(OP).set(LIST_MODULES); operation.get(OP_ADDR).set(PathAddress.parseCLIStyleAddress("/" + NODE_TYPE + "=" + EAR_DEPLOYMENT_NAME + "/subdeployment=" + INNER_WAR_ARCHIVE_NAME).toModelNode()); if (verbose) { operation.get(VERBOSE).set(Boolean.TRUE.toString()); } final ModelNode operationResult = managementClient.getControllerClient().execute(operation); // check whether the operation was successful assertTrue(Operations.isSuccessfulOutcome(operationResult)); // check standard/detailed output if (!verbose) { // check whether modules are ordered alphabetically assertTrue(isOrderedAlphabetically(operationResult)); // check module presence assertTrue(checkModulesListPresence(operationResult, "deployment." + EAR_DEPLOYMENT_NAME)); // check user defined module with custom slot assertTrue(checkModulesListPresence(operationResult, TEST_MODULE)); // check module absence assertFalse(checkModulesListPresence(operationResult, EXAMPLE_MODULE_TO_EXCLUDE)); // check system and user dependencies presence assertTrue(checkModulesListNonEmptiness(operationResult)); } else { // check other attributes presence only assertTrue(checkDetailedOutput(operationResult)); } } /** * Checks given module presence in the "list-modules" command output. * @param operationResult - operation object to extract result from * @param moduleName - name of the module expected to be present * @return true if given module is present in any (system, local, user) list of module dependencies */ private boolean checkModulesListPresence(ModelNode operationResult, String moduleName) { boolean isModulePresent = false; for (Property dependenciesGroup : operationResult.get(RESULT).asPropertyList()) { List<Property> list = dependenciesGroup .getValue() .asPropertyList() .stream() .filter(dependency -> dependency.getValue().asString().equalsIgnoreCase(moduleName)) .collect(Collectors.toList()); if (list.size() > 0) isModulePresent = true; } return isModulePresent; } /** * Checks whether the module output information contains at least one of the "optional", "export" and "import-services" attributes. * @param operationResult - operation object to extract result from * @return true if detailed output is present */ private boolean checkDetailedOutput(ModelNode operationResult) { boolean isDetailedOutput = false; for (Property dependenciesGroup : operationResult.get(RESULT).asPropertyList()) { for (ModelNode dependency : dependenciesGroup.getValue().asList()) { isDetailedOutput = dependency .asPropertyList() .stream() .map(Property::getName) .anyMatch(attributeName -> attributeName.equalsIgnoreCase("optional") || attributeName.equalsIgnoreCase("import-services") || attributeName.equalsIgnoreCase("export") ); } } return isDetailedOutput; } /** * Checks whether both system and user dependencies lists are not empty. * @param operationResult - operation object to extract result from * @return true if both system and user dependencies lists are not empty */ private boolean checkModulesListNonEmptiness(ModelNode operationResult) { boolean isSystemDependenciesPresent = false; boolean isUserDependenciesPresent = false; for (Property dependenciesGroup : operationResult.get(RESULT).asPropertyList()) { if (dependenciesGroup.getName().equalsIgnoreCase("system-dependencies")) { // check system dependencies list non-emptiness isSystemDependenciesPresent = !dependenciesGroup.getValue().asPropertyList().isEmpty(); } if (dependenciesGroup.getName().equalsIgnoreCase("user-dependencies")) { // check system dependencies list non-emptiness isUserDependenciesPresent = !dependenciesGroup.getValue().asPropertyList().isEmpty(); } } return isSystemDependenciesPresent && isUserDependenciesPresent; } private static String prepareJBossEarDeploymentStructure() { return "<jboss-deployment-structure>\n" + " <deployment>\n" + " <exclusions>\n" + " <module name=\"" + EXAMPLE_MODULE_TO_EXCLUDE + "\"/>\n" + " </exclusions>\n" + " </deployment>\n" + " <sub-deployment name=\"" + INNER_WAR_ARCHIVE_NAME + "\">\n" + " <exclusions>\n" + " <module name=\"" + EXAMPLE_MODULE_TO_EXCLUDE + "\"/>\n" + " </exclusions>\n" + " <dependencies>\n" + " <module name=\"" + TEST_MODULE + "\"/>\n" + " </dependencies>\n" + " </sub-deployment>\n" + "</jboss-deployment-structure>\n"; } private boolean isOrderedAlphabetically(ModelNode operationResult) { List<String> dependenciesList; List<Property> list; boolean isSorted = true; for (Property dependenciesGroup : operationResult.get(RESULT).asPropertyList()) { dependenciesList = new ArrayList<>(); list = dependenciesGroup.getValue().asPropertyList(); for (Property dependency : list) { dependenciesList.add(dependency.getValue().asString()); } isSorted = isSorted(dependenciesList); } return isSorted; } private boolean isSorted(List<String> list) { boolean sorted = true; for (int i = 1; i < list.size(); i++) { if (list.get(i - 1).compareTo(list.get(i)) > 0) { sorted = false; } } return sorted; } }
11,029
42.769841
173
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/moduleslisting/UserModuleSetupTask.java
/* * JBoss, Home of Professional Open Source. * Copyright 2023, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.moduleslisting; import org.jboss.as.arquillian.api.ServerSetupTask; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.test.module.util.TestModule; public class UserModuleSetupTask implements ServerSetupTask { private volatile TestModule testModule; @Override public void setup(ManagementClient arg0, String arg1) throws Exception { testModule = new TestModule(DeploymentModulesListTestCase.TEST_MODULE); testModule.create(); } @Override public void tearDown(ManagementClient arg0, String arg1) throws Exception { if (testModule != null) { testModule.remove(); } } }
1,743
38.636364
79
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/transientdependencies/Servlet.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.transientdependencies; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; /** * @author Jaikiran Pai */ public class Servlet extends HttpServlet { static final String SUCCESS = "success"; @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { final String className = req.getParameter("className"); try { final Class<?> klass = Thread.currentThread().getContextClassLoader().loadClass(className); resp.getOutputStream().print(SUCCESS); } catch (ClassNotFoundException cnfe) { throw new RuntimeException("Could not load a class: " + className + " which was expected to be available", cnfe); } } }
1,993
39.693878
125
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/transientdependencies/RarTransientDependenciesTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.transientdependencies; import java.net.URL; import java.util.concurrent.TimeUnit; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.test.integration.common.HttpRequest; import org.jboss.as.test.integration.jca.beanvalidation.ra.ValidConnectionFactory; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.exporter.ZipExporter; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.ResourceAdapterArchive; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * Tests that a rar deployments transitive deps are made available to a deployment that references the rar * * @author Stuart Douglas * @author Jaikiran Pai */ @RunWith(Arquillian.class) @RunAsClient public class RarTransientDependenciesTestCase { /** * Creates a .ear which has the following packaging structure: * <p/> * rar-transient-dep.ear * | * |--- rardeployment.rar (RAR deployment) * | | * | |--- META-INF * | | | * | | |--- ra.xml * | | | * | | |--- MANIFEST.MF containing -> Class-Path: transient.jar (to point to the jar at the root of the .ear) * | * | * |--- referenceingwebapp.war (war deployment) * | | * | | * | |--- org.jboss.as.test.integration.deployment.classloading.transientdependencies.Servlet (the servlet which tries to access the class in the transient.jar, when invoked) * | * | * |--- transient.jar (simple jar file and NOT a deployment. this jar is referenced via the Class-Path manifest attribute in the .rar and as a result, is transitively expected to be available for access in the .war) * | | * | |--- org.jboss.as.test.integration.deployment.classloading.transientdependencies.JarClass * * @return */ @Deployment public static Archive<?> createDeployment() { final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "rar-transient-dep.ear"); final ResourceAdapterArchive rar = ShrinkWrap.create(ResourceAdapterArchive.class, "rardeployment.rar"); JavaArchive jar1 = ShrinkWrap.create(JavaArchive.class, "main.jar"); jar1.addPackage(ValidConnectionFactory.class.getPackage()); rar.add(jar1, "/", ZipExporter.class); rar.addAsManifestResource(RarTransientDependenciesTestCase.class.getPackage(), "MANIFEST.MF", "MANIFEST.MF"); rar.addAsManifestResource(RarTransientDependenciesTestCase.class.getPackage(), "ra.xml", "ra.xml"); // add the .rar to the .ear ear.addAsModule(rar); // now create the transient.jar with the JarClass.class final JavaArchive transientDepJar = ShrinkWrap.create(JavaArchive.class, "transient.jar"); transientDepJar.addClass(JarClass.class); // add this jar to the root of the .ear as simple jar and not as a module. the .rar in the .ear will have a Class-Path reference // to this jar ear.add(transientDepJar, "/", ZipExporter.class); // finally create and add the .war to the .ear final WebArchive war = ShrinkWrap.create(WebArchive.class, "referenceingwebapp.war"); war.addClasses(RarTransientDependenciesTestCase.class, Servlet.class); war.addAsWebInfResource(RarTransientDependenciesTestCase.class.getPackage(), "web.xml", "web.xml"); ear.addAsModule(war); return ear; } /** * Tests that a class available in a jar, which is added as a Class-Path manifest attribute of a .rar is available for access from within a class * in a .war deployment, belonging to the same .ear top level deployment. This tests section EE.8.3 (Class Loading Requirements) of Jakarta EE 8 spec * * @param baseUrl * @throws Exception */ @Test public void testTransitiveDependencyAccessViaRar(@ArquillianResource URL baseUrl) throws Exception { final String url = "http://" + baseUrl.getHost() + ":" + baseUrl.getPort() + "/referenceingwebapp/servlet?className=" + JarClass.class.getName(); final String res = HttpRequest.get(url, 2, TimeUnit.SECONDS); Assert.assertEquals(Servlet.SUCCESS, res); } }
5,711
43.976378
219
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/transientdependencies/JarClass.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.transientdependencies; /** * @author Stuart Douglas */ public class JarClass { }
1,162
39.103448
84
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/sar/SarMainClass.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.sar; public class SarMainClass { }
1,115
40.333333
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/sar/SarClassLoadingTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.sar; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; 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 org.junit.runner.RunWith; /** * Tests that nested jars in a sar are picked up as resource roots and loaded from the same class loader. * * @author Tomasz Adamski */ @RunWith(Arquillian.class) public class SarClassLoadingTestCase { @Deployment public static Archive<?> deployment() { JavaArchive sar = ShrinkWrap.create(JavaArchive.class, "sarClassLoadingTest.sar"); sar.addClasses(SarClassLoadingTestCase.class, SarMainClass.class); JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "inner.jar"); jar.addClasses(SarSupportClass.class); sar.add(jar, "/", ZipExporter.class); return sar; } @Test public void testSarClassLoading() { SarMainClass cl = new SarMainClass(); SarSupportClass cl2 = new SarSupportClass(); Assert.assertEquals(cl.getClass().getClassLoader(), cl2.getClass().getClassLoader()); } }
2,344
38.745763
105
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/sar/SarSupportClass.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.sar; public class SarSupportClass { }
1,118
40.444444
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/rar/RarMainClass.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.rar; public class RarMainClass { }
1,115
40.333333
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/rar/RarClassLoadingTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.rar; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.test.integration.jca.beanvalidation.ra.ValidConnectionFactory; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.exporter.ZipExporter; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.ResourceAdapterArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * Tests that nesteled jars in a rar are picked up as resource roots and loaded from the same class loader. * * @author Stuart Douglas */ @RunWith(Arquillian.class) public class RarClassLoadingTestCase { @Deployment public static Archive<?> deployment() { ResourceAdapterArchive rar = ShrinkWrap.create(ResourceAdapterArchive.class, "rarClassLoadingTest.rar"); JavaArchive jar1 = ShrinkWrap.create(JavaArchive.class, "main.jar"); jar1.addClasses(RarClassLoadingTestCase.class, RarMainClass.class); jar1.addPackage(ValidConnectionFactory.class.getPackage()); rar.add(jar1, "/", ZipExporter.class); JavaArchive jar2 = ShrinkWrap.create(JavaArchive.class, "support.jar"); jar2.addClasses(RarSupportClass.class); rar.add(jar2, "some/random/directory", ZipExporter.class); rar.addAsManifestResource(RarClassLoadingTestCase.class.getPackage(), "ra.xml", "ra.xml"); return rar; } @Test public void testRarClassLoading() { RarMainClass cl = new RarMainClass(); RarSupportClass cl2 = new RarSupportClass(); Assert.assertEquals(cl.getClass().getClassLoader(), cl2.getClass().getClassLoader()); } }
2,831
41.268657
112
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/rar/RarSupportClass.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.rar; public class RarSupportClass { }
1,118
40.444444
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/ear/EarClassPath2TestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.ear; import java.nio.charset.StandardCharsets; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.ByteArrayAsset; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; @RunWith(Arquillian.class) public class EarClassPath2TestCase { @Deployment public static Archive<?> deploy() { WebArchive war = ShrinkWrap.create(WebArchive.class); JavaArchive libJar = ShrinkWrap.create(JavaArchive.class); libJar.addClasses(TestAA.class, EarClassPath2TestCase.class); libJar.addAsManifestResource(new ByteArrayAsset("Class-Path: ../../../cp.jar\n".getBytes(StandardCharsets.UTF_8)), "MANIFEST.MF"); war.addAsLibraries(libJar); EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class); ear.addAsModule(war); JavaArchive earLib = ShrinkWrap.create(JavaArchive.class, "cp.jar"); earLib.addClass(TestBB.class); ear.addAsModule(earLib); return ear; } @Test public void testWebInfLibAccessible() throws ClassNotFoundException { loadClass("org.jboss.as.test.integration.deployment.classloading.ear.TestAA"); } @Test public void testClassPathEntryAccessible() throws ClassNotFoundException { loadClass("org.jboss.as.test.integration.deployment.classloading.ear.TestBB"); } private static Class<?> loadClass(String name) throws ClassNotFoundException { ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (cl != null) { return Class.forName(name, false, cl); } else return Class.forName(name); } }
3,018
39.797297
138
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/ear/EarClassLoadingTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.ear; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; @RunWith(Arquillian.class) public class EarClassLoadingTestCase { @Deployment public static Archive<?> deploy() { WebArchive war = ShrinkWrap.create(WebArchive.class); JavaArchive libJar = ShrinkWrap.create(JavaArchive.class); libJar.addClass(TestAA.class); war.addAsLibraries(libJar); EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class); ear.addAsModule(war); JavaArchive earLib = ShrinkWrap.create(JavaArchive.class); earLib.addClass(TestBB.class); earLib.addClass(EarClassLoadingTestCase.class); ear.addAsLibraries(earLib); return ear; } @Test(expected = ClassNotFoundException.class) public void testWebInfLibNotAccessible() throws ClassNotFoundException { loadClass("org.jboss.as.test.integration.deployment.classloading.ear.TestAA"); } @Test public void testLibAccessible() throws ClassNotFoundException { loadClass("org.jboss.as.test.integration.deployment.classloading.ear.TestBB"); } private static Class<?> loadClass(String name) throws ClassNotFoundException { ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (cl != null) { return Class.forName(name, false, cl); } else return Class.forName(name); } }
2,835
38.943662
86
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/ear/EarManifestDependencyPropagatedTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.ear; import org.junit.Assert; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Test; import org.junit.runner.RunWith; /** * tests that dependencies added to items in the ear are propagated to sub deployments. */ @RunWith(Arquillian.class) public class EarManifestDependencyPropagatedTestCase { public static final String CLASS_FILE_WRITER_CLASS = "org.jboss.classfilewriter.ClassFile"; public static final String JANDEX_CLASS = "org.jboss.jandex.Index"; @Deployment public static Archive<?> deploy() { EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class,"eartest.ear"); JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class,"ejbmodule.jar"); ejbJar.addClasses(EarManifestDependencyPropagatedTestCase.class); ejbJar.addAsManifestResource(emptyEjbJar(), "ejb-jar.xml"); ejbJar.addAsManifestResource(new StringAsset("Dependencies: io.smallrye.jandex\n"),"MANIFEST.MF"); ear.addAsModule(ejbJar); JavaArchive earLib = ShrinkWrap.create(JavaArchive.class, "libjar.jar"); earLib.addAsManifestResource(new StringAsset("Dependencies: org.jboss.classfilewriter\n"),"MANIFEST.MF"); earLib.addClass(EarLibClassLoadingClass.class); ear.addAsLibraries(earLib); return ear; } @Test public void testClassFileWriterAccessible() throws ClassNotFoundException { loadClass(CLASS_FILE_WRITER_CLASS); EarLibClassLoadingClass.loadClass(CLASS_FILE_WRITER_CLASS); } @Test public void testJandexAccessibility() throws ClassNotFoundException { loadClass(JANDEX_CLASS); try { EarLibClassLoadingClass.loadClass(JANDEX_CLASS); Assert.fail("Expected class loading to fail"); } catch (ClassNotFoundException e) { } } private static Class<?> loadClass(String name) throws ClassNotFoundException { ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (cl != null) { return Class.forName(name, false, cl); } else return Class.forName(name); } private static StringAsset emptyEjbJar() { return new StringAsset( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<ejb-jar xmlns=\"https://jakarta.ee/xml/ns/jakartaee\" \n" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n" + " xsi:schemaLocation=\"https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/ejb-jar_4_0.xsd\"\n" + " version=\"4.0\">\n" + " \n" + "</ejb-jar>"); } }
4,073
40.151515
141
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/ear/EarClassPath3TestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.ear; import java.nio.charset.StandardCharsets; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.ByteArrayAsset; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; @RunWith(Arquillian.class) public class EarClassPath3TestCase { @Deployment public static Archive<?> deploy() { WebArchive war = ShrinkWrap.create(WebArchive.class); JavaArchive libJar = ShrinkWrap.create(JavaArchive.class); libJar.addClasses(TestAA.class, EarClassPath3TestCase.class); libJar.addAsManifestResource(new ByteArrayAsset("Class-Path: ../../../cp.jar\n".getBytes(StandardCharsets.UTF_8)), "MANIFEST.MF"); war.addAsLibraries(libJar); EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class); ear.addAsModule(war); JavaArchive earLib = ShrinkWrap.create(JavaArchive.class, "cp.jar"); earLib.addClass(TestBB.class); ear.addAsModule(earLib); earLib = ShrinkWrap.create(JavaArchive.class, "cp.jar"); earLib.addClass(TestBB.class); ear.addAsModule(earLib); return ear; } @Test public void testWebInfLibAccessible() throws ClassNotFoundException { loadClass("org.jboss.as.test.integration.deployment.classloading.ear.TestAA"); } @Test public void testClassPathEntryAccessible() throws ClassNotFoundException { loadClass("org.jboss.as.test.integration.deployment.classloading.ear.TestBB"); } private static Class<?> loadClass(String name) throws ClassNotFoundException { ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (cl != null) { return Class.forName(name, false, cl); } else return Class.forName(name); } }
3,155
39.987013
138
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/ear/EarLibClassPathTransitiveClosureTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.ear; import java.nio.charset.StandardCharsets; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.ByteArrayAsset; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; @RunWith(Arquillian.class) public class EarLibClassPathTransitiveClosureTestCase { @Deployment public static Archive<?> deploy() { WebArchive war = ShrinkWrap.create(WebArchive.class); JavaArchive libJar = ShrinkWrap.create(JavaArchive.class); libJar.addClasses(TestAA.class, EarLibClassPathTransitiveClosureTestCase.class); war.addAsLibraries(libJar); EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class); ear.addAsModule(war); JavaArchive earLib = ShrinkWrap.create(JavaArchive.class, "earLib.jar"); earLib.addAsManifestResource(new ByteArrayAsset("Class-Path: ../cp1.jar\n".getBytes(StandardCharsets.UTF_8)), "MANIFEST.MF"); ear.addAsLibraries(earLib); earLib = ShrinkWrap.create(JavaArchive.class, "cp1.jar"); earLib.addAsManifestResource(new ByteArrayAsset("Class-Path: cp2.jar\n".getBytes(StandardCharsets.UTF_8)), "MANIFEST.MF"); ear.addAsModule(earLib); earLib = ShrinkWrap.create(JavaArchive.class, "cp2.jar"); earLib.addClass(TestBB.class); ear.addAsModule(earLib); return ear; } @Test public void testWebInfLibAccessible() throws ClassNotFoundException { loadClass("org.jboss.as.test.integration.deployment.classloading.ear.TestAA"); } @Test public void testClassPathEntryAccessible() throws ClassNotFoundException { loadClass("org.jboss.as.test.integration.deployment.classloading.ear.TestBB"); } private static Class<?> loadClass(String name) throws ClassNotFoundException { ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (cl != null) { return Class.forName(name, false, cl); } else return Class.forName(name); } }
3,389
40.851852
133
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/ear/TestBB.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.ear; public class TestBB { }
1,109
40.111111
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/ear/TestAA.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.ear; public class TestAA { }
1,109
40.111111
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/ear/EarJbossStructureDepedenciesTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.ear; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; @RunWith(Arquillian.class) public class EarJbossStructureDepedenciesTestCase { @Deployment public static Archive<?> deploy() { WebArchive war = ShrinkWrap.create(WebArchive.class, "test.war"); war.addClasses(TestAA.class, EarJbossStructureDepedenciesTestCase.class); EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class); ear.addAsModule(war); //test the 1.0 parser ear.addAsManifestResource(new StringAsset( "<jboss-deployment-structure xmlns=\"urn:jboss:deployment-structure:1.0\">" + "<deployment>" + "</deployment>" + "<sub-deployment name=\"test.war\">" + " <dependencies>" + " <module name=\"org.jboss.classfilewriter\" />" + " </dependencies>" + "</sub-deployment>" + "</jboss-deployment-structure>"), "jboss-deployment-structure.xml"); JavaArchive earLib = ShrinkWrap.create(JavaArchive.class, "earLib.jar"); earLib.addClass(TestBB.class); ear.addAsLibraries(earLib); ear.addAsManifestResource(createPermissionsXmlAsset(new RuntimePermission("getClassLoader")), "permissions.xml"); return ear; } @Test(expected = ClassNotFoundException.class) public void testEarDoesNotHaveAccessToClassfilewriter() throws ClassNotFoundException { loadClass("org.jboss.classfilewriter.ClassFile", TestBB.class.getClassLoader()); } @Test public void testWarHasAccessToClassFileWriter() throws ClassNotFoundException { loadClass("org.jboss.classfilewriter.ClassFile", getClass().getClassLoader()); } private static Class<?> loadClass(String name, ClassLoader cl) throws ClassNotFoundException { return Class.forName(name, false, cl); } }
3,580
43.7625
121
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/ear/EarLibClassLoadingClass.java
/* * JBoss, Home of Professional Open Source. * Copyright 2012, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.ear; /** * @author Stuart Douglas */ public class EarLibClassLoadingClass { public static void loadClass(final String className) throws ClassNotFoundException { EarLibClassLoadingClass.class.getClassLoader().loadClass(className); } }
1,341
37.342857
88
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/ear/WarCanAccessEjbJarTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.ear; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; @RunWith(Arquillian.class) public class WarCanAccessEjbJarTestCase { @Deployment public static Archive<?> deploy() { EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class); JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "otherjar.jar"); jar.addClass(TestAA.class); jar.addAsResource(emptyEjbJar(), "META-INF/ejb-jar.xml"); ear.addAsModule(jar); WebArchive war = ShrinkWrap.create(WebArchive.class, "testwar.war"); war.addClass(WarCanAccessEjbJarTestCase.class); war.addAsResource(new StringAsset("Class-Path: otherjar.jar\n"),"META-INF/MANIFEST.MF"); ear.addAsModule(war); return ear; } @Test public void testEjbJarCanAccessOtherEjbJar() throws ClassNotFoundException { loadClass("org.jboss.as.test.integration.deployment.classloading.ear.TestAA"); } private static Class<?> loadClass(String name) throws ClassNotFoundException { ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (cl != null) { return Class.forName(name, false, cl); } else return Class.forName(name); } private static StringAsset emptyEjbJar() { return new StringAsset( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<ejb-jar xmlns=\"https://jakarta.ee/xml/ns/jakartaee\" \n" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n" + " xsi:schemaLocation=\"https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/ejb-jar_4_0.xsd\"\n" + " version=\"4.0\">\n" + " \n" + "</ejb-jar>"); } }
3,288
39.604938
141
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/ear/EarJbossStructureRestrictedVisibilityTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.ear; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.test.integration.rar.HelloWorldConnection; import org.jboss.as.test.integration.rar.HelloWorldConnectionFactory; import org.jboss.as.test.integration.rar.HelloWorldConnectionFactoryImpl; import org.jboss.as.test.integration.rar.HelloWorldConnectionImpl; import org.jboss.as.test.integration.rar.HelloWorldManagedConnection; import org.jboss.as.test.integration.rar.HelloWorldManagedConnectionFactory; import org.jboss.as.test.integration.rar.HelloWorldManagedConnectionMetaData; import org.jboss.as.test.integration.rar.HelloWorldResourceAdapter; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.ResourceAdapterArchive; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; /** * Tests the ear-subdeployments-isolated option in jboss-deployment-structure.xml * * By default ejb-jar's are made visible to each other, this option removes this default visibility * */ @RunWith(Arquillian.class) public class EarJbossStructureRestrictedVisibilityTestCase { @Deployment public static Archive<?> deploy() { EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class); WebArchive war = ShrinkWrap.create(WebArchive.class,"test.war"); war.addClasses(TestAA.class); ear.addAsModule(war); JavaArchive ejb = ShrinkWrap.create(JavaArchive.class, "ejb1.jar"); ejb.addClasses(MyEjb.class, EarJbossStructureRestrictedVisibilityTestCase.class); ear.addAsModule(ejb); ejb = ShrinkWrap.create(JavaArchive.class, "ejb2.jar"); ejb.addClasses(MyEjb2.class); ear.addAsModule(ejb); ResourceAdapterArchive rar = ShrinkWrap.create(ResourceAdapterArchive.class, "rar.rar"); JavaArchive rarJar = ShrinkWrap.create(JavaArchive.class, "rarJar.jar"); rarJar.addClass(RarClass.class); rarJar.addClasses(HelloWorldResourceAdapter.class, HelloWorldConnection.class, HelloWorldConnectionFactory.class, HelloWorldConnectionFactoryImpl.class, HelloWorldConnectionImpl.class, HelloWorldManagedConnection.class, HelloWorldManagedConnectionFactory.class, HelloWorldManagedConnectionMetaData.class); rar.addAsLibraries(rarJar); ear.addAsModule(rar); ear.addAsManifestResource(new StringAsset( "<jboss-deployment-structure><ear-subdeployments-isolated>true</ear-subdeployments-isolated></jboss-deployment-structure>"), "jboss-deployment-structure.xml"); return ear; } @Test(expected = ClassNotFoundException.class) public void testWarModuleStillNotAccessible() throws ClassNotFoundException { loadClass("org.jboss.as.test.integration.deployment.classloading.ear.TestAA",getClass().getClassLoader()); } @Test(expected = ClassNotFoundException.class) public void testOtherEjbJarNotAcessible() throws ClassNotFoundException { loadClass("org.jboss.as.test.integration.deployment.classloading.ear.MyEjb2",getClass().getClassLoader()); } @Test public void testRarModuleIsAccessible() throws ClassNotFoundException { loadClass("org.jboss.as.test.integration.deployment.classloading.ear.RarClass",getClass().getClassLoader()); } private static Class<?> loadClass(String name, ClassLoader cl) throws ClassNotFoundException { if (cl != null) { return Class.forName(name, false, cl); } else return Class.forName(name); } }
4,995
42.443478
139
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/ear/EjbJarCanAccessOtherEjbJarTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.ear; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Test; import org.junit.runner.RunWith; @RunWith(Arquillian.class) public class EjbJarCanAccessOtherEjbJarTestCase { @Deployment public static Archive<?> deploy() { EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class); JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "otherjar.jar"); jar.addClass(TestAA.class); jar.addAsResource(emptyEjbJar(), "META-INF/ejb-jar.xml"); ear.addAsModule(jar); jar = ShrinkWrap.create(JavaArchive.class, "testjar.jar"); jar.addClass(EjbJarCanAccessOtherEjbJarTestCase.class); jar.addAsResource(emptyEjbJar(), "META-INF/ejb-jar.xml"); jar.addAsManifestResource(new StringAsset("Class-Path: otherjar.jar\n"),"MANIFEST.MF"); ear.addAsModule(jar); return ear; } @Test public void testEjbJarCanAccessOtherEjbJar() throws ClassNotFoundException { loadClass("org.jboss.as.test.integration.deployment.classloading.ear.TestAA"); } private static Class<?> loadClass(String name) throws ClassNotFoundException { ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (cl != null) { return Class.forName(name, false, cl); } else return Class.forName(name); } private static StringAsset emptyEjbJar() { return new StringAsset( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<ejb-jar xmlns=\"https://jakarta.ee/xml/ns/jakartaee\" \n" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n" + " xsi:schemaLocation=\"https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/ejb-jar_4_0.xsd\"\n" + " version=\"4.0\">\n" + " \n" + "</ejb-jar>"); } }
3,310
39.876543
141
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/ear/EarClassPath1TestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.ear; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; @RunWith(Arquillian.class) public class EarClassPath1TestCase { @Deployment public static Archive<?> deploy() { WebArchive war = ShrinkWrap.create(WebArchive.class); JavaArchive libJar = ShrinkWrap.create(JavaArchive.class); libJar.addClasses(TestAA.class, EarClassPath1TestCase.class); war.addAsLibraries(libJar); EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class); ear.addAsModule(war); JavaArchive earLib = ShrinkWrap.create(JavaArchive.class, "cp.jar"); earLib.addClass(TestBB.class); ear.addAsModule(earLib); return ear; } @Test public void testWebInfLibAccessible() throws ClassNotFoundException { loadClass("org.jboss.as.test.integration.deployment.classloading.ear.TestAA"); } @Test(expected = ClassNotFoundException.class) public void testEarJarNotAccessible() throws ClassNotFoundException { loadClass("org.jboss.as.test.integration.deployment.classloading.ear.TestBB"); } private static Class<?> loadClass(String name) throws ClassNotFoundException { ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (cl != null) { return Class.forName(name, false, cl); } else return Class.forName(name); } }
2,818
39.271429
86
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/ear/RarClass.java
package org.jboss.as.test.integration.deployment.classloading.ear; /** * @author Stuart Douglas */ public class RarClass { }
128
15.125
66
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/ear/EarJbossStructureAdditionalModuleTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.ear; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; @RunWith(Arquillian.class) public class EarJbossStructureAdditionalModuleTestCase { @Deployment public static Archive<?> deploy() { WebArchive war = ShrinkWrap.create(WebArchive.class, "test.war"); war.addClasses(TestAA.class, EarJbossStructureAdditionalModuleTestCase.class); EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class); ear.addAsModule(war); ear.addAsManifestResource(new StringAsset( "<jboss-deployment-structure>" + "<sub-deployment name=\"test.war\">" + "<dependencies>" + "<module name=\"deployment.somemodule\" />" + "</dependencies>" + "</sub-deployment>" + "<module name=\"deployment.somemodule\">" + "<resources><resource-root path=\"someModule.jar\"/></resources>" + "</module>" + "</jboss-deployment-structure>"), "jboss-deployment-structure.xml"); JavaArchive earLib = ShrinkWrap.create(JavaArchive.class, "someModule.jar"); earLib.addClass(TestBB.class); ear.addAsModule(earLib); return ear; } @Test public void testWarHassAccessToAdditionalModule() throws ClassNotFoundException { loadClass("org.jboss.as.test.integration.deployment.classloading.ear.TestBB", getClass().getClassLoader()); } private static Class<?> loadClass(String name, ClassLoader cl) throws ClassNotFoundException { if (cl != null) { return Class.forName(name, false, cl); } else return Class.forName(name); } }
3,261
42.493333
115
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/ear/MyEjb.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.ear; import jakarta.ejb.Stateless; /** * @author Stuart Douglas */ @Stateless public class MyEjb { public void doStuff() { } }
1,219
32.888889
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/ear/EarJbossStructureCascadeExclusionsTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2015, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.ear; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; @RunWith(Arquillian.class) public class EarJbossStructureCascadeExclusionsTestCase { @Deployment public static Archive<?> deploy() { WebArchive war = ShrinkWrap.create(WebArchive.class, "test.war"); war.addClasses(TestAA.class, EarJbossStructureCascadeExclusionsTestCase.class); EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class); ear.addAsModule(war); //test the 1.3 structure parser cascade exclusions ear.addAsManifestResource(new StringAsset( "<jboss-deployment-structure xmlns=\"urn:jboss:deployment-structure:1.3\">" + "<ear-exclusions-cascaded-to-subdeployments>true</ear-exclusions-cascaded-to-subdeployments>" + "<deployment>" + " <exclusions>" + " <module name=\"org.jboss.logging\" />" + " </exclusions>" + "</deployment>" + "<sub-deployment name=\"test.war\">" + " <dependencies>" + " <module name=\"org.jboss.classfilewriter\" />" + " </dependencies>" + "</sub-deployment>" + "</jboss-deployment-structure>"), "jboss-deployment-structure.xml"); return ear; } @Test(expected = ClassNotFoundException.class) public void testWarDoesNotHaveAccessToClassJbossLoggingLogger() throws ClassNotFoundException { loadClass("org.jboss.logging.Logger", getClass().getClassLoader()); } @Test public void testWarDoesHaveAccessToClassSlf4jLogger() throws ClassNotFoundException { loadClass("org.slf4j.Logger", getClass().getClassLoader()); } private static Class<?> loadClass(String name, ClassLoader cl) throws ClassNotFoundException { return Class.forName(name, false, cl); } }
3,448
43.792208
119
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/ear/WarCannotAccessOtherWarTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.ear; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; @RunWith(Arquillian.class) public class WarCannotAccessOtherWarTestCase { @Deployment public static Archive<?> deploy() { EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class); WebArchive war = ShrinkWrap.create(WebArchive.class); war.addClass(TestAA.class); ear.addAsModule(war); war = ShrinkWrap.create(WebArchive.class); war.addClass(WarCannotAccessOtherWarTestCase.class); ear.addAsModule(war); return ear; } @Test(expected = ClassNotFoundException.class) public void testWarCannotAccessOtherWar() throws ClassNotFoundException { loadClass("org.jboss.as.test.integration.deployment.classloading.ear.TestAA"); } private static Class<?> loadClass(String name) throws ClassNotFoundException { ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (cl != null) { return Class.forName(name, false, cl); } else return Class.forName(name); } }
2,464
36.348485
86
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/ear/EarClassPathTransitiveClosureTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.ear; import java.nio.charset.StandardCharsets; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.ByteArrayAsset; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.Assert; @RunWith(Arquillian.class) public class EarClassPathTransitiveClosureTestCase { @Deployment public static Archive<?> deploy() { WebArchive war = ShrinkWrap.create(WebArchive.class); JavaArchive libJar = ShrinkWrap.create(JavaArchive.class); libJar.addClasses(TestAA.class, EarClassPathTransitiveClosureTestCase.class); war.addAsLibraries(libJar); EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class); ear.addAsModule(war); JavaArchive earLib = ShrinkWrap.create(JavaArchive.class, "earLib.jar"); earLib.addAsManifestResource(new ByteArrayAsset("Class-Path: ../cp1.jar\n".getBytes(StandardCharsets.UTF_8)), "MANIFEST.MF"); ear.addAsLibraries(earLib); earLib = ShrinkWrap.create(JavaArchive.class, "cp1.jar"); earLib.addAsManifestResource(new ByteArrayAsset("Class-Path: cp2.jar\n".getBytes(StandardCharsets.UTF_8)), "MANIFEST.MF"); ear.addAsModule(earLib); earLib = ShrinkWrap.create(JavaArchive.class, "cp2.jar"); earLib.addAsManifestResource(new ByteArrayAsset("Class-Path: a/b/c\n".getBytes(StandardCharsets.UTF_8)), "MANIFEST.MF"); earLib.addClass(TestBB.class); ear.addAsModule(earLib); ear.add(new StringAsset("Hello World"), "a/b/c", "testfile.file"); return ear; } @Test public void testWebInfLibAccessible() throws ClassNotFoundException { loadClass("org.jboss.as.test.integration.deployment.classloading.ear.TestAA"); } @Test public void testClassPathEntryAccessible() throws ClassNotFoundException { loadClass("org.jboss.as.test.integration.deployment.classloading.ear.TestBB"); } /** * AS7-2539 */ @Test public void testArbitraryDirectoryAccessible() throws ClassNotFoundException { Assert.assertNotNull("getResource returned null URL for testfile.file", getClass().getClassLoader().getResource("testfile.file")); } private static Class<?> loadClass(String name) throws ClassNotFoundException { ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (cl != null) { return Class.forName(name, false, cl); } else return Class.forName(name); } }
3,936
40.442105
138
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/ear/EarJbossStructureExtendedVisibilityTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.ear; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; /** * Tests the ear-subdeployments-isolated option in jboss-deployment-structure.xml * * By default ejb-jar's should not be visible to each other, with this option enabled they are. * */ @RunWith(Arquillian.class) public class EarJbossStructureExtendedVisibilityTestCase { @Deployment public static Archive<?> deploy() { EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class); WebArchive war = ShrinkWrap.create(WebArchive.class,"test.war"); war.addClasses(TestAA.class); ear.addAsModule(war); JavaArchive ejb = ShrinkWrap.create(JavaArchive.class, "ejb1.jar"); ejb.addClasses(MyEjb.class, EarJbossStructureExtendedVisibilityTestCase.class); ear.addAsModule(ejb); ejb = ShrinkWrap.create(JavaArchive.class, "ejb2.jar"); ejb.addClasses(MyEjb2.class); ear.addAsModule(ejb); ear.addAsManifestResource(new StringAsset( "<jboss-deployment-structure><ear-subdeployments-isolated>false</ear-subdeployments-isolated></jboss-deployment-structure>"), "jboss-deployment-structure.xml"); return ear; } @Test(expected = ClassNotFoundException.class) public void testWarModuleStillNotAccessible() throws ClassNotFoundException { loadClass("org.jboss.as.test.integration.deployment.classloading.ear.TestAA",getClass().getClassLoader()); } @Test public void testOtherEjbJarAcessible() throws ClassNotFoundException { loadClass("org.jboss.as.test.integration.deployment.classloading.ear.MyEjb2",getClass().getClassLoader()); } private static Class<?> loadClass(String name, ClassLoader cl) throws ClassNotFoundException { if (cl != null) { return Class.forName(name, false, cl); } else return Class.forName(name); } }
3,393
38.465116
140
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/ear/EarClassPath4TestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.ear; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; @RunWith(Arquillian.class) public class EarClassPath4TestCase { @Deployment public static Archive<?> deploy() { EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "cptest.ear"); WebArchive war = ShrinkWrap.create(WebArchive.class, "web.war"); war.addAsResource(new StringAsset("Class-Path: ejb-jar.jar other-jar.jar \n"),"META-INF/MANIFEST.MF"); war.addClasses(EarClassPath4TestCase.class); ear.addAsModule(war); JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "ejb-jar.jar"); jar.addClass(MyEjb.class); ear.addAsModule(jar); jar = ShrinkWrap.create(JavaArchive.class, "other-jar.jar"); jar.addClass(TestAA.class); ear.addAsModule(jar); return ear; } @Test public void testClassPathEjbJarAccessible() throws ClassNotFoundException { loadClass("org.jboss.as.test.integration.deployment.classloading.ear.MyEjb"); } @Test public void testClassPathOtherJarAccessible() throws ClassNotFoundException { loadClass("org.jboss.as.test.integration.deployment.classloading.ear.TestAA"); } private static Class<?> loadClass(String name) throws ClassNotFoundException { ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (cl != null) { return Class.forName(name, false, cl); } else return Class.forName(name); } }
2,991
37.857143
110
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/ear/MyEjb2.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.ear; import jakarta.ejb.Stateless; /** * @author Stuart Douglas */ @Stateless public class MyEjb2 { public void doStuff() { } }
1,220
32.916667
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/ear/subcc/TestCC.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.ear.subcc; public class TestCC { }
1,115
40.333333
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/ear/subdeployments/ClassInJar.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.ear.subdeployments; public class ClassInJar { public String invokeToStringOnClassloaderOfClass (String className) throws InstantiationException, IllegalAccessException, ClassNotFoundException{ ClassLoader cl = Class.forName(className).getClassLoader(); if(cl == null) { return "bootstrap class loader"; } return cl.toString(); } }
1,464
43.393939
150
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/ear/subdeployments/SubDeploymentAvailableInClassPathTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.ear.subdeployments; import java.net.URL; import javax.naming.InitialContext; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.OperateOnDeployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.arquillian.api.ContainerResource; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.test.integration.deployment.classloading.ear.subdeployments.ejb.EJBBusinessInterface; import org.jboss.as.test.integration.deployment.classloading.ear.subdeployments.ejb.SimpleSLSB; import org.jboss.as.test.integration.deployment.classloading.ear.subdeployments.servlet.EjbInvokeClassloaderToStringServlet; import org.jboss.as.test.integration.deployment.classloading.ear.subdeployments.servlet.EjbInvokingServlet; import org.jboss.as.test.integration.deployment.classloading.ear.subdeployments.servlet.HelloWorldServlet; import org.jboss.as.test.integration.deployment.classloading.ear.subdeployments.servlet.ServletInOtherWar; import org.jboss.logging.Logger; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.ClassAsset; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.exporter.ZipExporter; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * Tests various scenarios for class access between subdeployments within a .ear. * * @see https://issues.jboss.org/browse/AS7-306 * User: Jaikiran Pai */ @RunWith(Arquillian.class) @RunAsClient public class SubDeploymentAvailableInClassPathTestCase { private static final Logger logger = Logger.getLogger(SubDeploymentAvailableInClassPathTestCase.class); private static final String OTHER_WEB_APP_CONTEXT = "other-war"; @Deployment(name = "ear-with-single-war", testable = false) public static EnterpriseArchive createEar() { final JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, "ejb.jar"); ejbJar.addClasses(EJBBusinessInterface.class, SimpleSLSB.class); final WebArchive war = ShrinkWrap.create(WebArchive.class, "war-access-to-ejb.war"); war.addClasses(HelloWorldServlet.class, EjbInvokingServlet.class); final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "war-access-to-ejb.ear"); ear.addAsModule(ejbJar); ear.addAsModule(war); return ear; } @Deployment(name = "ear-with-exploded-war", testable = false) public static EnterpriseArchive createEarWithExplodedWar() { final JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, "ejb.jar"); ejbJar.addClasses(EJBBusinessInterface.class, SimpleSLSB.class); final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "exploded.ear"); ear.addAsModule(ejbJar); ear.add(new StringAsset("OK!"), "exploded.war/index.jsp"); ear.add(new ClassAsset(EjbInvokingServlet.class), "exploded.war/WEB-INF/classes/" + EjbInvokingServlet.class.getName().replace('.', '/') + ".class"); final JavaArchive servletJar = ShrinkWrap.create(JavaArchive.class, "servlet.jar"); servletJar.addClass(HelloWorldServlet.class); ear.add(servletJar, "exploded.war/WEB-INF/lib", ZipExporter.class); return ear; } @Deployment(name = "ear-with-multiple-wars", testable = false) public static EnterpriseArchive createEarWithMultipleWars() { final JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, "ejb.jar"); ejbJar.addClasses(EJBBusinessInterface.class, SimpleSLSB.class); final WebArchive war = ShrinkWrap.create(WebArchive.class, "war-access-to-war.war"); war.addClasses(HelloWorldServlet.class, EjbInvokingServlet.class); final WebArchive otherWar = ShrinkWrap.create(WebArchive.class, OTHER_WEB_APP_CONTEXT + ".war"); otherWar.addClass(ServletInOtherWar.class); final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "war-access-to-war.ear"); ear.addAsModule(ejbJar); ear.addAsModule(war); ear.addAsModule(otherWar); return ear; } @Deployment(name = "ear-with-war-and-jar", testable = false) public static EnterpriseArchive createEarWithWarJarAndLib() { final JavaArchive servletLogicJar = ShrinkWrap.create(JavaArchive.class, "servlet-logic.jar"); servletLogicJar.addClasses(ClassInJar.class); final WebArchive war = ShrinkWrap.create(WebArchive.class, "war-access-to-jar.war"); war.addClasses(EjbInvokeClassloaderToStringServlet.class); war.addAsManifestResource(new StringAsset("Class-Path: servlet-logic.jar"), "MANIFEST.MF"); final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "war-access-to-jar.ear"); ear.addAsModule(servletLogicJar); ear.addAsModule(war); JavaArchive libraryJar = ShrinkWrap.create(JavaArchive.class, "javax-naming-test-impl.jar"); libraryJar.addClass(InitialContext.class); ear.addAsLibrary(libraryJar); return ear; } /** * Tests that for a .ear like this one: * myapp.ear * | * |--- web.war * | * |--- ejb.jar * <p/> * the classes within the web.war have access to the classes in the ejb.jar * * @throws Exception */ @Test @OperateOnDeployment("ear-with-single-war") public void testEjbClassAvailableInServlet(@ArquillianResource(HelloWorldServlet.class) URL baseUrl) throws Exception { try (CloseableHttpClient httpClient = HttpClients.createDefault()) { final String message = "JBossAS7"; final String requestURL = baseUrl.toURI() + HelloWorldServlet.URL_PATTERN + "?" + HelloWorldServlet.PARAMETER_NAME + "=" + message; final HttpGet request = new HttpGet(requestURL); final HttpResponse response = httpClient.execute(request); final HttpEntity entity = response.getEntity(); Assert.assertNotNull("Response message from servlet was null", entity); final String responseMessage = EntityUtils.toString(entity); Assert.assertEquals("Unexpected echo message from servlet", message, responseMessage); } } /** * Tests that for a .ear like this one: * myapp.ear * | * |--- web.war/WEB-INF/classes * |--- web.war/index.jsp * | * |--- ejb.jar * <p/> * <p/> * the classes within the web.war have access to the classes in the ejb.jar * web.war is a folder, not an archive. * * @throws Exception */ @Test @OperateOnDeployment("ear-with-exploded-war") public void testExplodedWarInEar(@ArquillianResource(HelloWorldServlet.class) URL baseUrl) throws Exception { try (CloseableHttpClient httpClient = HttpClients.createDefault()) { String message = "OK!"; String requestURL = baseUrl.toURI() + "/index.jsp"; HttpGet request = new HttpGet(requestURL); HttpResponse response = httpClient.execute(request); HttpEntity entity = response.getEntity(); Assert.assertNotNull("Response message from servlet was null", entity); String responseMessage = EntityUtils.toString(entity); Assert.assertEquals("Unexpected echo message from servlet", message, responseMessage); message = "JBossAS7"; requestURL = baseUrl.toURI() + HelloWorldServlet.URL_PATTERN + "?" + HelloWorldServlet.PARAMETER_NAME + "=" + message; request = new HttpGet(requestURL); response = httpClient.execute(request); entity = response.getEntity(); Assert.assertNotNull("Response message from servlet was null", entity); responseMessage = EntityUtils.toString(entity); Assert.assertEquals("Unexpected echo message from servlet", message, responseMessage); } } /** * Tests that for a .ear like this one: * myapp.ear * | * |--- web.war * | * |--- ejb.jar * <p/> * <p/> * the classes within the ejb.jar *don't* have access to the classes in the web.war * * @throws Exception */ @Test @OperateOnDeployment("ear-with-single-war") public void testServletClassNotAvailableToEjbInEar(@ArquillianResource(EjbInvokingServlet.class) URL baseUrl) throws Exception { try (CloseableHttpClient httpClient = HttpClients.createDefault()) { final String classInWar = HelloWorldServlet.class.getName(); final String requestURL = baseUrl.toURI() + EjbInvokingServlet.URL_PATTERN + "?" + EjbInvokingServlet.CLASS_IN_WAR_PARAMETER + "=" + classInWar; final HttpGet request = new HttpGet(requestURL); final HttpResponse response = httpClient.execute(request); final HttpEntity entity = response.getEntity(); Assert.assertNotNull("Response message from servlet was null", entity); final String responseMessage = EntityUtils.toString(entity); Assert.assertEquals("Unexpected echo message from servlet", EjbInvokingServlet.SUCCESS_MESSAGE, responseMessage); } } /** * Tests that for a .ear like this one: * myapp.ear * | * |--- lib/javax-naming-test-impl.jar this jar contains override for javax.naming.Binding class * | which has to be resolved from implicit modules * | * |--- war-access-to-jar.war * | * |--- servlet-logic.jar * <p/> * the classes within the war-access-to-jar.war have access to the classes in the servlet-logic.jar * and servlet-logic.jar has implicit module dependencies first in class path * * @throws Exception */ @Test @OperateOnDeployment("ear-with-war-and-jar") public void testWarSeeJarAndJarSeeImplicitModulesFirst(@ArquillianResource(EjbInvokeClassloaderToStringServlet.class) URL baseUrl) throws Exception { try (CloseableHttpClient httpClient = HttpClients.createDefault()) { final String requestURL = baseUrl.toURI() + EjbInvokeClassloaderToStringServlet.URL_PATTERN + "?" + EjbInvokeClassloaderToStringServlet.CLASS_NAME_PARAMETER + "=javax.naming.InitialContext"; final HttpGet request = new HttpGet(requestURL); final HttpResponse response = httpClient.execute(request); final HttpEntity entity = response.getEntity(); Assert.assertNotNull("Response message from servlet was null", entity); final String responseMessage = EntityUtils.toString(entity); // expected is that class is loaded from implicit module // app's class loader toString returns: ModuleClassLoader for Module deployment.war-access-to-jar.ear:main from Service Module Loader Assert.assertEquals("Unexpected response from servlet", "bootstrap class loader", responseMessage); } } /** * Tests that for a .ear like this one: * myapp.ear * | * |--- web-one.war * | * |--- web-two.war * <p/> * <p/> * the classes within the web-one.war *don't* have access to the classes in the web-two.war * * @throws Exception */ @Test @OperateOnDeployment("ear-with-multiple-wars") public void testWarsDontSeeEachOtherInEar(@ContainerResource ManagementClient managementClient) throws Exception { try (CloseableHttpClient httpClient = HttpClients.createDefault()) { final String classInOtherWar = HelloWorldServlet.class.getName(); final String requestURL = managementClient.getWebUri() + "/" + OTHER_WEB_APP_CONTEXT + ServletInOtherWar.URL_PATTERN + "?" + ServletInOtherWar.CLASS_IN_OTHER_WAR_PARAMETER + "=" + classInOtherWar; final HttpGet request = new HttpGet(requestURL); final HttpResponse response = httpClient.execute(request); final HttpEntity entity = response.getEntity(); Assert.assertNotNull("Response message from servlet was null", entity); final String responseMessage = EntityUtils.toString(entity); Assert.assertEquals("Unexpected echo message from servlet", ServletInOtherWar.SUCCESS_MESSAGE, responseMessage); } } }
14,017
45.726667
157
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/ear/subdeployments/ejb/EJBBusinessInterface.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.ear.subdeployments.ejb; /** * User: jpai */ public interface EJBBusinessInterface { String echo(String msg); void loadClass(String className) throws ClassNotFoundException; }
1,275
35.457143
85
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/ear/subdeployments/ejb/SimpleSLSB.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.ear.subdeployments.ejb; import jakarta.ejb.Local; import jakarta.ejb.Stateless; /** * User: jpai */ @Stateless @Local(EJBBusinessInterface.class) public class SimpleSLSB implements EJBBusinessInterface { @Override public String echo(String msg) { return msg; } @Override public void loadClass(String className) throws ClassNotFoundException { this.getClass().getClassLoader().loadClass(className); } }
1,534
33.111111
85
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/ear/subdeployments/servlet/HelloWorldServlet.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.ear.subdeployments.servlet; import org.jboss.as.test.integration.deployment.classloading.ear.subdeployments.ejb.EJBBusinessInterface; import jakarta.ejb.EJB; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; /** * User: Jaikiran Pai */ @WebServlet(name = "HelloWorldServlet", urlPatterns = HelloWorldServlet.URL_PATTERN) public class HelloWorldServlet extends HttpServlet { public static final String URL_PATTERN = "/helloworld"; public static final String PARAMETER_NAME = "message"; @EJB private EJBBusinessInterface echoBean; @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { final String message = req.getParameter(PARAMETER_NAME); if (message == null) { throw new ServletException(PARAMETER_NAME + " parameter not set in request"); } final String echo = this.echoBean.echo(message); // print out the echo message resp.getOutputStream().print(echo); } }
2,313
38.896552
113
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/ear/subdeployments/servlet/EjbInvokingServlet.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.ear.subdeployments.servlet; import org.jboss.as.test.integration.deployment.classloading.ear.subdeployments.ejb.EJBBusinessInterface; import jakarta.ejb.EJB; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; /** * User: jpai */ @WebServlet(urlPatterns = EjbInvokingServlet.URL_PATTERN) public class EjbInvokingServlet extends HttpServlet { public static final String URL_PATTERN = "/ejbinvokingservlet"; public static final String CLASS_IN_WAR_PARAMETER = "classInWar"; public static final String SUCCESS_MESSAGE = "Success"; public static final String FAILURE_MESSAGE = "Failure"; @EJB private EJBBusinessInterface bean; @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { final String classInWar = req.getParameter(CLASS_IN_WAR_PARAMETER); if (classInWar == null) { throw new ServletException(CLASS_IN_WAR_PARAMETER + " parameter not set in request"); } try { bean.loadClass(classInWar); // .war class shouldn't have been visible to an EJB in a .jar resp.getOutputStream().print(FAILURE_MESSAGE); } catch (ClassNotFoundException cnfe) { // the ClassNotFoundException is expected since the class in the .war isn't expected to be visible to the // EJB in the .jar resp.getOutputStream().print(SUCCESS_MESSAGE); } } }
2,753
38.913043
117
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/ear/subdeployments/servlet/EjbInvokeClassloaderToStringServlet.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.ear.subdeployments.servlet; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; /** * Servlet invoking toString() method on class loader of class supplied as request parameter */ @WebServlet(urlPatterns = EjbInvokeClassloaderToStringServlet.URL_PATTERN) public class EjbInvokeClassloaderToStringServlet extends HttpServlet { public static final String URL_PATTERN = "/invokeToStringOnClassloaderOfClass"; public static final String CLASS_NAME_PARAMETER = "className"; @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { final String className = req.getParameter(CLASS_NAME_PARAMETER); if (className == null) { throw new ServletException(CLASS_NAME_PARAMETER + " parameter not set in request"); } try { // Invoke toString() method on className Class<?> classInJar = Class .forName("org.jboss.as.test.integration.deployment.classloading.ear.subdeployments.ClassInJar"); Method invokeToStringOnClassloaderOfClassClassMethod; invokeToStringOnClassloaderOfClassClassMethod = classInJar.getMethod("invokeToStringOnClassloaderOfClass", String.class); resp.getOutputStream().print(invokeToStringOnClassloaderOfClassClassMethod.invoke(classInJar.newInstance(), className).toString()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException | SecurityException | IllegalArgumentException | InvocationTargetException ex) { resp.getOutputStream().print(ex.toString()); } } }
3,049
47.412698
143
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/ear/subdeployments/servlet/ServletInOtherWar.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.ear.subdeployments.servlet; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; /** * User: jpai */ @WebServlet(name = "OtherServlet", urlPatterns = ServletInOtherWar.URL_PATTERN) public class ServletInOtherWar extends HttpServlet { public static final String URL_PATTERN = "/otherservlet"; public static final String CLASS_IN_OTHER_WAR_PARAMETER = "classInOtherWar"; public static final String SUCCESS_MESSAGE = "Success"; public static final String FAILURE_MESSAGE = "Failure"; @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { final String classInOtherWar = req.getParameter(CLASS_IN_OTHER_WAR_PARAMETER); if (classInOtherWar == null) { throw new ServletException(CLASS_IN_OTHER_WAR_PARAMETER + " parameter not set in request"); } try { Class<?> klass = this.getClass().getClassLoader().loadClass(classInOtherWar); // class from one war wasn't expected to be visible to other war resp.getOutputStream().print(FAILURE_MESSAGE); } catch (ClassNotFoundException cnfe) { // the ClassNotFoundException is expected since class in one war isn't expected to be visible to // another war (even if it belongs to the same .ear) resp.getOutputStream().print(SUCCESS_MESSAGE); } } }
2,701
40.569231
113
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/war/WarInEarChildFirstClassLoadingTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.war; import jakarta.ejb.Stateless; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.junit.Assert; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.test.integration.deployment.classloading.ear.TestBB; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; import org.jboss.as.test.integration.common.WebInfLibClass; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; @RunWith(Arquillian.class) public class WarInEarChildFirstClassLoadingTestCase { @Deployment public static Archive<?> deploy() { WebArchive war = ShrinkWrap.create(WebArchive.class); war.addClasses(WebInfLibClass.class, WarInEarChildFirstClassLoadingTestCase.class, Stateless.class); EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class); ear.addAsModule(war); JavaArchive earLib = ShrinkWrap.create(JavaArchive.class, "cp.jar"); earLib.addAsManifestResource(new StringAsset("Dependencies: \n"), "MANIFEST.MF"); //AS7-5547, make sure an empty dependencies entry is fine earLib.addClasses(TestBB.class, WebInfLibClass.class); ear.addAsLibrary(earLib); ear.addAsManifestResource(createPermissionsXmlAsset(new RuntimePermission("getClassLoader")), "permissions.xml"); return ear; } @Test public void testChildFirst() throws ClassNotFoundException { Assert.assertNotSame(Stateless.class.getClassLoader(), getClass().getClassLoader()); } @Test public void testMultipleClasses() throws ClassNotFoundException { Class<?> clazz = loadClass(WebInfLibClass.class.getName(), TestBB.class.getClassLoader()); Assert.assertNotSame(WebInfLibClass.class, clazz); } private static Class<?> loadClass(String name, ClassLoader cl) throws ClassNotFoundException { if (cl != null) { return Class.forName(name, false, cl); } else return Class.forName(name); } }
3,381
41.810127
147
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/war/WarChildFirstClassLoadingTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.war; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; import jakarta.ejb.Stateless; import org.junit.Assert; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; @RunWith(Arquillian.class) public class WarChildFirstClassLoadingTestCase { @Deployment public static Archive<?> deploy() { WebArchive war = ShrinkWrap.create(WebArchive.class); war.addClasses(WarChildFirstClassLoadingTestCase.class, Stateless.class); war.addAsManifestResource(createPermissionsXmlAsset(new RuntimePermission("getClassLoader")), "permissions.xml"); return war; } @Test public void testChildFirst() throws ClassNotFoundException { Assert.assertNotSame(Stateless.class.getClassLoader(), getClass().getClassLoader()); } }
2,148
38.072727
121
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/transformer/DummyClassFileTransformer1.java
/* * JBoss, Home of Professional Open Source * Copyright 2011, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.transformer; import org.jboss.modules.ClassTransformer; import java.nio.ByteBuffer; import java.security.ProtectionDomain; import java.util.Set; import java.util.concurrent.ConcurrentSkipListSet; /** * @author Marius Bogoevici */ public class DummyClassFileTransformer1 implements ClassTransformer { public static boolean wasActive = false; public static Set<String> transformedClassNames = new ConcurrentSkipListSet<String>(); @Override public ByteBuffer transform(ClassLoader loader, String className, ProtectionDomain protectionDomain, ByteBuffer classfileBuffer) throws IllegalArgumentException { transformedClassNames.add(className); wasActive = true; return classfileBuffer; } }
1,815
37.638298
166
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/transformer/DummyClassFileTransformer2.java
/* * JBoss, Home of Professional Open Source * Copyright 2011, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.transformer; import org.jboss.modules.ClassTransformer; import java.nio.ByteBuffer; import java.security.ProtectionDomain; import java.util.Set; import java.util.concurrent.ConcurrentSkipListSet; /** * @author Marius Bogoevici */ public class DummyClassFileTransformer2 implements ClassTransformer { public static boolean wasActive = false; public static Set<String> transformedClassNames = new ConcurrentSkipListSet<String> (); @Override public ByteBuffer transform(ClassLoader loader, String className, ProtectionDomain protectionDomain, ByteBuffer classfileBuffer) throws IllegalArgumentException { transformedClassNames.add(className); wasActive = true; return classfileBuffer; } }
1,816
37.659574
166
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/transformer/WarJbossStructureClassFileTransformerTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2011, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.classloading.transformer; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.test.integration.deployment.classloading.ear.TestAA; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * @author Marius Bogoevici */ @RunWith(Arquillian.class) public class WarJbossStructureClassFileTransformerTestCase { public static final String CLASS_NAME = "org.jboss.as.test.integration.deployment.classloading.ear.TestAA"; public static final String TRANSFORMER1_CLASS_NAME_CANONICAL = "org/jboss/as/testsuite/integration/deployment/classloading/ear/DummyClassFileTransformer1"; public static final String TRANSFORMER2_CLASS_NAME_CANONICAL = "org/jboss/as/testsuite/integration/deployment/classloading/ear/DummyClassFileTransformer2"; @Deployment public static Archive<?> deploy() { WebArchive war = ShrinkWrap.create(WebArchive.class, "test.war"); war.addClasses(TestAA.class, DummyClassFileTransformer1.class, DummyClassFileTransformer2.class, WarJbossStructureClassFileTransformerTestCase.class); war.addAsManifestResource(new StringAsset( "<jboss-deployment-structure xmlns=\"urn:jboss:deployment-structure:1.0\">\n" + " <deployment>\n" + " <transformers>\n" + " <transformer class=\"" + DummyClassFileTransformer1.class.getName() + "\"/>\n" + " <transformer class=\"" + DummyClassFileTransformer2.class.getName() + "\"/>\n" + " </transformers>\n" + " </deployment>\n" + "</jboss-deployment-structure>"), "jboss-deployment-structure.xml"); return war; } @Test public void testTransformerApplied() throws ClassNotFoundException { loadClass(CLASS_NAME, getClass().getClassLoader()); Assert.assertTrue(DummyClassFileTransformer1.wasActive); Assert.assertTrue(DummyClassFileTransformer2.wasActive); String canonicalClassName = CLASS_NAME.replace(".", "/"); Assert.assertTrue(DummyClassFileTransformer1.transformedClassNames.contains(canonicalClassName)); Assert.assertTrue(DummyClassFileTransformer2.transformedClassNames.contains(canonicalClassName)); Assert.assertFalse(DummyClassFileTransformer1.transformedClassNames.contains(TRANSFORMER2_CLASS_NAME_CANONICAL)); Assert.assertFalse(DummyClassFileTransformer2.transformedClassNames.contains(TRANSFORMER1_CLASS_NAME_CANONICAL)); } private static Class<?> loadClass(String name, ClassLoader cl) throws ClassNotFoundException { if (cl != null) { return Class.forName(name, false, cl); } else return Class.forName(name); } }
4,119
47.470588
159
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/subdirectory/MessageServlet.java
package org.jboss.as.test.integration.deployment.subdirectory; import jakarta.ejb.EJB; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; /** * @author Stuart Douglas */ @WebServlet(urlPatterns = "/message") public class MessageServlet extends HttpServlet { @EJB private MessageBean messageBean; @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.getWriter().write(messageBean.getMessage()); } }
706
27.28
113
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/subdirectory/SubDirectoryModuleDeploymentTestCase.java
package org.jboss.as.test.integration.deployment.subdirectory; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.StatusLine; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.ArchiveAsset; import org.jboss.shrinkwrap.api.exporter.ZipExporter; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import java.net.URL; import static org.junit.Assert.assertEquals; /** * WFLY-29 */ @RunWith(Arquillian.class) @RunAsClient public class SubDirectoryModuleDeploymentTestCase { @Deployment public static Archive<?> createDeployment() { final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "subdirectory.ear"); final JavaArchive jarOne = ShrinkWrap.create(JavaArchive.class, "ejb.jar"); jarOne.addClass(MessageBean.class); ear.addAsModule(new ArchiveAsset(jarOne, ZipExporter.class), "subdir/ejb/ejb.jar"); final WebArchive war = ShrinkWrap.create(WebArchive.class, "web.war"); war.addClass(MessageServlet.class); ear.addAsModule(new ArchiveAsset(war, ZipExporter.class), "subdir/web/web.war"); return ear; } @ArquillianResource protected URL url; @Test public void testModulesInSubDeployments() throws Exception { try (CloseableHttpClient httpclient = HttpClients.createDefault()){ HttpGet httpget = new HttpGet(url.toExternalForm() + "message"); HttpResponse response = httpclient.execute(httpget); HttpEntity entity = response.getEntity(); StatusLine statusLine = response.getStatusLine(); assertEquals(200, statusLine.getStatusCode()); String result = EntityUtils.toString(entity); Assert.assertEquals("Hello World", result); } } }
2,477
32.945205
101
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/subdirectory/MessageBean.java
package org.jboss.as.test.integration.deployment.subdirectory; import jakarta.ejb.Stateless; /** * @author Stuart Douglas */ @Stateless public class MessageBean { public String getMessage() { return "Hello World"; } }
239
15
62
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/jcedeployment/JCETestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.jcedeployment; import static java.util.concurrent.TimeUnit.SECONDS; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; import static org.junit.Assert.assertEquals; import java.io.File; import java.io.FilePermission; import java.lang.reflect.ReflectPermission; import java.net.URL; import java.security.SecurityPermission; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.test.integration.common.HttpRequest; import org.jboss.as.test.integration.deployment.jcedeployment.provider.DummyProvider; import org.jboss.logging.Logger; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.exporter.ZipExporter; import org.jboss.shrinkwrap.api.importer.ZipImporter; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Assume; import org.junit.Test; import org.junit.runner.RunWith; /** * This tests a JCE provider bundled in an EAR. * See AS7-6068 for more details. * * @author <a href="mailto:[email protected]">Ivo Studensky</a> */ @RunWith(Arquillian.class) @RunAsClient public class JCETestCase { private static final Logger log = Logger.getLogger(JCETestCase.class); @Deployment public static Archive<?> deployment() throws Exception { final JavaArchive jce = ShrinkWrap.create(JavaArchive.class, "jcetest.jar") .addPackage(DummyProvider.class.getPackage()); final File jceJar = new File("target/jcetest.jar"); jce.as(ZipExporter.class).exportTo(jceJar, true); final File signedJceJar = new File("target/jcetestsigned.jar"); JavaArchive signedJce; if (isJCETestable()) { // see genkey-jcetest-keystore in pom.xml for the keystore creation final JarSignerUtil signer = new JarSignerUtil(new File("target/jcetest.keystore"), "password", "password", /* alias */ "test"); signer.sign(jceJar, signedJceJar); signer.verify(signedJceJar); signedJce = ShrinkWrap.create(ZipImporter.class, "jcetestsigned.jar") .importFrom(signedJceJar).as(JavaArchive.class); } else { log.trace("skipping the test since it can run on Oracle JDK only"); signedJce = jce; } final WebArchive war = ShrinkWrap.create(WebArchive.class, "test.war") .addClasses(ControllerServlet.class); final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "jcetest.ear") .addAsLibrary(signedJce) .addAsModule(war) .addAsManifestResource(JCETestCase.class.getPackage(), "jboss-deployment-structure.xml", "jboss-deployment-structure.xml"); // ControllerServlet and DummyProvider need the following perms for their "dirty" game ear.addAsManifestResource(createPermissionsXmlAsset( new FilePermission("target/jcetest.keystore", "read"), new RuntimePermission("accessDeclaredMembers"), new ReflectPermission("suppressAccessChecks"), new RuntimePermission("accessClassInPackage.sun.security.validator"), new SecurityPermission("putProviderProperty.DP"), new SecurityPermission("insertProvider"), new RuntimePermission("getProtectionDomain") ), "permissions.xml"); return ear; } @ArquillianResource private URL url; @Test public void testJCE() throws Exception { Assume.assumeTrue( "Skipping test as 'javax.crypto.JarVerifier' does not contain a field called 'providerValidator'.", isJCETestable()); String result = performCall(url, "controller"); assertEquals("ok", result); } private String performCall(final URL url, final String urlPattern) throws Exception { return HttpRequest.get(url.toExternalForm() + urlPattern, 1000, SECONDS); } private static boolean isJCETestable() { try { final Class<?> cls = Class.forName("javax.crypto.JarVerifier"); cls.getDeclaredField("providerValidator"); } catch (Exception e) { return false; } return true; } }
5,627
41.636364
140
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/jcedeployment/JarSignerUtil.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.jcedeployment; import java.io.File; import java.io.IOException; import java.nio.file.Files; /** * Utility for signing jars. * * @author Tomaz Cerar */ class JarSignerUtil { private File keystore; private String storePass; private String keyPass; private String alias; JarSignerUtil(final File keystore, final String storePass, final String keyPass, final String alias) { this.keystore = keystore; this.storePass = storePass; this.keyPass = keyPass; this.alias = alias; } public void verify(final File jar) throws Exception { String[] args = {"-verify", "-verbose", jar.getAbsolutePath()}; run(args); } private void run(String[] args) { try { String home = System.getenv("JAVA_HOME"); if (home == null) { home = System.getProperty("java.home"); } String jarSigner = home + File.separator + "bin" + File.separator + "jarsigner"; StringBuilder command = new StringBuilder(jarSigner); for (String a : args) { command.append(" ").append(a); } Process process = Runtime.getRuntime().exec(command.toString()); int result = process.waitFor(); } catch (Exception e) { throw new RuntimeException("could not sign", e); } } void sign(final File jar, final File signedJar) throws IOException { copyFile(jar, signedJar); try { sign(signedJar); } catch (Exception e) { throw new IOException(e); } } private void sign(final File jar) throws Exception { String[] args = { "-keystore", keystore.getAbsolutePath(), "-storepass", storePass, "-keypass", keyPass, jar.getAbsolutePath(), alias }; run(args); } private static void copyFile(final File src, final File dst) throws IOException { Files.copy(src.toPath(), dst.toPath()); } }
3,155
32.221053
106
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/jcedeployment/ControllerServlet.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.jcedeployment; import org.jboss.as.test.integration.deployment.jcedeployment.provider.DummyProvider; import org.jboss.logging.Logger; import javax.crypto.Cipher; import jakarta.servlet.ServletConfig; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Field; import java.net.URL; import java.nio.file.Files; import java.nio.file.Paths; import java.security.CodeSource; import java.security.KeyStore; import java.security.ProtectionDomain; import java.security.Provider; import java.security.Security; import java.security.cert.X509Certificate; import java.util.Arrays; import java.util.Map; /** * This servlet requires Oracle JDK 7 as it uses javax.crypto.JarVerifier * and sun.security.validator.SimpleValidator in the init method. * * @author <a href="mailto:[email protected]">Carlo de Wolf</a> * @author <a href="mailto:[email protected]">Ivo Studensky</a> */ @WebServlet(name = "ControllerServlet", urlPatterns = {"/controller"}) public class ControllerServlet extends HttpServlet { private static final Logger log = Logger.getLogger(ControllerServlet.class); public void init(ServletConfig config) throws ServletException { try { final KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); try (InputStream in = Files.newInputStream(Paths.get("target/jcetest.keystore"))){ keyStore.load(in, "password".toCharArray()); } final X509Certificate testCertificate = (X509Certificate) keyStore.getCertificate("test"); assert testCertificate != null; // the three musketeers who are guarding the crown are hardcoded in jse.jar (JarVerifier) final Object validator = get("javax.crypto.JarVerifier", "providerValidator", Object.class); // sun.security.validator.SimpleValidator get(validator, "trustedX500Principals", Map.class).put(testCertificate.getIssuerX500Principal(), Arrays.asList(testCertificate)); } catch (ClassNotFoundException e) { throw new ServletException("This requires being run on Oracle JDK 7.", e); } catch (Exception e) { throw new ServletException("Cannot install the certificate to the validator.", e); } java.security.Security.addProvider(new DummyProvider()); } private static <T> T get(final Object obj, final String fieldName, Class<T> type) throws NoSuchFieldException, IllegalAccessException { final Field field = obj.getClass().getDeclaredField(fieldName); field.setAccessible(true); return type.cast(field.get(obj)); } private static <T> T get(final String className, final String fieldName, Class<T> type) throws NoSuchFieldException, IllegalAccessException, ClassNotFoundException { final Class<?> cls = Class.forName(className); final Field field = cls.getDeclaredField(fieldName); field.setAccessible(true); return type.cast(field.get(null)); } protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { Provider[] providers = Security.getProviders(); for (int i = 0; i < providers.length; i++) { final Provider provider = providers[i]; log.debug("Provider name: " + provider.getName()); log.debug("Provider information: " + provider.getInfo()); log.debug("Provider version: " + provider.getVersion()); URL url = null; ProtectionDomain pd = provider.getClass().getProtectionDomain(); if (pd != null) { CodeSource cs = pd.getCodeSource(); if (cs != null) { url = cs.getLocation(); } } log.debug("Provider code base: " + url); } Cipher.getInstance("DummyAlg/DummyMode/DummyPadding", "DP"); response.getWriter().write("ok"); response.getWriter().close(); } catch (Exception e) { throw new ServletException(e); } } }
5,487
41.542636
169
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/jcedeployment/provider/DPCipher.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.jcedeployment.provider; import javax.crypto.BadPaddingException; import javax.crypto.IllegalBlockSizeException; import javax.crypto.NoSuchPaddingException; import java.security.AlgorithmParameters; import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.Key; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import java.security.spec.AlgorithmParameterSpec; /** * @author <a href="mailto:[email protected]">Ivo Studensky</a> */ public interface DPCipher { String name(); void setMode(String mode) throws NoSuchAlgorithmException; void setPadding(String padding) throws NoSuchPaddingException; byte[] getIV(); AlgorithmParameters getParameters(); int getBlockSize(); int getOutputSize(int inputLen); void init(int opmode, Key key, SecureRandom secureRandom) throws InvalidKeyException; void init(int opmode, Key key, AlgorithmParameterSpec algorithmParameterSpec, SecureRandom secureRandom) throws InvalidKeyException, InvalidAlgorithmParameterException; void init(int opmode, Key key, AlgorithmParameters algorithmParameters, SecureRandom secureRandom) throws InvalidKeyException, InvalidAlgorithmParameterException; byte[] update(byte[] input, int inputOffset, int inputLen); byte[] doFinal(byte[] input, int inputOffset, int inputLen) throws IllegalBlockSizeException, BadPaddingException; }
2,528
39.142857
172
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/jcedeployment/provider/CipherAdapter.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.jcedeployment.provider; import javax.crypto.BadPaddingException; import javax.crypto.CipherSpi; import javax.crypto.IllegalBlockSizeException; import javax.crypto.NoSuchPaddingException; import javax.crypto.ShortBufferException; import java.security.AlgorithmParameters; import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.Key; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import java.security.spec.AlgorithmParameterSpec; /** * @author <a href="mailto:[email protected]">Ivo Studensky</a> */ public class CipherAdapter extends CipherSpi { DPCipher cipherInstance; protected CipherAdapter(String cipherName) { if (DummyProvider.DUMMY_CIPHER.equals(cipherName)) cipherInstance = new DummyCipher(); if (cipherInstance == null) throw new InternalError("Unsupported cipher function " + cipherName + "!"); } @Override protected void engineSetMode(String mode) throws NoSuchAlgorithmException { cipherInstance.setMode(mode); } @Override protected void engineSetPadding(String padding) throws NoSuchPaddingException { cipherInstance.setPadding(padding); } @Override protected byte[] engineGetIV() { return cipherInstance.getIV(); } @Override protected AlgorithmParameters engineGetParameters() { return cipherInstance.getParameters(); } @Override protected int engineGetBlockSize() { return cipherInstance.getBlockSize(); } @Override protected int engineGetOutputSize(int inputLen) { return cipherInstance.getOutputSize(inputLen); } @Override protected void engineInit(int opmode, Key key, SecureRandom secureRandom) throws InvalidKeyException { cipherInstance.init(opmode, key, secureRandom); } @Override protected void engineInit(int opmode, Key key, AlgorithmParameterSpec algorithmParameterSpec, SecureRandom secureRandom) throws InvalidKeyException, InvalidAlgorithmParameterException { cipherInstance.init(opmode, key, algorithmParameterSpec, secureRandom); } @Override protected void engineInit(int opmode, Key key, AlgorithmParameters algorithmParameters, SecureRandom secureRandom) throws InvalidKeyException, InvalidAlgorithmParameterException { cipherInstance.init(opmode, key, algorithmParameters, secureRandom); } @Override protected byte[] engineUpdate(byte[] input, int inputOffset, int inputLen) { return cipherInstance.update(input, inputOffset, inputLen); } @Override protected int engineUpdate(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws ShortBufferException { int result = engineGetOutputSize(inputLen); if ((output.length - outputOffset) < result) throw new ShortBufferException(); byte[] buf = engineUpdate(input, inputOffset, inputLen); result = buf.length; if ((output.length - outputOffset) < result) throw new ShortBufferException(); System.arraycopy(buf, 0, output, outputOffset, result); return result; } @Override protected byte[] engineDoFinal(byte[] input, int inputOffset, int inputLen) throws IllegalBlockSizeException, BadPaddingException { return cipherInstance.doFinal(input, inputOffset, inputLen); } @Override protected int engineDoFinal(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws ShortBufferException, IllegalBlockSizeException, BadPaddingException { int result = engineGetOutputSize(inputLen); if ((output.length - outputOffset) < result) throw new ShortBufferException(); byte[] buf = engineDoFinal(input, inputOffset, inputLen); result = buf.length; if ((output.length - outputOffset) < result) throw new ShortBufferException(); System.arraycopy(buf, 0, output, outputOffset, result); return result; } }
5,181
36.824818
189
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/jcedeployment/provider/DummyProvider.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.jcedeployment.provider; import java.security.Provider; /** * Testing JCE provider which provides one dummy cipher only. * * @author <a href="mailto:[email protected]">Ivo Studensky</a> */ public final class DummyProvider extends Provider { public static String PROVIDER_NAME = "DP"; public static String DUMMY_CIPHER = "dummycipher"; public DummyProvider() { super(PROVIDER_NAME, 0.1, "Dummy Provider v0.1"); put("Cipher.DummyAlg/DummyMode/DummyPadding", DummyCipherSpi.class.getName()); } }
1,608
36.418605
86
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/jcedeployment/provider/DummyCipher.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.jcedeployment.provider; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; import javax.crypto.IllegalBlockSizeException; import javax.crypto.NoSuchPaddingException; import java.nio.charset.StandardCharsets; import java.security.AlgorithmParameters; import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.Key; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import java.security.spec.AlgorithmParameterSpec; /** * @author <a href="mailto:[email protected]">Ivo Studensky</a> */ public class DummyCipher implements DPCipher { String cipher; int opmode; public DummyCipher() { } public String name() { return DummyProvider.DUMMY_CIPHER; } @Override public void setMode(String mode) throws NoSuchAlgorithmException { // nothing to do } @Override public void setPadding(String padding) throws NoSuchPaddingException { // nothing to do } @Override public void init(int opmode, Key key, SecureRandom secureRandom) throws InvalidKeyException { init(opmode); } @Override public void init(int opmode, Key key, AlgorithmParameterSpec algorithmParameterSpec, SecureRandom secureRandom) throws InvalidKeyException, InvalidAlgorithmParameterException { init(opmode); } @Override public void init(int opmode, Key key, AlgorithmParameters algorithmParameters, SecureRandom secureRandom) throws InvalidKeyException, InvalidAlgorithmParameterException { init(opmode); } private void init(int opmode) { this.opmode = opmode; switch (opmode) { case Cipher.ENCRYPT_MODE: cipher = "decrypted"; break; case Cipher.DECRYPT_MODE: cipher = "encrypted"; break; } } @Override public byte[] getIV() { return null; } @Override public AlgorithmParameters getParameters() { return null; } @Override public int getBlockSize() { return 0; } @Override public int getOutputSize(int inputLen) { return "encrypted".length(); } @Override public byte[] update(byte[] input, int inputOffset, int inputLen) { return new byte[0]; } @Override public byte[] doFinal(byte[] input, int inputOffset, int inputLen) throws IllegalBlockSizeException, BadPaddingException { switch (opmode) { case Cipher.ENCRYPT_MODE: cipher = "encrypted"; break; case Cipher.DECRYPT_MODE: cipher = "decrypted"; break; } return cipher.getBytes(StandardCharsets.UTF_8).clone(); } }
3,901
29.248062
180
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/jcedeployment/provider/DummyCipherSpi.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.jcedeployment.provider; /** * @author <a href="mailto:[email protected]">Ivo Studensky</a> */ public class DummyCipherSpi extends CipherAdapter { public DummyCipherSpi() { super(DummyProvider.DUMMY_CIPHER); } }
1,304
39.78125
72
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/DeploymentOverlayTestCase.java
package org.jboss.as.test.integration.deployment.deploymentoverlay; import java.io.IOException; import java.nio.charset.StandardCharsets; import javax.naming.InitialContext; import javax.naming.NamingException; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.arquillian.api.ServerSetupTask; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.controller.client.OperationBuilder; import org.jboss.as.controller.client.helpers.Operations; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.as.test.integration.management.ManagementOperations; import org.jboss.as.test.integration.management.util.MgmtOperationException; import org.jboss.as.test.shared.FileUtils; import org.jboss.dmr.ModelNode; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * @author Stuart Douglas */ @RunWith(Arquillian.class) @ServerSetup(DeploymentOverlayTestCase.DeploymentOverlayTestCaseServerSetup.class) public class DeploymentOverlayTestCase { public static final String TEST_OVERLAY = "test"; public static final String TEST_WILDCARD = "test-wildcard"; static class DeploymentOverlayTestCaseServerSetup implements ServerSetupTask { @Override public void setup(final ManagementClient managementClient, final String containerId) throws Exception { ModelNode op = new ModelNode(); op.get(ModelDescriptionConstants.OP_ADDR).set(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, TEST_OVERLAY); op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.ADD); ManagementOperations.executeOperation(managementClient.getControllerClient(), op); //add an override that will not be linked via a wildcard op = new ModelNode(); op.get(ModelDescriptionConstants.OP_ADDR).set(new ModelNode()); op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.UPLOAD_DEPLOYMENT_BYTES); op.get(ModelDescriptionConstants.BYTES).set(FileUtils.readFile(DeploymentOverlayTestCase.class, "override.xml").getBytes(StandardCharsets.UTF_8)); ModelNode result = ManagementOperations.executeOperation(managementClient.getControllerClient(), op); //add the content op = new ModelNode(); ModelNode addr = new ModelNode(); addr.add(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, TEST_OVERLAY); addr.add(ModelDescriptionConstants.CONTENT, "WEB-INF/web.xml"); op.get(ModelDescriptionConstants.OP_ADDR).set(addr); op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.ADD); op.get(ModelDescriptionConstants.CONTENT).get(ModelDescriptionConstants.HASH).set(result); ManagementOperations.executeOperation(managementClient.getControllerClient(), op); //add the non-wildcard link op = new ModelNode(); addr = new ModelNode(); addr.add(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, TEST_OVERLAY); addr.add(ModelDescriptionConstants.DEPLOYMENT, "test.war"); op.get(ModelDescriptionConstants.OP_ADDR).set(addr); op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.ADD); ManagementOperations.executeOperation(managementClient.getControllerClient(), op); //add the deployment overlay that will be linked via wildcard op = new ModelNode(); op.get(ModelDescriptionConstants.OP_ADDR).set(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, TEST_WILDCARD); op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.ADD); ManagementOperations.executeOperation(managementClient.getControllerClient(), op); op = new ModelNode(); addr = new ModelNode(); addr.add(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, TEST_WILDCARD); addr.add(ModelDescriptionConstants.CONTENT, "WEB-INF/web.xml"); op.get(ModelDescriptionConstants.OP_ADDR).set(addr); op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.ADD); op.get(ModelDescriptionConstants.CONTENT).get(ModelDescriptionConstants.BYTES).set(FileUtils.readFile(DeploymentOverlayTestCase.class, "wildcard-override.xml").getBytes(StandardCharsets.UTF_8)); ManagementOperations.executeOperation(managementClient.getControllerClient(), op); op = new ModelNode(); addr = new ModelNode(); addr.add(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, TEST_WILDCARD); addr.add(ModelDescriptionConstants.CONTENT, "WEB-INF/classes/wildcard-new-file"); op.get(ModelDescriptionConstants.OP_ADDR).set(addr); op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.ADD); op.get(ModelDescriptionConstants.CONTENT).get(ModelDescriptionConstants.INPUT_STREAM_INDEX).set(0); OperationBuilder builder = new OperationBuilder(op, true); builder.addInputStream(DeploymentOverlayTestCase.class.getResourceAsStream("wildcard-new-file")); ManagementOperations.executeOperation(managementClient.getControllerClient(), builder.build()); //add the wildcard link op = new ModelNode(); addr = new ModelNode(); addr.add(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, TEST_WILDCARD); addr.add(ModelDescriptionConstants.DEPLOYMENT, "*.war"); op.get(ModelDescriptionConstants.OP_ADDR).set(addr); op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.ADD); ManagementOperations.executeOperation(managementClient.getControllerClient(), op); } @Override public void tearDown(final ManagementClient managementClient, final String containerId) throws Exception { removeContentItem(managementClient, TEST_OVERLAY, "WEB-INF/web.xml"); removeDeploymentItem(managementClient, TEST_OVERLAY, "test.war"); ModelNode op = new ModelNode(); op.get(ModelDescriptionConstants.OP_ADDR).set(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, TEST_OVERLAY); op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.REMOVE); ManagementOperations.executeOperation(managementClient.getControllerClient(), op); removeDeploymentItem(managementClient, TEST_WILDCARD, "*.war"); removeContentItem(managementClient, TEST_WILDCARD, "WEB-INF/web.xml"); removeContentItem(managementClient, TEST_WILDCARD, "WEB-INF/classes/wildcard-new-file"); op = new ModelNode(); op.get(ModelDescriptionConstants.OP_ADDR).set(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, TEST_WILDCARD); op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.REMOVE); ManagementOperations.executeOperation(managementClient.getControllerClient(), op); } private void removeContentItem(final ManagementClient managementClient, final String overlayName, final String content) throws IOException, MgmtOperationException { final ModelNode addr = new ModelNode(); addr.add(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, overlayName); addr.add(ModelDescriptionConstants.CONTENT, content); final ModelNode op = Operations.createRemoveOperation(addr); ManagementOperations.executeOperation(managementClient.getControllerClient(), op); } private void removeDeploymentItem(final ManagementClient managementClient, final String overlayName, final String deploymentRuntimeName) throws IOException, MgmtOperationException { final ModelNode addr = new ModelNode(); addr.add(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, overlayName); addr.add(ModelDescriptionConstants.DEPLOYMENT, deploymentRuntimeName); final ModelNode op = Operations.createRemoveOperation(addr); ManagementOperations.executeOperation(managementClient.getControllerClient(), op); } } @Deployment public static Archive<?> deploy() { return ShrinkWrap.create(WebArchive.class, "test.war") .addPackage(DeploymentOverlayTestCase.class.getPackage()) .setWebXML(DeploymentOverlayTestCase.class.getPackage(), "web.xml"); } @ArquillianResource private InitialContext initialContext; @Test public void testContentOverridden() throws NamingException { Assert.assertEquals("OVERRIDDEN", initialContext.lookup("java:module/env/simpleString")); } @Test public void testAddingNewFile() { Assert.assertNotNull(getClass().getClassLoader().getResource("wildcard-new-file")); } }
9,194
50.657303
206
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/OverlayServlet.java
/* * Copyright (C) 2016 Red Hat, inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301 USA */ package org.jboss.as.test.integration.deployment.deploymentoverlay; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; /** * @author <a href="mailto:[email protected]">Emmanuel Hugonnet</a> (c) 2015 Red Hat, inc. */ @WebServlet(name = "OverlayServlet", urlPatterns = {"/overlay/"}, loadOnStartup = 1) public class OverlayServlet extends HttpServlet { @Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try (InputStream from = getClass().getClassLoader().getResourceAsStream("wildcard-new-file")) { OutputStream output = resp.getOutputStream(); final byte[] buffer = new byte[4096]; int read = 0; while ((read = from.read(buffer)) != -1) { output.write(buffer, 0, read); } output.flush(); } } }
2,101
38.660377
115
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/SimpleServlet.java
/* * Copyright (C) 2016 Red Hat, inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301 USA */ package org.jboss.as.test.integration.deployment.deploymentoverlay; import java.io.IOException; import javax.naming.InitialContext; import javax.naming.NamingException; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; /** * @author <a href="mailto:[email protected]">Emmanuel Hugonnet</a> (c) 2015 Red Hat, inc. */ @WebServlet(name = "SimpleServlet", urlPatterns = {"/simple/"}, loadOnStartup = 1) public class SimpleServlet extends HttpServlet { @Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try { InitialContext initialContext = new InitialContext(); resp.getWriter().append(initialContext.lookup("java:module/env/simpleString").toString()); } catch (NamingException ex) { throw new ServletException(ex); } } }
1,997
39.77551
115
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/AffectedDeploymentOverlayTestCase.java
/* * Copyright 2017 Red Hat, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.as.test.integration.deployment.deploymentoverlay; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.CONTENT; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DEPLOYMENT; import java.io.IOException; import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.concurrent.TimeUnit; import org.hamcrest.CoreMatchers; import org.hamcrest.MatcherAssert; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.client.OperationBuilder; import org.jboss.as.controller.client.helpers.Operations; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.as.test.integration.common.HttpRequest; import org.jboss.as.test.integration.management.base.ContainerResourceMgmtTestBase; import org.jboss.as.test.shared.FileUtils; import org.jboss.dmr.ModelNode; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; /** * @author Stuart Douglas * @author Emmanuel Hugonnet (c) 2017 Red Hat, inc. */ @RunWith(Arquillian.class) @RunAsClient public class AffectedDeploymentOverlayTestCase extends ContainerResourceMgmtTestBase { private static final String DEPLOYMENT_NAME = "test.war"; public static final String TEST_OVERLAY = "test"; public static final String TEST_WILDCARD = "test-wildcard"; private static final PathAddress TEST_OVERLAY_ADDRESS = PathAddress.pathAddress(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, TEST_OVERLAY); private static final PathAddress TEST_WILDCARD_ADDRESS = PathAddress.pathAddress(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, TEST_WILDCARD); @Before public void setup() throws Exception { getModelControllerClient().execute(Operations.createAddOperation(TEST_OVERLAY_ADDRESS.toModelNode())); //add an override that will not be linked via a wildcard //add the content ModelNode op = Operations.createAddOperation(TEST_OVERLAY_ADDRESS.append(ModelDescriptionConstants.CONTENT, "WEB-INF/web.xml").toModelNode()); op.get(ModelDescriptionConstants.CONTENT).get(ModelDescriptionConstants.INPUT_STREAM_INDEX).set(0); OperationBuilder builder = new OperationBuilder(op, true); builder.addInputStream(AffectedDeploymentOverlayTestCase.class.getResourceAsStream("override.xml")); getModelControllerClient().execute(builder.build()); //add the non-wildcard link getModelControllerClient().execute(Operations.createAddOperation(TEST_OVERLAY_ADDRESS.append(DEPLOYMENT, DEPLOYMENT_NAME).toModelNode())); //add the deployment overlay that will be linked via wildcard getModelControllerClient().execute(Operations.createAddOperation(TEST_WILDCARD_ADDRESS.toModelNode())); op = Operations.createAddOperation(TEST_WILDCARD_ADDRESS.append(ModelDescriptionConstants.CONTENT, "WEB-INF/web.xml").toModelNode()); op.get(ModelDescriptionConstants.CONTENT).get(ModelDescriptionConstants.BYTES).set( FileUtils.readFile(AffectedDeploymentOverlayTestCase.class, "wildcard-override.xml").getBytes(StandardCharsets.UTF_8)); getModelControllerClient().execute(op); op = Operations.createAddOperation(TEST_WILDCARD_ADDRESS.append(ModelDescriptionConstants.CONTENT, "WEB-INF/classes/wildcard-new-file").toModelNode()); op.get(ModelDescriptionConstants.CONTENT).get(ModelDescriptionConstants.INPUT_STREAM_INDEX).set(0); builder = new OperationBuilder(op, true); builder.addInputStream(AffectedDeploymentOverlayTestCase.class.getResourceAsStream("wildcard-new-file")); getModelControllerClient().execute(builder.build()); } @After public void tearDown() throws Exception { getModelControllerClient().execute(Operations.createRemoveOperation(TEST_OVERLAY_ADDRESS.append(CONTENT, "WEB-INF/web.xml").toModelNode())); getModelControllerClient().execute(Operations.createRemoveOperation(TEST_OVERLAY_ADDRESS.append(DEPLOYMENT, DEPLOYMENT_NAME).toModelNode())); getModelControllerClient().execute(Operations.createRemoveOperation(TEST_OVERLAY_ADDRESS.toModelNode())); getModelControllerClient().execute(Operations.createRemoveOperation(TEST_WILDCARD_ADDRESS.append(DEPLOYMENT, "*.war").toModelNode())); getModelControllerClient().execute(Operations.createRemoveOperation(TEST_WILDCARD_ADDRESS.append(CONTENT, "WEB-INF/web.xml").toModelNode())); getModelControllerClient().execute(Operations.createRemoveOperation(TEST_WILDCARD_ADDRESS.append(CONTENT, "WEB-INF/classes/wildcard-new-file").toModelNode())); getModelControllerClient().execute(Operations.createRemoveOperation(TEST_WILDCARD_ADDRESS.toModelNode())); } @Deployment(name = DEPLOYMENT_NAME) public static Archive<?> deploy() { return ShrinkWrap.create(WebArchive.class, DEPLOYMENT_NAME) .addPackage(AffectedDeploymentOverlayTestCase.class.getPackage()) .setWebXML(AffectedDeploymentOverlayTestCase.class.getPackage(), "web.xml"); } @Test public void testContentOverridden(@ArquillianResource URL url) throws Exception { String response = HttpRequest.get(url + "/simple/", 10, TimeUnit.SECONDS); Assert.assertEquals("Overlay doesn't contain valid output", "UPDATED", response.trim()); try { HttpRequest.get(url + "/overlay/", 10, TimeUnit.SECONDS); Assert.fail("Overlay servlet shouldn't be up and working properly"); } catch (IOException ioex) { MatcherAssert.assertThat(ioex.getMessage(), CoreMatchers.containsString("HTTP Status 500 Response:")); } getModelControllerClient().execute(Operations.createOperation("redeploy-links", TEST_OVERLAY_ADDRESS.toModelNode())); response = HttpRequest.get(url + "/simple/", 10, TimeUnit.SECONDS); Assert.assertEquals("Overlay doesn't contain valid output", "OVERRIDDEN", response.trim()); try { HttpRequest.get(url + "/overlay/", 10, TimeUnit.SECONDS); Assert.fail("Overlay servlet shouldn't be up and working properly"); } catch (IOException ioex) { MatcherAssert.assertThat(ioex.getMessage(), CoreMatchers.containsString("HTTP Status 500 Response:")); } //add the wildcard link getModelControllerClient().execute(Operations.createAddOperation(TEST_WILDCARD_ADDRESS.append(ModelDescriptionConstants.DEPLOYMENT, "*.war").toModelNode())); getModelControllerClient().execute(Operations.createOperation("redeploy-links", TEST_OVERLAY_ADDRESS.toModelNode()));//This will redeploy the deployment response = HttpRequest.get(url + "/simple/", 10, TimeUnit.SECONDS); Assert.assertEquals("Overlay doesn't contain valid output", "OVERRIDDEN", response.trim()); response = HttpRequest.get(url + "/overlay/", 10, TimeUnit.SECONDS); Assert.assertEquals("Overlay doesn't contain valid output", "test", response.trim()); getModelControllerClient().execute(Operations.createOperation("redeploy-links", TEST_WILDCARD_ADDRESS.toModelNode()));//This will redeploy the deployment response = HttpRequest.get(url + "/simple/", 10, TimeUnit.SECONDS); Assert.assertEquals("Overlaydoesn't contain valid output", "OVERRIDDEN", response.trim()); response = HttpRequest.get(url + "/overlay/", 10, TimeUnit.SECONDS); Assert.assertEquals("Overlay doesn't contain valid output", "test", response.trim()); } }
8,542
57.115646
167
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/ExplodedDeploymentOverlayTestCase.java
/* * Copyright (C) 2016 Red Hat, inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301 USA */ package org.jboss.as.test.integration.deployment.deploymentoverlay; import java.io.IOException; import java.nio.charset.StandardCharsets; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.util.EntityUtils; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.controller.client.OperationBuilder; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.as.test.integration.management.ManagementOperations; import org.jboss.as.test.integration.management.util.MgmtOperationException; import org.jboss.as.test.shared.FileUtils; import org.jboss.dmr.ModelNode; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; /** * @author <a href="mailto:[email protected]">Emmanuel Hugonnet</a> (c) 2015 Red Hat, inc. */ @RunWith(Arquillian.class) @RunAsClient public class ExplodedDeploymentOverlayTestCase { public static final String TEST_OVERLAY = "test"; public static final String TEST_WILDCARD = "test-wildcard"; @ArquillianResource private ManagementClient managementClient; @Before public void setup() throws Exception { ModelNode op = new ModelNode(); op.get(ModelDescriptionConstants.OP_ADDR).set(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, TEST_OVERLAY); op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.ADD); ManagementOperations.executeOperation(managementClient.getControllerClient(), op); //add an override that will not be linked via a wildcard //add the content op = new ModelNode(); ModelNode addr = new ModelNode(); addr.add(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, TEST_OVERLAY); addr.add(ModelDescriptionConstants.CONTENT, "WEB-INF/web.xml"); op.get(ModelDescriptionConstants.OP_ADDR).set(addr); op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.ADD); op.get(ModelDescriptionConstants.CONTENT).get(ModelDescriptionConstants.INPUT_STREAM_INDEX).set(0); OperationBuilder builder = new OperationBuilder(op, true); builder.addInputStream(ExplodedDeploymentOverlayTestCase.class.getResourceAsStream("override.xml")); ManagementOperations.executeOperation(managementClient.getControllerClient(), builder.build()); //add the non-wildcard link op = new ModelNode(); addr = new ModelNode(); addr.add(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, TEST_OVERLAY); addr.add(ModelDescriptionConstants.DEPLOYMENT, "exploded-test.war"); op.get(ModelDescriptionConstants.OP_ADDR).set(addr); op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.ADD); ManagementOperations.executeOperation(managementClient.getControllerClient(), op); //add the deployment overlay that will be linked via wildcard op = new ModelNode(); op.get(ModelDescriptionConstants.OP_ADDR).set(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, TEST_WILDCARD); op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.ADD); ManagementOperations.executeOperation(managementClient.getControllerClient(), op); op = new ModelNode(); addr = new ModelNode(); addr.add(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, TEST_WILDCARD); addr.add(ModelDescriptionConstants.CONTENT, "WEB-INF/web.xml"); op.get(ModelDescriptionConstants.OP_ADDR).set(addr); op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.ADD); op.get(ModelDescriptionConstants.CONTENT).get(ModelDescriptionConstants.BYTES).set( FileUtils.readFile(ExplodedDeploymentOverlayTestCase.class, "wildcard-override.xml").getBytes(StandardCharsets.UTF_8)); ManagementOperations.executeOperation(managementClient.getControllerClient(), op); op = new ModelNode(); addr = new ModelNode(); addr.add(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, TEST_WILDCARD); addr.add(ModelDescriptionConstants.CONTENT, "WEB-INF/classes/wildcard-new-file"); op.get(ModelDescriptionConstants.OP_ADDR).set(addr); op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.ADD); op.get(ModelDescriptionConstants.CONTENT).get(ModelDescriptionConstants.INPUT_STREAM_INDEX).set(0); builder = new OperationBuilder(op, true); builder.addInputStream(ExplodedDeploymentOverlayTestCase.class.getResourceAsStream("wildcard-new-file")); ManagementOperations.executeOperation(managementClient.getControllerClient(), builder.build()); //add the wildcard link op = new ModelNode(); addr = new ModelNode(); addr.add(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, TEST_WILDCARD); addr.add(ModelDescriptionConstants.DEPLOYMENT, "*.war"); op.get(ModelDescriptionConstants.OP_ADDR).set(addr); op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.ADD); ManagementOperations.executeOperation(managementClient.getControllerClient(), op); //Deploy exploded deployement addr = new ModelNode(); addr.add(ModelDescriptionConstants.DEPLOYMENT, "exploded-test.war"); op = new ModelNode(); op.get(ModelDescriptionConstants.OP_ADDR).set(addr); op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.READ_ATTRIBUTE_OPERATION); op.get(ModelDescriptionConstants.NAME).set("content[0]"); ModelNode result = ManagementOperations.executeOperation(managementClient.getControllerClient(), op); if (!result.hasDefined(ModelDescriptionConstants.ARCHIVE) || result.get(ModelDescriptionConstants.ARCHIVE).asBoolean(true)) { op = new ModelNode(); op.get(ModelDescriptionConstants.OP_ADDR).set(addr); op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.UNDEPLOY); ManagementOperations.executeOperation(managementClient.getControllerClient(), op); op = new ModelNode(); op.get(ModelDescriptionConstants.OP).set("explode"); op.get(ModelDescriptionConstants.OP_ADDR).set(addr); ManagementOperations.executeOperation(managementClient.getControllerClient(), op); op = new ModelNode(); op.get(ModelDescriptionConstants.OP_ADDR).set(addr); op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.DEPLOY); ManagementOperations.executeOperation(managementClient.getControllerClient(), op); } } @After public void tearDown() throws Exception { removeContentItem(managementClient, TEST_OVERLAY, "WEB-INF/web.xml"); removeDeploymentItem(managementClient, TEST_OVERLAY, "exploded-test.war"); ModelNode op = new ModelNode(); op.get(ModelDescriptionConstants.OP_ADDR).set(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, TEST_OVERLAY); op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.REMOVE); ManagementOperations.executeOperation(managementClient.getControllerClient(), op); removeDeploymentItem(managementClient, TEST_WILDCARD, "*.war"); removeContentItem(managementClient, TEST_WILDCARD, "WEB-INF/web.xml"); removeContentItem(managementClient, TEST_WILDCARD, "WEB-INF/classes/wildcard-new-file"); op = new ModelNode(); op.get(ModelDescriptionConstants.OP_ADDR).set(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, TEST_WILDCARD); op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.REMOVE); ManagementOperations.executeOperation(managementClient.getControllerClient(), op); } private void removeContentItem(final ManagementClient managementClient, final String w, final String a) throws IOException, MgmtOperationException { final ModelNode op; final ModelNode addr; op = new ModelNode(); addr = new ModelNode(); addr.add(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, w); addr.add(ModelDescriptionConstants.CONTENT, a); op.get(ModelDescriptionConstants.OP_ADDR).set(addr); op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.REMOVE); ManagementOperations.executeOperation(managementClient.getControllerClient(), op); } private void removeDeploymentItem(final ManagementClient managementClient, final String w, final String a) throws IOException, MgmtOperationException { final ModelNode op; final ModelNode addr; op = new ModelNode(); addr = new ModelNode(); addr.add(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, w); addr.add(ModelDescriptionConstants.DEPLOYMENT, a); op.get(ModelDescriptionConstants.OP_ADDR).set(addr); op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.REMOVE); ManagementOperations.executeOperation(managementClient.getControllerClient(), op); } private void updateDeployment(String file, String targetPath) throws IOException, MgmtOperationException { final ModelNode op = new ModelNode(); op.get(ModelDescriptionConstants.OP).set("add-content"); final ModelNode addr = new ModelNode(); addr.add(ModelDescriptionConstants.DEPLOYMENT, "exploded-test.war"); op.get(ModelDescriptionConstants.OP_ADDR).set(addr); ModelNode updatedFile = new ModelNode(); updatedFile.get(ModelDescriptionConstants.INPUT_STREAM_INDEX).set(0); updatedFile.get("target-path").set(targetPath); op.get(ModelDescriptionConstants.CONTENT).add(updatedFile); OperationBuilder builder = new OperationBuilder(op, true); builder.addInputStream(ExplodedDeploymentOverlayTestCase.class.getResourceAsStream(file)); ManagementOperations.executeOperation(managementClient.getControllerClient(), builder.build()); } @Test public void testContentOverridden() throws Exception { final String requestURL = managementClient.getWebUri() + "/exploded-test/simple/"; final HttpGet request = new HttpGet(requestURL); final HttpClient httpClient = new DefaultHttpClient(); HttpResponse response = httpClient.execute(request); String responseMessage = EntityUtils.toString(response.getEntity()); Assert.assertEquals("OVERRIDDEN",responseMessage); updateDeployment("update.xml","WEB-INF/web.xml"); response = httpClient.execute(request); responseMessage = EntityUtils.toString(response.getEntity()); Assert.assertEquals("OVERRIDDEN",responseMessage); updateDeployment("web.xml","WEB-INF/web.xml"); } @Test public void testAddingNewFile() throws Exception { final HttpClient httpClient = new DefaultHttpClient(); String requestURL = managementClient.getWebUri() + "/exploded-test/overlay/"; HttpGet request = new HttpGet(requestURL); HttpResponse response = httpClient.execute(request); String responseMessage = EntityUtils.toString(response.getEntity()); Assert.assertEquals("test",responseMessage); updateDeployment("web.xml", "WEB-INF/classes/wildcard-new-file"); response = httpClient.execute(request); responseMessage = EntityUtils.toString(response.getEntity()); Assert.assertEquals("test",responseMessage); updateDeployment("web.xml", "WEB-INF/classes/wildcard-new-file"); updateDeployment("index.html", "index.html"); requestURL = managementClient.getWebUri() + "/exploded-test/index.html"; request = new HttpGet(requestURL); response = httpClient.execute(request); responseMessage = EntityUtils.toString(response.getEntity()); Assert.assertTrue(responseMessage, responseMessage.contains("Simple Content test for exploded-test.war")); } @Deployment() public static Archive<?> deploy() { return ShrinkWrap.create(WebArchive.class, "exploded-test.war") .addClass(SimpleServlet.class) .addClass(OverlayServlet.class) .setWebXML(SimpleServlet.class.getPackage(), "web.xml"); } }
13,713
50.556391
155
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/AbstractOverlayTestBase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.deploymentoverlay; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.Map; import java.util.Set; import org.jboss.arquillian.container.test.api.Deployer; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.as.test.integration.management.ManagementOperations; import org.jboss.as.test.integration.management.util.MgmtOperationException; import org.jboss.as.test.integration.security.common.SecurityTraceLoggingServerSetupTask; import org.jboss.dmr.ModelNode; import org.jboss.logging.Logger; /** * @author baranowb * @author lgao */ // Uncomment if TRACE logging is necessary. Don't leave it on all the time; CI resources aren't free. //@ServerSetup(AbstractOverlayTestBase.TraceLoggingSetup.class) public abstract class AbstractOverlayTestBase { protected static final Logger LOGGER = Logger.getLogger(AbstractOverlayTestBase.class); @ArquillianResource protected ManagementClient managementClient; @ArquillianResource protected Deployer deployer; private boolean removeOverlay = false; public void setupOverlay(final String deployment, final String overlayName, final Map<String, String> overlay) throws Exception { // create overlay ModelNode op = new ModelNode(); op.get(ModelDescriptionConstants.OP_ADDR).set(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, overlayName); op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.ADD); ManagementOperations.executeOperation(managementClient.getControllerClient(), op); removeOverlay=true; for (Map.Entry<String, String> overlayItem : overlay.entrySet()) { // add content op = new ModelNode(); op.get(ModelDescriptionConstants.OP_ADDR).set(new ModelNode()); op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.UPLOAD_DEPLOYMENT_BYTES); op.get(ModelDescriptionConstants.BYTES).set(overlayItem.getValue().getBytes(StandardCharsets.UTF_8)); ModelNode result = ManagementOperations.executeOperation(managementClient.getControllerClient(), op); // link content to specific file op = new ModelNode(); ModelNode addr = new ModelNode(); addr.add(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, overlayName); addr.add(ModelDescriptionConstants.CONTENT, overlayItem.getKey()); op.get(ModelDescriptionConstants.OP_ADDR).set(addr); op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.ADD); op.get(ModelDescriptionConstants.CONTENT).get(ModelDescriptionConstants.HASH).set(result); ManagementOperations.executeOperation(managementClient.getControllerClient(), op); } // add link op = new ModelNode(); ModelNode addr = new ModelNode(); addr.add(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, overlayName); addr.add(ModelDescriptionConstants.DEPLOYMENT, deployment); op.get(ModelDescriptionConstants.OP_ADDR).set(addr); op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.ADD); ManagementOperations.executeOperation(managementClient.getControllerClient(), op); op = new ModelNode(); addr = new ModelNode(); addr.add(ModelDescriptionConstants.DEPLOYMENT, deployment); op.get(ModelDescriptionConstants.OP_ADDR).set(addr); op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.REDEPLOY); ManagementOperations.executeOperation(managementClient.getControllerClient(), op); } public void setupOverlay(final String deployment, final String overlayName, final String overlayPath, final String overlayedContent) throws Exception { setupOverlay(deployment, overlayName, Collections.singletonMap(overlayPath, overlayedContent)); } public void removeOverlay(final String deployment, final String overlayName, final Set<String> overlayPaths) throws Exception { if (!removeOverlay) { return; } for (String overlayPath : overlayPaths) { removeContentItem(overlayName, overlayPath); } removeDeploymentItem(overlayName, deployment); ModelNode op = new ModelNode(); op.get(ModelDescriptionConstants.OP_ADDR).set(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, overlayName); op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.REMOVE); ManagementOperations.executeOperation(managementClient.getControllerClient(), op); removeOverlay = false; } public void removeOverlay(final String deployment, final String overlayName, final String overlayPath) throws Exception { removeOverlay(deployment, overlayName, Collections.singleton(overlayPath)); } protected void removeContentItem(final String w, final String a) throws IOException, MgmtOperationException { final ModelNode op; final ModelNode addr; op = new ModelNode(); addr = new ModelNode(); addr.add(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, w); addr.add(ModelDescriptionConstants.CONTENT, a); op.get(ModelDescriptionConstants.OP_ADDR).set(addr); op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.REMOVE); ManagementOperations.executeOperation(managementClient.getControllerClient(), op); } protected void removeDeploymentItem(final String w, final String a) throws IOException, MgmtOperationException { final ModelNode op; final ModelNode addr; op = new ModelNode(); addr = new ModelNode(); addr.add(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, w); addr.add(ModelDescriptionConstants.DEPLOYMENT, a); op.get(ModelDescriptionConstants.OP_ADDR).set(addr); op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.REMOVE); ManagementOperations.executeOperation(managementClient.getControllerClient(), op); } public static class TraceLoggingSetup extends SecurityTraceLoggingServerSetupTask { @Override protected Collection<String> getCategories(ManagementClient managementClient, String containerId) { Set<String> coll = new HashSet<>(super.getCategories(managementClient, containerId)); coll.add("org.jboss.sasl"); coll.add("org.jboss.as.ejb3"); coll.add("org.jboss.as.remoting"); coll.add("org.jboss.remoting3"); coll.add("org.jboss.remoting"); coll.add("org.jboss.naming.remote"); return coll; } } }
8,003
45.265896
125
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/jar/OverlayableInterface.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.deploymentoverlay.jar; import jakarta.ejb.Remote; /** * @author baranowb * */ @Remote public interface OverlayableInterface { String ORIGINAL = "ORIGINAL"; String OVERLAYED = "OVERLAYED"; String RESOURCE_NAME = "file.txt"; String RESOURCE_META_INF = "x/"+RESOURCE_NAME; String RESOURCE = "META-INF/"+RESOURCE_META_INF; String STATIC = "STATIC"; String RESOURCE_STATIC_NAME = "static.txt"; String RESOURCE_STATIC_META_INF = "x/"+RESOURCE_STATIC_NAME; String RESOURCE_STATIC = "META-INF/"+RESOURCE_STATIC_META_INF; String fetchResource() throws Exception; String fetchResourceStatic() throws Exception; }
1,728
35.020833
71
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/jar/OverlayEJB.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.deploymentoverlay.jar; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; import jakarta.ejb.Singleton; /** * @author baranowb * */ @Singleton public class OverlayEJB implements OverlayableInterface { @Override public String fetchResource() throws Exception { return fetch(RESOURCE); } @Override public String fetchResourceStatic() throws Exception { return fetch(RESOURCE_STATIC); } protected String fetch(final String res) throws Exception { try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(res)) { if (is == null) { return null; } try (InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8); BufferedReader br = new BufferedReader(isr);) { return br.readLine(); } } } }
2,045
32.540984
91
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/jar/OverlayNonExistingResourceTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.deploymentoverlay.jar; import javax.naming.InitialContext; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * @author baranowb */ @RunWith(Arquillian.class) @RunAsClient public class OverlayNonExistingResourceTestCase extends JarOverlayTestBase { private static final String OVERLAY = "HAL9000"; private static final String DEPLOYMENT_OVERLAYED = "overlayed"; private static final String DEPLOYMENT_OVERLAYED_ARCHIVE = DEPLOYMENT_OVERLAYED + ".jar"; @Deployment(name = DEPLOYMENT_OVERLAYED) public static Archive<?> createDeployment() throws Exception { return createOverlayedArchive(false, DEPLOYMENT_OVERLAYED_ARCHIVE); } @Test public void testOverlay() throws Exception { final InitialContext ctx = getInitialContext(); try { OverlayableInterface iface = (OverlayableInterface) ctx.lookup(getEjbBinding("", DEPLOYMENT_OVERLAYED, "", OverlayEJB.class, OverlayableInterface.class)); Assert.assertEquals("Overlayed resource does not match pre-overlay expectations!", null, iface.fetchResource()); Assert.assertEquals("Static resource does not match pre-overlay expectations!", OverlayableInterface.STATIC, iface.fetchResourceStatic()); setupOverlay(DEPLOYMENT_OVERLAYED_ARCHIVE, OVERLAY, OverlayableInterface.RESOURCE, OverlayableInterface.OVERLAYED); Assert.assertEquals("Overlayed resource does not match post-overlay expectations!", OverlayableInterface.OVERLAYED, iface.fetchResource()); Assert.assertEquals("Static resource does not match post-overlay expectations!", OverlayableInterface.STATIC, iface.fetchResourceStatic()); } finally { try { ctx.close(); } catch (Exception e) { LOGGER.error("Closing context failed", e); } try { removeOverlay(DEPLOYMENT_OVERLAYED_ARCHIVE, OVERLAY, OverlayableInterface.RESOURCE); } catch (Exception e) { LOGGER.error("Removing overlay failed", e); } } } }
3,427
43.519481
151
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/jar/OverlayExistingResourceTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.deploymentoverlay.jar; import javax.naming.InitialContext; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * @author baranowb * */ @RunWith(Arquillian.class) @RunAsClient public class OverlayExistingResourceTestCase extends JarOverlayTestBase { private static final String OVERLAY = "HAL9000"; private static final String DEPLOYMENT_OVERLAYED = "overlayed"; private static final String DEPLOYMENT_OVERLAYED_ARCHIVE = DEPLOYMENT_OVERLAYED + ".jar"; @Deployment(name = DEPLOYMENT_OVERLAYED) public static Archive<?> createDeployment() throws Exception { return createOverlayedArchive(true, DEPLOYMENT_OVERLAYED_ARCHIVE); } @Test public void testOverlay() throws Exception { final InitialContext ctx = getInitialContext(); try{ OverlayableInterface iface = (OverlayableInterface) ctx.lookup(getEjbBinding("", DEPLOYMENT_OVERLAYED, "", OverlayEJB.class, OverlayableInterface.class)); Assert.assertEquals("Overlayed resource does not match pre-overlay expectations!", OverlayableInterface.ORIGINAL, iface.fetchResource()); Assert.assertEquals("Static resource does not match pre-overlay expectations!", OverlayableInterface.STATIC, iface.fetchResourceStatic()); setupOverlay(DEPLOYMENT_OVERLAYED_ARCHIVE, OVERLAY, OverlayableInterface.RESOURCE, OverlayableInterface.OVERLAYED); Assert.assertEquals("Overlayed resource does not match post-overlay expectations!", OverlayableInterface.OVERLAYED, iface.fetchResource()); Assert.assertEquals("Static resource does not match post-overlay expectations!", OverlayableInterface.STATIC, iface.fetchResourceStatic()); } finally { try { ctx.close(); } catch (Exception e) { LOGGER.error("Closing context failed", e); } try { removeOverlay(DEPLOYMENT_OVERLAYED_ARCHIVE, OVERLAY, OverlayableInterface.RESOURCE); } catch (Exception e) { LOGGER.error("Removing overlay failed", e); } } } }
3,473
43.538462
151
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/jar/JarOverlayTestBase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.deploymentoverlay.jar; import java.util.Hashtable; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import org.jboss.as.test.integration.deployment.deploymentoverlay.AbstractOverlayTestBase; import org.jboss.as.test.shared.TestSuiteEnvironment; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.JavaArchive; /** * @author baranowb * */ public class JarOverlayTestBase extends AbstractOverlayTestBase { public static Archive<?> createOverlayedArchive(final boolean resourcePresent, final String deploymentOverlayedArchive){ final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, deploymentOverlayedArchive); jar.addClasses(OverlayableInterface.class, OverlayEJB.class); jar.addAsManifestResource(new StringAsset(OverlayableInterface.STATIC), OverlayableInterface.RESOURCE_STATIC_META_INF); if(resourcePresent){ jar.addAsManifestResource(new StringAsset(OverlayableInterface.ORIGINAL), OverlayableInterface.RESOURCE_META_INF); } return jar; } protected static InitialContext getInitialContext() throws NamingException { final Hashtable<String, String> env = new Hashtable<>(); env.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); env.put(Context.INITIAL_CONTEXT_FACTORY, org.wildfly.naming.client.WildFlyInitialContextFactory.class.getName()); env.put(Context.PROVIDER_URL, "remote+http://" + TestSuiteEnvironment.getServerAddress() + ":" + 8080); return new InitialContext(env); } protected static String getEjbBinding(final String rtModuleName, final String module, final String distinct, final Class bean, final Class iface) { final String appName = rtModuleName; final String moduleName = module; final String distinctName = distinct; final String beanName = bean.getSimpleName(); final String viewClassName = iface.getName(); return "ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName; } }
3,300
44.219178
130
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/ear/EarOverlayTestBase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.deploymentoverlay.ear; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.jboss.as.test.integration.deployment.deploymentoverlay.jar.OverlayableInterface; import org.jboss.as.test.integration.deployment.deploymentoverlay.war.WarOverlayTestBase; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.WebArchive; /** * @author baranowb * @author lgao * */ public class EarOverlayTestBase extends WarOverlayTestBase { public static final String WEB = "web"; public static final String WEB_ARCHIVE = WEB + ".war"; public static final String WEB_OVERLAY = WEB_ARCHIVE + "/" + OVERLAY_HTML; public static final String RESOURCE_IN_JAR_OVERLAY = "jar/overlay.txt"; public static final String META_RESOURCE_IN_JAR_OVERLAY = "META-INF/" + RESOURCE_IN_JAR_OVERLAY; public static final String RESOURCE_IN_JAR_STATIC = "jar/static.txt"; public static final String META_RESOURCE_IN_JAR_STATIC = "META-INF/" + RESOURCE_IN_JAR_STATIC; public static final String SERVLETS_JAR = "echoservlet.jar"; public static final String JAR_IN_WAR_OVERLAY_PATH = WEB_ARCHIVE + "/" + SERVLETS_JAR + "/" + META_RESOURCE_IN_JAR_OVERLAY; public static Archive<?> createEARWithOverlayedArchive(final boolean resourcePresent, String deploymentOverlayedArchive, final String deploymentTopArchve){ EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, deploymentTopArchve); Archive<?> jar = createOverlayedArchive(resourcePresent,deploymentOverlayedArchive); ear.addAsModule(jar); WebArchive war = ShrinkWrap.create(WebArchive.class, WEB_ARCHIVE); war.add(new StringAsset(OverlayableInterface.STATIC), STATIC_HTML); if (resourcePresent) { war.add(new StringAsset(OverlayableInterface.ORIGINAL), OVERLAY_HTML); } JavaArchive servlets = ShrinkWrap.create(JavaArchive.class, SERVLETS_JAR); servlets.addClasses(EchoStaticServlet.class, EchoOverlayServlet.class); servlets.addAsManifestResource(new StringAsset(OverlayableInterface.STATIC), RESOURCE_IN_JAR_STATIC); if (resourcePresent) { servlets.addAsManifestResource(new StringAsset(OverlayableInterface.ORIGINAL), RESOURCE_IN_JAR_OVERLAY); } war.addAsLibraries(servlets); ear.addAsModule(war); return ear; } @SuppressWarnings("serial") @WebServlet("/echoStatic") public static class EchoStaticServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try (InputStream input = getClass().getClassLoader().getResourceAsStream(META_RESOURCE_IN_JAR_STATIC); InputStreamReader inputReader = new InputStreamReader(input, StandardCharsets.UTF_8); BufferedReader reader = new BufferedReader(inputReader)) { resp.getWriter().write(reader.readLine()); resp.flushBuffer(); } } } @SuppressWarnings("serial") @WebServlet("/echoOverlay") public static class EchoOverlayServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try (InputStream input = getClass().getClassLoader().getResourceAsStream(META_RESOURCE_IN_JAR_OVERLAY)) { if (input == null) { resp.sendError(404); return; } try (InputStreamReader inputReader = new InputStreamReader(input, StandardCharsets.UTF_8); BufferedReader reader = new BufferedReader(inputReader)) { resp.getWriter().write(reader.readLine()); resp.flushBuffer(); } } } } }
5,522
43.902439
159
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/ear/OverlayNonExistingResourceTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.deploymentoverlay.ear; import java.util.HashMap; import java.util.Map; import javax.naming.InitialContext; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.test.integration.deployment.deploymentoverlay.jar.OverlayEJB; import org.jboss.as.test.integration.deployment.deploymentoverlay.jar.OverlayableInterface; import org.jboss.shrinkwrap.api.Archive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * @author baranowb * @author lgao * */ @RunWith(Arquillian.class) @RunAsClient public class OverlayNonExistingResourceTestCase extends EarOverlayTestBase { private static final String OVERLAY = "HAL9000"; private static final String DEPLOYMENT_OVERLAYED = "overlayed"; private static final String DEPLOYMENT_OVERLAYED_ARCHIVE = DEPLOYMENT_OVERLAYED + ".jar"; private static final String DEPLOYMENT_SHELL = "shell"; private static final String DEPLOYMENT_SHELL_ARCHIVE = DEPLOYMENT_SHELL + ".ear"; private static final String RESOURCE = "/"+DEPLOYMENT_OVERLAYED_ARCHIVE+"//"+OverlayableInterface.RESOURCE; @Deployment(name = DEPLOYMENT_SHELL) public static Archive<?> createDeployment() throws Exception { return createEARWithOverlayedArchive(false, DEPLOYMENT_OVERLAYED_ARCHIVE,DEPLOYMENT_SHELL_ARCHIVE); } @Test public void testOverlay() throws Exception { final InitialContext ctx = getInitialContext(); Map<String, String> overlay = new HashMap<String, String>(); try{ OverlayableInterface iface = (OverlayableInterface) ctx.lookup(getEjbBinding(DEPLOYMENT_SHELL, DEPLOYMENT_OVERLAYED, "", OverlayEJB.class, OverlayableInterface.class)); Assert.assertEquals("Overlayed resource in ear/jar does not match pre-overlay expectations!", null, iface.fetchResource()); Assert.assertEquals("Static resource in ear/jar does not match pre-overlay expectations!", OverlayableInterface.STATIC, iface.fetchResourceStatic()); Assert.assertEquals("HTML resource in ear/war does not match pre-overlay expectations!", null, readContent(managementClient.getWebUri() + "/" + WEB + "/" + OVERLAY_HTML)); Assert.assertEquals("HTML Static resource in ear/war does not match pre-overlay expectations!", OverlayableInterface.STATIC, readContent(managementClient.getWebUri() + "/" + WEB + "/" + STATIC_HTML)); Assert.assertEquals("Static resource in ear/war/jar does not match pre-overlay expectations!", OverlayableInterface.STATIC, readContent(managementClient.getWebUri() + "/" + WEB + "/echoStatic")); Assert.assertEquals("Resource in ear/war/jar does not match pre-overlay expectations!", null, readContent(managementClient.getWebUri() + "/" + WEB + "/echoOverlay")); overlay.put(RESOURCE, OverlayableInterface.OVERLAYED); overlay.put(WEB_OVERLAY, OverlayableInterface.OVERLAYED); setupOverlay(DEPLOYMENT_SHELL_ARCHIVE, OVERLAY, overlay); Assert.assertEquals("Overlayed resource in ear/jar does not match post-overlay expectations!", OverlayableInterface.OVERLAYED, iface.fetchResource()); Assert.assertEquals("Static resource in ear/jar does not match post-overlay expectations!", OverlayableInterface.STATIC, iface.fetchResourceStatic()); Assert.assertEquals("HTML static resource in ear/war does not match post-overlay expectations!", OverlayableInterface.STATIC, readContent(managementClient.getWebUri() + "/" + WEB + "/" + STATIC_HTML)); Assert.assertEquals("HTML resource in ear/war does not match post-overlay expectations!", OverlayableInterface.OVERLAYED, readContent(managementClient.getWebUri() + "/" + WEB + "/" + OVERLAY_HTML)); } finally { try { ctx.close(); } catch (Exception e) { LOGGER.error("Closing context failed", e); } try { removeOverlay(DEPLOYMENT_SHELL_ARCHIVE, OVERLAY, overlay.keySet()); } catch (Exception e) { LOGGER.error("Removing overlay failed", e); } } } }
5,478
49.731481
162
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/ear/OverlayExistingResourceTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.deploymentoverlay.ear; import java.util.HashMap; import java.util.Map; import javax.naming.InitialContext; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.test.integration.deployment.deploymentoverlay.jar.OverlayEJB; import org.jboss.as.test.integration.deployment.deploymentoverlay.jar.OverlayableInterface; import org.jboss.shrinkwrap.api.Archive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * @author baranowb * @author lgao * */ @RunWith(Arquillian.class) @RunAsClient public class OverlayExistingResourceTestCase extends EarOverlayTestBase { private static final String OVERLAY = "HAL9000"; private static final String DEPLOYMENT_OVERLAYED = "overlayed"; private static final String DEPLOYMENT_OVERLAYED_ARCHIVE = DEPLOYMENT_OVERLAYED + ".jar"; private static final String DEPLOYMENT_SHELL = "shell"; private static final String DEPLOYMENT_SHELL_ARCHIVE = DEPLOYMENT_SHELL + ".ear"; private static final String RESOURCE = "/"+DEPLOYMENT_OVERLAYED_ARCHIVE+"//"+OverlayableInterface.RESOURCE; @Deployment(name = DEPLOYMENT_SHELL) public static Archive<?> createDeployment() throws Exception { return createEARWithOverlayedArchive(true, DEPLOYMENT_OVERLAYED_ARCHIVE,DEPLOYMENT_SHELL_ARCHIVE); } @Test public void testOverlay() throws Exception { final InitialContext ctx = getInitialContext(); Map<String, String> overlay = new HashMap<String, String>(); try{ OverlayableInterface iface = (OverlayableInterface) ctx.lookup(getEjbBinding(DEPLOYMENT_SHELL, DEPLOYMENT_OVERLAYED, "", OverlayEJB.class, OverlayableInterface.class)); Assert.assertEquals("Overlayed resource does not match pre-overlay expectations!", OverlayableInterface.ORIGINAL, iface.fetchResource()); Assert.assertEquals("Static resource does not match pre-overlay expectations!", OverlayableInterface.STATIC, iface.fetchResourceStatic()); Assert.assertEquals("HTML resource in ear/war does not match pre-overlay expectations!", OverlayableInterface.ORIGINAL, readContent(managementClient.getWebUri() + "/" + WEB + "/" + OVERLAY_HTML)); Assert.assertEquals("HTML Static in ear/war resource does not match pre-overlay expectations!", OverlayableInterface.STATIC, readContent(managementClient.getWebUri() + "/" + WEB + "/" + STATIC_HTML)); Assert.assertEquals("Static resource in ear/war/jar does not match pre-overlay expectations!", OverlayableInterface.STATIC, readContent(managementClient.getWebUri() + "/" + WEB + "/echoStatic")); Assert.assertEquals("Resource in ear/war/jar does not match pre-overlay expectations!", OverlayableInterface.ORIGINAL, readContent(managementClient.getWebUri() + "/" + WEB + "/echoOverlay")); overlay.put(RESOURCE, OverlayableInterface.OVERLAYED); overlay.put(WEB_OVERLAY, OverlayableInterface.OVERLAYED); setupOverlay(DEPLOYMENT_SHELL_ARCHIVE, OVERLAY, overlay); Assert.assertEquals("Overlayed resource in ear/jar does not match post-overlay expectations!", OverlayableInterface.OVERLAYED, iface.fetchResource()); Assert.assertEquals("Static resource in ear/jar does not match post-overlay expectations!", OverlayableInterface.STATIC, iface.fetchResourceStatic()); Assert.assertEquals("HTML static resource in ear/war does not match post-overlay expectations!", OverlayableInterface.STATIC, readContent(managementClient.getWebUri() + "/" + WEB + "/" + STATIC_HTML)); Assert.assertEquals("HTML resource in ear/war does not match post-overlay expectations!", OverlayableInterface.OVERLAYED, readContent(managementClient.getWebUri() + "/" + WEB + "/" + OVERLAY_HTML)); } finally { try { ctx.close(); } catch (Exception e) { LOGGER.error("Closing context failed", e); } try { removeOverlay(DEPLOYMENT_SHELL_ARCHIVE, OVERLAY, overlay.keySet()); } catch (Exception e) { LOGGER.error("Removing overlay failed", e); } } } }
5,527
50.185185
162
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/war/OverlayNonExistingResourceTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.deploymentoverlay.war; import java.util.HashMap; import java.util.Map; import javax.naming.InitialContext; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.test.integration.deployment.deploymentoverlay.jar.OverlayEJB; import org.jboss.as.test.integration.deployment.deploymentoverlay.jar.OverlayableInterface; import org.jboss.shrinkwrap.api.Archive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * @author baranowb * @author lgao * */ @RunWith(Arquillian.class) @RunAsClient public class OverlayNonExistingResourceTestCase extends WarOverlayTestBase { private static final String OVERLAY = "HAL9000"; private static final String DEPLOYMENT_OVERLAYED = "overlayed"; private static final String DEPLOYMENT_OVERLAYED_ARCHIVE = DEPLOYMENT_OVERLAYED + ".jar"; private static final String DEPLOYMENT_SHELL = "shell"; private static final String DEPLOYMENT_SHELL_ARCHIVE = DEPLOYMENT_SHELL + ".war"; private static final String RESOURCE = "/WEB-INF/lib/"+DEPLOYMENT_OVERLAYED_ARCHIVE+"//"+OverlayableInterface.RESOURCE; @Deployment(name = DEPLOYMENT_SHELL) public static Archive<?> createDeployment() throws Exception { return createWARWithOverlayedArchive(false, DEPLOYMENT_OVERLAYED_ARCHIVE,DEPLOYMENT_SHELL_ARCHIVE); } @Test public void testOverlay() throws Exception { final InitialContext ctx = getInitialContext(); Map<String, String> overlay = new HashMap<String, String>(); try{ OverlayableInterface iface = (OverlayableInterface) ctx.lookup(getEjbBinding("", DEPLOYMENT_SHELL, "", OverlayEJB.class, OverlayableInterface.class)); Assert.assertEquals("Overlayed resource in war/jar does not match pre-overlay expectations!", null, iface.fetchResource()); Assert.assertEquals("Static resource in war/jar does not match pre-overlay expectations!", OverlayableInterface.STATIC, iface.fetchResourceStatic()); Assert.assertEquals("HTML resource in war does not match pre-overlay expectations!", null, readContent(managementClient.getWebUri() + "/" + DEPLOYMENT_SHELL + "/" + OVERLAY_HTML)); Assert.assertEquals("HTML Static resource in war does not match pre-overlay expectations!", OverlayableInterface.STATIC, readContent(managementClient.getWebUri() + "/" + DEPLOYMENT_SHELL + "/" + STATIC_HTML)); overlay.put(RESOURCE, OverlayableInterface.OVERLAYED); overlay.put(OVERLAY_HTML, OverlayableInterface.OVERLAYED); setupOverlay(DEPLOYMENT_SHELL_ARCHIVE, OVERLAY, overlay); Assert.assertEquals("Overlayed resource in war/jar does not match post-overlay expectations!", OverlayableInterface.OVERLAYED, iface.fetchResource()); Assert.assertEquals("Static resource in war/jar does not match post-overlay expectations!", OverlayableInterface.STATIC, iface.fetchResourceStatic()); Assert.assertEquals("HTML static resource in war does not match post-overlay expectations!", OverlayableInterface.STATIC, readContent(managementClient.getWebUri() + "/" + DEPLOYMENT_SHELL + "/" + STATIC_HTML)); Assert.assertEquals("HTML resource in war does not match post-overlay expectations!", OverlayableInterface.OVERLAYED, readContent(managementClient.getWebUri() + "/" + DEPLOYMENT_SHELL + "/" + OVERLAY_HTML)); } finally { try { ctx.close(); } catch (Exception e) { LOGGER.error("Closing context failed", e); } try { removeOverlay(DEPLOYMENT_SHELL_ARCHIVE, OVERLAY, overlay.keySet()); } catch (Exception e) { LOGGER.error("Removing overlay failed", e); } } } }
5,013
47.679612
158
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/war/OverlayExistingResourceTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.deploymentoverlay.war; import java.util.HashMap; import java.util.Map; import javax.naming.InitialContext; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.test.integration.deployment.deploymentoverlay.jar.OverlayEJB; import org.jboss.as.test.integration.deployment.deploymentoverlay.jar.OverlayableInterface; import org.jboss.shrinkwrap.api.Archive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * @author baranowb * @author lgao * */ @RunWith(Arquillian.class) @RunAsClient public class OverlayExistingResourceTestCase extends WarOverlayTestBase { private static final String OVERLAY = "HAL9000"; private static final String DEPLOYMENT_OVERLAYED = "overlayed"; private static final String DEPLOYMENT_OVERLAYED_ARCHIVE = DEPLOYMENT_OVERLAYED + ".jar"; private static final String DEPLOYMENT_SHELL = "shell"; private static final String DEPLOYMENT_SHELL_ARCHIVE = DEPLOYMENT_SHELL + ".war"; private static final String RESOURCE = "/WEB-INF/lib/"+DEPLOYMENT_OVERLAYED_ARCHIVE+"//"+OverlayableInterface.RESOURCE; @Deployment(name = DEPLOYMENT_SHELL) public static Archive<?> createDeployment() throws Exception { return createWARWithOverlayedArchive(true, DEPLOYMENT_OVERLAYED_ARCHIVE,DEPLOYMENT_SHELL_ARCHIVE); } @Test public void testOverlay() throws Exception { final InitialContext ctx = getInitialContext(); Map<String, String> overlay = new HashMap<String, String>(); try{ OverlayableInterface iface = (OverlayableInterface) ctx.lookup(getEjbBinding("", DEPLOYMENT_SHELL, "", OverlayEJB.class, OverlayableInterface.class)); Assert.assertEquals("Overlayed resource in war/jar does not match pre-overlay expectations!", OverlayableInterface.ORIGINAL, iface.fetchResource()); Assert.assertEquals("Static resource in war/jar does not match pre-overlay expectations!", OverlayableInterface.STATIC, iface.fetchResourceStatic()); Assert.assertEquals("HTML resource in war does not match pre-overlay expectations!", OverlayableInterface.ORIGINAL, readContent(managementClient.getWebUri() + "/" + DEPLOYMENT_SHELL + "/" + OVERLAY_HTML)); Assert.assertEquals("HTML static resource in war does not match pre-overlay expectations!", OverlayableInterface.STATIC, readContent(managementClient.getWebUri() + "/" + DEPLOYMENT_SHELL + "/" + STATIC_HTML)); overlay.put(RESOURCE, OverlayableInterface.OVERLAYED); overlay.put(OVERLAY_HTML, OverlayableInterface.OVERLAYED); setupOverlay(DEPLOYMENT_SHELL_ARCHIVE, OVERLAY, overlay); Assert.assertEquals("Overlayed resource in war/jar does not match post-overlay expectations!", OverlayableInterface.OVERLAYED, iface.fetchResource()); Assert.assertEquals("Static resource in war/jar does not match post-overlay expectations!", OverlayableInterface.STATIC, iface.fetchResourceStatic()); Assert.assertEquals("HTML static resource in war does not match post-overlay expectations!", OverlayableInterface.STATIC, readContent(managementClient.getWebUri() + "/" + DEPLOYMENT_SHELL + "/" + STATIC_HTML)); Assert.assertEquals("HTML resource in war does not match post-overlay expectations!", OverlayableInterface.OVERLAYED, readContent(managementClient.getWebUri() + "/" + DEPLOYMENT_SHELL + "/" + OVERLAY_HTML)); } finally { try { ctx.close(); } catch (Exception e) { LOGGER.error("Closing context failed", e); } try { removeOverlay(DEPLOYMENT_SHELL_ARCHIVE, OVERLAY, overlay.keySet()); } catch (Exception e) { LOGGER.error("Removing overlay failed", e); } } } }
5,127
48.786408
162
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/war/WarOverlayTestBase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.deploymentoverlay.war; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.nio.charset.StandardCharsets; import org.jboss.as.test.integration.deployment.deploymentoverlay.jar.JarOverlayTestBase; import org.jboss.as.test.integration.deployment.deploymentoverlay.jar.OverlayableInterface; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; /** * @author baranowb * @author lgao * */ public class WarOverlayTestBase extends JarOverlayTestBase{ public static final String OVERLAY_HTML = "overlay.html"; public static final String STATIC_HTML = "static.html"; public static Archive<?> createWARWithOverlayedArchive(final boolean resourcePresent, String deploymentOverlayedArchive, final String deploymentTopArchve){ WebArchive war = ShrinkWrap.create(WebArchive.class, deploymentTopArchve); Archive<?> jar = createOverlayedArchive(resourcePresent,deploymentOverlayedArchive); if (resourcePresent) { war.add(new StringAsset(OverlayableInterface.ORIGINAL), OVERLAY_HTML); } war.add(new StringAsset(OverlayableInterface.STATIC), STATIC_HTML); war.addAsLibrary(jar); return war; } public static String readContent(String url) throws IOException { HttpURLConnection conn = null; try { conn = (HttpURLConnection)new URL(url).openConnection(); conn.connect(); int httpCode = conn.getResponseCode(); if (httpCode == 200) { try (InputStream input = conn.getInputStream(); InputStreamReader inputReader = new InputStreamReader(input, StandardCharsets.UTF_8); BufferedReader reader = new BufferedReader(inputReader)) { return reader.readLine(); } } else if (httpCode == 404) { return null; } throw new RuntimeException("Un expected response code: " + httpCode); } finally { if (conn != null) { conn.disconnect(); } } } }
3,418
39.223529
159
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/excludesubsystem/ExcludeEESubsystemTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2019, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.excludesubsystem; import org.jboss.arquillian.container.test.api.Deployer; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.logging.Logger; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Test; import org.junit.runner.RunWith; /** * Tests excluding subsystems via jboss-deployment-structure.xml * Test for WFLY-12472 */ @RunWith(Arquillian.class) public class ExcludeEESubsystemTestCase { private static final Logger logger = Logger.getLogger(ExcludeEESubsystemTestCase.class); private static final String EXCLUDE_SUBSYSTEM_EE = "excludeSubsystemEE"; @ArquillianResource private Deployer deployer; @Deployment(name = EXCLUDE_SUBSYSTEM_EE, managed = false) public static Archive<?> createDeployment() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, EXCLUDE_SUBSYSTEM_EE + ".war"); jar.addAsManifestResource(ExcludeEESubsystemTestCase.class.getPackage(), "jboss-deployment-structure-exclude-ee.xml", "jboss-deployment-structure.xml"); jar.addPackage(ExcludeEESubsystemTestCase.class.getPackage()); return jar; } // Test that simple deployment runs without ee subsystem as required by Infinispan @Test public void testDeploy() throws Exception { deployer.deploy(EXCLUDE_SUBSYSTEM_EE); deployer.undeploy(EXCLUDE_SUBSYSTEM_EE); } }
2,667
39.424242
125
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/excludesubsystem/SimpleEjb.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.excludesubsystem; import jakarta.ejb.Stateless; @Stateless public class SimpleEjb { }
1,161
37.733333
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/excludesubsystem/ExcludeEjbSubsystemTestCase.java
package org.jboss.as.test.integration.deployment.excludesubsystem; import javax.naming.NameNotFoundException; import javax.naming.NamingException; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.logging.Logger; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * Tests excluding a subsystem via jboss-deployment-structure.xml */ @RunWith(Arquillian.class) public class ExcludeEjbSubsystemTestCase { private static final Logger logger = Logger.getLogger(ExcludeEjbSubsystemTestCase.class); @ArquillianResource private javax.naming.InitialContext initialContext; @Deployment public static Archive<?> createDeployment() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "excludeSubsystem.jar"); jar.addAsManifestResource(ExcludeEjbSubsystemTestCase.class.getPackage(), "jboss-deployment-structure.xml", "jboss-deployment-structure.xml"); jar.addPackage(ExcludeEjbSubsystemTestCase.class.getPackage()); return jar; } @Test public void testEjbNotInstalled() throws NamingException { try { Object result = initialContext.lookup("java:module/" + SimpleEjb.class.getSimpleName()); Assert.fail("Expected lookup to fail, instead " + result + " was returned"); } catch (NameNotFoundException expected) {} } }
1,632
33.744681
150
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/resourcelisting/EarResourceListingTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.resourcelisting; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.test.integration.common.WebInfLibClass; import org.jboss.as.test.shared.ResourceListingUtils; import org.jboss.logging.Logger; import org.jboss.modules.ModuleClassLoader; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @RunWith(Arquillian.class) public class EarResourceListingTestCase { private static final Logger log = Logger.getLogger(EarResourceListingTestCase.class); private static final String INNER_WAR_ARCHIVE_NAME = "innerWarDeployment.war"; private static final String INNER_JAR_ARCHIVE_NAME = "innerJarLibrary.jar"; @Deployment public static Archive<?> deploy() { EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class); JavaArchive earLib = ShrinkWrap.create(JavaArchive.class); earLib.addClasses(EarResourceListingTestCase.class, ResourceListingUtils.class); earLib.addAsManifestResource(EmptyAsset.INSTANCE, "emptyJarLibResource.properties"); earLib.addAsManifestResource(EmptyAsset.INSTANCE, "properties/nestedJarLib.properties"); ear.addAsLibraries(earLib); WebArchive war = ShrinkWrap.create(WebArchive.class, INNER_WAR_ARCHIVE_NAME); war.addClass(TestA.class); war.add(EmptyAsset.INSTANCE, "META-INF/example.txt"); war.add(EmptyAsset.INSTANCE, "META-INF/properties/nested.properties"); war.add(EmptyAsset.INSTANCE, "example2.txt"); war.addAsResource(EarResourceListingTestCase.class.getPackage(), "TextFile1.txt", "TextFile1.txt"); war.addAsWebInfResource(EarResourceListingTestCase.class.getPackage(), "web.xml", "web.xml"); JavaArchive libJar = ShrinkWrap.create(JavaArchive.class, INNER_JAR_ARCHIVE_NAME); libJar.addClass(WebInfLibClass.class); war.addAsLibraries(libJar); ear.addAsModules(libJar, war); ear.addAsManifestResource(EmptyAsset.INSTANCE, "MANIFEST.MF"); ear.addAsResource(EmptyAsset.INSTANCE, "emptyEarResource"); ear.addAsManifestResource(EarResourceListingTestCase.class.getPackage(), "application.xml", "application.xml"); return ear; } @Test() public void testRecursiveEARResourceRetrieval() { log.trace("Test non-recursive listing of resources in EAR deployment"); doTestEARResourceRetrieval(true, "/"); } @Test() public void testNonRecursiveEARResourceRetrieval() { log.trace("Test recursive listing of resources in EAR deployment"); doTestEARResourceRetrieval(false, "/"); } @Test() public void testRecursiveEARResourceRetrievalForSpecifiedRootDir() { log.trace("Test recursive listing of resources in EAR deployment for root dir /META-INF"); doTestEARResourceRetrieval(true, "/META-INF"); } @Test() public void testNonRecursiveEARResourceRetrievalForSpecifiedRootDir() { log.trace("Test non-recursive listing of resources in EAR deployment for root dir /META-INF"); doTestEARResourceRetrieval(false, "/META-INF"); } private void doTestEARResourceRetrieval(boolean recursive, String rootDir) { ModuleClassLoader classLoader = (ModuleClassLoader) getClass().getClassLoader(); List<String> foundResources = ResourceListingUtils.listResources(classLoader, rootDir, recursive); // only resources in EAR library should be listed List<String> resourcesInDeployment = new ArrayList<>(); resourcesInDeployment.add(ResourceListingUtils.classToPath(EarResourceListingTestCase.class)); resourcesInDeployment.add(ResourceListingUtils.classToPath(ResourceListingUtils.class)); resourcesInDeployment.add("META-INF/emptyJarLibResource.properties"); resourcesInDeployment.add("META-INF/properties/nestedJarLib.properties"); ResourceListingUtils.filterResources(resourcesInDeployment, rootDir, !recursive); Collections.sort(foundResources); Collections.sort(resourcesInDeployment); log.trace("List of expected resources:"); for (String expectedResource : resourcesInDeployment) { log.trace(expectedResource); } log.trace("List of found resources: "); for (String foundResource : foundResources) { log.trace(foundResource); } Assert.assertArrayEquals("Not all resources from EAR archive are correctly listed", resourcesInDeployment.toArray(), foundResources.toArray()); } }
6,023
43.622222
151
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/resourcelisting/TestA.java
package org.jboss.as.test.integration.deployment.resourcelisting; /** * @author: [email protected] */ public class TestA { }
130
15.375
65
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/resourcelisting/JarResourceListingTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.deployment.resourcelisting; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.test.shared.ResourceListingUtils; import org.jboss.logging.Logger; import org.jboss.modules.ModuleClassLoader; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @RunWith(Arquillian.class) public class JarResourceListingTestCase { private static final Logger log = Logger.getLogger(JarResourceListingTestCase.class); @Deployment public static Archive<?> deploy() { JavaArchive jar = ShrinkWrap.create(JavaArchive.class); jar.addClasses(JarResourceListingTestCase.class, ResourceListingUtils.class); jar.add(EmptyAsset.INSTANCE, "META-INF/example.txt"); jar.add(EmptyAsset.INSTANCE, "META-INF/properties/nested.properties"); jar.addAsManifestResource(EmptyAsset.INSTANCE, "MANIFEST.MF"); // shrink wrapper creates it in default, this way it is more clear that it's there jar.add(EmptyAsset.INSTANCE, "example2.txt"); jar.addAsResource(JarResourceListingTestCase.class.getPackage(), "TextFile1.txt", "TextFile1.txt"); return jar; } @Test() public void testRecursiveJARResourceRetrieval() { log.trace("Test non-recursive listing of resources in JAR deployment"); doTestJARResourceRetrieval(true, "/"); } @Test() public void testNonRecursiveJARResourceRetrieval() { log.trace("Test recursive listing of resources in JAR deployment"); doTestJARResourceRetrieval(false, "/"); } @Test() public void testRecursiveJARResourceRetrievalForSpecifiedRootDir() { log.trace("Test recursive listing of resources in JAR deployment for root dir /META-INF"); doTestJARResourceRetrieval(true, "/META-INF"); } @Test() public void testNonRecursiveJARResourceRetrievalForSpecifiedRootDir() { log.trace("Test non-recursive listing of resources in JAR deployment for root dir /META-INF"); doTestJARResourceRetrieval(false, "/META-INF"); } private void doTestJARResourceRetrieval(boolean recursive, String rootDir) { ModuleClassLoader classLoader = (ModuleClassLoader) getClass().getClassLoader(); List<String> foundResources = ResourceListingUtils.listResources(classLoader, rootDir, recursive); // only resources in JAR library should be listed List<String> resourcesInDeployment = new ArrayList<>(); resourcesInDeployment.add(ResourceListingUtils.classToPath(JarResourceListingTestCase.class)); resourcesInDeployment.add(ResourceListingUtils.classToPath(ResourceListingUtils.class)); resourcesInDeployment.add("META-INF/example.txt"); resourcesInDeployment.add("META-INF/properties/nested.properties"); resourcesInDeployment.add("META-INF/MANIFEST.MF"); resourcesInDeployment.add("example2.txt"); resourcesInDeployment.add("TextFile1.txt"); ResourceListingUtils.filterResources(resourcesInDeployment, rootDir, !recursive); Collections.sort(foundResources); Collections.sort(resourcesInDeployment); log.trace("List of expected resources:"); for (String expectedResource : resourcesInDeployment) { log.trace(expectedResource); } log.trace("List of found resources: "); for (String foundResource : foundResources) { log.trace(foundResource); } Assert.assertArrayEquals("Not all resources from JAR archive are correctly listed", resourcesInDeployment.toArray(), foundResources.toArray()); } }
4,979
41.931034
153
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/web/security/SecuredServlet.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.web.security; import java.io.IOException; import java.io.Writer; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.HttpConstraint; import jakarta.servlet.annotation.ServletSecurity; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; /** * A simple servlet that just writes back a string * * @author Anil Saldhana */ @WebServlet(name = "SecuredServlet", urlPatterns = { "/secured/" }, loadOnStartup = 1) @ServletSecurity(@HttpConstraint(rolesAllowed = { "gooduser" })) public class SecuredServlet extends HttpServlet { private static final long serialVersionUID = 1L; @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { Writer writer = resp.getWriter(); writer.write("GOOD"); } }
2,011
37.692308
113
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/web/security/servlet/methods/SecuredServlet.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.web.security.servlet.methods; import java.io.IOException; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.HttpMethodConstraint; import jakarta.servlet.annotation.ServletSecurity; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; /** * Simple servlet that secures GET, HEAD and TRACE methods. * * @author Jan Tymel */ @WebServlet(name = "SecuredServlet", urlPatterns = {"/secured/"}, loadOnStartup = 1) @ServletSecurity( httpMethodConstraints = { @HttpMethodConstraint(value = "GET", rolesAllowed = "role"), @HttpMethodConstraint(value = "HEAD", rolesAllowed = "role"), @HttpMethodConstraint(value = "TRACE", rolesAllowed = "role") } ) public class SecuredServlet extends HttpServlet { // See the comment in DenyUncoveredHttpMethodsTestCase class above testCustomMethod() @Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setStatus(HttpServletResponse.SC_OK); } }
2,249
40.666667
115
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/web/security/servlet/methods/DenyUncoveredHttpMethodsTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.web.security.servlet.methods; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import java.io.IOException; import java.net.URL; import jakarta.servlet.http.HttpServletResponse; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpDelete; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpHead; import org.apache.http.client.methods.HttpOptions; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPut; import org.apache.http.client.methods.HttpTrace; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.impl.client.DefaultHttpClient; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; /** * Tests whether the <deny-uncovered-http-methods/> tag in web.xml behavior is correct. * * @author Jan Tymel */ @RunWith(Arquillian.class) @RunAsClient public class DenyUncoveredHttpMethodsTestCase { @ArquillianResource(SecuredServlet.class) URL deploymentURL; @Test public void testCorrectUserAndPassword() throws Exception { HttpGet httpGet = new HttpGet(getURL()); HttpResponse response = getHttpResponse(httpGet); assertThat(statusCodeOf(response), is(HttpServletResponse.SC_UNAUTHORIZED)); } @Test public void testHeadMethod() throws Exception { HttpHead httpHead = new HttpHead(getURL()); HttpResponse response = getHttpResponse(httpHead); assertThat(statusCodeOf(response), is(HttpServletResponse.SC_UNAUTHORIZED)); } @Test public void testTraceMethod() throws Exception { HttpTrace httpTrace = new HttpTrace(getURL()); HttpResponse response = getHttpResponse(httpTrace); assertThat(statusCodeOf(response), is(HttpServletResponse.SC_METHOD_NOT_ALLOWED)); } @Test public void testPostMethod() throws Exception { HttpPost httpPost = new HttpPost(getURL()); HttpResponse response = getHttpResponse(httpPost); assertThat(statusCodeOf(response), is(HttpServletResponse.SC_FORBIDDEN)); } @Test public void testPutMethod() throws Exception { HttpPut httpPut = new HttpPut(getURL()); HttpResponse response = getHttpResponse(httpPut); assertThat(statusCodeOf(response), is(HttpServletResponse.SC_FORBIDDEN)); } @Test public void testDeleteMethod() throws Exception { HttpDelete httpDelete = new HttpDelete(getURL()); HttpResponse response = getHttpResponse(httpDelete); assertThat(statusCodeOf(response), is(HttpServletResponse.SC_FORBIDDEN)); } @Test public void testOptionsMethod() throws Exception { HttpOptions httpOptions = new HttpOptions(getURL()); HttpResponse response = getHttpResponse(httpOptions); assertThat(statusCodeOf(response), is(HttpServletResponse.SC_FORBIDDEN)); } /** * Tests whether the <deny-uncovered-http-methods/> tag filters methods before the servlet is called. This test creates * custom HTTP method and tries to invoke it. If <deny-uncovered-http-methods/> works correctly status code 403 should be * returned. 403 should be returned also in case the servlet returns anything else for unknown HTTP methods as well. * * @throws Exception */ @Test public void testCustomMethod() throws Exception { HttpUriRequest request = new HttpGet(getURL()) { @Override public String getMethod() { return "customMethod"; } }; HttpResponse response = getHttpResponse(request); assertThat(statusCodeOf(response), is(HttpServletResponse.SC_FORBIDDEN)); } private HttpResponse getHttpResponse(HttpUriRequest request) throws IOException { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpResponse response = httpClient.execute(request); return response; } private int statusCodeOf(HttpResponse response) { return response.getStatusLine().getStatusCode(); } private String getURL() { return deploymentURL.toString() + "secured/"; } @Deployment public static WebArchive deployment() throws IOException { WebArchive war = ShrinkWrap.create(WebArchive.class, "deny-uncovered-http-methods.war"); war.addClass(SecuredServlet.class); Package warPackage = DenyUncoveredHttpMethodsTestCase.class.getPackage(); war.setWebXML(warPackage, "web.xml"); return war; } }
5,962
34.706587
125
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/web/security/runas/ServletRunAsTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.web.security.runas; import static java.net.HttpURLConnection.HTTP_OK; import static org.jboss.as.test.integration.web.security.runas.CallProtectedEjbServlet.DESTROY_METHOD_NOT_PASS; import static org.jboss.as.test.integration.web.security.runas.CallProtectedEjbServlet.DESTROY_METHOD_PASS; import static org.jboss.as.test.integration.web.security.runas.CallProtectedEjbServlet.DOGET_METHOD_NOT_PASS; import static org.jboss.as.test.integration.web.security.runas.CallProtectedEjbServlet.DOGET_METHOD_PASS; import static org.jboss.as.test.integration.web.security.runas.CallProtectedEjbServlet.INIT_METHOD_NOT_PASS; import static org.jboss.as.test.integration.web.security.runas.CallProtectedEjbServlet.INIT_METHOD_PASS; import static org.junit.Assert.assertTrue; import java.io.BufferedReader; import java.io.File; import java.io.FilePermission; import java.io.IOException; import java.net.URL; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import org.apache.commons.io.FileUtils; import org.jboss.arquillian.container.test.api.Deployer; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.OperateOnDeployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.junit.InSequence; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.test.integration.security.common.Utils; import org.jboss.as.test.shared.ServerReload; import org.jboss.as.test.shared.integration.ejb.security.PermissionUtils; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; /** * Test case for RunAs in Servlet. It tests secured EJB invocation in HttpServlet init(), doGet() and destroy() methods. * * @author olukas */ @RunWith(Arquillian.class) @RunAsClient public class ServletRunAsTestCase { private static final String DEPLOYMENT = "deployment"; private static String correctRoleResult; private static String incorrectRoleResult; private static final File WORK_DIR = new File("ServletRunAsTestCase-" + System.currentTimeMillis()); private static final File CORRECT_ROLE_AND_STOP_SERVER = new File(WORK_DIR, "correctRoleAndStopServer.log"); private static final File INCORRECT_ROLE_AND_STOP_SERVER = new File(WORK_DIR, "incorrectRoleAndStopServer.log"); private static final File CORRECT_ROLE_AND_UNDEPLOY = new File(WORK_DIR, "correctRoleAndUndeploy.log"); private static final File INCORRECT_ROLE_AND_UNDEPLOY = new File(WORK_DIR, "incorrectRoleAndUndeploy.log"); @ArquillianResource private ManagementClient managementClient; @ArquillianResource Deployer deployer; @Test @InSequence(Integer.MIN_VALUE) public void initialize() throws Exception { deployer.deploy(DEPLOYMENT); WORK_DIR.mkdirs(); } /** * Access Servlet which uses RunAs with correct role needed for secured EJB invocation. * <p> * This method will run init() and doGet() method and stores results. * * @param url * @throws Exception */ @Test @InSequence(1) @OperateOnDeployment(DEPLOYMENT) public void runServletWithCorrectRole(@ArquillianResource URL url) throws Exception { final URL servletUrl = new URL(url.toExternalForm() + RunAsAdminServlet.SERVLET_PATH.substring(1) + "?" + Utils.encodeQueryParam(CallProtectedEjbServlet.FILE_PARAM, CORRECT_ROLE_AND_UNDEPLOY.getAbsolutePath())); correctRoleResult = Utils.makeCall(servletUrl.toURI(), HTTP_OK); } /** * Check whether Servlet which uses RunAs with correct role needed for secured EJB invocation can correctly invoked that EJB * method in HttpServlet.init() method. * * @throws Exception */ @Test @InSequence(2) public void checkInitMethodWithCorrectRole() throws Exception { assertTrue("EJB invocation failed in init() method of Servlet which uses RunAs with correct role.", correctRoleResult.contains(INIT_METHOD_PASS + HelloBean.HELLO)); } /** * Check whether Servlet which uses RunAs with correct role needed for secured EJB invocation can correctly invoked that EJB * method in HttpServlet.doGet() method. * * @throws Exception */ @Test @InSequence(3) public void checkDoGetMethodWithCorrectRole() throws Exception { assertTrue("EJB invocation failed in doGet() method of Servlet which uses RunAs with correct role.", correctRoleResult.contains(DOGET_METHOD_PASS + HelloBean.HELLO)); } /** * Access Servlet which uses RunAs with different role than in needed for secured EJB invocation. * <p> * This method will run init() and doGet() method and stores results. * * @param url * @throws Exception */ @Test @InSequence(4) @OperateOnDeployment(DEPLOYMENT) public void runServletWithIncorrectRole(@ArquillianResource URL url) throws Exception { final URL servletUrl = new URL(url.toExternalForm() + RunAsUserServlet.SERVLET_PATH.substring(1) + "?" + Utils.encodeQueryParam(CallProtectedEjbServlet.FILE_PARAM, INCORRECT_ROLE_AND_UNDEPLOY.getAbsolutePath())); incorrectRoleResult = Utils.makeCall(servletUrl.toURI(), HTTP_OK); } /** * Check whether Servlet which uses RunAs with different role than in needed for secured EJB invocation cannot correctly * invoked that EJB method in HttpServlet.init() method. * * @throws Exception */ @Test @InSequence(5) public void checkInitMethodWithIncorrectRole() throws Exception { assertTrue("EJB invocation did not failed in init() method of Servlet which uses RunAs with incorrect role.", incorrectRoleResult.contains(INIT_METHOD_NOT_PASS)); } /** * Check whether Servlet which uses RunAs with different role than in needed for secured EJB invocation cannot correctly * invoked that EJB method in HttpServlet.doGet() method. * * @throws Exception */ @Test @InSequence(6) public void checkDoGetMethodWithIncorrectRole() throws Exception { assertTrue("EJB invocation did not failed in doGet() method of Servlet which uses RunAs with incorrect role.", incorrectRoleResult.contains(DOGET_METHOD_NOT_PASS)); } /** * Stop server for invoking HttpServlet.destroy() method during undeploying. * * @throws Exception */ @Test @InSequence(7) public void runDestroyMethodInUndeploying() throws Exception { deployer.undeploy(DEPLOYMENT); } /** * Check whether Servlet which uses RunAs with correct role needed for secured EJB invocation can correctly invoked that EJB * method in HttpServlet.destroy() method during undeploying application. * * @throws Exception */ @Test @InSequence(8) public void checkDestroyInUndeployingMethodWithCorrectRole() throws Exception { assertTrue("EJB invocation failed in destroy() method of Servlet which uses RunAs with correct role during undeploying.", readFirstLineOfFile(CORRECT_ROLE_AND_UNDEPLOY).contains(DESTROY_METHOD_PASS + HelloBean.HELLO)); } /** * Check whether Servlet which uses RunAs with different role than in needed for secured EJB invocation cannot correctly * invoked that EJB method in HttpServlet.destroy() method during undeploying application. * * @throws Exception */ @Test @InSequence(9) public void checkDestroyInUndeployingMethodWithIncorrectRole() throws Exception { assertTrue("EJB invocation did not failed in destroy() method of Servlet which uses RunAs with incorrect role during " + "undeploying.", readFirstLineOfFile(INCORRECT_ROLE_AND_UNDEPLOY).contains(DESTROY_METHOD_NOT_PASS)); } /** * Restart server for invoking HttpServlet.destroy() method during stopping server. It also hit Servlet for initialization * of Servlet before server is restarted. * * @param url * @throws Exception */ @Test @InSequence(10) @OperateOnDeployment(DEPLOYMENT) public void runDestroyMethodInStopServer(@ArquillianResource URL url) throws Exception { deployer.deploy(DEPLOYMENT); URL servletUrl = new URL(url.toExternalForm() + RunAsAdminServlet.SERVLET_PATH.substring(1) + "?" + Utils.encodeQueryParam(CallProtectedEjbServlet.FILE_PARAM, CORRECT_ROLE_AND_STOP_SERVER.getAbsolutePath())); Utils.makeCall(servletUrl.toURI(), HTTP_OK); servletUrl = new URL(url.toExternalForm() + RunAsUserServlet.SERVLET_PATH.substring(1) + "?" + Utils.encodeQueryParam(CallProtectedEjbServlet.FILE_PARAM, INCORRECT_ROLE_AND_STOP_SERVER.getAbsolutePath())); Utils.makeCall(servletUrl.toURI(), HTTP_OK); ServerReload.executeReloadAndWaitForCompletion(managementClient, 50000); } /** * Check whether Servlet which uses RunAs with correct role needed for secured EJB invocation can correctly invoked that EJB * method in HttpServlet.destroy() method during stopping server. * * @throws Exception */ @Test @InSequence(11) public void checkDestroyMethodInStopServerWithCorrectRole() throws Exception { assertTrue("EJB invocation failed in destroy() method of Servlet which uses RunAs with correct role during stopping " + "server.", readFirstLineOfFile(CORRECT_ROLE_AND_STOP_SERVER).contains(DESTROY_METHOD_PASS + HelloBean.HELLO)); } /** * Check whether Servlet which uses RunAs with different role than in needed for secured EJB invocation cannot correctly * invoked that EJB method in HttpServlet.destroy() method during stopping server. * * @throws Exception */ @Test @InSequence(12) public void checkDestroyMethodInStopServerWithIncorrectRole() throws Exception { assertTrue("EJB invocation did not failed in destroy() method of Servlet which uses RunAs with incorrect role " + "during stopping server.", readFirstLineOfFile(INCORRECT_ROLE_AND_STOP_SERVER).contains(DESTROY_METHOD_NOT_PASS)); } @Test @InSequence(Integer.MAX_VALUE) public void finish() throws Exception { deployer.undeploy(DEPLOYMENT); FileUtils.deleteQuietly(WORK_DIR); } @Deployment(name = DEPLOYMENT, managed = false, testable = false) public static WebArchive deployment() throws Exception { WebArchive war = ShrinkWrap.create(WebArchive.class, "servlet-runas.war"); war.addClasses(CallProtectedEjbServlet.class, RunAsAdminServlet.class, RunAsUserServlet.class, Hello.class, HelloBean.class); war.addAsWebResource(PermissionUtils.createPermissionsXmlAsset(new FilePermission(WORK_DIR.getAbsolutePath() + "/*", "read,write")), "META-INF/permissions.xml"); return war; } private String readFirstLineOfFile(File file) throws IOException { try (BufferedReader br = Files.newBufferedReader(file.toPath(), StandardCharsets.UTF_8)) { return br.readLine(); } } }
12,526
42.346021
169
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/web/security/runas/HelloBean.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.web.security.runas; import jakarta.annotation.security.DeclareRoles; import jakarta.annotation.security.RolesAllowed; import jakarta.ejb.Remote; import jakarta.ejb.Stateless; /** * @author olukas */ @DeclareRoles({HelloBean.AUTHORIZED_ROLE, HelloBean.NOT_AUTHORIZED_ROLE}) @Stateless @RolesAllowed(HelloBean.AUTHORIZED_ROLE) @Remote(Hello.class) public class HelloBean implements Hello { public static final String AUTHORIZED_ROLE = "Admin"; public static final String NOT_AUTHORIZED_ROLE = "User"; public static final String HELLO = "Hello!"; @Override public String sayHello() { return HELLO; } }
1,700
33.714286
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/web/security/runas/RunAsUserServlet.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.web.security.runas; import jakarta.annotation.security.DeclareRoles; import jakarta.annotation.security.RunAs; import jakarta.servlet.annotation.WebServlet; /** * RunAs annotated servlet which calls protected EJB method {@link Hello#sayHello()}. Role used in RunAs in not correct role for * protected EJB method. * * @author olukas */ @WebServlet(RunAsUserServlet.SERVLET_PATH) @DeclareRoles({HelloBean.AUTHORIZED_ROLE, HelloBean.NOT_AUTHORIZED_ROLE}) @RunAs(HelloBean.NOT_AUTHORIZED_ROLE) public class RunAsUserServlet extends CallProtectedEjbServlet { private static final long serialVersionUID = 1L; public static final String SERVLET_PATH = "/RunAsUserServlet"; }
1,756
38.931818
128
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/web/security/runas/Hello.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.web.security.runas; /** * @author olukas */ public interface Hello { String sayHello(); }
1,159
36.419355
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/web/security/runas/CallProtectedEjbServlet.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software 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 Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.web.security.runas; import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintWriter; import jakarta.annotation.security.DeclareRoles; import jakarta.ejb.EJB; import javax.naming.NamingException; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.jboss.logging.Logger; /** * Protected servlet which calls protected EJB method {@link Hello#sayHello()}. * * @author olukas */ @WebServlet(CallProtectedEjbServlet.SERVLET_PATH) @DeclareRoles({HelloBean.AUTHORIZED_ROLE, HelloBean.NOT_AUTHORIZED_ROLE}) public class CallProtectedEjbServlet extends HttpServlet { private static final long serialVersionUID = 1L; private static final Logger LOGGER = Logger.getLogger(CallProtectedEjbServlet.class); public static final String SERVLET_PATH = "/CallProtectedEjbServlet"; public static final String FILE_PARAM = "file"; public static final String INIT_METHOD_PASS = "init method passed."; public static final String INIT_METHOD_NOT_PASS = "init method did not pass."; public static final String DOGET_METHOD_PASS = "doGet method passed."; public static final String DOGET_METHOD_NOT_PASS = "doGet method did not pass."; public static final String DESTROY_METHOD_PASS = "destroy method passed."; public static final String DESTROY_METHOD_NOT_PASS = "destroy method did not pass."; private static String initMethodPass; private String filePath; @EJB private Hello ejb; @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { LOGGER.debug("Calling EJB protected method in doGet() method."); resp.setContentType("text/plain"); filePath = req.getParameter(FILE_PARAM); try (PrintWriter writer = resp.getWriter()) { writer.println(initMethodPass); try { String callProtectedEJB = callProtectedEJB(); writer.println(DOGET_METHOD_PASS + callProtectedEJB); } catch (Exception e) { writer.println(DOGET_METHOD_NOT_PASS); LOGGER.debug(e); } } } @Override public void init() throws ServletException { LOGGER.debug("Calling EJB protected method in init() method."); try { String callProtectedEJB = callProtectedEJB(); initMethodPass = INIT_METHOD_PASS + callProtectedEJB; } catch (Exception e) { initMethodPass = INIT_METHOD_NOT_PASS; LOGGER.debug(e); } } @Override public void destroy() { LOGGER.debug("Calling EJB protected method in destroy() method."); if (filePath == null) { LOGGER.warnf("RunAs testing servlet was not called with '%s' parameter provided.", FILE_PARAM); try { String callProtectedEJB = callProtectedEJB(); LOGGER.info(DESTROY_METHOD_PASS + callProtectedEJB); } catch (Exception e) { LOGGER.info(DESTROY_METHOD_NOT_PASS); LOGGER.debug(e); } } else { try (PrintWriter writer = new PrintWriter(filePath)) { LOGGER.infof("RunAs testing servlet will write result into file '%s'.", filePath); try { String callProtectedEJB = callProtectedEJB(); writer.println(DESTROY_METHOD_PASS + callProtectedEJB); } catch (Exception e) { writer.println(DESTROY_METHOD_NOT_PASS); LOGGER.debug(e); } } catch (FileNotFoundException ex) { throw new RuntimeException(ex); } } } protected String callProtectedEJB() throws NamingException { return ejb.sayHello(); } }
5,088
38.146154
113
java