use of org.apache.openejb.jee.WebserviceDescription$JAXB.writeWebserviceDescription in project tomee by apache.
the class SunConversion method mergeEjbConfig.
private void mergeEjbConfig(final EjbModule ejbModule, final SunEjbJar sunEjbJar) {
final EjbJar ejbJar = ejbModule.getEjbJar();
final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
if (openejbJar == null) {
return;
}
if (sunEjbJar == null) {
return;
}
if (sunEjbJar.getEnterpriseBeans() == null) {
return;
}
final Map<String, Map<String, WebserviceEndpoint>> endpointMap = new HashMap<String, Map<String, WebserviceEndpoint>>();
for (final Ejb ejb : sunEjbJar.getEnterpriseBeans().getEjb()) {
final EjbDeployment deployment = openejbJar.getDeploymentsByEjbName().get(ejb.getEjbName());
if (deployment == null) {
// warn no matching deployment
continue;
}
// ejb jndi name is the deploymentId
if (ejb.getJndiName() != null) {
deployment.setDeploymentId(ejb.getJndiName());
}
// map ejb-ref jndi name declaration to deploymentId
final Map<String, EjbLink> linksMap = deployment.getEjbLinksMap();
for (final EjbRef ref : ejb.getEjbRef()) {
if (ref.getJndiName() != null) {
String refName = ref.getEjbRefName();
refName = normalize(refName);
EjbLink link = linksMap.get(refName);
if (link == null) {
link = new EjbLink();
link.setEjbRefName(refName);
linksMap.put(refName, link);
deployment.getEjbLink().add(link);
}
link.setDeployentId(ref.getJndiName());
}
}
final Map<String, ResourceLink> resourceLinksMap = deployment.getResourceLinksMap();
for (final ResourceRef ref : ejb.getResourceRef()) {
if (ref.getJndiName() != null) {
String refName = ref.getResRefName();
refName = normalize(refName);
ResourceLink link = resourceLinksMap.get(refName);
if (link == null) {
link = new ResourceLink();
link.setResRefName(refName);
resourceLinksMap.put(refName, link);
deployment.getResourceLink().add(link);
}
link.setResId(ref.getJndiName());
}
}
for (final ResourceEnvRef ref : ejb.getResourceEnvRef()) {
if (ref.getJndiName() != null) {
String refName = ref.getResourceEnvRefName();
refName = normalize(refName);
ResourceLink link = resourceLinksMap.get(refName);
if (link == null) {
link = new ResourceLink();
link.setResRefName(refName);
resourceLinksMap.put(refName, link);
deployment.getResourceLink().add(link);
}
link.setResId(ref.getJndiName());
}
}
for (final MessageDestinationRef ref : ejb.getMessageDestinationRef()) {
if (ref.getJndiName() != null) {
String refName = ref.getMessageDestinationRefName();
refName = normalize(refName);
ResourceLink link = resourceLinksMap.get(refName);
if (link == null) {
link = new ResourceLink();
link.setResRefName(refName);
resourceLinksMap.put(refName, link);
deployment.getResourceLink().add(link);
}
link.setResId(ref.getJndiName());
}
}
final EnterpriseBean bean = ejbJar.getEnterpriseBeansByEjbName().get(ejb.getEjbName());
if (bean != null) {
final Map<String, ServiceRef> serviceRefMap = bean.getServiceRefMap();
for (final org.apache.openejb.jee.sun.ServiceRef ref : ejb.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);
}
}
}
}
if (ejb.getMdbResourceAdapter() != null) {
// resource adapter id is the MDB container ID
final String resourceAdapterId = ejb.getMdbResourceAdapter().getResourceAdapterMid();
deployment.setContainerId(resourceAdapterId);
}
endpointMap.put(ejb.getEjbName(), ejb.getWebserviceEndpointMap());
}
// map wsdl locations
if (ejbModule.getWebservices() != null) {
final Map<String, org.apache.openejb.jee.sun.WebserviceDescription> sunDescriptions = sunEjbJar.getEnterpriseBeans().getWebserviceDescriptionMap();
for (final WebserviceDescription description : ejbModule.getWebservices().getWebserviceDescription()) {
final org.apache.openejb.jee.sun.WebserviceDescription sunDescription = sunDescriptions.get(description.getWebserviceDescriptionName());
// get the serviceId if specified
String serviceId = null;
if (sunDescription != null) {
serviceId = extractSerivceId(sunDescription.getWsdlPublishLocation(), description.getWsdlFile());
}
if (serviceId != null) {
description.setId(serviceId);
}
for (final PortComponent port : description.getPortComponent()) {
// set the ejb bind location
final ServiceImplBean bean = port.getServiceImplBean();
if (bean != null && bean.getEjbLink() != null) {
final Map<String, WebserviceEndpoint> endpoints = endpointMap.get(bean.getEjbLink());
if (endpoints != null) {
final WebserviceEndpoint endpoint = endpoints.get(port.getPortComponentName());
if (endpoint != null && endpoint.getEndpointAddressUri() != null) {
port.setLocation(endpoint.getEndpointAddressUri());
}
}
}
}
}
}
}
use of org.apache.openejb.jee.WebserviceDescription$JAXB.writeWebserviceDescription in project tomee by apache.
the class DeploymentLoader method addWebservices.
private static void addWebservices(final WsModule wsModule) throws OpenEJBException {
final boolean webservicesEnabled = SystemInstance.get().getOptions().get(ConfigurationFactory.WEBSERVICES_ENABLED, true);
if (!webservicesEnabled) {
wsModule.getAltDDs().remove("webservices.xml");
// should be null already, but just for good measure
wsModule.setWebservices(null);
return;
}
// get location of webservices.xml file
final Object webservicesObject = wsModule.getAltDDs().get("webservices.xml");
if (webservicesObject == null || !(webservicesObject instanceof URL)) {
return;
}
final URL webservicesUrl = (URL) webservicesObject;
// determine the base url for this module (either file: or jar:)
URL moduleUrl;
try {
final File jarFile = new File(wsModule.getJarLocation());
moduleUrl = jarFile.toURI().toURL();
if (jarFile.isFile()) {
moduleUrl = new URL("jar", "", -1, moduleUrl + "!/");
}
} catch (final MalformedURLException e) {
logger.warning("Invalid module location " + wsModule.getJarLocation());
return;
}
// parse the webservices.xml file
final Map<URL, JavaWsdlMapping> jaxrpcMappingCache = new HashMap<URL, JavaWsdlMapping>();
final Webservices webservices = ReadDescriptors.readWebservices(webservicesUrl);
wsModule.setWebservices(webservices);
if ("file".equals(webservicesUrl.getProtocol())) {
wsModule.getWatchedResources().add(URLs.toFilePath(webservicesUrl));
}
// parse any jaxrpc-mapping-files mentioned in the webservices.xml file
for (final WebserviceDescription webserviceDescription : webservices.getWebserviceDescription()) {
final String jaxrpcMappingFile = webserviceDescription.getJaxrpcMappingFile();
if (jaxrpcMappingFile != null) {
final URL jaxrpcMappingUrl;
try {
jaxrpcMappingUrl = new URL(moduleUrl, jaxrpcMappingFile);
JavaWsdlMapping jaxrpcMapping = jaxrpcMappingCache.get(jaxrpcMappingUrl);
if (jaxrpcMapping == null) {
jaxrpcMapping = ReadDescriptors.readJaxrpcMapping(jaxrpcMappingUrl);
jaxrpcMappingCache.put(jaxrpcMappingUrl, jaxrpcMapping);
}
webserviceDescription.setJaxrpcMapping(jaxrpcMapping);
if ("file".equals(jaxrpcMappingUrl.getProtocol())) {
wsModule.getWatchedResources().add(URLs.toFilePath(jaxrpcMappingUrl));
}
} catch (final MalformedURLException e) {
logger.warning("Invalid jaxrpc-mapping-file location " + jaxrpcMappingFile);
}
}
}
}
use of org.apache.openejb.jee.WebserviceDescription$JAXB.writeWebserviceDescription 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()]);
}
use of org.apache.openejb.jee.WebserviceDescription$JAXB.writeWebserviceDescription in project tomee by apache.
the class Webservices$JAXB method _read.
public static final Webservices _read(final XoXMLStreamReader reader, RuntimeContext context) throws Exception {
// Check for xsi:nil
if (reader.isXsiNil()) {
return null;
}
if (context == null) {
context = new RuntimeContext();
}
final Webservices webservices = new Webservices();
context.beforeUnmarshal(webservices, LifecycleCallback.NONE);
ArrayList<Text> descriptions = null;
ArrayList<Text> displayNames = null;
LocalCollection<Icon> icon = null;
KeyedCollection<String, WebserviceDescription> webserviceDescription = null;
// Check xsi:type
final QName xsiType = reader.getXsiType();
if (xsiType != null) {
if (("webservicesType" != xsiType.getLocalPart()) || ("http://java.sun.com/xml/ns/javaee" != xsiType.getNamespaceURI())) {
return context.unexpectedXsiType(reader, Webservices.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, webservices);
webservices.id = id;
} else if (("version" == attribute.getLocalName()) && (("" == attribute.getNamespace()) || (attribute.getNamespace() == null))) {
// ATTRIBUTE: version
webservices.version = Adapters.collapsedStringAdapterAdapter.unmarshal(attribute.getValue());
} else if (XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI != attribute.getNamespace()) {
context.unexpectedAttribute(attribute, new QName("", "id"), new QName("", "version"));
}
}
// Read elements
for (final XoXMLStreamReader elementReader : reader.getChildElements()) {
if (("description" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
// ELEMENT: descriptions
final Text descriptionsItem = readText(elementReader, context);
if (descriptions == null) {
descriptions = new ArrayList<Text>();
}
descriptions.add(descriptionsItem);
} else if (("display-name" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
// ELEMENT: displayNames
final Text displayNamesItem = readText(elementReader, context);
if (displayNames == null) {
displayNames = new ArrayList<Text>();
}
displayNames.add(displayNamesItem);
} else if (("icon" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
// ELEMENT: icon
final Icon iconItem = readIcon(elementReader, context);
if (icon == null) {
icon = webservices.icon;
if (icon != null) {
icon.clear();
} else {
icon = new LocalCollection<Icon>();
}
}
icon.add(iconItem);
} else if (("webservice-description" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
// ELEMENT: webserviceDescription
final WebserviceDescription webserviceDescriptionItem = readWebserviceDescription(elementReader, context);
if (webserviceDescription == null) {
webserviceDescription = webservices.webserviceDescription;
if (webserviceDescription != null) {
webserviceDescription.clear();
} else {
webserviceDescription = new KeyedCollection<String, WebserviceDescription>();
}
}
webserviceDescription.add(webserviceDescriptionItem);
} else {
context.unexpectedElement(elementReader, new QName("http://java.sun.com/xml/ns/javaee", "description"), new QName("http://java.sun.com/xml/ns/javaee", "display-name"), new QName("http://java.sun.com/xml/ns/javaee", "icon"), new QName("http://java.sun.com/xml/ns/javaee", "webservice-description"));
}
}
if (descriptions != null) {
try {
webservices.setDescriptions(descriptions.toArray(new Text[descriptions.size()]));
} catch (final Exception e) {
context.setterError(reader, Webservices.class, "setDescriptions", Text[].class, e);
}
}
if (displayNames != null) {
try {
webservices.setDisplayNames(displayNames.toArray(new Text[displayNames.size()]));
} catch (final Exception e) {
context.setterError(reader, Webservices.class, "setDisplayNames", Text[].class, e);
}
}
if (icon != null) {
webservices.icon = icon;
}
if (webserviceDescription != null) {
webservices.webserviceDescription = webserviceDescription;
}
context.afterUnmarshal(webservices, LifecycleCallback.NONE);
return webservices;
}
Aggregations