Skip to content

Commit

Permalink
[WFLY-3657] Injection not working on JAXWS handlers specified with @H…
Browse files Browse the repository at this point in the history
…andlerChain on service endpoint interfaces
  • Loading branch information
asoldano committed Mar 4, 2015
1 parent 7d5ac63 commit fa3bfd9
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 9 deletions.
@@ -1,6 +1,6 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* Copyright 2015, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
Expand Down Expand Up @@ -46,11 +46,13 @@
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.server.deployment.module.ResourceRoot;
import org.jboss.as.webservices.util.ASHelper;
import org.jboss.as.webservices.logging.WSLogger;
import org.jboss.as.webservices.util.ASHelper;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.AnnotationValue;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.jandex.Index;
import org.jboss.vfs.VirtualFile;
import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedHandlerChainMetaData;
Expand All @@ -59,7 +61,10 @@
import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedHandlerMetaData;

/**
* Scans @HandlerChain annotations in the deployment
*
* @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
* @author <a href="mailto:alessio.soldano@jboss.com">Alessio Soldano</a>
*/
public final class WSHandlerChainAnnotationProcessor implements DeploymentUnitProcessor {

Expand Down Expand Up @@ -94,16 +99,38 @@ public void undeploy(final DeploymentUnit context) {
}

private static void processHandlerChainAnnotations(final ResourceRoot resourceRoot, final Index index, final WSEndpointHandlersMapping mapping) throws DeploymentUnitProcessingException {
final List<AnnotationInstance> handlerChainAnnotations = index.getAnnotations(HANDLER_CHAIN_ANNOTATION);

for (final AnnotationInstance handlerChainAnnotation : handlerChainAnnotations) {
final AnnotationTarget annotationTarget = handlerChainAnnotation.target();

final List<AnnotationInstance> webServiceAnnotations = index.getAnnotations(WEB_SERVICE_ANNOTATION);
final List<AnnotationInstance> webServiceProviderAnnotations = index.getAnnotations(WEB_SERVICE_PROVIDER_ANNOTATION);
for (final AnnotationInstance annotationInstance : webServiceAnnotations) {
final AnnotationTarget annotationTarget = annotationInstance.target();
if (annotationTarget instanceof ClassInfo) {
final ClassInfo classInfo = (ClassInfo) annotationTarget;
if (isJaxwsEndpoint(classInfo, index)) {
AnnotationInstance handlerChainAnnotationInstance = getHandlerChainAnnotationInstance(classInfo);
//JSR-181, Section 4.6.1: "The @HandlerChain annotation MAY be present on the endpoint interface and service
//implementation bean. The service implementation bean’s @HandlerChain is used if @HandlerChain is present on both."
if (handlerChainAnnotationInstance == null) {
handlerChainAnnotationInstance = getEndpointInterfaceHandlerChainAnnotationInstance(classInfo, index);
}
if (handlerChainAnnotationInstance != null) {
final String endpointClass = classInfo.name().toString();
processHandlerChainAnnotation(resourceRoot, handlerChainAnnotationInstance, endpointClass, mapping);
}
}
} else {
// We ignore fields & methods annotated with @HandlerChain.
// These are used always in combination with @WebServiceRef
// which are always referencing JAXWS client proxies only.
}
}
for (final AnnotationInstance annotationInstance : webServiceProviderAnnotations) {
final AnnotationTarget annotationTarget = annotationInstance.target();
if (annotationTarget instanceof ClassInfo) {
final ClassInfo classInfo = (ClassInfo) annotationTarget;
final AnnotationInstance handlerChainAnnotationInstance = getHandlerChainAnnotationInstance(classInfo);
if (handlerChainAnnotationInstance != null && isJaxwsEndpoint(classInfo, index)) {
final String endpointClass = classInfo.name().toString();
processHandlerChainAnnotation(resourceRoot, handlerChainAnnotation, endpointClass, mapping);
processHandlerChainAnnotation(resourceRoot, handlerChainAnnotationInstance, endpointClass, mapping);
}
} else {
// We ignore fields & methods annotated with @HandlerChain.
Expand All @@ -113,6 +140,25 @@ private static void processHandlerChainAnnotations(final ResourceRoot resourceRo
}
}

private static AnnotationInstance getHandlerChainAnnotationInstance(final ClassInfo classInfo) {
List<AnnotationInstance> list = classInfo.annotations().get(HANDLER_CHAIN_ANNOTATION);
return list != null && !list.isEmpty() ? list.iterator().next() : null;
}

private static AnnotationInstance getEndpointInterfaceHandlerChainAnnotationInstance(final ClassInfo classInfo, final Index index) {
AnnotationValue av = classInfo.annotations().get(WEB_SERVICE_ANNOTATION).iterator().next().value("endpointInterface");
if (av != null) {
String intf = av.asString();
if (intf != null && !intf.isEmpty()) {
ClassInfo intfClassInfo = index.getClassByName(DotName.createSimple(intf));
if (intfClassInfo != null && ASHelper.isJaxwsEndpointInterface(intfClassInfo)) {
return getHandlerChainAnnotationInstance(intfClassInfo);
}
}
}
return null;
}

private static void processHandlerChainAnnotation(final ResourceRoot resourceRoot, final AnnotationInstance handlerChainAnnotation, final String endpointClass, final WSEndpointHandlersMapping mapping) throws DeploymentUnitProcessingException {
final String handlerChainConfigFile = handlerChainAnnotation.value("file").asString();
InputStream is = null;
Expand Down Expand Up @@ -177,5 +223,4 @@ private static boolean isJaxwsEndpoint(final ClassInfo clazz, final Index index)
final boolean isWebServiceProvider = clazz.annotations().containsKey(WEB_SERVICE_PROVIDER_ANNOTATION);
return isWebService || isWebServiceProvider;
}

}
Expand Up @@ -198,6 +198,13 @@ public static boolean isJaxwsService(final ClassInfo current, final Index index)
return false;
}

public static boolean isJaxwsEndpointInterface(final ClassInfo clazz) {
final short flags = clazz.flags();
if (!Modifier.isInterface(flags)) return false;
if (!Modifier.isPublic(flags)) return false;
return clazz.annotations().containsKey(WEB_SERVICE_ANNOTATION);
}

public static boolean hasClassesFromPackage(final Index index, final String pck) {
for (ClassInfo ci : index.getKnownClasses()) {
if (ci.name().toString().startsWith(pck)) {
Expand Down

0 comments on commit fa3bfd9

Please sign in to comment.