From 3c756a21585f6e60ec7547b94fba0f5ad076f01f Mon Sep 17 00:00:00 2001 From: Lukas Jungmann Date: Wed, 2 Aug 2017 18:16:26 +0200 Subject: [PATCH] Fixes #21392: Web-service endpoint is not available for the deployed EJB application (#22063) --- .../handlers/WebServiceHandler.java | 94 +++++++++++-------- .../handlers/WebServiceProviderHandler.java | 78 ++++++++++++--- .../webservices/WebServicesApplication.java | 10 +- 3 files changed, 119 insertions(+), 63 deletions(-) diff --git a/appserver/webservices/connector/src/main/java/org/glassfish/webservices/connector/annotation/handlers/WebServiceHandler.java b/appserver/webservices/connector/src/main/java/org/glassfish/webservices/connector/annotation/handlers/WebServiceHandler.java index d517039c4f0..a6910c063b8 100644 --- a/appserver/webservices/connector/src/main/java/org/glassfish/webservices/connector/annotation/handlers/WebServiceHandler.java +++ b/appserver/webservices/connector/src/main/java/org/glassfish/webservices/connector/annotation/handlers/WebServiceHandler.java @@ -45,7 +45,6 @@ import java.lang.reflect.AnnotatedElement; import java.lang.annotation.Annotation; -import java.text.MessageFormat; import org.glassfish.apf.*; @@ -56,6 +55,7 @@ import com.sun.enterprise.deployment.annotation.context.EjbContext; import com.sun.enterprise.deployment.*; +import com.sun.enterprise.deployment.annotation.context.EjbsContext; import com.sun.enterprise.deployment.util.DOLUtils; import com.sun.enterprise.deployment.annotation.handlers.AbstractHandler; import com.sun.enterprise.util.LocalStringManagerImpl; @@ -188,15 +188,27 @@ public HandlerProcessingResult processAnnotation(AnnotationInfo annInfo) ape.setFatal(false); throw ape; }*/ - // let's see the type of web service we are dealing with... - if ((ejbProvider!= null) && ejbProvider.getType("javax.ejb.Stateless")!=null &&(annCtx - instanceof EjbContext)) { + if (ejbProvider != null && ejbProvider.getType("javax.ejb.Stateless") != null) { // this is an ejb ! - EjbContext ctx = (EjbContext) annCtx; - bundleDesc = ctx.getDescriptor().getEjbBundleDescriptor(); - bundleDesc.setSpecVersion("3.0"); - } else { + if (annCtx instanceof EjbContext) { + EjbContext ctx = (EjbContext) annCtx; + bundleDesc = ctx.getDescriptor().getEjbBundleDescriptor(); + bundleDesc.setSpecVersion("3.0"); + } else if (annCtx instanceof EjbsContext) { + String name = getEjbName(annElem); + for (EjbContext ejbCtx : ((EjbsContext) annCtx).getEjbContexts()) { + EjbDescriptor descriptor = ejbCtx.getDescriptor(); + if (name.equals(descriptor.getName())) { + bundleDesc = descriptor.getEjbBundleDescriptor(); + bundleDesc.setSpecVersion("3.0"); + break; + } + } + } + } + + if (bundleDesc == null) { // this has to be a servlet since there is no @Servlet annotation yet if(annCtx instanceof WebComponentContext) { bundleDesc = ((WebComponentContext)annCtx).getDescriptor().getWebBundleDescriptor(); @@ -466,37 +478,7 @@ public HandlerProcessingResult processAnnotation(AnnotationInfo annInfo) //TODO BM handle stateless - Stateless stateless = null; - try { - stateless = annElem.getAnnotation(javax.ejb.Stateless.class); - } catch (Exception e) { - if (logger.isLoggable(Level.FINE)) { - //This can happen in the web.zip installation where there is no ejb - //Just logging the error - conLogger.log(Level.FINE, LogUtils.EXCEPTION_THROWN, e); - } - } - Singleton singleton = null; - try { - singleton = annElem.getAnnotation(javax.ejb.Singleton.class); - } catch (Exception e) { - if (logger.isLoggable(Level.FINE)) { - //This can happen in the web.zip installation where there is no ejb - //Just logging the error - conLogger.log(Level.FINE, LogUtils.EXCEPTION_THROWN, e); - } - } - String name; - - - if ((stateless != null) &&((stateless).name()==null || stateless.name().length()>0)) { - name = stateless.name(); - } else if ((singleton != null) &&((singleton).name()==null || singleton.name().length()>0)) { - name = singleton.name(); - - }else { - name = ((Class) annElem).getSimpleName(); - } + String name = getEjbName(annElem); EjbDescriptor ejb = ((EjbBundleDescriptor) bundleDesc).getEjbByName(name); endpoint.setEjbComponentImpl(ejb); ejb.setWebServiceEndpointInterfaceName(endpoint.getServiceEndpointInterface()); @@ -605,4 +587,38 @@ private boolean isJaxwsRIDeployment(AnnotationInfo annInfo) { } return riDeployment; } + + private String getEjbName(AnnotatedElement annElem) { + Stateless stateless = null; + try { + stateless = annElem.getAnnotation(javax.ejb.Stateless.class); + } catch (Exception e) { + if (logger.isLoggable(Level.FINE)) { + //This can happen in the web.zip installation where there is no ejb + //Just logging the error + conLogger.log(Level.FINE, LogUtils.EXCEPTION_THROWN, e); + } + } + Singleton singleton = null; + try { + singleton = annElem.getAnnotation(javax.ejb.Singleton.class); + } catch (Exception e) { + if (logger.isLoggable(Level.FINE)) { + //This can happen in the web.zip installation where there is no ejb + //Just logging the error + conLogger.log(Level.FINE, LogUtils.EXCEPTION_THROWN, e); + } + } + String name; + + if ((stateless != null) && ((stateless).name() == null || stateless.name().length() > 0)) { + name = stateless.name(); + } else if ((singleton != null) && ((singleton).name() == null || singleton.name().length() > 0)) { + name = singleton.name(); + + } else { + name = ((Class) annElem).getSimpleName(); + } + return name; + } } diff --git a/appserver/webservices/connector/src/main/java/org/glassfish/webservices/connector/annotation/handlers/WebServiceProviderHandler.java b/appserver/webservices/connector/src/main/java/org/glassfish/webservices/connector/annotation/handlers/WebServiceProviderHandler.java index 6716337b6c6..25d50d09114 100644 --- a/appserver/webservices/connector/src/main/java/org/glassfish/webservices/connector/annotation/handlers/WebServiceProviderHandler.java +++ b/appserver/webservices/connector/src/main/java/org/glassfish/webservices/connector/annotation/handlers/WebServiceProviderHandler.java @@ -62,9 +62,12 @@ import com.sun.enterprise.deployment.WebServiceEndpoint; import com.sun.enterprise.deployment.EjbDescriptor; import com.sun.enterprise.deployment.WebComponentDescriptor; +import com.sun.enterprise.deployment.annotation.context.EjbsContext; import com.sun.enterprise.deployment.util.DOLUtils; import com.sun.enterprise.util.LocalStringManagerImpl; import java.util.logging.Level; +import javax.ejb.Singleton; +import javax.ejb.Stateless; import javax.xml.namespace.QName; @@ -150,12 +153,27 @@ public HandlerProcessingResult processAnnotation(AnnotationInfo annInfo) try { // let's see the type of web service we are dealing with... - if ((ejbProvider != null) && ejbProvider.getType("javax.ejb.Stateless") != null && (annCtx instanceof EjbContext)) { + if ((ejbProvider != null) && ejbProvider.getType("javax.ejb.Stateless") != null) { // this is an ejb ! - EjbContext ctx = (EjbContext) annCtx; - bundleDesc = ctx.getDescriptor().getEjbBundleDescriptor(); - bundleDesc.setSpecVersion("3.0"); - } else { + if (annCtx instanceof EjbContext) { + EjbContext ctx = (EjbContext) annCtx; + bundleDesc = ctx.getDescriptor().getEjbBundleDescriptor(); + bundleDesc.setSpecVersion("3.0"); + } else if (annCtx instanceof EjbsContext) { + String name = getEjbName(annElem); + for (EjbContext ejbCtx : ((EjbsContext) annCtx).getEjbContexts()) { + EjbDescriptor descriptor = ejbCtx.getDescriptor(); + if (name.equals(descriptor.getName())) { + bundleDesc = descriptor.getEjbBundleDescriptor(); + bundleDesc.setSpecVersion("3.0"); + break; + } + } + } + } + + if (bundleDesc == null) { + // this has to be a servlet if (annCtx instanceof WebComponentContext) { bundleDesc = ((WebComponentContext) annCtx).getDescriptor().getWebBundleDescriptor(); } else if (!(annCtx instanceof WebBundleContext)) { @@ -316,16 +334,12 @@ public HandlerProcessingResult processAnnotation(AnnotationInfo annInfo) endpoint.setWebComponentImpl(webComponent); } } else { - if(endpoint.getEjbLink() == null) { - EjbDescriptor[] ejbDescs = ((EjbBundleDescriptor) bundleDesc).getEjbByClassName(((Class)annElem).getName()); - if(ejbDescs.length != 1) { - throw new AnnotationProcessorException( - "Unable to find matching descriptor for EJB endpoint", - annInfo); - } - endpoint.setEjbComponentImpl(ejbDescs[0]); - ejbDescs[0].setWebServiceEndpointInterfaceName(endpoint.getServiceEndpointInterface()); - endpoint.setEjbLink(ejbDescs[0].getName()); + String name = getEjbName(annElem); + EjbDescriptor ejb = ((EjbBundleDescriptor) bundleDesc).getEjbByName(name); + endpoint.setEjbComponentImpl(ejb); + ejb.setWebServiceEndpointInterfaceName(endpoint.getServiceEndpointInterface()); + if (endpoint.getEjbLink()== null) { + endpoint.setEjbLink(ejb.getName()); } } @@ -378,4 +392,38 @@ private boolean ignoreWebserviceAnnotations(AnnotatedElement annElem, AnnotatedE } return false; } + + private String getEjbName(AnnotatedElement annElem) { + Stateless stateless = null; + try { + stateless = annElem.getAnnotation(javax.ejb.Stateless.class); + } catch (Exception e) { + if (logger.isLoggable(Level.FINE)) { + //This can happen in the web.zip installation where there is no ejb + //Just logging the error + conLogger.log(Level.FINE, LogUtils.EXCEPTION_THROWN, e); + } + } + Singleton singleton = null; + try { + singleton = annElem.getAnnotation(javax.ejb.Singleton.class); + } catch (Exception e) { + if (logger.isLoggable(Level.FINE)) { + //This can happen in the web.zip installation where there is no ejb + //Just logging the error + conLogger.log(Level.FINE, LogUtils.EXCEPTION_THROWN, e); + } + } + String name; + + if ((stateless != null) && ((stateless).name() == null || stateless.name().length() > 0)) { + name = stateless.name(); + } else if ((singleton != null) && ((singleton).name() == null || singleton.name().length() > 0)) { + name = singleton.name(); + + } else { + name = ((Class) annElem).getSimpleName(); + } + return name; + } } diff --git a/appserver/webservices/jsr109-impl/src/main/java/org/glassfish/webservices/WebServicesApplication.java b/appserver/webservices/jsr109-impl/src/main/java/org/glassfish/webservices/WebServicesApplication.java index e48ab201e00..bdd93c77406 100644 --- a/appserver/webservices/jsr109-impl/src/main/java/org/glassfish/webservices/WebServicesApplication.java +++ b/appserver/webservices/jsr109-impl/src/main/java/org/glassfish/webservices/WebServicesApplication.java @@ -144,7 +144,6 @@ private ArrayList getEjbEndpoints() { return ejbendpoints; } - private void collectEjbEndpoints(BundleDescriptor bundleDesc) { WebServicesDescriptor wsDesc = bundleDesc.getWebServices(); for (WebService ws : wsDesc.getWebServices()) { @@ -155,15 +154,8 @@ private void collectEjbEndpoints(BundleDescriptor bundleDesc) { } } } - //For ejb webservices in war we need to get the extension descriptors - //from the WebBundleDescriptor and process those too - //http://monaco.sfbay/detail.jsf?cr=6956406 - for (EjbBundleDescriptor ejbD : bundleDesc.getExtensionsDescriptors(EjbBundleDescriptor.class)) { - collectEjbEndpoints(ejbD); - } - - } + public boolean stop(ApplicationContext stopContext) { try { Iterator iter = ejbendpoints.iterator();