org.wildfly.swarm.jaxrs.JAXRSArchive Java Examples

The following examples show how to use org.wildfly.swarm.jaxrs.JAXRSArchive. 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: DefaultApplicationDeploymentProcessor.java    From thorntail with Apache License 2.0 6 votes vote down vote up
@Override
public void process() throws Exception {
    if (this.deploymentContext != null && this.deploymentContext.isImplicit()) {
        return;
    }

    if (!archive.getName().endsWith(".war")) {
        return;
    }

    if (hasApplicationPathOrServletMapping(archive)) {
        return;
    }

    if (applicationPath.isExplicit()) {
        addGeneratedApplication(archive.as(JAXRSArchive.class));
    }
}
 
Example #3
Source File: FractionUsageAnalyzerTest.java    From thorntail with Apache License 2.0 6 votes vote down vote up
@Test
public void testFractionMatching() throws Exception {
    JAXRSArchive archive = ShrinkWrap.create(JAXRSArchive.class);
    archive.addClass(MyResource.class);
    FractionUsageAnalyzer analyzer = new FractionUsageAnalyzer();

    final File out = Files.createTempFile(archive.getName(), ".war").toFile();
    archive.as(ZipExporter.class).exportTo(out, true);

    analyzer.source(out);
    assertThat(analyzer.detectNeededFractions()
                       .stream()
                       .filter(fd -> fd.getArtifactId().equals("jaxrs"))
                       .count())
            .isEqualTo(1);

    out.delete();
}
 
Example #4
Source File: DefaultApplicationDeploymentProcessorTest.java    From thorntail with Apache License 2.0 6 votes vote down vote up
@Test
public void testApplicationPathAnnotation_None_And_ChangeThePath() throws Exception {
    String applicationPath = "/api";

    JAXRSArchive archive = ShrinkWrap.create(JAXRSArchive.class);
    DefaultApplicationDeploymentProcessor processor = new DefaultApplicationDeploymentProcessor(archive);
    processor.applicationPath.set(applicationPath);

    processor.process();

    try (InputStream in = archive.get(PATH).getAsset().openStream()) {
        ClassReader reader = new ClassReader(in);
        ClassNode node = new ClassNode();

        reader.accept(node, 0);
        List<AnnotationNode> visibleAnnotations = node.visibleAnnotations;

        assertThat(visibleAnnotations.size()).isEqualTo(1);
        assertThat(visibleAnnotations.get(0).values).contains(applicationPath);
    } catch (IOException ignored) {
    }
}
 
Example #5
Source File: DroolsDeploymentProducer.java    From thorntail with Apache License 2.0 6 votes vote down vote up
@Produces
public Archive droolsWar() throws Exception {
    if (System.getProperty("org.drools.server.swarm.web.conf") == null) {
        //Path dir = Files.createTempDirectory("swarm-keycloak-config");
        File dir = TempFileManager.INSTANCE.newTempDirectory("swarm-drools-web-config", ".d");
        System.setProperty("org.drools.server.swarm.conf", dir.getAbsolutePath());
        Files.copy(getClass().getClassLoader().getResourceAsStream("config/web/web.xml"),
                dir.toPath().resolve("web.xml"),
                StandardCopyOption.REPLACE_EXISTING);
        Files.copy(getClass().getClassLoader().getResourceAsStream("config/web/jboss-web.xml"),
                dir.toPath().resolve("jboss-web.xml"),
                StandardCopyOption.REPLACE_EXISTING);
        configFolder = dir.toPath().toString();
    }

    DroolsMessages.MESSAGES.configurationDirectory(configFolder);

    JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class, "drools-server.war");
    deployment.addAllDependencies();

    deployment.addAsWebInfResource(new File(configFolder + "/web.xml"), "web.xml");
    deployment.addAsWebInfResource(new File(configFolder + "/jboss-web.xml"), "jboss-web.xml");

    return deployment;
}
 
Example #6
Source File: TracingInstaller.java    From thorntail with Apache License 2.0 6 votes vote down vote up
@Override
public void process() throws Exception {
  if (archive.getName().endsWith(".war")) {
    JAXRSArchive jaxrsArchive = archive.as(JAXRSArchive.class);

    WebXmlAsset webXmlAsset = jaxrsArchive.findWebXmlAsset();

    webXmlAsset.addListener(CONTEXT_LISTENER);

    String userProviders = webXmlAsset.getContextParam(RESTEASY_PROVIDERS);

    String providers =
            userProviders == null
                    ? TRACING_FEATURE
                    : userProviders + "," + TRACING_FEATURE;


    webXmlAsset.setContextParam(RESTEASY_PROVIDERS, providers);
  }
}
 
Example #7
Source File: App.java    From drools-workshop with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    Container container = new Container();

    JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class);
    deployment.as(TopologyArchive.class).advertise("restaurantService");
    deployment.setContextRoot("/api");
    deployment.addPackages(true, "org.jboss.shrinkwrap.api");
    deployment.addAsLibrary(container.createDefaultDeployment());
    deployment.addAllDependencies();
    container.start();
    container.deploy(deployment);

    Topology lookup = Topology.lookup();
    lookup.addListener(new TopologyListener() {
        @Override
        public void onChange(Topology tplg) {
            System.out.println(">>> Delivery Service: The Topology Has Changed!");
            printTopology(lookup);
        }
    });
    
    printTopology(lookup);

}
 
Example #8
Source File: App.java    From drools-workshop with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    Container container = new Container();

    JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class);
    deployment.as(TopologyArchive.class).advertise("deliveryService");
    deployment.setContextRoot("/api");
    deployment.addPackages(true, "org.jboss.shrinkwrap.api");
    deployment.addAsLibrary(container.createDefaultDeployment());
    deployment.addAllDependencies();
    container.start();
    container.deploy(deployment);
    
    Topology lookup = Topology.lookup();
    lookup.addListener(new TopologyListener() {
        @Override
        public void onChange(Topology tplg) {
            System.out.println(">>> Delivery Service: The Topology Has Changed!");
            printTopology(lookup);
        }
    });
    
    printTopology(lookup);
    
}
 
Example #9
Source File: FractionUsageAnalyzerTest.java    From thorntail with Apache License 2.0 6 votes vote down vote up
@Test
public void testExplodedFractionMatching() throws Exception {
    JAXRSArchive archive = ShrinkWrap.create(JAXRSArchive.class);
    archive.addClass(MyResource.class);
    FractionUsageAnalyzer analyzer = new FractionUsageAnalyzer();

    File dirFile = TempFileManager.INSTANCE.newTempDirectory("fractionusagetest", null);
    archive.as(ExplodedExporter.class).exportExplodedInto(dirFile);

    analyzer.source(dirFile);
    assertThat(analyzer.detectNeededFractions()
                       .stream()
                       .filter(fd -> fd.getArtifactId().equals("jaxrs"))
                       .count())
            .isEqualTo(1);
}
 
Example #10
Source File: App.java    From drools-workshop with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    Container container = new Container();

    JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class);
    deployment.as(TopologyArchive.class).advertise("foodService");
    deployment.setContextRoot("/api");
    deployment.addPackages(true, "org.jboss.shrinkwrap.api");
    deployment.addAsLibrary(container.createDefaultDeployment());
    deployment.addAllDependencies();
    container.start();
    container.deploy(deployment);
    
    Topology lookup = Topology.lookup();
    lookup.addListener(new TopologyListener() {
        @Override
        public void onChange(Topology tplg) {
            System.out.println(">>> Delivery Service: The Topology Has Changed!");
            printTopology(lookup);
        }
    });
    
    printTopology(lookup);
    
}
 
Example #11
Source File: DefaultApplicationDeploymentProcessorTest.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Test
public void testMalformedWebXmlApplicationServletMappingAbsent() throws Exception {
    JAXRSArchive archive = ShrinkWrap.create(JAXRSArchive.class);
    archive.addClass(MyResource.class);
    archive.setWebXML(new StringAsset("blablabla"));
    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);
    assertThat(generated).isNotNull();
}
 
Example #12
Source File: JAXRSArchiveImpl.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new JAXRS Archive with any type storage engine as backing.
 *
 * @param delegate The storage backing.
 */
public JAXRSArchiveImpl(Archive<?> delegate) {
    super(JAXRSArchive.class, delegate);

    setDefaultContextRoot();
    addGeneratedApplication();
    addExceptionMapperForFavicon();
}
 
Example #13
Source File: DefaultApplicationDeploymentProcessorTest.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@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 #14
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 #15
Source File: DefaultApplicationDeploymentProcessorTest.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Test
public void testApplicationPathAnnotation_DirectlyInArchive() throws Exception {
    JAXRSArchive archive = ShrinkWrap.create(JAXRSArchive.class);
    archive.addClass(MySampleApplication.class);
    DefaultApplicationDeploymentProcessor processor = new DefaultApplicationDeploymentProcessor(archive);

    processor.process();

    Node generated = archive.get(PATH);
    assertThat(generated).isNull();
}
 
Example #16
Source File: DefaultApplicationDeploymentProcessorTest.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Test
public void testApplicationPathAnnotation_InWebInfLibArchive() throws Exception {
    JavaArchive subArchive = ShrinkWrap.create(JavaArchive.class, "mysubarchive.jar");
    subArchive.addClass(MySampleApplication.class);
    JAXRSArchive archive = ShrinkWrap.create(JAXRSArchive.class);
    archive.addAsLibrary(subArchive);
    DefaultApplicationDeploymentProcessor processor = new DefaultApplicationDeploymentProcessor(archive);

    processor.process();

    Node generated = archive.get(PATH);
    assertThat(generated).isNull();
}
 
Example #17
Source File: DefaultApplicationDeploymentProcessorTest.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Test
public void testWebXmlApplicationServletMappingPresent() throws Exception {
    JAXRSArchive archive = ShrinkWrap.create(JAXRSArchive.class);
    archive.addClass(MyResource.class);
    archive.setWebXML(new StringAsset(
            "<web-app><servlet-mapping><servlet-name>Faces Servlet</servlet-name><url-pattern>*.jsf</url-pattern></servlet-mapping><servlet-mapping><servlet-name>javax.ws.rs.core.Application</servlet-name><url-pattern>/foo/*</url-pattern></servlet-mapping></web-app>"));
    DefaultApplicationDeploymentProcessor processor = new DefaultApplicationDeploymentProcessor(archive);

    processor.process();

    Node generated = archive.get(PATH);
    assertThat(generated).isNull();
}
 
Example #18
Source File: DefaultApplicationDeploymentProcessorTest.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Test
public void testWebXmlApplicationServletMappingAbsent() throws Exception {
    JAXRSArchive archive = ShrinkWrap.create(JAXRSArchive.class);
    archive.addClass(MyResource.class);
    archive.setWebXML(new StringAsset("<web-app><display-name>Foo</display-name></web-app>"));
    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);
    assertThat(generated).isNotNull();
}
 
Example #19
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 #20
Source File: ServiceClientProcessor.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@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 #21
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 #22
Source File: DefaultApplicationDeploymentProcessor.java    From thorntail with Apache License 2.0 5 votes vote down vote up
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: MPJWTAuthExtensionArchivePreparer.java    From thorntail with Apache License 2.0 5 votes vote down vote up
private void addFilterRegistrar() {
    JAXRSArchive jaxrsArchive = archive.as(JAXRSArchive.class);
    WebXmlAsset webXmlAsset = jaxrsArchive.findWebXmlAsset();
    String userProviders = webXmlAsset.getContextParam(RESTEASY_PROVIDERS);

    String filterRegistrar = JWTAuthorizationFilterRegistrar.class.getName();

    String providers =
            userProviders == null
                    ? filterRegistrar
                    : userProviders + "," + filterRegistrar;

    webXmlAsset.setContextParam(RESTEASY_PROVIDERS, providers);
}
 
Example #24
Source File: WebXMLAdapter.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Override
public void process() {
    if (archive.getName().endsWith(".war")) {
        JAXRSArchive jaxrsArchive = archive.as(JAXRSArchive.class);
        jaxrsArchive.findWebXmlAsset().setContextParam(
                "resteasy.providers", SERVER_SIDE_FILTERS
        );
    }
}
 
Example #25
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 #26
Source File: DefaultJAXRSWarDeploymentFactory.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Override
public Archive create() throws Exception {
    Archive archive = super.create();
    // SWARM-917: only implicitly consider it a JAXRS archive if it happens to actually be one,
    // in order to prevent gratuitous creation of @ApplicationPath stuff just because
    // jaxrs-api classes are on the classpath.
    if (JAXRSArchive.isJAXRS(archive)) {
        archive = archive.as(JAXRSArchive.class).staticContent();
        setup(archive);
    }
    return archive;
}
 
Example #27
Source File: Main.java    From thorntail with Apache License 2.0 5 votes vote down vote up
public static void main(String... args) throws Exception {
    swarm = new Swarm(args);
    swarm.start();
    JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class, "myapp.war");
    deployment.addClass(MyResource.class);
    deployment.setContextRoot("rest");
    deployment.addAllDependencies();
    swarm.deploy(deployment);
}
 
Example #28
Source File: KeycloakMicroprofileJwtWithoutJsonTest.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Deployment
public static Archive<?> createDeployment() {
    JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class, "test.war");
    deployment.addClass(SecuredApplication.class);
    deployment.addClass(SecuredResource.class);
    deployment.addAsResource("project-no-keycloak-json.yml", "project-defaults.yml");
    return deployment;
}
 
Example #29
Source File: KeycloakMicroprofileJwtTest.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Deployment
public static Archive<?> createDeployment() {
    JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class, "test.war");
    deployment.addClass(SecuredApplication.class);
    deployment.addClass(SecuredResource.class);
    deployment.addAsWebInfResource("keycloak.json");
    deployment.addAsResource("project-defaults.yml");
    return deployment;
}
 
Example #30
Source File: JWTAndOpentracingIntegrationTest.java    From thorntail with Apache License 2.0 5 votes vote down vote up
protected static JAXRSArchive initDeployment() {
    JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class);
    deployment.addClass(JWTTestResource.class);
    deployment.addClass(TestApplication.class);
    deployment.addAsManifestResource(new ClassLoaderAsset("keys/public-key.pem"), "/MP-JWT-SIGNER");
    return deployment;
}