Java Code Examples for org.jboss.shrinkwrap.api.spec.WebArchive#get()

The following examples show how to use org.jboss.shrinkwrap.api.spec.WebArchive#get() . These examples are extracted from open source projects. 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
@Override
public void process(Archive<?> applicationArchive, TestClass testClass) {
    if (applicationArchive instanceof WebArchive) {
        WebArchive war = applicationArchive.as(WebArchive.class);
        Node libNode = war.get(PATH_LIBRARY);
        if (libNode != null) {
            for (Node child : libNode.getChildren()) {
                Asset childAsset = child.getAsset();
                if (childAsset instanceof ArchiveAsset) {
                    ArchiveAsset archiveAsset = (ArchiveAsset) childAsset;
                    if (archiveAsset.getArchive() instanceof JavaArchive) {
                        JavaArchive libArchive = (JavaArchive) archiveAsset.getArchive();
                        libArchive.deleteClass(testClass.getName());
                    }
                }
            }
        }
    }
}
 
Example 2
public void process(WebArchive webArchive) {
    Node metaInfConfig = webArchive.get("/META-INF/microprofile-config.properties");
    
    if (metaInfConfig == null) {
        if (webArchive.get("/WEB-INF/classes/publicKey.pem") != null) {
            webArchive.addAsResource("META-INF/public-key.properties", "META-INF/microprofile-config.properties");
        } else {
            webArchive.addAsResource("META-INF/microprofile-config.properties");
        }
    } else {
        webArchive.addAsResource(metaInfConfig.getAsset(), "META-INF/microprofile-config.properties");
        webArchive.delete("/META-INF/microprofile-config.properties");
    }
    
    System.out.printf("WebArchive: %s\n", webArchive.toString(true));
}
 
Example 3
protected void handleWebArchive(WebArchive war) {
    final Node lib = war.get("WEB-INF/lib");
    if (lib != null) {
        final Set<Node> libs = lib.getChildren();
        for (Node jar : libs) {
            if (jar.getPath().get().contains("appengine-api"))
                return;
        }
    }

    // do not add GAE jar; e.g. CapeDwarf can work off GAE module
    boolean ignoreGaeJar = Boolean.getBoolean("ignore.gae.jar");
    if (ignoreGaeJar == false) {
        war.addAsLibraries(Maven.resolver()
            .loadPomFromFile("pom.xml")
            .resolve("com.google.appengine:appengine-api-1.0-sdk")
            .withTransitivity()
            .as(File.class)
        );
    }
}
 
Example 4
Source Project: quarkus   File: JwtTckArchiveProcessor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void process(Archive<?> applicationArchive, TestClass testClass) {
    if (System.getProperty(KEY_NAME) != null) {
        System.clearProperty(KEY_NAME);
    }

    if (!(applicationArchive instanceof WebArchive)) {
        return;
    }

    WebArchive war = WebArchive.class.cast(applicationArchive);
    Node configProps = war.get("/META-INF/microprofile-config.properties");
    Node publicKeyNode = war.get("/WEB-INF/classes/publicKey.pem");
    Node publicKey4kNode = war.get("/WEB-INF/classes/publicKey4k.pem");

    if (configProps == null && publicKeyNode == null && publicKey4kNode == null) {
        return;
    }

    if (configProps == null) {
        if (publicKey4kNode != null) {
            addPublicKeyToEnv(publicKey4kNode);
        } else if (publicKeyNode != null) {
            addPublicKeyToEnv(publicKeyNode);
        }
    }
}
 
Example 5
protected void doBefore(MergeLifecycleEvent event) {
    Class<?> clazz = event.getCallerClass();
    if (clazz != null && clazz.getName().contains("tck.datastore") == false) {
        WebArchive war = event.getDeployment();
        if (war.get("WEB-INF/classes/capedwarf-compatibility.properties") == null) {
            Properties properties = new Properties();
            properties.put("disable.metadata", Boolean.TRUE.toString());
            CapeDwarfArchiveProcessor.addCompatibility(war, properties);
        }
    }
}
 
Example 6
@Override
protected void handleWebArchive(WebArchive war) {
    Node node = war.get(WEB_XML_PATH);
    if (node == null) {
        throw new IllegalStateException("No web.xml in .war: " + war.toString(true));
    }

    war.addClass(GetLoginUrlServlet.class);

    WebAppDescriptor webXml = Descriptors.importAs(WebAppDescriptor.class).fromStream(node.getAsset().openStream());
    war.delete(WEB_XML_PATH); // delete first, so we can re-add
    webXml.servlet(UserLogin.USER_LOGIN_SERVLET_PATH + "-servlet", GetLoginUrlServlet.class.getName(), new String[]{"/" + UserLogin.USER_LOGIN_SERVLET_PATH});
    war.setWebXML(new StringAsset(webXml.exportAsString()));
}
 
Example 7
@Override
public void process(Archive<?> appArchive, TestClass testClass) {
    if (!(appArchive instanceof WebArchive)) {
        return;
    }
    log.info("Preparing archive: " + appArchive);
    // Only augment archives with a node indicating a MP-JWT test
    WebArchive war = WebArchive.class.cast(appArchive);
    Node configProps = war.get("/META-INF/microprofile-config.properties");
    Node publicKeyNode = war.get("/WEB-INF/classes/publicKey.pem");
    Node publicKey4kNode = war.get("/WEB-INF/classes/publicKey4k.pem");
    Node mpJWT = war.get("MP-JWT");
    if (configProps == null && publicKeyNode == null && publicKey4kNode == null && mpJWT == null) {
        return;
    }

    if (configProps != null) {
        StringWriter sw = new StringWriter();
        InputStream is = configProps.getAsset().openStream();
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(is))) {
            String line = reader.readLine();
            while(line != null) {
                sw.write(line);
                sw.write('\n');
                line = reader.readLine();
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
        log.info("mp-config.props: "+sw.toString());
    } else {
        log.info("NO mp-config.props, adding /META-INF/MP-JWT-SIGNER");
        if(publicKey4kNode != null) {
            war.addAsManifestResource(publicKey4kNode.getAsset(), "MP-JWT-SIGNER");
        } else if(publicKeyNode != null) {
            war.addAsManifestResource(publicKeyNode.getAsset(), "MP-JWT-SIGNER");
        }
    }
    // This allows for test specific web.xml files. Generally this should not be needed.
    String warName = war.getName();
    String webXmlName = "/WEB-INF/" + warName + ".xml";
    URL webXml = WFSwarmWarArchiveProcessor.class.getResource(webXmlName);
    if (webXml != null) {
        war.setWebXML(webXml);
    }
    //
    String projectDefaults = "project-defaults.yml";
    war.addAsResource(projectDefaults, "/project-defaults.yml")
            .addAsWebInfResource("jwt-roles.properties", "classes/jwt-roles.properties")
    ;
    log.info("Augmented war: \n"+war.toString(true));
}
 
Example 8
@Test
public void testDeployment() throws IOException {
  WebArchive webArchive = ShrinkWrap.create( WebArchive.class, "test-acrhive" );

  UrlRewriteRulesDescriptorImpl rewriteRules = new UrlRewriteRulesDescriptorImpl();

  Map<String,String> providerParams = new HashMap<>();
  providerParams.put( "test-host-external", "test-host-internal" );
  Provider provider = new Provider();
  provider.setEnabled( true );
  provider.setName( "hostmap" );
  provider.setParams(  providerParams );

  DeploymentContext context = EasyMock.createNiceMock( DeploymentContext.class );
  EasyMock.expect( context.getDescriptor( "rewrite" ) ).andReturn( rewriteRules ).anyTimes();
  EasyMock.expect( context.getWebArchive() ).andReturn( webArchive ).anyTimes();
  EasyMock.replay( context );

  HostmapDeploymentContributor contributor = new HostmapDeploymentContributor();

  assertThat( contributor.getRole(), is("hostmap") );
  assertThat( contributor.getName(), is( "static" ) );

  // Just make sure it doesn't blow up.
  contributor.contributeFilter( null, null, null, null, null );

  // Just make sure it doesn't blow up.
  contributor.initializeContribution( context );

  contributor.contributeProvider( context, provider );

  HostmapFunctionDescriptor funcDesc = rewriteRules.getFunction( "hostmap" );
  assertThat( funcDesc.config(), is( "/WEB-INF/hostmap.txt" ) );

  Node node = webArchive.get( "/WEB-INF/hostmap.txt" );
  String asset = IOUtils.toString( node.getAsset().openStream(), StandardCharsets.UTF_8 );
  assertThat( asset, containsString( "test-host-external=test-host-internal" ) );

  // Just make sure it doesn't blow up.
  contributor.finalizeContribution( context );

}
 
Example 9
Source Project: knox   File: DeploymentFactoryFuncTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test( timeout = MEDIUM_TIMEOUT )
public void testDeploymentWithServicesAndApplications() throws Exception {
  LOG_ENTER();
  GatewayTestConfig config = new GatewayTestConfig();
  File targetDir = new File(System.getProperty("user.dir"), "target");
  File gatewayDir = new File(targetDir, "gateway-home-" + UUID.randomUUID());
  gatewayDir.mkdirs();
  config.setGatewayHomeDir(gatewayDir.getAbsolutePath());
  File deployDir = new File(config.getGatewayDeploymentDir());
  deployDir.mkdirs();
  URL serviceUrl = TestUtils.getResourceUrl( DeploymentFactoryFuncTest.class, "test-apps/minimal-test-app/service.xml" );
  File serviceFile = new File( serviceUrl.toURI() );
  File appsDir = serviceFile.getParentFile().getParentFile();
  config.setGatewayApplicationsDir(appsDir.getAbsolutePath());

  DefaultGatewayServices srvcs = new DefaultGatewayServices();
  Map<String, String> options = new HashMap<>();
  options.put("persist-master", "false");
  options.put("master", "password");
  try {
    DeploymentFactory.setGatewayServices(srvcs);
    srvcs.init(config, options);
  } catch (ServiceLifecycleException e) {
    e.printStackTrace(); // I18N not required.
  }

  Topology topology = new Topology();
  topology.setName( "test-topology" );

  Application app;

  topology.setName( "test-cluster" );
  Service service = new Service();
  service.setRole( "WEBHDFS" );
  service.addUrl( "http://localhost:50070/test-service-url" );
  topology.addService( service );

  app = new Application();
  app.setName( "minimal-test-app" );
  app.addUrl( "/minimal-test-app-path-one" );
  topology.addApplication( app );

  app.setName( "minimal-test-app" );
  app.addUrl( "/minimal-test-app-path-two" );
  topology.addApplication( app );

  EnterpriseArchive archive = DeploymentFactory.createDeployment( config, topology );
  assertThat( archive, notNullValue() );

  Document doc;
  org.jboss.shrinkwrap.api.Node node;

  node = archive.get( "META-INF/topology.xml" );
  assertThat( "Find META-INF/topology.xml", node, notNullValue() );
  doc = XmlUtils.readXml( node.getAsset().openStream() );
  assertThat( "Parse META-INF/topology.xml", doc, notNullValue() );

  node = archive.get( "%2F" );
  assertThat( "Find %2F", node, notNullValue() );
  node = archive.get( "%2F/WEB-INF/gateway.xml" );
  assertThat( "Find %2F/WEB-INF/gateway.xml", node, notNullValue() );
  doc = XmlUtils.readXml( node.getAsset().openStream() );
  assertThat( "Parse %2F/WEB-INF/gateway.xml", doc, notNullValue() );

  WebArchive war = archive.getAsType( WebArchive.class, "%2Fminimal-test-app-path-one" );
  assertThat( "Find %2Fminimal-test-app-path-one", war, notNullValue() );
  node = war.get( "/WEB-INF/gateway.xml" );
  assertThat( "Find %2Fminimal-test-app-path-one/WEB-INF/gateway.xml", node, notNullValue() );
  doc = XmlUtils.readXml( node.getAsset().openStream() );
  assertThat( "Parse %2Fminimal-test-app-path-one/WEB-INF/gateway.xml", doc, notNullValue() );

  war = archive.getAsType( WebArchive.class, "%2Fminimal-test-app-path-two" );
  assertThat( "Find %2Fminimal-test-app-path-two", war, notNullValue() );
  node = war.get( "/WEB-INF/gateway.xml" );
  assertThat( "Find %2Fminimal-test-app-path-two/WEB-INF/gateway.xml", node, notNullValue() );
  doc = XmlUtils.readXml( node.getAsset().openStream() );
  assertThat( "Parse %2Fminimal-test-app-path-two/WEB-INF/gateway.xml", doc, notNullValue() );

  LOG_EXIT();
}