org.jboss.shrinkwrap.api.asset.ByteArrayAsset Java Examples
The following examples show how to use
org.jboss.shrinkwrap.api.asset.ByteArrayAsset.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ShrinkWrapFatJarPackageService.java From vertx-maven-plugin with Apache License 2.0 | 6 votes |
/** * Generate the manifest for the über jar. */ private static void generateManifest(JavaArchive jar, Map<String, String> entries) throws IOException { Manifest manifest = new Manifest(); Attributes attributes = manifest.getMainAttributes(); attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0"); if (entries != null) { for (Map.Entry<String, String> entry : entries.entrySet()) { attributes.put(new Attributes.Name(entry.getKey()), entry.getValue()); } } ByteArrayOutputStream bout = new ByteArrayOutputStream(); manifest.write(bout); bout.close(); byte[] bytes = bout.toByteArray(); //TODO: merge existing manifest with current one jar.setManifest(new ByteArrayAsset(bytes)); }
Example #2
Source File: BuildTool.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 6 votes |
private void addWildFlySwarmProperties() throws IOException { Properties props = new Properties(); Enumeration<?> propNames = this.properties.propertyNames(); while (propNames.hasMoreElements()) { String eachName = (String) propNames.nextElement(); String eachValue = this.properties.get(eachName).toString(); props.put(eachName, eachValue); } props.setProperty(BootstrapProperties.APP_ARTIFACT, this.projectAsset.getSimpleName()); if (this.bundleDependencies) { props.setProperty(BootstrapProperties.BUNDLED_DEPENDENCIES, "true"); } ByteArrayOutputStream propsBytes = new ByteArrayOutputStream(); props.store(propsBytes, "Generated by WildFly Swarm"); this.archive.addAsManifestResource(new ByteArrayAsset(propsBytes.toByteArray()), "wildfly-swarm.properties"); }
Example #3
Source File: SecuredImpl.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 6 votes |
private Asset createAsset(InputStream in) { StringBuilder str = new StringBuilder(); try (BufferedReader reader = new BufferedReader(new InputStreamReader(in))) { String line = null; while ((line = reader.readLine()) != null) { str.append(line).append("\n"); } } catch (IOException e) { e.printStackTrace(); } return new ByteArrayAsset(str.toString().getBytes()); }
Example #4
Source File: WebXmlContainer.java From thorntail with Apache License 2.0 | 6 votes |
/** * Add the default Thorntail {@code favicon.ico} handler. * * @return This archive. */ @SuppressWarnings("unchecked") default T addFaviconExceptionHandler() throws IOException { // Add FaviconServletExtension String path = "WEB-INF/classes/" + FaviconServletExtension.EXTENSION_NAME.replace('.', '/') + ".class"; byte[] generatedExtension; generatedExtension = FaviconFactory.createFaviconServletExtension(FaviconServletExtension.EXTENSION_NAME); add(new ByteArrayAsset(generatedExtension), path); // Add FaviconErrorHandler path = "WEB-INF/classes/" + FaviconServletExtension.HANDLER_NAME.replace('.', '/') + ".class"; byte[] generatedHandler; generatedHandler = FaviconFactory.createFaviconErrorHandler(FaviconServletExtension.HANDLER_NAME); add(new ByteArrayAsset(generatedHandler), path); // Add services entry for FaviconServletExtension this.addAsServiceProvider(ServletExtension.class.getName(), FaviconServletExtension.EXTENSION_NAME); return (T) this; }
Example #5
Source File: BuildTool.java From thorntail with Apache License 2.0 | 6 votes |
private void addJarManifest() { Manifest manifest = new Manifest(); Attributes attrs = manifest.getMainAttributes(); attrs.put(Attributes.Name.MANIFEST_VERSION, "1.0"); attrs.put(Attributes.Name.MAIN_CLASS, Main.class.getName()); attrs.put(new Attributes.Name("Multi-Release"), "true"); try { ByteArrayOutputStream out = new ByteArrayOutputStream(); manifest.write(out); out.close(); byte[] bytes = out.toByteArray(); this.archive.addAsManifestResource(new ByteArrayAsset(bytes), "MANIFEST.MF"); } catch (IOException e) { e.printStackTrace(); } }
Example #6
Source File: ShrinkWrapFatJarPackageService.java From vertx-maven-plugin with Apache License 2.0 | 6 votes |
/** * Generate the manifest for the über jar. */ private void generateManifest(JavaArchive jar, Map<String, String> entries) throws IOException, MojoExecutionException { Manifest manifest = new Manifest(); Attributes attributes = manifest.getMainAttributes(); attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0"); if (entries != null) { for (Map.Entry<String, String> entry : entries.entrySet()) { attributes.put(new Attributes.Name(entry.getKey()), entry.getValue()); } } ByteArrayOutputStream bout = new ByteArrayOutputStream(); manifest.write(bout); bout.close(); byte[] bytes = bout.toByteArray(); //TODO: merge existing manifest with current one jar.setManifest(new ByteArrayAsset(bytes)); }
Example #7
Source File: ArchiveProvider.java From gazpachoquest with GNU General Public License v3.0 | 6 votes |
static WebArchive base(String warName) { PomEquippedResolveStage resolver = Maven.resolver().loadPomFromFile("pom.xml"); return ShrinkWrap .create(WebArchive.class, warName + ".war") .addClasses(FRAMEWORK_CLASSES) .addAsLibraries(resolver.resolve("com.vaadin:vaadin-server:7.1.6").withoutTransitivity().asSingleFile()) .addAsLibraries(resolver.resolve("com.vaadin:vaadin-shared:7.1.6").withoutTransitivity().asSingleFile()) .addAsWebInfResource(new ByteArrayAsset(VaadinExtension.class.getName().getBytes()), ArchivePaths.create("services/javax.enterprise.inject.spi.Extension")) .addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml")); /*- MavenDependencyResolver resolver = DependencyResolvers.use(MavenDependencyResolver.class).loadMetadataFromPom( "pom.xml"); return ShrinkWrap .create(WebArchive.class, warName + ".war") .addClasses(FRAMEWORK_CLASSES) .addAsLibraries(resolver.artifact("com.vaadin:vaadin-server:7.1.6").resolveAsFiles()) .addAsLibraries(resolver.artifact("com.vaadin:vaadin-shared:7.1.6").resolveAsFiles()) .addAsWebInfResource(new ByteArrayAsset(VaadinExtension.class.getName().getBytes()), ArchivePaths.create("services/javax.enterprise.inject.spi.Extension")) .addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml")); */ }
Example #8
Source File: TestFoxPlatformClientAsEjbModule_onePaAsLib.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
/** * Deployment layout * * test-application.ear * |-- lib / * |-- processes.jar * |-- META-INF/processes.xml * |-- org/camunda/bpm/integrationtest/testDeployProcessArchive.bpmn20.xml * * |-- fox-platform-client.jar <<===============================|| * || Class-Path reference * |-- test.war (contains the test-class but also processes) || * |-- META-INF/MANIFEST.MF =================================|| * |-- WEB-INF/beans.xml * |-- + test classes * */ @Deployment public static EnterpriseArchive onePaAsLib() { JavaArchive processArchiveJar = ShrinkWrap.create(JavaArchive.class, "processes.jar") .addAsResource("org/camunda/bpm/integrationtest/testDeployProcessArchive.bpmn20.xml") .addAsResource("META-INF/processes.xml", "META-INF/processes.xml"); JavaArchive foxPlatformClientJar = DeploymentHelper.getEjbClient(); WebArchive testJar = ShrinkWrap.create(WebArchive.class, "test.war") .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") .setManifest(new ByteArrayAsset(("Class-Path: " + foxPlatformClientJar.getName()+"\n").getBytes())) .addClass(AbstractFoxPlatformIntegrationTest.class) .addClass(TestFoxPlatformClientAsEjbModule_onePaAsLib.class); return ShrinkWrap.create(EnterpriseArchive.class, "onePaAsLib.ear") .addAsLibrary(processArchiveJar) .addAsModule(foxPlatformClientJar) .addAsModule(testJar) .addAsLibrary(DeploymentHelper.getEngineCdi()); }
Example #9
Source File: AccessLogFileTestCase.java From quarkus with Apache License 2.0 | 6 votes |
@Override public JavaArchive get() { Path logDirectory; try { logDirectory = Files.createTempDirectory("quarkus-tests"); //backslash is an escape char, we need this to be properly formatted for windows Properties p = new Properties(); p.setProperty("quarkus.http.access-log.enabled", "true"); p.setProperty("quarkus.http.access-log.log-to-file", "true"); p.setProperty("quarkus.http.access-log.base-file-name", "server"); p.setProperty("quarkus.http.access-log.log-directory", logDirectory.toAbsolutePath().toString()); ByteArrayOutputStream out = new ByteArrayOutputStream(); p.store(out, null); return ShrinkWrap.create(JavaArchive.class) .add(new ByteArrayAsset(out.toByteArray()), "application.properties"); } catch (IOException e) { throw new RuntimeException(e); } }
Example #10
Source File: TestFoxPlatformClientAsEjbModule_twoPasAsLib.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
/** * Deployment layout * * test-application.ear * |-- lib / * |-- processes1.jar * |-- META-INF/processes.xml * |-- org/camunda/bpm/integrationtest/deployment/ear/process1.bpmn20.xml * |-- processes2.jar * |-- META-INF/processes.xml * |-- org/camunda/bpm/integrationtest/deployment/ear/process2.bpmn20.xml * * |-- fox-platform-client.jar <<===============================|| * || Class-Path reference * |-- test.war (contains the test-class but also processes) || * |-- META-INF/MANIFEST.MF =================================|| * |-- WEB-INF/beans.xml * |-- + test classes * */ @Deployment public static EnterpriseArchive twoPasAsLib() { JavaArchive processArchive1Jar = ShrinkWrap.create(JavaArchive.class, "processes1.jar") .addAsResource("org/camunda/bpm/integrationtest/deployment/ear/process1.bpmn20.xml") .addAsResource("org/camunda/bpm/integrationtest/deployment/ear/pa1.xml", "META-INF/processes.xml"); JavaArchive processArchive2Jar = ShrinkWrap.create(JavaArchive.class, "processes.jar") .addAsResource("org/camunda/bpm/integrationtest/deployment/ear/process2.bpmn20.xml") .addAsResource("org/camunda/bpm/integrationtest/deployment/ear/pa2.xml", "META-INF/processes.xml"); JavaArchive foxPlatformClientJar = DeploymentHelper.getEjbClient(); WebArchive testJar = ShrinkWrap.create(WebArchive.class, "client-test.war") .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") .setManifest(new ByteArrayAsset(("Class-Path: " + foxPlatformClientJar.getName()+"\n").getBytes())) .addClass(AbstractFoxPlatformIntegrationTest.class) .addClass(TestFoxPlatformClientAsEjbModule_twoPasAsLib.class); return ShrinkWrap.create(EnterpriseArchive.class, "twoPasAsLib.ear") .addAsLibrary(processArchive1Jar) .addAsLibrary(processArchive2Jar) .addAsModule(foxPlatformClientJar) .addAsModule(testJar) .addAsLibrary(DeploymentHelper.getEngineCdi()); }
Example #11
Source File: AbstractRotatingFileHandlerTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
static Asset createLoggingConfiguration(final Class<? extends FileHandler> handlerType, final String fileName, final Map<String, String> additionalProperties) throws IOException { final Properties properties = new Properties(); // Configure the root logger properties.setProperty("logger.level", "INFO"); properties.setProperty("logger.handlers", fileName); // Configure the handler properties.setProperty("handler." + fileName, handlerType.getName()); properties.setProperty("handler." + fileName + ".level", "ALL"); properties.setProperty("handler." + fileName + ".formatter", "json"); final StringBuilder configProperties = new StringBuilder("append,autoFlush,fileName"); for (String key : additionalProperties.keySet()) { configProperties.append(',').append(key); } properties.setProperty("handler." + fileName + ".properties", configProperties.toString()); properties.setProperty("handler." + fileName + ".append", "false"); properties.setProperty("handler." + fileName + ".autoFlush", "true"); properties.setProperty("handler." + fileName + ".fileName", "${jboss.server.log.dir}" + File.separatorChar + fileName); // Add the additional properties for (Map.Entry<String, String> entry : additionalProperties.entrySet()) { properties.setProperty("handler." + fileName + "." + entry.getKey(), entry.getValue()); } // Add the JSON formatter properties.setProperty("formatter.json", "org.jboss.logmanager.formatters.JsonFormatter"); final ByteArrayOutputStream out = new ByteArrayOutputStream(); properties.store(new OutputStreamWriter(out, StandardCharsets.UTF_8), null); return new ByteArrayAsset(out.toByteArray()); }
Example #12
Source File: MigrationContextSwitchClassesTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
protected static Asset modelAsAsset(BpmnModelInstance modelInstance) { ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); Bpmn.writeModelToStream(byteStream, modelInstance); byte[] bytes = byteStream.toByteArray(); return new ByteArrayAsset(bytes); }
Example #13
Source File: LayoutIT.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 5 votes |
@Test public void testGetManifest() throws Exception { JavaArchive archive = createBootstrapArchive(); archive.addAsManifestResource(EmptyAsset.INSTANCE, "wildfly-swarm.properties"); Manifest manifest = new Manifest(); manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); manifest.getMainAttributes().put(new Attributes.Name("Wildfly-Swarm-Main-Class"), "MyMainClass"); ByteArrayOutputStream out = new ByteArrayOutputStream(); manifest.write(out); out.close(); archive.addAsManifestResource(new ByteArrayAsset(out.toByteArray()), "MANIFEST.MF"); ClassLoader cl = createClassLoader(archive); Class<?> layoutClass = cl.loadClass(Layout.class.getName()); Method getInstance = layoutClass.getMethod("getInstance"); Object layout = getInstance.invoke(layoutClass); Method isUberJar = layoutClass.getMethod("isUberJar"); Object result = isUberJar.invoke(layout); assertThat(result).isEqualTo(true); Method getManifest = layoutClass.getMethod("getManifest"); Manifest fetchedManifest = (Manifest) getManifest.invoke(layout); assertThat(fetchedManifest).isNotNull(); assertThat(fetchedManifest.getMainAttributes().get(new Attributes.Name("Wildfly-Swarm-Main-Class"))).isEqualTo("MyMainClass"); }
Example #14
Source File: AbstractBootstrapIntegrationTestCase.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 5 votes |
protected JavaArchive createBootstrapArchive(String mainClassName, String appArtifact) throws IOException { JavaArchive archive = ShrinkWrap.create(JavaArchive.class); archive.as(ZipImporter.class).importFrom(new JarFile(findBootstrapJar())); Properties props = new Properties(); if (appArtifact != null) { props.put(BootstrapProperties.APP_ARTIFACT, appArtifact); } ByteArrayOutputStream propsOut = new ByteArrayOutputStream(); props.store(propsOut, ""); propsOut.close(); archive.addAsManifestResource(new ByteArrayAsset(propsOut.toByteArray()), "wildfly-swarm.properties"); if (appArtifact != null) { String conf = "path:" + appArtifact + "\n"; archive.addAsManifestResource(new ByteArrayAsset(conf.getBytes()), "wildfly-swarm-application.conf"); } if (mainClassName != null) { Manifest manifest = new Manifest(); manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); manifest.getMainAttributes().put(new Attributes.Name("Wildfly-Swarm-Main-Class"), mainClassName); ByteArrayOutputStream out = new ByteArrayOutputStream(); manifest.write(out); out.close(); archive.addAsManifestResource(new ByteArrayAsset(out.toByteArray()), "MANIFEST.MF"); } return archive; }
Example #15
Source File: JAXRSArchiveImpl.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 5 votes |
protected void addExceptionMapperForFavicon() { try { add(new ByteArrayAsset(FaviconExceptionMapperFactory.create()), "WEB-INF/classes/org/wildfly/swarm/generated/FaviconExceptionMapper.class"); addClass(FaviconHandler.class); addModule("org.jboss.modules"); } catch (IOException e) { e.printStackTrace(); } }
Example #16
Source File: JAXRSArchiveImpl.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 5 votes |
protected void addGeneratedApplication() { Map<ArchivePath, Node> content = getArchive().getContent(); boolean applicationFound = false; for (Map.Entry<ArchivePath, Node> entry : content.entrySet()) { Node node = entry.getValue(); Asset asset = node.getAsset(); if (hasApplicationPathAnnotation(node.getPath(), asset)) { applicationFound = true; break; } } if (!applicationFound) { String name = "org.wildfly.swarm.generated.WildFlySwarmDefaultJAXRSApplication"; String path = "WEB-INF/classes/" + name.replace('.', '/') + ".class"; byte[] generatedApp = new byte[0]; try { generatedApp = ApplicationFactory2.create(name, "/"); add(new ByteArrayAsset(generatedApp), path); addHandlers(new ApplicationHandler(this, path)); } catch (IOException e) { e.printStackTrace(); } } }
Example #17
Source File: MigrationContextSwitchBeansTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
protected static Asset modelAsAsset(BpmnModelInstance modelInstance) { ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); Bpmn.writeModelToStream(byteStream, modelInstance); byte[] bytes = byteStream.toByteArray(); return new ByteArrayAsset(bytes); }
Example #18
Source File: ServiceClientProcessor.java From thorntail with Apache License 2.0 | 5 votes |
@Override public void process() { Collection<ClassInfo> serviceClients = index.getKnownDirectImplementors((DotName.createSimple(ServiceClient.class.getName()))); serviceClients.forEach(info -> { String name = info.name().toString() + "_generated"; String path = "WEB-INF/classes/" + name.replace('.', '/') + ".class"; archive.as(JAXRSArchive.class).add(new ByteArrayAsset(ClientServiceFactory.createImpl(name, info)), path); }); }
Example #19
Source File: MPJWTAuthExtensionArchivePreparer.java From thorntail with Apache License 2.0 | 5 votes |
private void createRolePropertiesFileFromMap() { StringBuilder sb = new StringBuilder(); for (Map.Entry<String, String> entry : fraction.getRolesPropertiesMap().entrySet()) { sb.append(entry.getKey()).append('=').append(entry.getValue()).append('\n'); } archive.add(new ByteArrayAsset(sb.toString().getBytes()), "WEB-INF/classes/autogenerated-roles.properties"); }
Example #20
Source File: SecuredArchivePreparer.java From thorntail with Apache License 2.0 | 5 votes |
private Asset createKeycloakJsonAsset(InputStream in) throws IOException { StringBuilder str = new StringBuilder(); try (BufferedReader reader = new BufferedReader(new InputStreamReader(in))) { String line = null; while ((line = reader.readLine()) != null) { str.append(line).append("\n"); } } return new ByteArrayAsset(str.toString().getBytes()); }
Example #21
Source File: TestUtil.java From cap-community with MIT License | 5 votes |
public static WebArchive createDeployment(final Class<?>... classesUnderTest) { return ShrinkWrap .create(WebArchive.class) .addClasses(classesUnderTest) .addClasses(RequestContextServletFilter.class, RequestContextCallable.class) .addClass(TenantRequestContextListener.class) .addClass(UserRequestContextListener.class) .addClass(DestinationsRequestContextListener.class) .addAsManifestResource("arquillian.xml") .setWebXML("web.xml") .addAsWebInfResource("spring-security.xml") .addAsWebInfResource(new ByteArrayAsset("<beans/>".getBytes()), ArchivePaths.create("beans.xml")); }
Example #22
Source File: DefaultApplicationDeploymentProcessor.java From thorntail with Apache License 2.0 | 5 votes |
private void addGeneratedApplication(JAXRSArchive archive) { String name = "org.wildfly.swarm.generated.WildFlySwarmDefaultJAXRSApplication"; String path = "WEB-INF/classes/" + name.replace('.', '/') + ".class"; byte[] generatedApp; try { generatedApp = DefaultApplicationFactory.create(name, applicationPath.get()); archive.add(new ByteArrayAsset(generatedApp), path); archive.addHandlers(new ApplicationHandler(archive, path)); } catch (IOException e) { e.printStackTrace(); } }
Example #23
Source File: SwaggerArchivePreparerTest.java From thorntail with Apache License 2.0 | 5 votes |
@Test public void testWithSwaggerConfInWebInfClasses() { JAXRSArchive archive = ShrinkWrap.create(JAXRSArchive.class); archive.addResource(MyResource.class); archive.addResource(MyOtherResource.class); archive.add(new ByteArrayAsset("packages: com.myapp.mysubstuff".getBytes()), "WEB-INF/classes/META-INF/swarm.swagger.conf"); SwaggerArchivePreparer preparer = new SwaggerArchivePreparer(archive); preparer.process(); SwaggerArchive swaggerArchive = archive.as(SwaggerArchive.class); assertThat(swaggerArchive.getResourcePackages()).containsOnly("com.myapp.mysubstuff"); }
Example #24
Source File: SwaggerArchivePreparerTest.java From thorntail with Apache License 2.0 | 5 votes |
@Test public void testWithSwaggerConfInRoot() { JAXRSArchive archive = ShrinkWrap.create(JAXRSArchive.class); archive.addResource(MyResource.class); archive.addResource(MyOtherResource.class); archive.add(new ByteArrayAsset("packages: com.myapp.mysubstuff".getBytes()), "META-INF/swarm.swagger.conf"); SwaggerArchivePreparer preparer = new SwaggerArchivePreparer(archive); preparer.process(); SwaggerArchive swaggerArchive = archive.as(SwaggerArchive.class); assertThat(swaggerArchive.getResourcePackages()).containsOnly("com.myapp.mysubstuff"); }
Example #25
Source File: BuildTool.java From thorntail with Apache License 2.0 | 5 votes |
private void addWildFlySwarmApplicationManifest() { WildFlySwarmManifest manifest = this.dependencyManager.getWildFlySwarmManifest(); this.properties.put("thorntail.uberjar.build.user", System.getProperty("user.name")); if (!this.hollow) { this.properties.put(BootstrapProperties.APP_ARTIFACT, this.projectAsset.getSimpleName()); } manifest.setProperties(this.properties); manifest.bundleDependencies(this.bundleDependencies); manifest.setMainClass(this.mainClass); manifest.setHollow(this.hollow); this.archive.add(new ByteArrayAsset(manifest.toString().getBytes(StandardCharsets.UTF_8)), WildFlySwarmManifest.CLASSPATH_LOCATION); }
Example #26
Source File: TestUtil.java From cloud-s4-sdk-examples with Apache License 2.0 | 5 votes |
public static WebArchive createDeployment( final Class<?>... classesUnderTest ) { return ShrinkWrap .create(WebArchive.class) .addClasses(classesUnderTest) .addClass(RequestContextServletFilter.class) .addClass(TenantRequestContextListener.class) .addClass(DestinationsRequestContextListener.class) .addAsManifestResource("arquillian.xml") .addAsWebInfResource(new ByteArrayAsset("<beans/>".getBytes()), ArchivePaths.create("beans.xml")); }
Example #27
Source File: TestUtil.java From cloud-s4-sdk-examples with Apache License 2.0 | 5 votes |
public static WebArchive createDeployment( final Class<?>... classesUnderTest ) { return ShrinkWrap .create(WebArchive.class) .addClasses(classesUnderTest) .addClasses(RequestContextServletFilter.class, RequestContextCallable.class) .addClass(TenantRequestContextListener.class) .addClass(UserRequestContextListener.class) .addClass(DestinationsRequestContextListener.class) .addAsManifestResource("arquillian.xml") .addAsWebInfResource(new ByteArrayAsset("<beans/>".getBytes()), ArchivePaths.create("beans.xml")); }
Example #28
Source File: TeiidOpenShiftClient.java From syndesis with Apache License 2.0 | 5 votes |
protected void buildDataSourceBuilders(Model model, GenericArchive archive) { for (String name : model.getSourceNames()) { try { String str = null; String replacement = model.getSourceConnectionJndiName(name); String translatorName = model.getSourceTranslatorName(name); final String resourceName; if ("salesforce".equals(translatorName)) { resourceName = "s2i/Salesforce.mustache"; } else if ("mongodb".equals(translatorName)) { resourceName = "s2i/MongoDB.mustache"; } else { resourceName = "s2i/Jdbc.mustache"; } try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(resourceName)) { str = inputStreamToString(is); } str = str.replace("{{packageName}}", "io.integration"); str = str.replace("{{dsName}}", replacement); archive.add(new ByteArrayAsset(ObjectConverterUtil .convertToByteArray(new ByteArrayInputStream(str.getBytes("UTF-8")))), "/src/main/java/io/integration/DataSources" + replacement + ".java"); } catch (IOException e) { throw handleError(e); } } }
Example #29
Source File: MicroOuterDeployer.java From piranha with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Gets a class loader that provides access to the classes in WEB-INF of a web application archive. * * @param applicationArchive the web application archive to provide access to * @param piranhaClassloader the parent class loader containing the Piranha runtime classes * @return A class loader giving access to the application code */ ClassLoader getWebInfClassLoader(Archive<?> applicationArchive, ClassLoader piranhaClassloader) { // Create the resource that holds all classes from the WEB-INF/classes folder ShrinkWrapResource applicationResource = new ShrinkWrapResource("/WEB-INF/classes", applicationArchive); // Create the resources that hold all classes from the WEB-INF/lib folder. // Each resource holds the classes from a single jar ShrinkWrapResource jarResources = new ShrinkWrapResource("/WEB-INF/lib", applicationArchive); List<ShrinkWrapResource> webLibResources = jarResources.getAllLocations() .filter(location -> location.endsWith(".jar")) .map(location -> importAsShrinkWrapResource(jarResources, location)) .collect(toList()); // Create a separate archive that contains an index of the application archive and the library archives. // This index can be obtained from the class loader by getting the "META-INF/piranha.idx" resource. ShrinkWrapResource indexResource = new ShrinkWrapResource( ShrinkWrap.create(JavaArchive.class) .add(new ByteArrayAsset(createIndex(applicationResource, webLibResources)), "META-INF/piranha.idx")); IsolatingResourceManagerClassLoader classLoader = new IsolatingResourceManagerClassLoader(piranhaClassloader, "WebInf Loader"); // Add the resources representing the application archive and index archive to the resource manager DefaultResourceManager manager = new DefaultResourceManager(); manager.addResource(applicationResource); for (ShrinkWrapResource webLibResource : webLibResources) { manager.addResource(webLibResource); } manager.addResource(indexResource); // Make the application and library classes, as well as the index available to the class loader by setting the resource manager // that contains these. classLoader.setResourceManager(manager); return classLoader; }
Example #30
Source File: TestUtil.java From cloud-s4-sdk-book with Apache License 2.0 | 5 votes |
public static WebArchive createDeployment( final Class<?>... classesUnderTest ) { return ShrinkWrap .create(WebArchive.class) .addClasses(classesUnderTest) .addClasses(RequestContextServletFilter.class, RequestContextCallable.class) .addClass(TenantRequestContextListener.class) .addClass(UserRequestContextListener.class) .addClass(DestinationsRequestContextListener.class) .addAsManifestResource("arquillian.xml") .addAsWebInfResource(new ByteArrayAsset("<beans/>".getBytes()), ArchivePaths.create("beans.xml")); }