Search in sources :

Example 1 with HandlerChain

use of org.apache.openejb.jee.HandlerChain in project tomee by apache.

the class ConfigurationFactory method toHandlerChainInfo.

public static List<HandlerChainInfo> toHandlerChainInfo(final HandlerChains chains) {
    final List<HandlerChainInfo> handlerChains = new ArrayList<HandlerChainInfo>();
    if (chains == null) {
        return handlerChains;
    }
    for (final HandlerChain handlerChain : chains.getHandlerChain()) {
        final HandlerChainInfo handlerChainInfo = new HandlerChainInfo();
        handlerChainInfo.serviceNamePattern = handlerChain.getServiceNamePattern();
        handlerChainInfo.portNamePattern = handlerChain.getPortNamePattern();
        handlerChainInfo.protocolBindings.addAll(handlerChain.getProtocolBindings());
        for (final Handler handler : handlerChain.getHandler()) {
            final HandlerInfo handlerInfo = new HandlerInfo();
            handlerInfo.handlerName = handler.getHandlerName();
            handlerInfo.handlerClass = handler.getHandlerClass();
            handlerInfo.soapHeaders.addAll(handler.getSoapHeader());
            handlerInfo.soapRoles.addAll(handler.getSoapRole());
            for (final ParamValue param : handler.getInitParam()) {
                handlerInfo.initParams.setProperty(param.getParamName(), param.getParamValue());
            }
            handlerChainInfo.handlers.add(handlerInfo);
        }
        handlerChains.add(handlerChainInfo);
    }
    return handlerChains;
}
Also used : HandlerChain(org.apache.openejb.jee.HandlerChain) HandlerChainInfo(org.apache.openejb.assembler.classic.HandlerChainInfo) ArrayList(java.util.ArrayList) Handler(org.apache.openejb.jee.Handler) ParamValue(org.apache.openejb.jee.ParamValue) HandlerInfo(org.apache.openejb.assembler.classic.HandlerInfo)

Example 2 with HandlerChain

use of org.apache.openejb.jee.HandlerChain in project tomee by apache.

the class HandlerChains$JAXB method _read.

public static final HandlerChains _read(final XoXMLStreamReader reader, RuntimeContext context) throws Exception {
    // Check for xsi:nil
    if (reader.isXsiNil()) {
        return null;
    }
    if (context == null) {
        context = new RuntimeContext();
    }
    final HandlerChains handlerChains = new HandlerChains();
    context.beforeUnmarshal(handlerChains, LifecycleCallback.NONE);
    List<HandlerChain> handlerChain = null;
    // Check xsi:type
    final QName xsiType = reader.getXsiType();
    if (xsiType != null) {
        if (("handler-chainsType" != xsiType.getLocalPart()) || ("http://java.sun.com/xml/ns/javaee" != xsiType.getNamespaceURI())) {
            return context.unexpectedXsiType(reader, HandlerChains.class);
        }
    }
    // Read attributes
    for (final Attribute attribute : reader.getAttributes()) {
        if (("id" == attribute.getLocalName()) && (("" == attribute.getNamespace()) || (attribute.getNamespace() == null))) {
            // ATTRIBUTE: id
            final String id = Adapters.collapsedStringAdapterAdapter.unmarshal(attribute.getValue());
            context.addXmlId(reader, id, handlerChains);
            handlerChains.id = id;
        } else if (XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI != attribute.getNamespace()) {
            context.unexpectedAttribute(attribute, new QName("", "id"));
        }
    }
    // Read elements
    for (final XoXMLStreamReader elementReader : reader.getChildElements()) {
        if (("handler-chain" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: handlerChain
            final HandlerChain handlerChainItem = readHandlerChain(elementReader, context);
            if (handlerChain == null) {
                handlerChain = handlerChains.handlerChain;
                if (handlerChain != null) {
                    handlerChain.clear();
                } else {
                    handlerChain = new ArrayList<HandlerChain>();
                }
            }
            handlerChain.add(handlerChainItem);
        } else {
            context.unexpectedElement(elementReader, new QName("http://java.sun.com/xml/ns/javaee", "handler-chain"));
        }
    }
    if (handlerChain != null) {
        handlerChains.handlerChain = handlerChain;
    }
    context.afterUnmarshal(handlerChains, LifecycleCallback.NONE);
    return handlerChains;
}
Also used : HandlerChain$JAXB.writeHandlerChain(org.apache.openejb.jee.HandlerChain$JAXB.writeHandlerChain) HandlerChain$JAXB.readHandlerChain(org.apache.openejb.jee.HandlerChain$JAXB.readHandlerChain) Attribute(org.metatype.sxc.util.Attribute) QName(javax.xml.namespace.QName) RuntimeContext(org.metatype.sxc.jaxb.RuntimeContext) XoXMLStreamReader(org.metatype.sxc.util.XoXMLStreamReader)

Example 3 with HandlerChain

use of org.apache.openejb.jee.HandlerChain in project tomee by apache.

the class HandlerChains$JAXB method _write.

public static final void _write(final XoXMLStreamWriter writer, final HandlerChains handlerChains, RuntimeContext context) throws Exception {
    if (handlerChains == null) {
        writer.writeXsiNil();
        return;
    }
    if (context == null) {
        context = new RuntimeContext();
    }
    if (HandlerChains.class != handlerChains.getClass()) {
        context.unexpectedSubclass(writer, handlerChains, HandlerChains.class);
        return;
    }
    context.beforeMarshal(handlerChains, LifecycleCallback.NONE);
    // ATTRIBUTE: id
    final String idRaw = handlerChains.id;
    if (idRaw != null) {
        String id = null;
        try {
            id = Adapters.collapsedStringAdapterAdapter.marshal(idRaw);
        } catch (final Exception e) {
            context.xmlAdapterError(handlerChains, "id", CollapsedStringAdapter.class, String.class, String.class, e);
        }
        writer.writeAttribute("", "", "id", id);
    }
    // ELEMENT: handlerChain
    final List<HandlerChain> handlerChain = handlerChains.handlerChain;
    if (handlerChain != null) {
        for (final HandlerChain handlerChainItem : handlerChain) {
            if (handlerChainItem != null) {
                writer.writeStartElementWithAutoPrefix("http://java.sun.com/xml/ns/javaee", "handler-chain");
                writeHandlerChain(writer, handlerChainItem, context);
                writer.writeEndElement();
            }
        }
    }
    context.afterMarshal(handlerChains, LifecycleCallback.NONE);
}
Also used : HandlerChain$JAXB.writeHandlerChain(org.apache.openejb.jee.HandlerChain$JAXB.writeHandlerChain) HandlerChain$JAXB.readHandlerChain(org.apache.openejb.jee.HandlerChain$JAXB.readHandlerChain) CollapsedStringAdapter(javax.xml.bind.annotation.adapters.CollapsedStringAdapter) RuntimeContext(org.metatype.sxc.jaxb.RuntimeContext)

Example 4 with HandlerChain

use of org.apache.openejb.jee.HandlerChain in project tomee by apache.

the class FinderFactory method ensureMinimalClasses.

public static Class<?>[] ensureMinimalClasses(final DeploymentModule module) {
    final Collection<Class<?>> finderClasses = new HashSet<>();
    if (EjbModule.class.isInstance(module)) {
        final EjbModule ejb = EjbModule.class.cast(module);
        final EnterpriseBean[] enterpriseBeans = ejb.getEjbJar().getEnterpriseBeans();
        ClassLoader classLoader = ejb.getClassLoader();
        if (classLoader == null) {
            classLoader = Thread.currentThread().getContextClassLoader();
        }
        for (final EnterpriseBean bean : enterpriseBeans) {
            final String name;
            if (SessionBean.class.isInstance(bean)) {
                final SessionBean sessionBean = SessionBean.class.cast(bean);
                if (sessionBean.getProxy() == null) {
                    name = sessionBean.getEjbClass();
                } else {
                    name = sessionBean.getProxy();
                }
            } else {
                name = bean.getEjbClass();
            }
            try {
                final Class<?> clazz = classLoader.loadClass(name);
                finderClasses.addAll(ancestors(clazz));
            } catch (final ClassNotFoundException e) {
            // no-op
            }
        }
        if (ejb.getWebservices() != null) {
            for (final WebserviceDescription webservice : ejb.getWebservices().getWebserviceDescription()) {
                for (final PortComponent port : webservice.getPortComponent()) {
                    if (port.getHandlerChains() == null) {
                        continue;
                    }
                    for (final HandlerChain handlerChain : port.getHandlerChains().getHandlerChain()) {
                        for (final Handler handler : handlerChain.getHandler()) {
                            if (handler.getHandlerClass() != null) {
                                try {
                                    finderClasses.addAll(ancestors(classLoader.loadClass(handler.getHandlerClass())));
                                } catch (final ClassNotFoundException e) {
                                // no-op
                                }
                            }
                        }
                    }
                }
            }
        }
        for (final org.apache.openejb.jee.Interceptor interceptor : ejb.getEjbJar().getInterceptors()) {
            try {
                finderClasses.addAll(ancestors(classLoader.loadClass(interceptor.getInterceptorClass())));
            } catch (final ClassNotFoundException e) {
            // no-op
            }
        }
        final Beans beans = ejb.getBeans();
        if (beans != null && ejb.getEjbJar() != null) {
            for (final List<String> managedClasses : beans.getManagedClasses().values()) {
                for (final String name : managedClasses) {
                    try {
                        finderClasses.addAll(ancestors(classLoader.loadClass(name)));
                    } catch (final ClassNotFoundException e) {
                    // no-op
                    }
                }
            }
            for (final String name : beans.getInterceptors()) {
                try {
                    finderClasses.addAll(ancestors(classLoader.loadClass(name)));
                } catch (final ClassNotFoundException e) {
                // no-op
                }
            }
            for (final String name : beans.getAlternativeClasses()) {
                try {
                    finderClasses.addAll(ancestors(classLoader.loadClass(name)));
                } catch (final ClassNotFoundException e) {
                // no-op
                }
            }
            for (final String name : beans.getDecorators()) {
                try {
                    finderClasses.addAll(ancestors(classLoader.loadClass(name)));
                } catch (final ClassNotFoundException e) {
                // no-op
                }
            }
        }
    } else if (WebModule.class.isInstance(module)) {
        final WebModule web = WebModule.class.cast(module);
        final ClassLoader classLoader = web.getClassLoader();
        if (web.getWebApp() != null) {
            for (final Servlet s : web.getWebApp().getServlet()) {
                final String servletClass = s.getServletClass();
                if (servletClass == null) {
                    continue;
                }
                try {
                    finderClasses.addAll(ancestors(classLoader.loadClass(servletClass)));
                } catch (final ClassNotFoundException e) {
                // no-op
                }
            }
            for (final String s : web.getRestClasses()) {
                try {
                    finderClasses.addAll(ancestors(classLoader.loadClass(s)));
                } catch (final ClassNotFoundException e) {
                // no-op
                }
            }
            for (final String s : web.getEjbWebServices()) {
                try {
                    finderClasses.addAll(ancestors(classLoader.loadClass(s)));
                } catch (final ClassNotFoundException e) {
                // no-op
                }
            }
        }
    }
    return finderClasses.toArray(new Class<?>[finderClasses.size()]);
}
Also used : EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) PortComponent(org.apache.openejb.jee.PortComponent) Handler(org.apache.openejb.jee.Handler) SessionBean(org.apache.openejb.jee.SessionBean) HandlerChain(org.apache.openejb.jee.HandlerChain) Beans(org.apache.openejb.jee.Beans) WebserviceDescription(org.apache.openejb.jee.WebserviceDescription) Servlet(org.apache.openejb.jee.Servlet) HashSet(java.util.HashSet)

Aggregations

Handler (org.apache.openejb.jee.Handler)2 HandlerChain (org.apache.openejb.jee.HandlerChain)2 HandlerChain$JAXB.readHandlerChain (org.apache.openejb.jee.HandlerChain$JAXB.readHandlerChain)2 HandlerChain$JAXB.writeHandlerChain (org.apache.openejb.jee.HandlerChain$JAXB.writeHandlerChain)2 RuntimeContext (org.metatype.sxc.jaxb.RuntimeContext)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 CollapsedStringAdapter (javax.xml.bind.annotation.adapters.CollapsedStringAdapter)1 QName (javax.xml.namespace.QName)1 HandlerChainInfo (org.apache.openejb.assembler.classic.HandlerChainInfo)1 HandlerInfo (org.apache.openejb.assembler.classic.HandlerInfo)1 Beans (org.apache.openejb.jee.Beans)1 EnterpriseBean (org.apache.openejb.jee.EnterpriseBean)1 ParamValue (org.apache.openejb.jee.ParamValue)1 PortComponent (org.apache.openejb.jee.PortComponent)1 Servlet (org.apache.openejb.jee.Servlet)1 SessionBean (org.apache.openejb.jee.SessionBean)1 WebserviceDescription (org.apache.openejb.jee.WebserviceDescription)1 Attribute (org.metatype.sxc.util.Attribute)1 XoXMLStreamReader (org.metatype.sxc.util.XoXMLStreamReader)1