use of org.apache.openejb.jee.SessionBean$JAXB.readSessionBean in project tomee by apache.
the class LegacyProcessor method process.
public static void process(final Class<?> clazz, final EnterpriseBean bean) {
if (bean instanceof SessionBean) {
final SessionBean sessionBean = (SessionBean) bean;
if (sessionBean.getSessionType() == STATEFUL && SessionSynchronization.class.isAssignableFrom(clazz)) {
try {
sessionBean.getAfterBegin().add(new LifecycleCallback(clazz.getMethod("afterBegin")));
sessionBean.getBeforeCompletion().add(new LifecycleCallback(clazz.getMethod("beforeCompletion")));
sessionBean.getAfterCompletion().add(new LifecycleCallback(clazz.getMethod("afterCompletion", boolean.class)));
} catch (final NoSuchMethodException e) {
// Ignore, should never happen
}
}
if (javax.ejb.SessionBean.class.isAssignableFrom(clazz)) {
final ResourceEnvRef ref = new ResourceEnvRef("javax.ejb.SessionBean/sessionContext", SessionContext.class);
final InjectionTarget target = new InjectionTarget();
target.setInjectionTargetClass(clazz);
target.setInjectionTargetName("sessionContext");
ref.getInjectionTarget().add(target);
sessionBean.getResourceEnvRef().add(ref);
}
}
if (bean instanceof MessageDrivenBean) {
final MessageDrivenBean messageDrivenBean = (MessageDrivenBean) bean;
if (javax.ejb.MessageDrivenBean.class.isAssignableFrom(clazz)) {
final ResourceEnvRef ref = new ResourceEnvRef("javax.ejb.MessageDrivenBean/messageDrivenContext", MessageDrivenContext.class);
final InjectionTarget target = new InjectionTarget();
target.setInjectionTargetClass(clazz);
target.setInjectionTargetName("messageDrivenContext");
ref.getInjectionTarget().add(target);
messageDrivenBean.getResourceEnvRef().add(ref);
}
}
}
use of org.apache.openejb.jee.SessionBean$JAXB.readSessionBean in project tomee by apache.
the class MergeWebappJndiContext method merge.
private void merge(final EjbModule ejbModule, final WebModule webModule) {
final JndiConsumer webApp = webModule.getWebApp();
final EjbJar ejbJar = ejbModule.getEjbJar();
for (final EnterpriseBean bean : ejbJar.getEnterpriseBeans()) {
merge(bean.getEnvEntryMap(), webApp.getEnvEntryMap());
merge(bean.getEjbRefMap(), webApp.getEjbRefMap());
merge(bean.getEjbLocalRefMap(), webApp.getEjbLocalRefMap());
merge(bean.getServiceRefMap(), webApp.getServiceRefMap());
merge(bean.getResourceRefMap(), webApp.getResourceRefMap());
merge(bean.getResourceEnvRefMap(), webApp.getResourceEnvRefMap());
merge(bean.getMessageDestinationRefMap(), webApp.getMessageDestinationRefMap());
merge(bean.getPersistenceContextRefMap(), webApp.getPersistenceContextRefMap());
merge(bean.getPersistenceUnitRefMap(), webApp.getPersistenceUnitRefMap());
mergeUserTransaction(bean.getResourceRefMap(), webApp.getResourceRefMap(), webApp);
mergeUserTransaction(bean.getResourceEnvRefMap(), webApp.getResourceEnvRefMap(), webApp);
mergeUserTransaction(webApp.getResourceRefMap(), bean.getResourceRefMap(), bean);
mergeUserTransaction(webApp.getResourceEnvRefMap(), bean.getResourceEnvRefMap(), bean);
}
// easy way to get a JndiConsumer
final SessionBean aggregator = new SessionBean();
for (final EnterpriseBean a : ejbJar.getEnterpriseBeans()) {
aggregator.getEnvEntryMap().putAll(a.getEnvEntryMap());
aggregator.getEjbRefMap().putAll(a.getEjbRefMap());
aggregator.getEjbLocalRefMap().putAll(a.getEjbLocalRefMap());
aggregator.getServiceRefMap().putAll(a.getServiceRefMap());
aggregator.getResourceRefMap().putAll(a.getResourceRefMap());
aggregator.getResourceEnvRefMap().putAll(a.getResourceEnvRefMap());
aggregator.getMessageDestinationRefMap().putAll(a.getMessageDestinationRefMap());
aggregator.getPersistenceContextRefMap().putAll(a.getPersistenceContextRefMap());
aggregator.getPersistenceUnitRefMap().putAll(a.getPersistenceUnitRefMap());
}
for (final EnterpriseBean a : ejbJar.getEnterpriseBeans()) {
copy(aggregator.getEnvEntryMap(), a.getEnvEntryMap());
copy(aggregator.getEjbRefMap(), a.getEjbRefMap());
copy(aggregator.getEjbLocalRefMap(), a.getEjbLocalRefMap());
copy(aggregator.getServiceRefMap(), a.getServiceRefMap());
copy(aggregator.getResourceRefMap(), a.getResourceRefMap());
copy(aggregator.getResourceEnvRefMap(), a.getResourceEnvRefMap());
copy(aggregator.getMessageDestinationRefMap(), a.getMessageDestinationRefMap());
copy(aggregator.getPersistenceContextRefMap(), a.getPersistenceContextRefMap());
copy(aggregator.getPersistenceUnitRefMap(), a.getPersistenceUnitRefMap());
mergeUserTransaction(aggregator.getResourceRefMap(), a.getResourceRefMap(), a);
mergeUserTransaction(aggregator.getResourceEnvRefMap(), a.getResourceEnvRefMap(), a);
}
}
use of org.apache.openejb.jee.SessionBean$JAXB.readSessionBean in project tomee by apache.
the class JndiEncInfoBuilder method buildDependsOnRefs.
public void buildDependsOnRefs(final EnterpriseBean enterpriseBean, final EnterpriseBeanInfo beanInfo, final String moduleId) throws OpenEJBException {
if (!(enterpriseBean instanceof SessionBean)) {
return;
}
final SessionBean sessionBean = (SessionBean) enterpriseBean;
final URI moduleUri;
if (moduleId == null) {
moduleUri = null;
} else {
moduleUri = URLs.uri(moduleId);
}
final EjbResolver ejbResolver = getEjbResolver(moduleId);
if (sessionBean.getDependsOn() != null) {
for (final String ejbName : sessionBean.getDependsOn()) {
final String deploymentId = ejbResolver.resolve(new SimpleRef(ejbName), moduleUri);
if (deploymentId != null) {
beanInfo.dependsOn.add(deploymentId);
}
}
}
}
use of org.apache.openejb.jee.SessionBean$JAXB.readSessionBean in project tomee by apache.
the class RemoveWebServices method deploy.
public AppModule deploy(final AppModule appModule) throws OpenEJBException {
for (final EjbModule ejbModule : appModule.getEjbModules()) {
final EjbJar ejbJar = ejbModule.getEjbJar();
final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
final Map<String, EjbDeployment> deployments = openejbJar.getDeploymentsByEjbName();
for (final EnterpriseBean bean : ejbJar.getEnterpriseBeans()) {
final String ejbName = bean.getEjbName();
final EjbDeployment ejbDeployment = deployments.get(ejbName);
// Clear any <service-ref> references from ejbs
bean.getServiceRef().clear();
if (!(bean instanceof SessionBean)) {
continue;
}
final SessionBean sessionBean = (SessionBean) bean;
if (sessionBean.getServiceEndpoint() == null) {
continue;
}
sessionBean.setServiceEndpoint(null);
// if not, then we should just delete it
if (sessionBean.getHome() != null) {
continue;
}
if (sessionBean.getLocalHome() != null) {
continue;
}
if (sessionBean.getBusinessLocal().size() > 0) {
continue;
}
if (sessionBean.getBusinessRemote().size() > 0) {
continue;
}
// Ok, delete away...
ejbJar.removeEnterpriseBean(ejbName);
openejbJar.removeEjbDeployment(ejbDeployment);
// As well, let's get rid of any transaction or security attributes
// associated with the bean we just deleted.
final AssemblyDescriptor assemblyDescriptor = ejbJar.getAssemblyDescriptor();
if (assemblyDescriptor != null) {
for (final MethodPermission permission : copy(assemblyDescriptor.getMethodPermission())) {
for (final Method method : copy(permission.getMethod())) {
if (method.getEjbName().equals(ejbName)) {
permission.getMethod().remove(method);
}
}
if (permission.getMethod().size() == 0) {
assemblyDescriptor.getMethodPermission().remove(permission);
}
}
for (final ContainerTransaction transaction : copy(assemblyDescriptor.getContainerTransaction())) {
for (final Method method : copy(transaction.getMethod())) {
if (method.getEjbName().equals(ejbName)) {
transaction.getMethod().remove(method);
}
}
if (transaction.getMethod().size() == 0) {
assemblyDescriptor.getContainerTransaction().remove(transaction);
}
}
for (final InterceptorBinding binding : copy(assemblyDescriptor.getInterceptorBinding())) {
if (binding.getEjbName().equals(ejbName)) {
assemblyDescriptor.getInterceptorBinding().remove(binding);
}
}
}
}
// Clear any <service-ref> references from interceptors
for (final Interceptor interceptor : ejbJar.getInterceptors()) {
interceptor.getServiceRef().clear();
}
}
return appModule;
}
use of org.apache.openejb.jee.SessionBean$JAXB.readSessionBean 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<>();
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 */ }
}
}
Aggregations