@SuppressWarnings("unchecked") private String findRelatedWebApp(final AppModule appModule, final String rootUrl) { for (final WebModule webModule : appModule.getWebModules()) { final List<URL> pXmls = (List<URL>) webModule.getAltDDs().get(DeploymentLoader.EAR_WEBAPP_PERSISTENCE_XML_JARS); if (pXmls != null) { for (final URL url : pXmls) { if (url.toExternalForm().contains(rootUrl)) { return webModule.getModuleId(); } } } } return null; }
@SuppressWarnings("unchecked") private String findRelatedWebApp(final AppModule appModule, final String rootUrl) { for (final WebModule webModule : appModule.getWebModules()) { final List<URL> pXmls = (List<URL>) webModule.getAltDDs().get(DeploymentLoader.EAR_WEBAPP_PERSISTENCE_XML_JARS); if (pXmls != null) { for (final URL url : pXmls) { if (url.toExternalForm().contains(rootUrl)) { return webModule.getModuleId(); } } } } return null; }
webFragmentUrls = (List<URL>) webModule.getAltDDs().get(WEB_FRAGMENT_XML); } catch (final ClassCastException e) { final Object value = webModule.getAltDDs().get(WEB_FRAGMENT_XML); webFragmentUrls = new ArrayList<URL>(); webFragmentUrls.add(URL.class.cast(value)); webModule.getAltDDs().put(WEB_FRAGMENT_XML, webFragmentUrls); webModule.getAltDDs().put(WEB_FRAGMENT_XML, webFragmentUrls);
webFragmentUrls = (List<URL>) webModule.getAltDDs().get(WEB_FRAGMENT_XML); } catch (final ClassCastException e) { final Object value = webModule.getAltDDs().get(WEB_FRAGMENT_XML); webFragmentUrls = new ArrayList<URL>(); webFragmentUrls.add(URL.class.cast(value)); webModule.getAltDDs().put(WEB_FRAGMENT_XML, webFragmentUrls); webModule.getAltDDs().put(WEB_FRAGMENT_XML, webFragmentUrls);
private SunWebApp getSunWebApp(WebModule webModule) { Object altDD = webModule.getAltDDs().get("sun-web.xml"); if (altDD instanceof String) { try { altDD = JaxbSun.unmarshal(SunWebApp.class, new ByteArrayInputStream(((String)altDD).getBytes())); } catch (Exception e) { // todo warn about not being able to parse sun descriptor } } if (altDD instanceof URL) { try { altDD = JaxbSun.unmarshal(SunWebApp.class, ((URL)altDD).openStream()); } catch (Exception e) { e.printStackTrace(); // todo warn about not being able to parse sun descriptor } } if (altDD instanceof SunWebApp) { return (SunWebApp) altDD; } return null; }
private SunWebApp getSunWebApp(final WebModule webModule) { Object altDD = webModule.getAltDDs().get("sun-web.xml"); if (altDD instanceof String) { try { altDD = JaxbSun.unmarshal(SunWebApp.class, new ByteArrayInputStream(((String) altDD).getBytes())); } catch (final Exception e) { // todo warn about not being able to parse sun descriptor } } if (altDD instanceof URL) { try { altDD = JaxbSun.unmarshal(SunWebApp.class, IO.read((URL) altDD)); } catch (final Exception e) { e.printStackTrace(); // todo warn about not being able to parse sun descriptor } } if (altDD instanceof SunWebApp) { return (SunWebApp) altDD; } return null; }
private SunWebApp getSunWebApp(final WebModule webModule) { Object altDD = webModule.getAltDDs().get("sun-web.xml"); if (altDD instanceof String) { try { altDD = JaxbSun.unmarshal(SunWebApp.class, new ByteArrayInputStream(((String) altDD).getBytes())); } catch (final Exception e) { // todo warn about not being able to parse sun descriptor } } if (altDD instanceof URL) { try { altDD = JaxbSun.unmarshal(SunWebApp.class, IO.read((URL) altDD)); } catch (final Exception e) { e.printStackTrace(); // todo warn about not being able to parse sun descriptor } } if (altDD instanceof SunWebApp) { return (SunWebApp) altDD; } return null; }
private void addBeansXmls(final WebModule webModule) { final List<URL> urls = webModule.getScannableUrls(); // parent returns nothing when calling getresources because we don't want here to be fooled by maven classloader final URLClassLoader loader = new URLClassLoader(urls.toArray(new URL[urls.size()]), new EmptyResourcesClassLoader()); final ArrayList<URL> xmls; try { xmls = Collections.list(loader.getResources("META-INF/beans.xml")); xmls.add((URL) webModule.getAltDDs().get("beans.xml")); } catch (final IOException e) { return; } Beans complete = null; for (final URL url : xmls) { if (url == null) { continue; } complete = mergeBeansXml(complete, url); } if (complete != null) { complete.removeDuplicates(); } webModule.getAltDDs().put("beans.xml", complete); }
public static void addBeansXmls(final WebModule webModule) { final List<URL> urls = webModule.getScannableUrls(); // parent returns nothing when calling getresources because we don't want here to be fooled by maven classloader final URLClassLoader loader = new URLClassLoader(urls.toArray(new URL[urls.size()]), new EmptyResourcesClassLoader()); final List<URL> xmls = new LinkedList<>(); try { final URL e = (URL) webModule.getAltDDs().get("beans.xml"); if (e != null) { // first! xmls.add(e); } xmls.addAll(Collections.list(loader.getResources("META-INF/beans.xml"))); } catch (final IOException e) { return; } final CompositeBeans complete = new CompositeBeans(); for (final URL url : xmls) { if (url == null) { continue; } mergeBeansXml(complete, url); } if (!complete.getDiscoveryByUrl().isEmpty()) { complete.removeDuplicates(); } webModule.getAltDDs().put("beans.xml", complete); }
private boolean isIn(final PersistenceUnit value, final WebModule war) { final Collection<URL> urls = (Collection<URL>) war.getAltDDs().get(DeploymentLoader.EAR_WEBAPP_PERSISTENCE_XML_JARS); if (urls == null || urls.isEmpty()) { return false; } final Collection<String> strUrls = new ArrayList<String>(); for (final URL url : urls) { strUrls.add(URLs.toFilePath(url)); } for (final PersistenceModule persistenceModule : module.getPersistenceModules()) { final Persistence persistence = persistenceModule.getPersistence(); final String rootUrl; try { rootUrl = URLs.toFilePath(new URL(persistenceModule.getRootUrl())); } catch (final MalformedURLException e) { continue; } for (final PersistenceUnit unit : persistence.getPersistenceUnit()) { if (unit == value) { if (strUrls.contains(rootUrl)) { return true; } } } } return false; }
private boolean isIn(final PersistenceUnit value, final WebModule war) { final Collection<URL> urls = (Collection<URL>) war.getAltDDs().get(DeploymentLoader.EAR_WEBAPP_PERSISTENCE_XML_JARS); if (urls == null || urls.isEmpty()) { return false; } final Collection<String> strUrls = new ArrayList<String>(); for (final URL url : urls) { strUrls.add(URLs.toFilePath(url)); } for (final PersistenceModule persistenceModule : module.getPersistenceModules()) { final Persistence persistence = persistenceModule.getPersistence(); final String rootUrl; try { rootUrl = URLs.toFilePath(new URL(persistenceModule.getRootUrl())); } catch (final MalformedURLException e) { continue; } for (final PersistenceUnit unit : persistence.getPersistenceUnit()) { if (unit == value) { if (strUrls.contains(rootUrl)) { return true; } } } } return false; }
private static boolean isMetadataComplete(final WebModule webModule, final EjbModule ejbModule) { if (webModule.getWebApp() == null) { return false; } if (!webModule.getWebApp().isMetadataComplete()) { return false; } // At this point we know the web.xml is metadata-complete // We need to determine if there are cdi or ejb xml files if (webModule.getAltDDs().get("beans.xml") == null) { return true; } if (ejbModule.getEjbJar() == null) { return true; } return ejbModule.getEjbJar().isMetadataComplete(); }
private static boolean isMetadataComplete(final WebModule webModule, final EjbModule ejbModule) { if (webModule.getWebApp() == null) { return false; } if (!webModule.getWebApp().isMetadataComplete()) { return false; } // At this point we know the web.xml is metadata-complete // We need to determine if there are cdi or ejb xml files if (webModule.getAltDDs().get("beans.xml") == null) { return true; } if (ejbModule.getEjbJar() == null) { return true; } return ejbModule.getEjbJar().isMetadataComplete(); }
/** * If the web.xml is metadata-complete and there is no ejb-jar.xml * then per specification we use the web.xml metadata-complete setting * to imply the same for EJBs. * * @param webModule WebModule * @param ejbModule EjbModule */ private static void fillEjbJar(final WebModule webModule, final EjbModule ejbModule) { final Object o = webModule.getAltDDs().get("ejb-jar.xml"); if (o != null) { return; } if (ejbModule.getEjbJar() != null) { return; } final EjbJar ejbJar = new EjbJar(); final WebApp webApp = webModule.getWebApp(); ejbJar.setMetadataComplete(webApp.isMetadataComplete()); ejbModule.setEjbJar(ejbJar); }
/** * If the web.xml is metadata-complete and there is no ejb-jar.xml * then per specification we use the web.xml metadata-complete setting * to imply the same for EJBs. * * @param webModule WebModule * @param ejbModule EjbModule */ private static void fillEjbJar(final WebModule webModule, final EjbModule ejbModule) { final Object o = webModule.getAltDDs().get("ejb-jar.xml"); if (o != null) { return; } if (ejbModule.getEjbJar() != null) { return; } final EjbJar ejbJar = new EjbJar(); final WebApp webApp = webModule.getWebApp(); ejbJar.setMetadataComplete(webApp.isMetadataComplete()); ejbModule.setEjbJar(ejbJar); }
private void readWebApp(WebModule webModule, AppModule appModule) throws OpenEJBException { if (webModule.getWebApp() != null) return; Object data = webModule.getAltDDs().get("web.xml"); if (data instanceof WebApp) { webModule.setWebApp((WebApp) data); } else if (data instanceof URL) { URL url = (URL) data; WebApp webApp = readWebApp(url); webModule.setWebApp(webApp); } else { DeploymentLoader.logger.debug("No web.xml found assuming annotated beans present: " + appModule.getJarLocation() + ", module: " + webModule.getModuleId()); webModule.setWebApp(new WebApp()); } }
private void readWebApp(final WebModule webModule, final AppModule appModule) throws OpenEJBException { if (webModule.getWebApp() != null) { mergeWebFragments(webModule); return; } final Object data = webModule.getAltDDs().get("web.xml"); if (data instanceof WebApp) { webModule.setWebApp((WebApp) data); } else if (data instanceof URL) { final URL url = (URL) data; final WebApp webApp = readWebApp(url); webModule.setWebApp(webApp); } else { DeploymentLoader.logger.debug("No web.xml found assuming annotated beans present: " + appModule.getJarLocation() + ", module: " + webModule.getModuleId()); webModule.setWebApp(new WebApp()); } mergeWebFragments(webModule); }
private void readWebApp(final WebModule webModule, final AppModule appModule) throws OpenEJBException { if (webModule.getWebApp() != null) { mergeWebFragments(webModule); return; } final Object data = webModule.getAltDDs().get("web.xml"); if (data instanceof WebApp) { webModule.setWebApp((WebApp) data); } else if (data instanceof URL) { final URL url = (URL) data; final WebApp webApp = readWebApp(url); webModule.setWebApp(webApp); } else { DeploymentLoader.logger.debug("No web.xml found assuming annotated beans present: " + appModule.getJarLocation() + ", module: " + webModule.getModuleId()); webModule.setWebApp(new WebApp()); } mergeWebFragments(webModule); }
private void mergeWebFragments(final WebModule webModule) { // web-fragment.xml, to get jndi entries to merge, other stuff is done by tomcat ATM final Collection<URL> urls = Collection.class.cast(webModule.getAltDDs().get("web-fragment.xml")); if (urls != null) { for (final URL rawUrl : urls) { if (rawUrl != null) { final Source url = getSource(rawUrl); try { final WebFragment webFragment = WebFragment.class.cast(JaxbJavaee.unmarshal(WebFragment.class, url.get(), false)); // in tomcat if the env entry is already don't override it mergeOnlyMissingEntries(webModule.getWebApp().getPersistenceContextRefMap(), webFragment.getPersistenceContextRef()); mergeOnlyMissingEntries(webModule.getWebApp().getPersistenceUnitRefMap(), webFragment.getPersistenceUnitRef()); mergeOnlyMissingEntries(webModule.getWebApp().getMessageDestinationRefMap(), webFragment.getMessageDestinationRef()); mergeOnlyMissingEntries(webModule.getWebApp().getDataSourceMap(), webFragment.getDataSource()); mergeOnlyMissingEntries(webModule.getWebApp().getEjbLocalRefMap(), webFragment.getEjbLocalRef()); mergeOnlyMissingEntries(webModule.getWebApp().getEjbRefMap(), webFragment.getEjbRef()); mergeOnlyMissingEntries(webModule.getWebApp().getServiceRefMap(), webFragment.getServiceRef()); mergeOnlyMissingEntries(webModule.getWebApp().getEnvEntryMap(), webFragment.getEnvEntry()); mergeOnlyMissingEntries(webModule.getWebApp().getResourceEnvRefMap(), webFragment.getResourceEnvRef()); mergeOnlyMissingEntries(webModule.getWebApp().getResourceRefMap(), webFragment.getResourceRef()); } catch (final Exception e) { logger.warning("can't read " + url.toString(), e); } } } } }
private void mergeWebFragments(final WebModule webModule) { // web-fragment.xml, to get jndi entries to merge, other stuff is done by tomcat ATM final Collection<URL> urls = Collection.class.cast(webModule.getAltDDs().get("web-fragment.xml")); if (urls != null) { for (final URL rawUrl : urls) { if (rawUrl != null) { final Source url = getSource(rawUrl); try { final WebFragment webFragment = WebFragment.class.cast(JaxbJavaee.unmarshal(WebFragment.class, url.get(), false)); // in tomcat if the env entry is already don't override it mergeOnlyMissingEntries(webModule.getWebApp().getPersistenceContextRefMap(), webFragment.getPersistenceContextRef()); mergeOnlyMissingEntries(webModule.getWebApp().getPersistenceUnitRefMap(), webFragment.getPersistenceUnitRef()); mergeOnlyMissingEntries(webModule.getWebApp().getMessageDestinationRefMap(), webFragment.getMessageDestinationRef()); mergeOnlyMissingEntries(webModule.getWebApp().getDataSourceMap(), webFragment.getDataSource()); mergeOnlyMissingEntries(webModule.getWebApp().getJMSConnectionFactoriesMap(), webFragment.getJMSConnectionFactories()); mergeOnlyMissingEntries(webModule.getWebApp().getEjbLocalRefMap(), webFragment.getEjbLocalRef()); mergeOnlyMissingEntries(webModule.getWebApp().getEjbRefMap(), webFragment.getEjbRef()); mergeOnlyMissingEntries(webModule.getWebApp().getServiceRefMap(), webFragment.getServiceRef()); mergeOnlyMissingEntries(webModule.getWebApp().getEnvEntryMap(), webFragment.getEnvEntry()); mergeOnlyMissingEntries(webModule.getWebApp().getResourceEnvRefMap(), webFragment.getResourceEnvRef()); mergeOnlyMissingEntries(webModule.getWebApp().getResourceRefMap(), webFragment.getResourceRef()); } catch (final Exception e) { logger.warning("can't read " + url.toString(), e); } } } } }