Search in sources :

Example 1 with WebApp$JAXB

use of org.apache.openejb.jee.WebApp$JAXB in project tomee by apache.

the class MaxChildTest method app.

@Module
public AppModule app() {
    final String jarLocation = "target/" + getClass().getSimpleName();
    return new AppModule(Thread.currentThread().getContextClassLoader(), jarLocation, new Application(), true) {

        {
            getEjbModules().add(new EjbModule(new EjbJar("app"), new OpenejbJar() {

                {
                    getPojoDeployment().add(new PojoDeployment() {

                        {
                            setClassName(SimpleContractImpl.class.getName());
                            getProperties().setProperty("cxf.jaxws.properties", "cxfLargeMsgSize");
                        }
                    });
                }
            }));
            getWebModules().add(new WebModule(new WebApp().contextRoot("app").addServlet("ws", SimpleContractImpl.class.getName(), "/ws"), "app", Thread.currentThread().getContextClassLoader(), jarLocation, "app"));
            getServices().add(new Service() {

                {
                    setId("cxfLargeMsgSize");
                    setClassName(Properties.class.getName());
                    getProperties().setProperty("org.apache.cxf.stax.maxChildElements", "1");
                }
            });
        }
    };
}
Also used : AppModule(org.apache.openejb.config.AppModule) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) EjbModule(org.apache.openejb.config.EjbModule) Service(org.apache.openejb.config.sys.Service) WebService(javax.jws.WebService) PojoDeployment(org.apache.openejb.jee.oejb3.PojoDeployment) WebModule(org.apache.openejb.config.WebModule) Application(org.apache.openejb.jee.Application) EjbJar(org.apache.openejb.jee.EjbJar) WebApp(org.apache.openejb.jee.WebApp) WebModule(org.apache.openejb.config.WebModule) EjbModule(org.apache.openejb.config.EjbModule) AppModule(org.apache.openejb.config.AppModule) Module(org.apache.openejb.testing.Module)

Example 2 with WebApp$JAXB

use of org.apache.openejb.jee.WebApp$JAXB in project tomee by apache.

the class SunConversion method convertModule.

public void convertModule(final WebModule webModule) {
    if (webModule == null) {
        return;
    }
    final WebApp webApp = webModule.getWebApp();
    if (webApp == null) {
        return;
    }
    final SunWebApp sunWebApp = getSunWebApp(webModule);
    if (sunWebApp == null) {
        return;
    }
    if (sunWebApp.getContextRoot() != null) {
        webModule.setContextRoot(sunWebApp.getContextRoot());
    }
    // map ejb-refs
    final Map<String, JndiReference> refMap = new TreeMap<String, JndiReference>();
    refMap.putAll(webApp.getEjbRefMap());
    refMap.putAll(webApp.getEjbLocalRefMap());
    // map ejb-ref jndi name declaration to deploymentId
    for (final EjbRef ref : sunWebApp.getEjbRef()) {
        if (ref.getJndiName() != null) {
            final String refName = ref.getEjbRefName();
            JndiReference ejbRef = refMap.get(refName);
            if (ejbRef == null) {
                ejbRef = new org.apache.openejb.jee.EjbRef();
                ejbRef.setName(refName);
                refMap.put(refName, ejbRef);
                webApp.getEjbRef().add((org.apache.openejb.jee.EjbRef) ejbRef);
            }
            ejbRef.setMappedName(ref.getJndiName());
        }
    }
    // map resource-env-refs and message-destination-refs
    final Map<String, JndiReference> resEnvMap = new TreeMap<String, JndiReference>();
    resEnvMap.putAll(webApp.getResourceRefMap());
    resEnvMap.putAll(webApp.getResourceEnvRefMap());
    resEnvMap.putAll(webApp.getMessageDestinationRefMap());
    for (final ResourceRef ref : sunWebApp.getResourceRef()) {
        if (ref.getJndiName() != null) {
            String refName = ref.getResRefName();
            refName = normalize(refName);
            final JndiReference resEnvRef = resEnvMap.get(refName);
            if (resEnvRef != null) {
                resEnvRef.setMappedName(ref.getJndiName());
            }
        }
    }
    for (final ResourceEnvRef ref : sunWebApp.getResourceEnvRef()) {
        if (ref.getJndiName() != null) {
            String refName = ref.getResourceEnvRefName();
            refName = normalize(refName);
            final JndiReference resEnvRef = resEnvMap.get(refName);
            if (resEnvRef != null) {
                resEnvRef.setMappedName(ref.getJndiName());
            }
        }
    }
    for (final MessageDestinationRef ref : sunWebApp.getMessageDestinationRef()) {
        if (ref.getJndiName() != null) {
            String refName = ref.getMessageDestinationRefName();
            refName = normalize(refName);
            final JndiReference resEnvRef = resEnvMap.get(refName);
            if (resEnvRef != null) {
                resEnvRef.setMappedName(ref.getJndiName());
            }
        }
    }
    final Map<String, ServiceRef> serviceRefMap = webApp.getServiceRefMap();
    for (final org.apache.openejb.jee.sun.ServiceRef ref : sunWebApp.getServiceRef()) {
        String refName = ref.getServiceRefName();
        refName = normalize(refName);
        final ServiceRef serviceRef = serviceRefMap.get(refName);
        if (serviceRef != null) {
            final Map<String, PortComponentRef> ports = new TreeMap<String, PortComponentRef>();
            for (final PortComponentRef portComponentRef : serviceRef.getPortComponentRef()) {
                ports.put(portComponentRef.getServiceEndpointInterface(), portComponentRef);
            }
            for (final PortInfo portInfo : ref.getPortInfo()) {
                final PortComponentRef portComponentRef = ports.get(portInfo.getServiceEndpointInterface());
                if (portComponentRef != null) {
                    final WsdlPort wsdlPort = portInfo.getWsdlPort();
                    if (wsdlPort != null) {
                        final QName qname = new QName(wsdlPort.getNamespaceURI(), wsdlPort.getLocalpart());
                        portComponentRef.setQName(qname);
                    }
                    for (final StubProperty stubProperty : portInfo.getStubProperty()) {
                        final String name = stubProperty.getName();
                        final String value = stubProperty.getValue();
                        portComponentRef.getProperties().setProperty(name, value);
                    }
                }
            }
            final String wsdlOverride = ref.getWsdlOverride();
            if (wsdlOverride != null && wsdlOverride.length() > 0) {
                final String serviceId = extractServiceId(wsdlOverride);
                serviceRef.setMappedName(serviceId);
            }
        }
    }
    // map wsdl locations
    if (webModule.getWebservices() != null) {
        final Map<String, WebserviceDescription> descriptions = webModule.getWebservices().getWebserviceDescriptionMap();
        for (final org.apache.openejb.jee.sun.WebserviceDescription sunDescription : sunWebApp.getWebserviceDescription()) {
            final WebserviceDescription description = descriptions.get(sunDescription.getWebserviceDescriptionName());
            if (description == null) {
                continue;
            }
            final String serviceId = extractSerivceId(sunDescription.getWsdlPublishLocation(), description.getWsdlFile());
            if (serviceId != null) {
                description.setId(serviceId);
            }
        }
    }
}
Also used : SunWebApp(org.apache.openejb.jee.sun.SunWebApp) WsdlPort(org.apache.openejb.jee.sun.WsdlPort) PortInfo(org.apache.openejb.jee.sun.PortInfo) MessageDestinationRef(org.apache.openejb.jee.sun.MessageDestinationRef) JndiReference(org.apache.openejb.jee.JndiReference) EjbRef(org.apache.openejb.jee.sun.EjbRef) ResourceEnvRef(org.apache.openejb.jee.sun.ResourceEnvRef) QName(javax.xml.namespace.QName) StubProperty(org.apache.openejb.jee.sun.StubProperty) TreeMap(java.util.TreeMap) PortComponentRef(org.apache.openejb.jee.PortComponentRef) WebserviceDescription(org.apache.openejb.jee.WebserviceDescription) ResourceRef(org.apache.openejb.jee.sun.ResourceRef) ServiceRef(org.apache.openejb.jee.ServiceRef) SunWebApp(org.apache.openejb.jee.sun.SunWebApp) WebApp(org.apache.openejb.jee.WebApp)

Example 3 with WebApp$JAXB

use of org.apache.openejb.jee.WebApp$JAXB in project tomee by apache.

the class WsDeployer method processPorts.

private void processPorts(final WebModule webModule) throws OpenEJBException {
    // map existing webservice port declarations by servlet link
    Webservices webservices = webModule.getWebservices();
    final Map<String, PortComponent> portMap = new TreeMap<String, PortComponent>();
    if (webservices != null) {
        for (final WebserviceDescription webserviceDescription : webservices.getWebserviceDescription()) {
            for (final PortComponent portComponent : webserviceDescription.getPortComponent()) {
                final ServiceImplBean serviceImplBean = portComponent.getServiceImplBean();
                if (serviceImplBean != null && serviceImplBean.getServletLink() != null) {
                    portMap.put(serviceImplBean.getServletLink(), portComponent);
                }
            }
        }
    }
    // map existing servlet-mapping declarations
    final WebApp webApp = webModule.getWebApp();
    final Map<String, ServletMapping> servletMappings = new TreeMap<String, ServletMapping>();
    for (final ServletMapping servletMapping : webApp.getServletMapping()) {
        servletMappings.put(servletMapping.getServletName(), servletMapping);
    }
    // add port declarations for Pojo webservices
    WebserviceDescription webserviceDescription;
    for (final Servlet servlet : webApp.getServlet()) {
        // the implementation class will be replaced by the WsServlet in the WsRegistry
        final String className = servlet.getServletClass();
        // Skip JSPs
        if (className == null) {
            continue;
        }
        try {
            final Class<?> clazz = webModule.getClassLoader().loadClass(className);
            if (JaxWsUtils.isWebService(clazz)) {
                // add servlet mapping if not already declared
                ServletMapping servletMapping = servletMappings.get(servlet.getServletName());
                final String serviceName = JaxWsUtils.getServiceName(clazz);
                if (servletMapping == null) {
                    servletMapping = new ServletMapping();
                    servletMapping.setServletName(servlet.getServletName());
                    final String location = "/" + serviceName;
                    servletMapping.getUrlPattern().add(location);
                    webApp.getServletMapping().add(servletMapping);
                }
                // if we don't have a webservices document yet, we're gonna need one now
                if (webservices == null) {
                    webservices = new Webservices();
                    webModule.setWebservices(webservices);
                }
                // add web service description element (maps to service)
                webserviceDescription = webservices.getWebserviceDescriptionMap().get(serviceName);
                if (webserviceDescription == null) {
                    webserviceDescription = new WebserviceDescription();
                    webserviceDescription.setWebserviceDescriptionName(serviceName);
                    webservices.getWebserviceDescription().add(webserviceDescription);
                }
                // define port if not already declared
                PortComponent portComponent = portMap.get(servlet.getServletName());
                if (portComponent == null) {
                    portComponent = new PortComponent();
                    portComponent.setPortComponentName(clazz.getSimpleName());
                    final ServiceImplBean serviceImplBean = new ServiceImplBean();
                    serviceImplBean.setServletLink(servlet.getServletName());
                    portComponent.setServiceImplBean(serviceImplBean);
                    webserviceDescription.getPortComponent().add(portComponent);
                }
                // default portId == host.moduleId.servletName
                if (portComponent.getId() == null) {
                    portComponent.setId(webModule.getHost() + "." + webModule.getModuleId() + "." + servlet.getServletName());
                }
                if (webserviceDescription.getId() == null) {
                    webserviceDescription.setId(webModule.getHost() + "." + webModule.getModuleId() + "." + servlet.getServletName());
                }
                // set port values from annotations if not already set
                if (portComponent.getServiceEndpointInterface() == null) {
                    portComponent.setServiceEndpointInterface(JaxWsUtils.getServiceInterface(clazz));
                }
                if (portComponent.getWsdlPort() == null) {
                    portComponent.setWsdlPort(JaxWsUtils.getPortQName(clazz));
                }
                if (webserviceDescription.getWsdlFile() == null) {
                    webserviceDescription.setWsdlFile(JaxWsUtils.getServiceWsdlLocation(clazz, webModule.getClassLoader()));
                }
                if (portComponent.getWsdlService() == null) {
                    final Definition definition = getWsdl(webModule, webserviceDescription.getWsdlFile());
                    if (definition != null && definition.getServices().size() == 1) {
                        final QName serviceQName = (QName) definition.getServices().keySet().iterator().next();
                        portComponent.setWsdlService(serviceQName);
                    } else {
                        portComponent.setWsdlService(JaxWsUtils.getServiceQName(clazz));
                    }
                }
                if (portComponent.getProtocolBinding() == null) {
                    portComponent.setProtocolBinding(JaxWsUtils.getBindingUriFromAnn(clazz));
                }
                configMtomAnnotation(clazz, portComponent);
                if (SOAPBinding.SOAP12HTTP_MTOM_BINDING.equals(portComponent.getProtocolBinding()) || SOAPBinding.SOAP11HTTP_MTOM_BINDING.equals(portComponent.getProtocolBinding())) {
                    portComponent.setEnableMtom(true);
                }
                // handlers
                if (portComponent.getHandlerChains() == null) {
                    final HandlerChains handlerChains = getHandlerChains(clazz, portComponent.getServiceEndpointInterface(), webModule.getClassLoader());
                    portComponent.setHandlerChains(handlerChains);
                }
            }
        } catch (final Exception e) {
            throw new OpenEJBException("Unable to load servlet class: " + className, e);
        }
    }
}
Also used : ServletMapping(org.apache.openejb.jee.ServletMapping) OpenEJBException(org.apache.openejb.OpenEJBException) PortComponent(org.apache.openejb.jee.PortComponent) ServiceImplBean(org.apache.openejb.jee.ServiceImplBean) QName(javax.xml.namespace.QName) Definition(javax.wsdl.Definition) HandlerChains(org.apache.openejb.jee.HandlerChains) Webservices(org.apache.openejb.jee.Webservices) TreeMap(java.util.TreeMap) MalformedURLException(java.net.MalformedURLException) OpenEJBException(org.apache.openejb.OpenEJBException) IOException(java.io.IOException) WebserviceDescription(org.apache.openejb.jee.WebserviceDescription) Servlet(org.apache.openejb.jee.Servlet) WebApp(org.apache.openejb.jee.WebApp)

Example 4 with WebApp$JAXB

use of org.apache.openejb.jee.WebApp$JAXB in project tomee by apache.

the class DeploymentLoader method addTagLibraries.

private void addTagLibraries(final WebModule webModule) throws OpenEJBException {
    final Set<URL> tldLocations = new HashSet<URL>();
    // web.xml contains tag lib locations in nested jsp config elements
    final File warFile = new File(webModule.getJarLocation());
    final WebApp webApp = webModule.getWebApp();
    if (webApp != null) {
        for (final JspConfig jspConfig : webApp.getJspConfig()) {
            for (final Taglib taglib : jspConfig.getTaglib()) {
                String location = taglib.getTaglibLocation();
                if (!location.startsWith("/")) {
                    // this reproduces a tomcat bug
                    location = "/WEB-INF/" + location;
                }
                try {
                    final File file = new File(warFile, location).getCanonicalFile().getAbsoluteFile();
                    tldLocations.addAll(TldScanner.scanForTagLibs(file));
                } catch (final IOException e) {
                    logger.warning("JSP tag library location bad: " + location, e);
                }
            }
        }
    }
    // WEB-INF/**/*.tld except in WEB-INF/classes and WEB-INF/lib
    Set<URL> urls = TldScanner.scanWarForTagLibs(warFile);
    tldLocations.addAll(urls);
    // Search all libs
    final ClassLoader parentClassLoader = webModule.getClassLoader().getParent();
    urls = TldScanner.scan(parentClassLoader);
    tldLocations.addAll(urls);
    // load the tld files
    for (final URL location : tldLocations) {
        final TldTaglib taglib = ReadDescriptors.readTldTaglib(location);
        if (taglib != null && taglib != ReadDescriptors.SKIP_TAGLIB) {
            webModule.getTaglibs().add(taglib);
            if ("file".equals(location.getProtocol())) {
                webModule.getWatchedResources().add(URLs.toFilePath(location));
            }
        }
    }
    // no more need + this classloader is a temp one in Servlet container so avoid mem leaks
    TldScanner.quickClean(parentClassLoader);
}
Also used : JspConfig(org.apache.openejb.jee.JspConfig) TldTaglib(org.apache.openejb.jee.TldTaglib) Taglib(org.apache.openejb.jee.Taglib) TldTaglib(org.apache.openejb.jee.TldTaglib) URLClassLoader(java.net.URLClassLoader) EmptyResourcesClassLoader(org.apache.openejb.core.EmptyResourcesClassLoader) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) File(java.io.File) URL(java.net.URL) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) WebApp(org.apache.openejb.jee.WebApp)

Example 5 with WebApp$JAXB

use of org.apache.openejb.jee.WebApp$JAXB in project tomee by apache.

the class DeploymentLoader method fillEjbJar.

/**
 * 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);
}
Also used : EjbJar(org.apache.openejb.jee.EjbJar) WebApp(org.apache.openejb.jee.WebApp)

Aggregations

WebApp (org.apache.openejb.jee.WebApp)24 AppInfo (org.apache.openejb.assembler.classic.AppInfo)7 Persistence (org.apache.openejb.jee.jpa.unit.Persistence)7 PersistenceUnit (org.apache.openejb.jee.jpa.unit.PersistenceUnit)7 File (java.io.File)6 IOException (java.io.IOException)6 URL (java.net.URL)6 ResourceInfo (org.apache.openejb.assembler.classic.ResourceInfo)6 WebModule (org.apache.openejb.config.WebModule)5 MalformedURLException (java.net.MalformedURLException)4 LinkedHashSet (java.util.LinkedHashSet)4 JarFile (java.util.jar.JarFile)4 HashSet (java.util.HashSet)3 OpenEJBException (org.apache.openejb.OpenEJBException)3 WebAppInfo (org.apache.openejb.assembler.classic.WebAppInfo)3 EjbJar (org.apache.openejb.jee.EjbJar)3 InputStream (java.io.InputStream)2 URLClassLoader (java.net.URLClassLoader)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2