org.jboss.shrinkwrap.api.asset.Asset Java Examples
The following examples show how to use
org.jboss.shrinkwrap.api.asset.Asset.
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: DisableFTEnableOnMethodTest.java From microprofile-fault-tolerance with Apache License 2.0 | 6 votes |
@Deployment public static WebArchive deploy() { Asset config = new DisableConfigAsset() .enable(DisableAnnotationClient.class, "failAndRetryOnce", Retry.class) .enable(DisableAnnotationClient.class, "failWithCircuitBreaker", CircuitBreaker.class) .enable(DisableAnnotationClient.class, "failWithTimeout", Timeout.class) .enable(DisableAnnotationClient.class, "asyncWaitThenReturn", Asynchronous.class) .enable(DisableAnnotationClient.class, "failRetryOnceThenFallback", Fallback.class) .enable(DisableAnnotationClient.class, "waitWithBulkhead", Bulkhead.class) .disableGlobally(); JavaArchive testJar = ShrinkWrap .create(JavaArchive.class, "ftDisableGloballyEnableMethod.jar") .addClasses(DisableAnnotationClient.class) .addPackage(Packages.UTILS) .addAsManifestResource(config, "microprofile-config.properties") .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml") .as(JavaArchive.class); WebArchive war = ShrinkWrap .create(WebArchive.class, "ftDisableGloballyEnableMethod.war") .addAsLibrary(testJar); return war; }
Example #2
Source File: JBossWebContainer.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 6 votes |
default JBossWebAsset findJbossWebAsset() { final Node jbossWeb = this.get(JBOSS_WEB_PATH); Asset asset; if (jbossWeb == null) { asset = new JBossWebAsset(); this.add(asset, JBOSS_WEB_PATH); } else { asset = jbossWeb.getAsset(); if (!(asset instanceof JBossWebAsset)) { asset = new JBossWebAsset(asset.openStream()); this.add(asset, JBOSS_WEB_PATH); } } return (JBossWebAsset) asset; }
Example #3
Source File: CamelMainRoutesFilterTest.java From camel-quarkus with Apache License 2.0 | 6 votes |
public static Asset applicationProperties() { Writer writer = new StringWriter(); Properties props = new Properties(); props.setProperty("quarkus.banner.enabled", "false"); props.setProperty("quarkus.camel.routes-discovery.enabled", "true"); props.setProperty("quarkus.camel.routes-discovery.exclude-patterns", "**/*Filtered"); try { props.store(writer, ""); } catch (IOException e) { throw new RuntimeException(e); } return new StringAsset(writer.toString()); }
Example #4
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 #5
Source File: JBossDeploymentStructureContainer.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 6 votes |
default JBossDeploymentStructureAsset getDescriptorAsset() { String path = PRIMARY_JBOSS_DEPLOYMENT_DESCRIPTOR_PATH; Node jbossDS = this.get(PRIMARY_JBOSS_DEPLOYMENT_DESCRIPTOR_PATH); if (jbossDS == null) { jbossDS = this.get(SECONDARY_JBOSS_DEPLOYMENT_DESCRIPTOR_PATH); if (jbossDS != null) { path = SECONDARY_JBOSS_DEPLOYMENT_DESCRIPTOR_PATH; } } Asset asset; if (jbossDS == null) { asset = new JBossDeploymentStructureAsset(); } else { asset = jbossDS.getAsset(); if (!(asset instanceof JBossDeploymentStructureAsset)) { asset = new JBossDeploymentStructureAsset(asset.openStream()); } } this.add(asset, path); return (JBossDeploymentStructureAsset) asset; }
Example #6
Source File: MessageFormattedMessageTest.java From deltaspike with Apache License 2.0 | 6 votes |
/** * X TODO creating a WebArchive is only a workaround because JavaArchive * cannot contain other archives. */ @Deployment public static WebArchive deploy() { Asset beansXml = new StringAsset( "<beans><alternatives>" + "<class>" + MessageFormatMessageInterpolator.class.getName() + "</class>" + "</alternatives></beans>" ); JavaArchive testJar = ShrinkWrap .create(JavaArchive.class, "messageFormattedMessageTest.jar") .addPackage(MessageFormattedMessageTest.class.getPackage()) .addAsManifestResource(beansXml, "beans.xml"); return ShrinkWrap .create(WebArchive.class, "messageFormattedMessageTest.war") .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreArchive()) .addAsLibraries(testJar) .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") .addAsServiceProvider(Extension.class, MessageBundleExtension.class); }
Example #7
Source File: ShrinkWrapResource.java From piranha with BSD 3-Clause "New" or "Revised" License | 6 votes |
public InputStream getResourceAsStreamByLocation(String location) { if (location == null) { return null; } Node node = getNode(archive, location); if (node == null) { return null; } Asset asset = node.getAsset(); if (asset == null) { // Node was a directory return new ShrinkWrapDirectoryInputStream(getContentFromNode(node)); } // Node was an asset return asset.openStream(); }
Example #8
Source File: DisableFTEnableGloballyTest.java From microprofile-fault-tolerance with Apache License 2.0 | 6 votes |
@Deployment public static WebArchive deploy() { Asset config = new DisableConfigAsset() .enable(Retry.class) .enable(CircuitBreaker.class) .enable(Timeout.class) .enable(Asynchronous.class) .enable(Fallback.class) .enable(Bulkhead.class) .disableGlobally(); JavaArchive testJar = ShrinkWrap .create(JavaArchive.class, "ftDisableGlobalEnableClass.jar") .addClasses(DisableAnnotationClient.class) .addPackage(Packages.UTILS) .addAsManifestResource(config, "microprofile-config.properties") .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml") .as(JavaArchive.class); WebArchive war = ShrinkWrap .create(WebArchive.class, "ftDisableGlobalEnableClass.war") .addAsLibrary(testJar); return war; }
Example #9
Source File: RibbonArchiveTest.java From thorntail with Apache License 2.0 | 6 votes |
@Test public void testAdvertiseMultiple() { JARArchive archive = ShrinkWrap.create(JARArchive.class, "myapp.war"); archive.as(RibbonArchive.class) .advertise("service-a") .advertise("service-b") .advertise("service-c"); Asset asset = archive.get(RibbonArchive.REGISTRATION_CONF).getAsset(); assertThat(asset).isNotNull(); assertThat(asset).isInstanceOf(StringAsset.class); String[] services = ((StringAsset) asset).getSource().split("\n"); assertThat(services).contains("service-a"); assertThat(services).contains("service-b"); assertThat(services).contains("service-c"); assertThat(archive.as(ServiceActivatorArchive.class).containsServiceActivator(RibbonArchiveImpl.SERVICE_ACTIVATOR_CLASS_NAME)).isTrue(); }
Example #10
Source File: DisableFTEnableOnClassTest.java From microprofile-fault-tolerance with Apache License 2.0 | 6 votes |
@Deployment public static WebArchive deploy() { Asset config = new DisableConfigAsset() .enable(DisableAnnotationClient.class, Retry.class) .enable(DisableAnnotationClient.class, CircuitBreaker.class) .enable(DisableAnnotationClient.class, Timeout.class) .enable(DisableAnnotationClient.class, Asynchronous.class) .enable(DisableAnnotationClient.class, Fallback.class) .enable(DisableAnnotationClient.class, Bulkhead.class) .disableGlobally(); JavaArchive testJar = ShrinkWrap .create(JavaArchive.class, "ftDisableGlobalEnableClass.jar") .addClasses(DisableAnnotationClient.class) .addPackage(Packages.UTILS) .addAsManifestResource(config, "microprofile-config.properties") .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml") .as(JavaArchive.class); WebArchive war = ShrinkWrap .create(WebArchive.class, "ftDisableGlobalEnableClass.war") .addAsLibrary(testJar); return war; }
Example #11
Source File: DisableAnnotationGloballyTest.java From microprofile-fault-tolerance with Apache License 2.0 | 6 votes |
@Deployment public static WebArchive deploy() { Asset config = new DisableConfigAsset() .disable(Retry.class) .disable(CircuitBreaker.class) .disable(Timeout.class) .disable(Asynchronous.class) .disable(Fallback.class) .disable(Bulkhead.class); JavaArchive testJar = ShrinkWrap .create(JavaArchive.class, "ftDisableGlobally.jar") .addClasses(DisableAnnotationClient.class) .addPackage(Packages.UTILS) .addAsManifestResource(config, "microprofile-config.properties") .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml") .as(JavaArchive.class); WebArchive war = ShrinkWrap .create(WebArchive.class, "ftDisableGlobally.war") .addAsLibrary(testJar); return war; }
Example #12
Source File: PatchingTestUtil.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
public static ResourceItem createVersionItem(final String targetVersion) { final Asset newManifest = new Asset() { @Override public InputStream openStream() { return new ByteArrayInputStream(ProductInfo.createVersionString(targetVersion).getBytes(StandardCharsets.UTF_8)); } }; final JavaArchive versionModuleJar = ShrinkWrap.create(JavaArchive.class); if (!ProductInfo.isProduct) { versionModuleJar.addPackage("org.jboss.as.version"); } versionModuleJar.addAsManifestResource(newManifest, "MANIFEST.MF"); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); versionModuleJar.as(ZipExporter.class).exportTo(baos); return new ResourceItem("as-version.jar", baos.toByteArray()); }
Example #13
Source File: DisableAnnotationOnClassTest.java From microprofile-fault-tolerance with Apache License 2.0 | 6 votes |
@Deployment public static WebArchive deploy() { Asset config = new DisableConfigAsset() .disable(DisableAnnotationClient.class, Retry.class) .disable(DisableAnnotationClient.class, CircuitBreaker.class) .disable(DisableAnnotationClient.class, Timeout.class) .disable(DisableAnnotationClient.class, Asynchronous.class) .disable(DisableAnnotationClient.class, Fallback.class) .disable(DisableAnnotationClient.class, Bulkhead.class); JavaArchive testJar = ShrinkWrap .create(JavaArchive.class, "ftDisableClass.jar") .addClasses(DisableAnnotationClient.class) .addPackage(Packages.UTILS) .addAsManifestResource(config, "microprofile-config.properties") .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml") .as(JavaArchive.class); WebArchive war = ShrinkWrap .create(WebArchive.class, "ftDisableClass.war") .addAsLibrary(testJar); return war; }
Example #14
Source File: DefaultApplicationDeploymentProcessor.java From thorntail with Apache License 2.0 | 6 votes |
static boolean hasApplicationServletMapping(Asset asset) { if (asset == null) { return false; } WebXmlAsset webXmlAsset; if (asset instanceof WebXmlAsset) { webXmlAsset = (WebXmlAsset) asset; } else { try { webXmlAsset = new WebXmlAsset(asset.openStream()); } catch (Exception e) { JAXRSMessages.MESSAGES.unableToParseWebXml(e); return false; } } return !webXmlAsset.getServletMapping(Application.class.getName()).isEmpty(); }
Example #15
Source File: DependencyManager.java From thorntail with Apache License 2.0 | 6 votes |
@Override public boolean isRemovable(Node node) { Asset asset = node.getAsset(); if (asset == null) { return false; } if (removableCheckSums == null) { initCheckSums(); } try (final InputStream inputStream = asset.openStream()) { String checksum = ChecksumUtil.calculateChecksum(inputStream); return this.removableCheckSums.contains(checksum); } catch (NoSuchAlgorithmException | IOException e) { e.printStackTrace(); } return false; }
Example #16
Source File: SwaggerArchiveImpl.java From thorntail with Apache License 2.0 | 6 votes |
private void loadOrCreateConfigurationAsset() throws IOException { Node node = getArchive().get(SWAGGER_CONFIGURATION_PATH); if (node == null && getArchive().getName().endsWith(".war")) { node = getArchive().get("WEB-INF/classes/" + SWAGGER_CONFIGURATION_PATH); } if (node != null) { Asset asset = node.getAsset(); if (asset instanceof SwaggerConfigurationAsset) { this.configurationAsset = (SwaggerConfigurationAsset) asset; } else { this.configurationAsset = new SwaggerConfigurationAsset(asset.openStream()); getArchive().add(this.configurationAsset, node.getPath()); } } else { this.configurationAsset = new SwaggerConfigurationAsset(); if (getArchive().getName().endsWith(".war")) { getArchive().add(this.configurationAsset, "WEB-INF/classes/" + SWAGGER_CONFIGURATION_PATH); } else { getArchive().add(this.configurationAsset, SWAGGER_CONFIGURATION_PATH); } } }
Example #17
Source File: JPAInjectionTest.java From tomee with Apache License 2.0 | 6 votes |
@Deployment(testable = false) public static WebArchive getArchive() { PersistenceDescriptor persistenceDescriptor = Descriptors.create(PersistenceDescriptor.class) .createPersistenceUnit() .name("test-pu") .transactionType("JTA") .clazz(PersistenceDescriptor.class.getName()) .jtaDataSource("test-ds") .up(); Asset persistenceAsset = new StringAsset(persistenceDescriptor.exportAsString()); return base("jsf-jpa-test.war").addAsWebInfResource(persistenceAsset, "persistence.xml") .addClasses(DummyManagedBean.class) .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") .addAsWebResource(new ClassLoaderAsset( JPAInjectionTest.class.getPackage().getName().replace('.', '/').concat("/").concat("dummy.xhtml")), "dummy.xhtml"); }
Example #18
Source File: TransactedJMSIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Deployment public static JavaArchive createdeployment() { final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "camel-jms-tx-tests"); archive.setManifest(new Asset() { @Override public InputStream openStream() { ManifestBuilder builder = new ManifestBuilder(); builder.addManifestHeader("Dependencies", "org.jboss.as.controller-client"); return builder.openStream(); } }); return archive; }
Example #19
Source File: NotificationFilter.java From appengine-tck with Apache License 2.0 | 5 votes |
protected static byte[] toBytes(Asset asset) { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); InputStream is = asset.openStream(); try { Utils.copyStream(is, baos); } finally { Utils.safeClose(is); } return baos.toByteArray(); } catch (IOException e) { throw new IllegalStateException(e); } }
Example #20
Source File: RibbonArchiveTest.java From thorntail with Apache License 2.0 | 5 votes |
@Test public void testAdvertiseExplicitName() { JARArchive archive = ShrinkWrap.create(JARArchive.class, "myapp.war"); archive.as(RibbonArchive.class) .advertise("myotherapp"); Asset asset = archive.get(RibbonArchive.REGISTRATION_CONF).getAsset(); assertThat(asset).isNotNull(); assertThat(asset).isInstanceOf(StringAsset.class); assertThat(((StringAsset) asset).getSource().trim()).isEqualTo("myotherapp"); assertThat(archive.as(ServiceActivatorArchive.class).containsServiceActivator(RibbonArchiveImpl.SERVICE_ACTIVATOR_CLASS_NAME)).isTrue(); }
Example #21
Source File: JAXRSArchiveImpl.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 5 votes |
@Override public void handle(ArchiveEvent event) { Asset asset = event.getAsset(); if (hasApplicationPathAnnotation(event.getPath(), asset)) { this.archive.delete(this.path); } }
Example #22
Source File: HostmapDeploymentContributor.java From knox with Apache License 2.0 | 5 votes |
@Override public void contributeProvider( DeploymentContext context, Provider provider ) { if( provider.isEnabled() ) { UrlRewriteRulesDescriptor rules = context.getDescriptor( REWRITE_ROLE_NAME ); if( rules != null ) { HostmapFunctionDescriptor func = rules.addFunction( HostmapFunctionDescriptor.FUNCTION_NAME ); if( func != null ) { Asset asset = createAsset( provider ); context.getWebArchive().addAsWebInfResource( asset, HostmapFunctionProcessor.DESCRIPTOR_DEFAULT_FILE_NAME ); func.config( HostmapFunctionProcessor.DESCRIPTOR_DEFAULT_LOCATION ); } } } }
Example #23
Source File: DefaultApplicationDeploymentProcessorTest.java From thorntail with Apache License 2.0 | 5 votes |
@Test public void testApplicationPathAnnotation_SpecifiedInProjectDefaults() throws Exception { JAXRSArchive archive = ShrinkWrap.create(JAXRSArchive.class, "app.war"); DefaultApplicationDeploymentProcessor processor = new DefaultApplicationDeploymentProcessor(archive); processor.applicationPath.set("/api-test"); // Simulate the behavior of loading the project defaults. processor.process(); Node generated = archive.get(PATH); Asset asset = generated.getAsset(); assertThat(generated).isNotNull(); assertThat(asset).isNotNull(); }
Example #24
Source File: UndertowHandlerTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Deployment public static JavaArchive createDeployment() { final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "undertow-handler-test"); archive.addClasses(HttpRequest.class); archive.setManifest(new Asset() { @Override public InputStream openStream() { ManifestBuilder builder = new ManifestBuilder(); builder.addManifestHeader("Dependencies", "org.wildfly.extension.undertow,io.undertow.core"); return builder.openStream(); } }); return archive; }
Example #25
Source File: HostmapDeploymentContributor.java From knox with Apache License 2.0 | 5 votes |
private Asset createAsset( Provider provider ) { StringWriter buffer = new StringWriter(); try(PrintWriter writer = new PrintWriter( buffer )) { for (Map.Entry<String, String> entry : provider.getParams().entrySet()) { String externalHosts = entry.getKey(); String internalHosts = entry.getValue(); writer.print(externalHosts); writer.print("="); writer.println(internalHosts); } } String string = buffer.toString(); return new StringAsset( string ); }
Example #26
Source File: MethodLevelInterceptorTest.java From deltaspike with Apache License 2.0 | 5 votes |
@Deployment public static WebArchive war() { Asset beansXml = new StringAsset( "<beans><interceptors><class>" + SimpleCacheInterceptor.class.getName() + "</class></interceptors></beans>" ); String simpleName = MethodLevelInterceptorTest.class.getSimpleName(); String archiveName = simpleName.substring(0, 1).toLowerCase() + simpleName.substring(1); //don't create a completely empty web-archive if (CdiContainerUnderTest.is(CONTAINER_WELD_2_0_0)) { return ShrinkWrap.create(WebArchive.class, archiveName + ".war") .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreAndPartialBeanArchive()); } JavaArchive testJar = ShrinkWrap.create(JavaArchive.class, archiveName + ".jar") .addPackage(MethodLevelInterceptorTest.class.getPackage()) .addPackage(TestPartialBeanBinding.class.getPackage()) .addAsManifestResource(beansXml, "beans.xml"); return ShrinkWrap.create(WebArchive.class, archiveName + ".war") .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreAndPartialBeanArchive()) .addAsLibraries(testJar) .addAsServiceProvider(Extension.class, SimpleCacheExtension.class) .addAsWebInfResource(beansXml, "beans.xml"); }
Example #27
Source File: DeploymentFactory.java From knox with Apache License 2.0 | 5 votes |
private static Asset toStringAsset( Topology topology ) { StringWriter writer = new StringWriter(); String xml; try { Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, true ); marshaller.marshal( topology, writer ); xml = writer.toString(); } catch (JAXBException e) { throw new DeploymentException( "Failed to marshall topology.", e ); } return new StringAsset( xml ); }
Example #28
Source File: JAXRSArchiveImpl.java From thorntail with Apache License 2.0 | 5 votes |
public static boolean isJAXRS(Archive<?> archive) { Map<ArchivePath, Node> content = archive.getContent(); for (Map.Entry<ArchivePath, Node> entry : content.entrySet()) { Node node = entry.getValue(); Asset asset = node.getAsset(); if (isJAXRS(node.getPath(), asset)) { return true; } } return false; }
Example #29
Source File: SwaggerArchiveTest.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 5 votes |
@Test public void testSwaggerConfiguration() { JARArchive archive = ShrinkWrap.create(JARArchive.class, "myapp.jar"); archive.as(SwaggerArchive.class) .setResourcePackages("com.tester.resource", "com.tester.other.resource") .setTitle("My Application API") .setLicenseUrl("http://myapplication.com/license.txt") .setLicense("Use at will") .setContextRoot("/tacos") .setDescription("This is a description of my API") .setHost("api.myapplication.com") .setContact("[email protected]") .setPrettyPrint(true) .setSchemes("http", "https") .setTermsOfServiceUrl("http://myapplication.com/tos.txt") .setVersion("1.0"); Asset asset = archive.get(SwaggerArchive.SWAGGER_CONFIGURATION_PATH).getAsset(); assertThat(asset).isNotNull(); assertThat(asset).isInstanceOf(SwaggerConfigurationAsset.class); SwaggerConfig config = new SwaggerConfig(asset.openStream()); assertThat(config.get(SwaggerConfig.Key.VERSION)).isEqualTo("1.0"); assertThat(config.get(SwaggerConfig.Key.TERMS_OF_SERVICE_URL)).isEqualTo("http://myapplication.com/tos.txt"); assertThat(config.get(SwaggerConfig.Key.PACKAGES)).isEqualTo("com.tester.resource,com.tester.other.resource"); }
Example #30
Source File: NotificationFilter.java From appengine-tck with Apache License 2.0 | 5 votes |
public boolean include(ArchivePath path) { Node node = uber.get(path); if (node != null && isAllowedDuplicate(node) == false) { Asset asset = node.getAsset(); if (asset != null) { Asset other = archive.get(path).getAsset(); validate(path, equal(asset, other)); } return false; } return true; }