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

Commit

Permalink
Fixes #21392: Web-service endpoint is not available for the deployed …
Browse files Browse the repository at this point in the history
…EJB application (#22063)
  • Loading branch information
lukasj authored and yaminikb committed Aug 2, 2017
1 parent 0c9c226 commit 3c756a2
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@

import java.lang.reflect.AnnotatedElement;
import java.lang.annotation.Annotation;
import java.text.MessageFormat;

import org.glassfish.apf.*;

Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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());
}
}

Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ private ArrayList<EjbEndpoint> getEjbEndpoints() {
return ejbendpoints;
}


private void collectEjbEndpoints(BundleDescriptor bundleDesc) {
WebServicesDescriptor wsDesc = bundleDesc.getWebServices();
for (WebService ws : wsDesc.getWebServices()) {
Expand All @@ -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<EjbEndpoint> iter = ejbendpoints.iterator();
Expand Down

0 comments on commit 3c756a2

Please sign in to comment.