use of org.apache.openejb.jee.PortComponent$JAXB.readPortComponent in project tomee by apache.
the class WsDeployer method processPorts.
private void processPorts(final EjbModule ejbModule) throws OpenEJBException {
// map existing webservice port declarations by servlet link
Webservices webservices = ejbModule.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.getEjbLink() != null) {
portMap.put(serviceImplBean.getEjbLink(), portComponent);
}
}
}
}
final Map<String, EjbDeployment> deploymentsByEjbName = ejbModule.getOpenejbJar().getDeploymentsByEjbName();
WebserviceDescription webserviceDescription;
for (final EnterpriseBean enterpriseBean : ejbModule.getEjbJar().getEnterpriseBeans()) {
// skip if this is not a webservices endpoint
if (!(enterpriseBean instanceof SessionBean)) {
continue;
}
final SessionBean sessionBean = (SessionBean) enterpriseBean;
if (sessionBean.getSessionType() == SessionType.STATEFUL) {
continue;
}
if (sessionBean.getSessionType() == SessionType.MANAGED) {
continue;
}
if (sessionBean.getServiceEndpoint() == null) {
continue;
}
final EjbDeployment deployment = deploymentsByEjbName.get(sessionBean.getEjbName());
if (deployment == null) {
continue;
}
final Class<?> ejbClass;
try {
ejbClass = ejbModule.getClassLoader().loadClass(sessionBean.getEjbClass());
} catch (final ClassNotFoundException e) {
throw new OpenEJBException("Unable to load ejb class: " + sessionBean.getEjbClass(), e);
}
// for now, skip all non jaxws beans
if (!JaxWsUtils.isWebService(ejbClass)) {
continue;
}
// create webservices dd if not defined
if (webservices == null) {
webservices = new Webservices();
ejbModule.setWebservices(webservices);
}
webserviceDescription = webservices.getWebserviceDescriptionMap().get(JaxWsUtils.getServiceName(ejbClass));
if (webserviceDescription == null) {
webserviceDescription = new WebserviceDescription();
if (JaxWsUtils.isWebService(ejbClass)) {
webserviceDescription.setWebserviceDescriptionName(JaxWsUtils.getServiceName(ejbClass));
}
// TODO else { /* create webserviceDescription name using some sort of jaxrpc data */ }
webservices.getWebserviceDescription().add(webserviceDescription);
}
// add a port component if we don't alrady have one
PortComponent portComponent = portMap.get(sessionBean.getEjbName());
if (portComponent == null) {
portComponent = new PortComponent();
if (webserviceDescription.getPortComponentMap().containsKey(JaxWsUtils.getPortQName(ejbClass).getLocalPart())) {
// when to webservices.xml is defined and when we want to
// publish more than one port for the same implementation by configuration
portComponent.setPortComponentName(sessionBean.getEjbName());
} else {
// JAX-WS Metadata specification default
portComponent.setPortComponentName(JaxWsUtils.getPortQName(ejbClass).getLocalPart());
}
webserviceDescription.getPortComponent().add(portComponent);
final ServiceImplBean serviceImplBean = new ServiceImplBean();
serviceImplBean.setEjbLink(sessionBean.getEjbName());
portComponent.setServiceImplBean(serviceImplBean);
// Checking if MTOM must be enabled
if (portComponent.getProtocolBinding() == null) {
portComponent.setProtocolBinding(JaxWsUtils.getBindingUriFromAnn(ejbClass));
}
configMtomAnnotation(ejbClass, portComponent);
if (SOAPBinding.SOAP12HTTP_MTOM_BINDING.equals(portComponent.getProtocolBinding()) || SOAPBinding.SOAP11HTTP_MTOM_BINDING.equals(portComponent.getProtocolBinding())) {
portComponent.setEnableMtom(true);
}
}
// default portId == deploymentId
if (portComponent.getId() == null) {
portComponent.setId(deployment.getDeploymentId());
}
if (webserviceDescription.getId() == null) {
webserviceDescription.setId(deployment.getDeploymentId());
}
// set service endpoint interface
if (portComponent.getServiceEndpointInterface() == null) {
portComponent.setServiceEndpointInterface(sessionBean.getServiceEndpoint());
}
// default location is /@WebService.serviceName/@WebService.name
if (JaxWsUtils.isWebService(ejbClass)) {
if (portComponent.getWsdlPort() == null) {
portComponent.setWsdlPort(JaxWsUtils.getPortQName(ejbClass));
}
if (webserviceDescription.getWsdlFile() == null) {
webserviceDescription.setWsdlFile(JaxWsUtils.getServiceWsdlLocation(ejbClass, ejbModule.getClassLoader()));
}
if (portComponent.getWsdlService() == null) {
final Definition definition = getWsdl(ejbModule, 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(ejbClass));
}
}
if (portComponent.getLocation() == null && webserviceDescription.getWsdlFile() != null) {
// set location based on wsdl port
final Definition definition = getWsdl(ejbModule, webserviceDescription.getWsdlFile());
final String locationURI = getLocationFromWsdl(definition, portComponent);
portComponent.setLocation(locationURI);
}
if (portComponent.getProtocolBinding() == null) {
portComponent.setProtocolBinding(JaxWsUtils.getBindingUriFromAnn(ejbClass));
}
// handlers
if (portComponent.getHandlerChains() == null) {
final HandlerChains handlerChains = getHandlerChains(ejbClass, sessionBean.getServiceEndpoint(), ejbModule.getClassLoader());
portComponent.setHandlerChains(handlerChains);
}
}
// TODO else { /* location JAX-RPC services comes from wsdl file */ }
}
}
use of org.apache.openejb.jee.PortComponent$JAXB.readPortComponent 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);
}
}
}
use of org.apache.openejb.jee.PortComponent$JAXB.readPortComponent in project tomee by apache.
the class WebserviceDescription$JAXB method _write.
public static final void _write(final XoXMLStreamWriter writer, final WebserviceDescription webserviceDescription, RuntimeContext context) throws Exception {
if (webserviceDescription == null) {
writer.writeXsiNil();
return;
}
if (context == null) {
context = new RuntimeContext();
}
final String prefix = writer.getUniquePrefix("http://java.sun.com/xml/ns/javaee");
if (WebserviceDescription.class != webserviceDescription.getClass()) {
context.unexpectedSubclass(writer, webserviceDescription, WebserviceDescription.class);
return;
}
context.beforeMarshal(webserviceDescription, LifecycleCallback.NONE);
// ATTRIBUTE: id
final String idRaw = webserviceDescription.id;
if (idRaw != null) {
String id = null;
try {
id = Adapters.collapsedStringAdapterAdapter.marshal(idRaw);
} catch (final Exception e) {
context.xmlAdapterError(webserviceDescription, "id", CollapsedStringAdapter.class, String.class, String.class, e);
}
writer.writeAttribute("", "", "id", id);
}
// ELEMENT: description
final String descriptionRaw = webserviceDescription.description;
String description = null;
try {
description = Adapters.collapsedStringAdapterAdapter.marshal(descriptionRaw);
} catch (final Exception e) {
context.xmlAdapterError(webserviceDescription, "description", CollapsedStringAdapter.class, String.class, String.class, e);
}
if (description != null) {
writer.writeStartElement(prefix, "description", "http://java.sun.com/xml/ns/javaee");
writer.writeCharacters(description);
writer.writeEndElement();
}
// ELEMENT: displayName
final String displayNameRaw = webserviceDescription.displayName;
String displayName = null;
try {
displayName = Adapters.collapsedStringAdapterAdapter.marshal(displayNameRaw);
} catch (final Exception e) {
context.xmlAdapterError(webserviceDescription, "displayName", CollapsedStringAdapter.class, String.class, String.class, e);
}
if (displayName != null) {
writer.writeStartElement(prefix, "display-name", "http://java.sun.com/xml/ns/javaee");
writer.writeCharacters(displayName);
writer.writeEndElement();
}
// ELEMENT: icon
final Icon icon = webserviceDescription.icon;
if (icon != null) {
writer.writeStartElement(prefix, "icon", "http://java.sun.com/xml/ns/javaee");
writeIcon(writer, icon, context);
writer.writeEndElement();
}
// ELEMENT: webserviceDescriptionName
final String webserviceDescriptionNameRaw = webserviceDescription.webserviceDescriptionName;
String webserviceDescriptionName = null;
try {
webserviceDescriptionName = Adapters.collapsedStringAdapterAdapter.marshal(webserviceDescriptionNameRaw);
} catch (final Exception e) {
context.xmlAdapterError(webserviceDescription, "webserviceDescriptionName", CollapsedStringAdapter.class, String.class, String.class, e);
}
if (webserviceDescriptionName != null) {
writer.writeStartElement(prefix, "webservice-description-name", "http://java.sun.com/xml/ns/javaee");
writer.writeCharacters(webserviceDescriptionName);
writer.writeEndElement();
} else {
context.unexpectedNullValue(webserviceDescription, "webserviceDescriptionName");
}
// ELEMENT: wsdlFile
final String wsdlFileRaw = webserviceDescription.wsdlFile;
String wsdlFile = null;
try {
wsdlFile = Adapters.collapsedStringAdapterAdapter.marshal(wsdlFileRaw);
} catch (final Exception e) {
context.xmlAdapterError(webserviceDescription, "wsdlFile", CollapsedStringAdapter.class, String.class, String.class, e);
}
if (wsdlFile != null) {
writer.writeStartElement(prefix, "wsdl-file", "http://java.sun.com/xml/ns/javaee");
writer.writeCharacters(wsdlFile);
writer.writeEndElement();
}
// ELEMENT: jaxrpcMappingFile
final String jaxrpcMappingFileRaw = webserviceDescription.jaxrpcMappingFile;
String jaxrpcMappingFile = null;
try {
jaxrpcMappingFile = Adapters.collapsedStringAdapterAdapter.marshal(jaxrpcMappingFileRaw);
} catch (final Exception e) {
context.xmlAdapterError(webserviceDescription, "jaxrpcMappingFile", CollapsedStringAdapter.class, String.class, String.class, e);
}
if (jaxrpcMappingFile != null) {
writer.writeStartElement(prefix, "jaxrpc-mapping-file", "http://java.sun.com/xml/ns/javaee");
writer.writeCharacters(jaxrpcMappingFile);
writer.writeEndElement();
}
// ELEMENT: portComponent
final KeyedCollection<String, PortComponent> portComponent = webserviceDescription.portComponent;
if (portComponent != null) {
for (final PortComponent portComponentItem : portComponent) {
if (portComponentItem != null) {
writer.writeStartElement(prefix, "port-component", "http://java.sun.com/xml/ns/javaee");
writePortComponent(writer, portComponentItem, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(webserviceDescription, "portComponent");
}
}
}
context.afterMarshal(webserviceDescription, LifecycleCallback.NONE);
}
use of org.apache.openejb.jee.PortComponent$JAXB.readPortComponent in project tomee by apache.
the class AppInfoBuilder method configureWebservices.
private List<PortInfo> configureWebservices(final Webservices webservices) {
final List<PortInfo> portMap = new ArrayList<PortInfo>();
if (webservices == null) {
return portMap;
}
for (final WebserviceDescription desc : webservices.getWebserviceDescription()) {
final String wsdlFile = desc.getWsdlFile();
final String serviceName = desc.getWebserviceDescriptionName();
for (final PortComponent port : desc.getPortComponent()) {
final PortInfo portInfo = new PortInfo();
final ServiceImplBean serviceImplBean = port.getServiceImplBean();
portInfo.serviceId = desc.getId();
portInfo.portId = port.getId();
portInfo.serviceLink = serviceImplBean.getEjbLink();
if (portInfo.serviceLink == null) {
portInfo.serviceLink = serviceImplBean.getServletLink();
}
portInfo.seiInterfaceName = port.getServiceEndpointInterface();
portInfo.portName = port.getPortComponentName();
portInfo.binding = port.getProtocolBinding();
portInfo.serviceName = serviceName;
portInfo.wsdlFile = wsdlFile;
portInfo.mtomEnabled = port.isEnableMtom();
portInfo.wsdlPort = port.getWsdlPort();
portInfo.wsdlService = port.getWsdlService();
portInfo.location = port.getLocation();
final List<HandlerChainInfo> handlerChains = ConfigurationFactory.toHandlerChainInfo(port.getHandlerChains());
portInfo.handlerChains.addAll(handlerChains);
// todo configure jaxrpc mappings here
portMap.add(portInfo);
}
}
return portMap;
}
use of org.apache.openejb.jee.PortComponent$JAXB.readPortComponent 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());
}
}
}
}
}
}
}
Aggregations