Java Code Examples for org.wildfly.swarm.jaxrs.JAXRSArchive#addResource()

The following examples show how to use org.wildfly.swarm.jaxrs.JAXRSArchive#addResource() . 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: SWARM_513Test.java    From thorntail with Apache License 2.0 6 votes vote down vote up
@Deployment(testable = true)
public static Archive createDeployment() throws Exception {
    URL url = Thread.currentThread().getContextClassLoader().getResource("project-test-defaults-path.yml");
    assertThat(url).isNotNull();
    File projectDefaults = new File(url.toURI());
    JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class, "myapp.war");
    deployment.addResource(TicketEndpoint.class);
    deployment.addClass(Ticket.class);
    deployment.addClass(Tickets.class);
    deployment.addClass(TicketDTO.class);

    deployment.addAsWebInfResource(new ClassLoaderAsset("META-INF/persistence.xml", SWARM_513Test.class.getClassLoader()), "classes/META-INF/persistence.xml");
    deployment.addAsWebInfResource(new ClassLoaderAsset("META-INF/import.sql", SWARM_513Test.class.getClassLoader()), "classes/META-INF/import.sql");

    deployment.addAsResource(projectDefaults, "/project-defaults.yml");
    return deployment;
}
 
Example 2
Source File: KeycloakMultitenancyTest.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Deployment
public static Archive<?> createDeployment() throws Exception {
    JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class, "test.war");
    deployment.addResource(SecuredApplication.class);
    deployment.addResource(SecuredResource.class);
    deployment.addAsResource("wildfly-swarm-keycloak-example-realm.json");
    deployment.addAsResource("keycloak.json", "keycloakTenant.json");
    deployment.addAsResource("project-multitenancy.yml", "project-defaults.yml");
    return deployment;
}
 
Example 3
Source File: KeycloakArquillianTest.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Deployment
public static Archive<?> createDeployment() throws Exception {
    JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class, "test.war");
    deployment.addResource(SecuredApplication.class);
    deployment.addResource(SecuredResource.class);
    deployment.addAsResource("wildfly-swarm-keycloak-example-realm.json");
    deployment.addAsResource("keycloak.json");
    deployment.addAsResource("project-default-kc-json.yml", "project-defaults.yml");
    return deployment;
}
 
Example 4
Source File: SwaggerArchivePreparerTest.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithoutSwaggerConf() {
    JAXRSArchive archive = ShrinkWrap.create(JAXRSArchive.class);

    archive.addResource(MyResource.class);
    archive.addResource(MyOtherResource.class);

    SwaggerArchivePreparer preparer = new SwaggerArchivePreparer(archive);
    preparer.process();

    SwaggerArchive swaggerArchive = archive.as(SwaggerArchive.class);

    assertThat(swaggerArchive.getResourcePackages()).containsOnly("com.myapp");
}
 
Example 5
Source File: SwaggerArchivePreparerTest.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@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 6
Source File: SwaggerArchivePreparerTest.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@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 7
Source File: App.java    From drools-workshop with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    Container container = new Container();

    container.start();

    JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class);
    deployment.setContextRoot("/api");
    deployment.addResource(ShoppingCartService.class);
    deployment.addResource(ShoppingCartServiceImpl.class);
    deployment.addClass(HttpStatusExceptionHandler.class);
    deployment.addClass(BusinessException.class);
    deployment.addAllDependencies();
    container.deploy(deployment);
}
 
Example 8
Source File: App.java    From drools-workshop with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    Container container = new Container();

    container.start();

    JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class);
    deployment.setContextRoot("/cep");
    deployment.addResource(TransactionEventService.class);
    deployment.addResource(TransactionEventServiceImpl.class);
    deployment.addClass(HttpStatusExceptionHandler.class);
    deployment.addClass(BusinessException.class);
    deployment.addAllDependencies();
    container.deploy(deployment);
}
 
Example 9
Source File: JAXRSTest.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Deployment
public static Archive createDeployment() throws Exception {
    JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class);
    deployment.addResource(MyResource.class);
    deployment.addAllDependencies();
    deployment.staticContent();
    return deployment;
}
 
Example 10
Source File: SwaggerArquillianTest.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Deployment(testable = false)
public static Archive createDeployment() throws Exception {
    JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class);
    deployment.addResource(Resource.class);
    deployment.addAllDependencies();
    return deployment;
}
 
Example 11
Source File: SwaggerConfiguration.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 4 votes vote down vote up
@Override
public void prepareArchive(Archive<?> a) {
    try {
        // Create a JAX-RS deployment archive
        JAXRSArchive deployment = a.as(JAXRSArchive.class).addModule("io.swagger");

        // Make the deployment a swagger archive
        SwaggerArchive swaggerArchive = deployment.as(SwaggerArchive.class);

        // Get the context root from the deployment and tell swagger about it
        swaggerArchive.setContextRoot(deployment.getContextRoot());

        // If the archive has not been configured with packages for swagger to scan
        // try to be smart about it, and find the topmost package that's not in the
        // org.wildfly.swarm package space
        if (!swaggerArchive.hasResourcePackages()) {
            String packageName = null;
            for (Map.Entry<ArchivePath, Node> entry : deployment.getContent().entrySet()) {
                final ArchivePath key = entry.getKey();
                if (key.get().endsWith(".class")) {
                    String parentPath = key.getParent().get();
                    parentPath = parentPath.replaceFirst("/", "");

                    String parentPackage = parentPath.replaceFirst(".*/classes/", "");
                    parentPackage = parentPackage.replaceAll("/", ".");

                    if (parentPackage.startsWith("org.wildfly.swarm")) {
                        System.out.println("[Swagger] Ignoring swarm package " + parentPackage);
                    } else {
                        packageName = parentPackage;
                        break;
                    }
                }
            }
            if (packageName == null) {
                System.err.println("[Swagger] No eligible packages for Swagger to scan.");
            } else {
                System.out.println("[Swagger] Configuring Swagger with " + packageName);
                swaggerArchive.setResourcePackages(packageName);
            }
        }

        // Now add the swagger resources to our deployment
        deployment.addResource(io.swagger.jaxrs.listing.ApiListingResource.class);
        deployment.addResource(io.swagger.jaxrs.listing.SwaggerSerializers.class);
    } catch (Exception e) {
        e.printStackTrace();
    }
}