Package org.apache.openejb.jee

Examples of org.apache.openejb.jee.WebApp


        // look at section 10.4.2 of the JSF v1.2 spec, bullet 1 for details
        final Set<URL> facesConfigLocations = new HashSet<URL>();

        // web.xml contains faces config locations in the context parameter javax.faces.CONFIG_FILES
        final File warFile = new File(webModule.getJarLocation());
        final WebApp webApp = webModule.getWebApp();
        if (webApp != null) {
            final String foundContextParam = webApp.contextParamsAsMap().get("javax.faces.CONFIG_FILES");
            if (foundContextParam != null) {
                // the value is a comma separated list of config files
                final String commaDelimitedListOfFiles = foundContextParam.trim();
                final String[] configFiles = commaDelimitedListOfFiles.split(",");
                // trim any extra spaces in each file
View Full Code Here


        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());
        }
    }
View Full Code Here

        }
        return connector;
    }

    public static WebApp readWebApp(URL url) throws OpenEJBException {
        WebApp webApp;
        try {
            webApp = (WebApp) JaxbJavaee.unmarshalJavaee(WebApp.class, IO.read(url));
        } catch (SAXException e) {
            throw new OpenEJBException("Cannot parse the web.xml file: " + url.toExternalForm(), e);
        } catch (JAXBException e) {
View Full Code Here

    private static HttpServer server;
    private static ServiceDaemon daemon;
    public static final String BASE_URL = "http://localhost:4204/my-web-app/my-app";

    @BeforeClass public static void start() throws Exception {
        WebApp webApp = new WebApp();
        webApp.setContextRoot("/my-web-app");
        webApp.setId("web");
        webApp.setVersion("2.5");
        WebModule webModule = new WebModule(webApp, webApp.getContextRoot(),
                Thread.currentThread().getContextClassLoader(), "myapp", webApp.getId());
        webModule.setFinder(new AnnotationFinder(new ClassesArchive(
                MyFirstRestClass.class, MySecondRestClass.class, MyNonListedRestClass.class,
                MyRESTApplication.class, MyExpertRestClass.class, HookedRest.class, RestWithInjections.class)).link());

        Assembler assembler = new Assembler();
        SystemInstance.get().setComponent(Assembler.class, assembler);

        AnnotationDeployer annotationDeployer = new AnnotationDeployer();
        ConfigurationFactory config = new ConfigurationFactory();
        assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
        assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
        assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));

        webModule = annotationDeployer.deploy(webModule);

        EjbJar ejbJar = new EjbJar("ejb");
        ejbJar.addEnterpriseBean(new StatelessBean(SimpleEJB.class));

        ConfigurationFactory factory = new ConfigurationFactory(false);

        AppModule appModule = new AppModule(Thread.currentThread().getContextClassLoader(), "foo");
        appModule.setModuleId("rest");
        appModule.getWebModules().add(webModule);
        appModule.getEjbModules().add(new EjbModule(ejbJar));
        annotationDeployer.deploy(appModule);

        AppInfo appInfo = factory.configureApplication(appModule);
        final AppContext application = assembler.createApplication(appInfo);

        Context ctx = (Context) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[]{Context.class}, new InvocationHandler() {
            @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                if (args.length == 1 && args[0].equals("SimpleEJBLocalBean")) {
                    return new SimpleEJB();
                }
                return method.invoke(new InitialContext(), args);
            }
        });

        CoreContainerSystem containerSystem = new CoreContainerSystem(new IvmJndiFactory());
        WebContext webContext = new WebContext(application);
        webContext.setId(webApp.getId());
        webContext.setClassLoader(webModule.getClassLoader());
        webContext.getInjections().add(new Injection("SimpleEJBLocalBean", "simple", RestWithInjections.class));
        webContext.setJndiEnc(ctx);
        containerSystem.addWebContext(webContext);
        SystemInstance.get().setComponent(ContainerSystem.class, containerSystem);
View Full Code Here

        // 1. resource-ref
        //
//        URL srcXML = classLoader.getResource("annotation/empty-web-src.xml");
//        XmlObject xmlObject = XmlObject.Factory.parse(srcXML, options);
//        WebAppDocument webAppDoc = (WebAppDocument) xmlObject.changeType(WebAppDocument.type);
        WebApp webApp = load("annotation/empty-web-src.xml", WebApp.class);
        ResourceAnnotationHelper.processAnnotations(webApp, classFinder, ResourceRefBuilder.ResourceRefProcessor.INSTANCE);
        URL expectedXML = classLoader.getResource("annotation/resource-ref-expected.xml");
        XmlObject expected = XmlObject.Factory.parse(expectedXML);
        log.debug("[@Resource <resource-ref> Source XML] " + '\n' + webApp.toString() + '\n');
        log.debug("[@Resource <resource-ref> Expected XML]" + '\n' + expected.toString() + '\n');
        List problems = new ArrayList();
        boolean ok = compareXmlObjects(webApp, expected, problems);
        assertTrue("Differences: " + problems, ok);
    }
View Full Code Here

        if (!(module instanceof WebModule)) {
            //not a web module, nothing to do
            return;
        }
        WebModule webModule = (WebModule) module;
        WebApp webApp = webModule.getSpecDD();
        if (!hasFacesServlet(webApp)) {
            return;
        }
        EnvironmentBuilder.mergeEnvironments(module.getEnvironment(), defaultEnvironment);
    }
View Full Code Here

        if (!(module instanceof WebModule)) {
            //not a web module, nothing to do
            return;
        }
        WebModule webModule = (WebModule) module;
        WebApp webApp = webModule.getSpecDD();
        if (!hasFacesServlet(webApp)) {
            return;
        }

        EARContext moduleContext = module.getEarContext();
View Full Code Here

        Long longVal = new Long(1234567890123456L);
        Float floatVal = new Float(123.456);
        Double doubleVal = new Double(12345.6789);
        Boolean booleanVal = Boolean.TRUE;

        WebApp webApp = load(TEST, WebApp.class);
        environmentEntryBuilder.buildNaming(webApp, null, module, componentContext);
        Context context = EnterpriseNamingContext.livenReferences(module.getJndiScope(JndiScope.comp), null, null, getClass().getClassLoader(), null, "comp/");
        Set actual = new HashSet();
        for (NamingEnumeration e = context.listBindings("comp/env"); e.hasMore();) {
            NameClassPair pair = (NameClassPair) e.next();
View Full Code Here

        Long longVal = new Long(6543210987654321L);
        Float floatVal = new Float(654.321);
        Double doubleVal = new Double(9876.54321);
        Boolean booleanVal = Boolean.FALSE;

        WebApp webApp = load(TEST, WebApp.class);
        XmlObject plan = XmlObject.Factory.parse(TEST_PLAN);
        XmlCursor cursor = plan.newCursor();
        try {
            cursor.toFirstChild();
            plan = cursor.getObject();
View Full Code Here

        if (!(module instanceof WebModule)) {
            // not a web module, nothing to do
            return;
        }
        WebModule webModule = (WebModule) module;
        WebApp webApp = webModule.getSpecDD();
        ServiceReference reference = bundle.getBundleContext().getServiceReference(PackageAdmin.class.getName());
        Set<Class<? extends Application>> applicationClasses = new HashSet<Class<? extends Application>>();
        try {
            PackageAdmin packageAdmin = (PackageAdmin) bundle.getBundleContext().getService(reference);

            BundleClassFinder bundleClassFinder = new BundleAssignableClassFinder(packageAdmin, bundle, new Class<?>[] { Application.class }, new ClassDiscoveryFilter() {

                @Override
                public boolean directoryDiscoveryRequired(String directory) {
                    return true;
                }

                @Override
                public boolean jarFileDiscoveryRequired(String jarUrl) {
                    return true;
                }

                @Override
                public boolean packageDiscoveryRequired(String packageName) {
                    return true;
                }

                @Override
                public boolean rangeDiscoveryRequired(DiscoveryRange discoveryRange) {
                    return discoveryRange.equals(DiscoveryRange.BUNDLE_CLASSPATH);
                }
            });

            Set<String> classes = bundleClassFinder.find();

            for (String clazz : classes) {
                applicationClasses.add(bundle.loadClass(clazz).asSubclass(Application.class));
            }

        } catch (Exception e) {
            throw new DeploymentException("Fail to scan javax.ws.rs.core.Application sub classes in application", e);
        } finally {
            bundle.getBundleContext().ungetService(reference);
        }

        // JAX-RS specific code here to initialize the runtime and setup the mapping etc.

        // there's no Application sub classes found
        if (applicationClasses == null || applicationClasses.size() == 0) {
            /*
             * TODO jaxrs 1.1 spec section 2.3.2 If no Application subclass is present the added servlet MUST be named ...
             */
            return;
        }

        /*
         *  jaxrs 1.1 spec section 2.3.2 If an Application subclass is present and there is already a servlet defined that has a servlet initialization
         * ...
         */
        Class<? extends Application> applicationClass;
        BundleClassLoader bundleClassLoader = new BundleClassLoader(bundle);
        for (Servlet servlet : webApp.getServlet()) {
            List<ParamValue> params = servlet.getInitParam();
            for (ParamValue parm : params) {
                if (!parm.getParamName().trim().equals("javax.ws.rs.Application")) {
                    continue;
                }
                for (Class<? extends Application> clazz : applicationClasses) {
                    if (clazz.getName().equalsIgnoreCase(parm.getParamValue().trim())) {
                        applicationClass = clazz;
                        Class<?> servletClass = null;
                        try {
                            servletClass = bundleClassLoader.loadClass(servlet.getServletClass());
                        } catch (ClassNotFoundException e) {
                            log.warn("failed to load servlet class:" + servlet.getServletClass());
                        }
                        if ((servletClass == null) || !servletClass.isAssignableFrom(HttpServlet.class)) {
                            servlet.setServletClass(REST_SERVLET_NAME);
                        }
                        ParamValue paramDeploymentConfig = new ParamValue();
                        paramDeploymentConfig.setParamName(RestServlet.DEPLOYMENT_CONF_PARAM);
                        paramDeploymentConfig.setParamValue(GeronimoWinkDeloymentConfiguration.class.getName());
                        servlet.getInitParam().add(paramDeploymentConfig);
                        return;
                    }
                }

            }
        }

        /*
         * jaxrs 1.1 spec section 2.3.2 If an Application subclass is present ...
         *
         *
         * TODO It is an error for more than one application to be deployed at the same effective servlet mapping
         */

        applicationClass = applicationClasses.iterator().next();

        Servlet restServletInfo = new Servlet();
        restServletInfo.setServletClass(REST_SERVLET_NAME);
        restServletInfo.setServletName(REST_SERVLET_NAME);

        ParamValue paramApplication = new ParamValue();
        paramApplication.setParamName("javax.ws.rs.Application");
        paramApplication.setParamValue(applicationClass.getName());
        restServletInfo.getInitParam().add(paramApplication);

        ParamValue paramDeploymentConfig = new ParamValue();
        paramDeploymentConfig.setParamName("deploymentConfiguration");
        paramDeploymentConfig.setParamValue(GeronimoWinkDeloymentConfiguration.class.getName());

        restServletInfo.getInitParam().add(paramDeploymentConfig);

        if (applicationClass.isAnnotationPresent(ApplicationPath.class)) {

            ApplicationPath ap = applicationClass.getAnnotation(ApplicationPath.class);

            String mapping = ap.value();

            if (!mapping.startsWith("/") || !mapping.startsWith("*.")) {

                mapping = "/" + mapping;
            }

            if (!mapping.endsWith("/*")) {

                if (mapping.endsWith("/"))
                    mapping = mapping + "*";
                else {
                    mapping = mapping + "/*";
                }
            }

            ServletMapping restServletMapping = new ServletMapping();
            restServletMapping.setServletName(REST_SERVLET_NAME);
            restServletMapping.getUrlPattern().add(mapping);
            webApp.getServletMapping().add(restServletMapping);

        }

        webApp.getServlet().add(restServletInfo);

    }
View Full Code Here

TOP

Related Classes of org.apache.openejb.jee.WebApp

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.