Skip to content
This repository was archived by the owner on Nov 15, 2022. It is now read-only.

Commit 3c756a2

Browse files
lukasjyaminikb
authored andcommitted
Fixes #21392: Web-service endpoint is not available for the deployed EJB application (#22063)
1 parent 0c9c226 commit 3c756a2

File tree

3 files changed

+119
-63
lines changed

3 files changed

+119
-63
lines changed

appserver/webservices/connector/src/main/java/org/glassfish/webservices/connector/annotation/handlers/WebServiceHandler.java

Lines changed: 55 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545

4646
import java.lang.reflect.AnnotatedElement;
4747
import java.lang.annotation.Annotation;
48-
import java.text.MessageFormat;
4948

5049
import org.glassfish.apf.*;
5150

@@ -56,6 +55,7 @@
5655
import com.sun.enterprise.deployment.annotation.context.EjbContext;
5756

5857
import com.sun.enterprise.deployment.*;
58+
import com.sun.enterprise.deployment.annotation.context.EjbsContext;
5959
import com.sun.enterprise.deployment.util.DOLUtils;
6060
import com.sun.enterprise.deployment.annotation.handlers.AbstractHandler;
6161
import com.sun.enterprise.util.LocalStringManagerImpl;
@@ -188,15 +188,27 @@ public HandlerProcessingResult processAnnotation(AnnotationInfo annInfo)
188188
ape.setFatal(false);
189189
throw ape;
190190
}*/
191-
192191
// let's see the type of web service we are dealing with...
193-
if ((ejbProvider!= null) && ejbProvider.getType("javax.ejb.Stateless")!=null &&(annCtx
194-
instanceof EjbContext)) {
192+
if (ejbProvider != null && ejbProvider.getType("javax.ejb.Stateless") != null) {
195193
// this is an ejb !
196-
EjbContext ctx = (EjbContext) annCtx;
197-
bundleDesc = ctx.getDescriptor().getEjbBundleDescriptor();
198-
bundleDesc.setSpecVersion("3.0");
199-
} else {
194+
if (annCtx instanceof EjbContext) {
195+
EjbContext ctx = (EjbContext) annCtx;
196+
bundleDesc = ctx.getDescriptor().getEjbBundleDescriptor();
197+
bundleDesc.setSpecVersion("3.0");
198+
} else if (annCtx instanceof EjbsContext) {
199+
String name = getEjbName(annElem);
200+
for (EjbContext ejbCtx : ((EjbsContext) annCtx).getEjbContexts()) {
201+
EjbDescriptor descriptor = ejbCtx.getDescriptor();
202+
if (name.equals(descriptor.getName())) {
203+
bundleDesc = descriptor.getEjbBundleDescriptor();
204+
bundleDesc.setSpecVersion("3.0");
205+
break;
206+
}
207+
}
208+
}
209+
}
210+
211+
if (bundleDesc == null) {
200212
// this has to be a servlet since there is no @Servlet annotation yet
201213
if(annCtx instanceof WebComponentContext) {
202214
bundleDesc = ((WebComponentContext)annCtx).getDescriptor().getWebBundleDescriptor();
@@ -466,37 +478,7 @@ public HandlerProcessingResult processAnnotation(AnnotationInfo annInfo)
466478

467479

468480
//TODO BM handle stateless
469-
Stateless stateless = null;
470-
try {
471-
stateless = annElem.getAnnotation(javax.ejb.Stateless.class);
472-
} catch (Exception e) {
473-
if (logger.isLoggable(Level.FINE)) {
474-
//This can happen in the web.zip installation where there is no ejb
475-
//Just logging the error
476-
conLogger.log(Level.FINE, LogUtils.EXCEPTION_THROWN, e);
477-
}
478-
}
479-
Singleton singleton = null;
480-
try {
481-
singleton = annElem.getAnnotation(javax.ejb.Singleton.class);
482-
} catch (Exception e) {
483-
if (logger.isLoggable(Level.FINE)) {
484-
//This can happen in the web.zip installation where there is no ejb
485-
//Just logging the error
486-
conLogger.log(Level.FINE, LogUtils.EXCEPTION_THROWN, e);
487-
}
488-
}
489-
String name;
490-
491-
492-
if ((stateless != null) &&((stateless).name()==null || stateless.name().length()>0)) {
493-
name = stateless.name();
494-
} else if ((singleton != null) &&((singleton).name()==null || singleton.name().length()>0)) {
495-
name = singleton.name();
496-
497-
}else {
498-
name = ((Class) annElem).getSimpleName();
499-
}
481+
String name = getEjbName(annElem);
500482
EjbDescriptor ejb = ((EjbBundleDescriptor) bundleDesc).getEjbByName(name);
501483
endpoint.setEjbComponentImpl(ejb);
502484
ejb.setWebServiceEndpointInterfaceName(endpoint.getServiceEndpointInterface());
@@ -605,4 +587,38 @@ private boolean isJaxwsRIDeployment(AnnotationInfo annInfo) {
605587
}
606588
return riDeployment;
607589
}
590+
591+
private String getEjbName(AnnotatedElement annElem) {
592+
Stateless stateless = null;
593+
try {
594+
stateless = annElem.getAnnotation(javax.ejb.Stateless.class);
595+
} catch (Exception e) {
596+
if (logger.isLoggable(Level.FINE)) {
597+
//This can happen in the web.zip installation where there is no ejb
598+
//Just logging the error
599+
conLogger.log(Level.FINE, LogUtils.EXCEPTION_THROWN, e);
600+
}
601+
}
602+
Singleton singleton = null;
603+
try {
604+
singleton = annElem.getAnnotation(javax.ejb.Singleton.class);
605+
} catch (Exception e) {
606+
if (logger.isLoggable(Level.FINE)) {
607+
//This can happen in the web.zip installation where there is no ejb
608+
//Just logging the error
609+
conLogger.log(Level.FINE, LogUtils.EXCEPTION_THROWN, e);
610+
}
611+
}
612+
String name;
613+
614+
if ((stateless != null) && ((stateless).name() == null || stateless.name().length() > 0)) {
615+
name = stateless.name();
616+
} else if ((singleton != null) && ((singleton).name() == null || singleton.name().length() > 0)) {
617+
name = singleton.name();
618+
619+
} else {
620+
name = ((Class) annElem).getSimpleName();
621+
}
622+
return name;
623+
}
608624
}

appserver/webservices/connector/src/main/java/org/glassfish/webservices/connector/annotation/handlers/WebServiceProviderHandler.java

Lines changed: 63 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,12 @@
6262
import com.sun.enterprise.deployment.WebServiceEndpoint;
6363
import com.sun.enterprise.deployment.EjbDescriptor;
6464
import com.sun.enterprise.deployment.WebComponentDescriptor;
65+
import com.sun.enterprise.deployment.annotation.context.EjbsContext;
6566
import com.sun.enterprise.deployment.util.DOLUtils;
6667
import com.sun.enterprise.util.LocalStringManagerImpl;
6768
import java.util.logging.Level;
69+
import javax.ejb.Singleton;
70+
import javax.ejb.Stateless;
6871

6972
import javax.xml.namespace.QName;
7073

@@ -150,12 +153,27 @@ public HandlerProcessingResult processAnnotation(AnnotationInfo annInfo)
150153

151154
try {
152155
// let's see the type of web service we are dealing with...
153-
if ((ejbProvider != null) && ejbProvider.getType("javax.ejb.Stateless") != null && (annCtx instanceof EjbContext)) {
156+
if ((ejbProvider != null) && ejbProvider.getType("javax.ejb.Stateless") != null) {
154157
// this is an ejb !
155-
EjbContext ctx = (EjbContext) annCtx;
156-
bundleDesc = ctx.getDescriptor().getEjbBundleDescriptor();
157-
bundleDesc.setSpecVersion("3.0");
158-
} else {
158+
if (annCtx instanceof EjbContext) {
159+
EjbContext ctx = (EjbContext) annCtx;
160+
bundleDesc = ctx.getDescriptor().getEjbBundleDescriptor();
161+
bundleDesc.setSpecVersion("3.0");
162+
} else if (annCtx instanceof EjbsContext) {
163+
String name = getEjbName(annElem);
164+
for (EjbContext ejbCtx : ((EjbsContext) annCtx).getEjbContexts()) {
165+
EjbDescriptor descriptor = ejbCtx.getDescriptor();
166+
if (name.equals(descriptor.getName())) {
167+
bundleDesc = descriptor.getEjbBundleDescriptor();
168+
bundleDesc.setSpecVersion("3.0");
169+
break;
170+
}
171+
}
172+
}
173+
}
174+
175+
if (bundleDesc == null) {
176+
// this has to be a servlet
159177
if (annCtx instanceof WebComponentContext) {
160178
bundleDesc = ((WebComponentContext) annCtx).getDescriptor().getWebBundleDescriptor();
161179
} else if (!(annCtx instanceof WebBundleContext)) {
@@ -316,16 +334,12 @@ public HandlerProcessingResult processAnnotation(AnnotationInfo annInfo)
316334
endpoint.setWebComponentImpl(webComponent);
317335
}
318336
} else {
319-
if(endpoint.getEjbLink() == null) {
320-
EjbDescriptor[] ejbDescs = ((EjbBundleDescriptor) bundleDesc).getEjbByClassName(((Class)annElem).getName());
321-
if(ejbDescs.length != 1) {
322-
throw new AnnotationProcessorException(
323-
"Unable to find matching descriptor for EJB endpoint",
324-
annInfo);
325-
}
326-
endpoint.setEjbComponentImpl(ejbDescs[0]);
327-
ejbDescs[0].setWebServiceEndpointInterfaceName(endpoint.getServiceEndpointInterface());
328-
endpoint.setEjbLink(ejbDescs[0].getName());
337+
String name = getEjbName(annElem);
338+
EjbDescriptor ejb = ((EjbBundleDescriptor) bundleDesc).getEjbByName(name);
339+
endpoint.setEjbComponentImpl(ejb);
340+
ejb.setWebServiceEndpointInterfaceName(endpoint.getServiceEndpointInterface());
341+
if (endpoint.getEjbLink()== null) {
342+
endpoint.setEjbLink(ejb.getName());
329343
}
330344
}
331345

@@ -378,4 +392,38 @@ private boolean ignoreWebserviceAnnotations(AnnotatedElement annElem, AnnotatedE
378392
}
379393
return false;
380394
}
395+
396+
private String getEjbName(AnnotatedElement annElem) {
397+
Stateless stateless = null;
398+
try {
399+
stateless = annElem.getAnnotation(javax.ejb.Stateless.class);
400+
} catch (Exception e) {
401+
if (logger.isLoggable(Level.FINE)) {
402+
//This can happen in the web.zip installation where there is no ejb
403+
//Just logging the error
404+
conLogger.log(Level.FINE, LogUtils.EXCEPTION_THROWN, e);
405+
}
406+
}
407+
Singleton singleton = null;
408+
try {
409+
singleton = annElem.getAnnotation(javax.ejb.Singleton.class);
410+
} catch (Exception e) {
411+
if (logger.isLoggable(Level.FINE)) {
412+
//This can happen in the web.zip installation where there is no ejb
413+
//Just logging the error
414+
conLogger.log(Level.FINE, LogUtils.EXCEPTION_THROWN, e);
415+
}
416+
}
417+
String name;
418+
419+
if ((stateless != null) && ((stateless).name() == null || stateless.name().length() > 0)) {
420+
name = stateless.name();
421+
} else if ((singleton != null) && ((singleton).name() == null || singleton.name().length() > 0)) {
422+
name = singleton.name();
423+
424+
} else {
425+
name = ((Class) annElem).getSimpleName();
426+
}
427+
return name;
428+
}
381429
}

appserver/webservices/jsr109-impl/src/main/java/org/glassfish/webservices/WebServicesApplication.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ private ArrayList<EjbEndpoint> getEjbEndpoints() {
144144
return ejbendpoints;
145145
}
146146

147-
148147
private void collectEjbEndpoints(BundleDescriptor bundleDesc) {
149148
WebServicesDescriptor wsDesc = bundleDesc.getWebServices();
150149
for (WebService ws : wsDesc.getWebServices()) {
@@ -155,15 +154,8 @@ private void collectEjbEndpoints(BundleDescriptor bundleDesc) {
155154
}
156155
}
157156
}
158-
//For ejb webservices in war we need to get the extension descriptors
159-
//from the WebBundleDescriptor and process those too
160-
//http://monaco.sfbay/detail.jsf?cr=6956406
161-
for (EjbBundleDescriptor ejbD : bundleDesc.getExtensionsDescriptors(EjbBundleDescriptor.class)) {
162-
collectEjbEndpoints(ejbD);
163-
}
164-
165-
166157
}
158+
167159
public boolean stop(ApplicationContext stopContext) {
168160
try {
169161
Iterator<EjbEndpoint> iter = ejbendpoints.iterator();

0 commit comments

Comments
 (0)