Search in sources :

Example 51 with VirtualFile

use of org.jboss.vfs.VirtualFile in project wildfly by wildfly.

the class PersistenceUnitParseProcessor method handleWarDeployment.

private void handleWarDeployment(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (!appClientContainerMode && isWarDeployment(deploymentUnit)) {
        int puCount;
        // ordered list of PUs
        List<PersistenceUnitMetadataHolder> listPUHolders = new ArrayList<PersistenceUnitMetadataHolder>(1);
        // handle WEB-INF/classes/META-INF/persistence.xml
        final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
        VirtualFile persistence_xml = deploymentRoot.getRoot().getChild(WEB_PERSISTENCE_XML);
        parse(persistence_xml, listPUHolders, deploymentUnit);
        PersistenceUnitMetadataHolder holder = normalize(listPUHolders);
        deploymentRoot.putAttachment(PersistenceUnitMetadataHolder.PERSISTENCE_UNITS, holder);
        addApplicationDependenciesOnProvider(deploymentUnit, holder);
        markDU(holder, deploymentUnit);
        puCount = holder.getPersistenceUnits().size();
        // look for persistence.xml in jar files in the META-INF/persistence.xml directory (these are not currently
        // handled as subdeployments)
        List<ResourceRoot> resourceRoots = deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS);
        for (ResourceRoot resourceRoot : resourceRoots) {
            if (resourceRoot.getRoot().getName().toLowerCase(Locale.ENGLISH).endsWith(JAR_FILE_EXTENSION)) {
                listPUHolders = new ArrayList<PersistenceUnitMetadataHolder>(1);
                persistence_xml = resourceRoot.getRoot().getChild(META_INF_PERSISTENCE_XML);
                parse(persistence_xml, listPUHolders, deploymentUnit);
                holder = normalize(listPUHolders);
                resourceRoot.putAttachment(PersistenceUnitMetadataHolder.PERSISTENCE_UNITS, holder);
                addApplicationDependenciesOnProvider(deploymentUnit, holder);
                markDU(holder, deploymentUnit);
                puCount += holder.getPersistenceUnits().size();
            }
        }
        ROOT_LOGGER.tracef("parsed persistence unit definitions for war %s", deploymentRoot.getRootName());
        incrementPersistenceUnitCount(deploymentUnit, puCount);
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) PersistenceUnitMetadataHolder(org.jboss.as.jpa.config.PersistenceUnitMetadataHolder) ArrayList(java.util.ArrayList) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 52 with VirtualFile

use of org.jboss.vfs.VirtualFile in project jersey by jersey.

the class VFSSchemeResourceFinderTest method testClassEnumeration.

/**
     * Test case for JERSEY-2197, JERSEY-2175.
     */
@Test
public void testClassEnumeration() throws Exception {
    // Count actual entries.
    int actualEntries = 0;
    try (JarFile jarFile = new JarFile(jaxRsApiPath)) {
        final Enumeration<JarEntry> entries = jarFile.entries();
        while (entries.hasMoreElements()) {
            final JarEntry entry = entries.nextElement();
            if (entry.getName().endsWith(".class")) {
                actualEntries++;
            }
        }
    }
    // Scan entries using VFS scanner.
    final VirtualFile mountDir = VFS.getChild("content");
    ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
    try (TempFileProvider provider = TempFileProvider.create("test", executor, false);
        Closeable mount = VFS.mountZip(VFS.getChild(jaxRsApiPath), mountDir, provider)) {
        ResourceFinder finder = new VfsSchemeResourceFinderFactory().create(new URI(mountDir.toURI().toString() + "/javax/ws/rs"), true);
        int scannedEntryCount = 0;
        while (finder.hasNext()) {
            // Fetch next entry.
            finder.next();
            try (InputStream classStream = finder.open()) {
                scannedEntryCount++;
            }
        }
        assertThat("Failed to enumerate all contents of javax.ws.rs-api.", scannedEntryCount, equalTo(actualEntries));
    } finally {
        executor.shutdownNow();
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) ResourceFinder(org.glassfish.jersey.server.ResourceFinder) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) InputStream(java.io.InputStream) Closeable(java.io.Closeable) TempFileProvider(org.jboss.vfs.TempFileProvider) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry) URI(java.net.URI) Test(org.junit.Test)

Example 53 with VirtualFile

use of org.jboss.vfs.VirtualFile in project wildfly by wildfly.

the class WSIntegrationProcessorJAXWS_JMS method getWsdlResourceRoot.

private static ResourceRoot getWsdlResourceRoot(final DeploymentUnit unit, final String wsdlPath) {
    final AttachmentList<ResourceRoot> resourceRoots = new AttachmentList<ResourceRoot>(ResourceRoot.class);
    final ResourceRoot root = unit.getAttachment(DEPLOYMENT_ROOT);
    resourceRoots.add(root);
    final AttachmentList<ResourceRoot> otherResourceRoots = unit.getAttachment(RESOURCE_ROOTS);
    if (otherResourceRoots != null) {
        resourceRoots.addAll(otherResourceRoots);
    }
    for (final ResourceRoot resourceRoot : resourceRoots) {
        VirtualFile file = resourceRoot.getRoot().getChild(wsdlPath);
        if (file.exists())
            return resourceRoot;
    }
    return null;
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) AttachmentList(org.jboss.as.server.deployment.AttachmentList)

Example 54 with VirtualFile

use of org.jboss.vfs.VirtualFile in project wildfly by wildfly.

the class WSIntegrationProcessorJAXWS_JMS method deploy.

@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit unit = phaseContext.getDeploymentUnit();
    if (DeploymentTypeMarker.isType(DeploymentType.EAR, unit)) {
        return;
    }
    final List<AnnotationInstance> webServiceAnnotations = getAnnotations(unit, WEB_SERVICE_ANNOTATION);
    // TODO: how about @WebServiceProvider JMS based endpoints?
    //group @WebService annotations in the deployment by wsdl contract location
    Map<String, List<AnnotationInstance>> map = new HashMap<String, List<AnnotationInstance>>();
    for (AnnotationInstance webServiceAnnotation : webServiceAnnotations) {
        final AnnotationValue wsdlLocation = webServiceAnnotation.value(WSDL_LOCATION);
        final AnnotationValue port = webServiceAnnotation.value(PORT_NAME);
        final AnnotationValue service = webServiceAnnotation.value(SERVICE_NAME);
        //support for contract-first development only: pick-up @WebService annotations referencing a provided wsdl contract only
        if (wsdlLocation != null && port != null && service != null) {
            String key = wsdlLocation.asString();
            List<AnnotationInstance> annotations = map.get(key);
            if (annotations == null) {
                annotations = new LinkedList<AnnotationInstance>();
                map.put(key, annotations);
            }
            annotations.add(webServiceAnnotation);
        }
    }
    //extract SOAP-over-JMS 1.0 bindings
    List<JMSEndpointMetaData> list = new LinkedList<JMSEndpointMetaData>();
    if (!map.isEmpty()) {
        for (String wsdlLocation : map.keySet()) {
            try {
                final ResourceRoot resourceRoot = getWsdlResourceRoot(unit, wsdlLocation);
                if (resourceRoot == null)
                    continue;
                final VirtualFile wsdlLocationFile = resourceRoot.getRoot().getChild(wsdlLocation);
                final URL url = wsdlLocationFile.toURL();
                SOAPAddressWSDLParser parser = new SOAPAddressWSDLParser(url);
                for (AnnotationInstance ai : map.get(wsdlLocation)) {
                    String port = ai.value(PORT_NAME).asString();
                    String service = ai.value(SERVICE_NAME).asString();
                    AnnotationValue targetNS = ai.value(TARGET_NAMESPACE);
                    String tns = targetNS != null ? targetNS.asString() : null;
                    QName serviceName = new QName(tns, service);
                    QName portName = new QName(tns, port);
                    String soapAddress = parser.filterSoapAddress(serviceName, portName, SOAPAddressWSDLParser.SOAP_OVER_JMS_NS);
                    if (soapAddress != null) {
                        ClassInfo webServiceClassInfo = (ClassInfo) ai.target();
                        String beanClassName = webServiceClassInfo.name().toString();
                        //service name ?
                        list.add(new JMSEndpointMetaData(beanClassName, port, beanClassName, wsdlLocation, soapAddress));
                    }
                }
            } catch (Exception ignore) {
                WSLogger.ROOT_LOGGER.cannotReadWsdl(wsdlLocation);
            }
        }
    }
    unit.putAttachment(JMS_ENDPOINT_METADATA_KEY, new JMSEndpointsMetaData(list));
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) JMSEndpointsMetaData(org.jboss.wsf.spi.metadata.jms.JMSEndpointsMetaData) LinkedList(java.util.LinkedList) URL(java.net.URL) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) JMSEndpointMetaData(org.jboss.wsf.spi.metadata.jms.JMSEndpointMetaData) AnnotationValue(org.jboss.jandex.AnnotationValue) LinkedList(java.util.LinkedList) AttachmentList(org.jboss.as.server.deployment.AttachmentList) List(java.util.List) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) SOAPAddressWSDLParser(org.jboss.ws.common.deployment.SOAPAddressWSDLParser) AnnotationInstance(org.jboss.jandex.AnnotationInstance) ClassInfo(org.jboss.jandex.ClassInfo)

Example 55 with VirtualFile

use of org.jboss.vfs.VirtualFile in project wildfly by wildfly.

the class AbstractDeploymentModelBuilder method newDeployment.

/**
     * Creates new Web Service deployment.
     *
     * @param unit deployment unit
     * @return archive deployment
     */
private ArchiveDeployment newDeployment(final DeploymentUnit unit) {
    WSLogger.ROOT_LOGGER.tracef("Creating new unified WS deployment model for %s", unit);
    final ResourceRoot deploymentRoot = unit.getAttachment(Attachments.DEPLOYMENT_ROOT);
    final VirtualFile root = deploymentRoot != null ? deploymentRoot.getRoot() : null;
    final ClassLoader classLoader;
    final Module module = unit.getAttachment(Attachments.MODULE);
    if (module == null) {
        classLoader = unit.getAttachment(CLASSLOADER_KEY);
        if (classLoader == null) {
            throw WSLogger.ROOT_LOGGER.classLoaderResolutionFailed(unit);
        }
    } else {
        classLoader = module.getClassLoader();
    }
    ArchiveDeployment parentDep = null;
    if (unit.getParent() != null) {
        final Module parentModule = unit.getParent().getAttachment(Attachments.MODULE);
        if (parentModule == null) {
            throw WSLogger.ROOT_LOGGER.classLoaderResolutionFailed(deploymentRoot);
        }
        WSLogger.ROOT_LOGGER.tracef("Creating new unified WS deployment model for %s", unit.getParent());
        parentDep = this.newDeployment(null, unit.getParent().getName(), parentModule.getClassLoader(), null);
    }
    final UnifiedVirtualFile uvf = root != null ? new VirtualFileAdaptor(root) : new ResourceLoaderAdapter(classLoader);
    final ArchiveDeployment dep = this.newDeployment(parentDep, unit.getName(), classLoader, uvf);
    //add an AnnotationInfo attachment that uses composite jandex index
    dep.addAttachment(AnnotationsInfo.class, new JandexAnnotationsInfo(unit));
    return dep;
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) UnifiedVirtualFile(org.jboss.wsf.spi.deployment.UnifiedVirtualFile) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) ArchiveDeployment(org.jboss.wsf.spi.deployment.ArchiveDeployment) UnifiedVirtualFile(org.jboss.wsf.spi.deployment.UnifiedVirtualFile) VirtualFileAdaptor(org.jboss.as.webservices.util.VirtualFileAdaptor) ResourceLoaderAdapter(org.jboss.ws.common.ResourceLoaderAdapter) Module(org.jboss.modules.Module)

Aggregations

VirtualFile (org.jboss.vfs.VirtualFile)93 ResourceRoot (org.jboss.as.server.deployment.module.ResourceRoot)36 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)29 InputStream (java.io.InputStream)28 IOException (java.io.IOException)23 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)22 Test (org.junit.Test)18 File (java.io.File)16 Closeable (java.io.Closeable)12 URI (java.net.URI)10 HashSet (java.util.HashSet)10 XMLStreamReader (javax.xml.stream.XMLStreamReader)10 Index (org.jboss.jandex.Index)10 SuffixMatchFilter (org.jboss.vfs.util.SuffixMatchFilter)10 ArrayList (java.util.ArrayList)9 XMLStreamException (javax.xml.stream.XMLStreamException)9 WarMetaData (org.jboss.as.web.common.WarMetaData)9 Indexer (org.jboss.jandex.Indexer)8 AnnotationRepository (org.jboss.jca.common.spi.annotations.repository.AnnotationRepository)8 XMLInputFactory (javax.xml.stream.XMLInputFactory)7