PageRenderTime 53ms CodeModel.GetById 30ms app.highlight 19ms RepoModel.GetById 1ms app.codeStats 0ms

/jboss-as-7.1.1.Final/webservices/server-integration/src/main/java/org/jboss/as/webservices/deployers/WSIntegrationProcessorJAXWS_JMS.java

#
Java | 159 lines | 112 code | 14 blank | 33 comment | 22 complexity | b39d55880e7d16a02599b9b7f323f032 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1/*
  2 * JBoss, Home of Professional Open Source.
  3 * Copyright 2011, Red Hat Middleware LLC, and individual contributors
  4 * as indicated by the @author tags. See the copyright.txt file in the
  5 * distribution for a full listing of individual contributors.
  6 *
  7 * This is free software; you can redistribute it and/or modify it
  8 * under the terms of the GNU Lesser General Public License as
  9 * published by the Free Software Foundation; either version 2.1 of
 10 * the License, or (at your option) any later version.
 11 *
 12 * This software is distributed in the hope that it will be useful,
 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 15 * Lesser General Public License for more details.
 16 *
 17 * You should have received a copy of the GNU Lesser General Public
 18 * License along with this software; if not, write to the Free
 19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 21 */
 22package org.jboss.as.webservices.deployers;
 23
 24import static org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT;
 25import static org.jboss.as.server.deployment.Attachments.RESOURCE_ROOTS;
 26import static org.jboss.as.webservices.WSLogger.ROOT_LOGGER;
 27import static org.jboss.as.webservices.util.ASHelper.getAnnotations;
 28import static org.jboss.as.webservices.util.DotNames.WEB_SERVICE_ANNOTATION;
 29import static org.jboss.as.webservices.util.WSAttachmentKeys.JMS_ENDPOINT_METADATA_KEY;
 30
 31import java.net.MalformedURLException;
 32import java.net.URL;
 33import java.util.HashMap;
 34import java.util.LinkedList;
 35import java.util.List;
 36import java.util.Map;
 37
 38import javax.xml.namespace.QName;
 39
 40import org.jboss.as.ee.structure.DeploymentType;
 41import org.jboss.as.ee.structure.DeploymentTypeMarker;
 42import org.jboss.as.server.deployment.AttachmentList;
 43import org.jboss.as.server.deployment.DeploymentPhaseContext;
 44import org.jboss.as.server.deployment.DeploymentUnit;
 45import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
 46import org.jboss.as.server.deployment.DeploymentUnitProcessor;
 47import org.jboss.as.server.deployment.module.ResourceRoot;
 48import org.jboss.as.webservices.util.VirtualFileAdaptor;
 49import org.jboss.jandex.AnnotationInstance;
 50import org.jboss.jandex.AnnotationValue;
 51import org.jboss.jandex.ClassInfo;
 52import org.jboss.vfs.VirtualFile;
 53import org.jboss.ws.common.deployment.SOAPAddressWSDLParser;
 54import org.jboss.wsf.spi.deployment.UnifiedVirtualFile;
 55import org.jboss.wsf.spi.metadata.jms.JMSEndpointMetaData;
 56import org.jboss.wsf.spi.metadata.jms.JMSEndpointsMetaData;
 57
 58/**
 59 * DUP for detecting JMS WS endpoints
 60 *
 61 * @author <a href="mailto:alessio.soldano@jboss.com">Alessio Soldano</a>
 62 */
 63public final class WSIntegrationProcessorJAXWS_JMS implements DeploymentUnitProcessor {
 64
 65    private static final String WSDL_LOCATION = "wsdlLocation";
 66    private static final String PORT_NAME = "portName";
 67    private static final String SERVICE_NAME = "serviceName";
 68    private static final String TARGET_NAMESPACE = "targetNamespace";
 69
 70    @Override
 71    public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
 72        final DeploymentUnit unit = phaseContext.getDeploymentUnit();
 73        if (DeploymentTypeMarker.isType(DeploymentType.EAR, unit)) {
 74            return;
 75        }
 76        final List<AnnotationInstance> webServiceAnnotations = getAnnotations(unit, WEB_SERVICE_ANNOTATION);
 77        // TODO: how about @WebServiceProvider JMS based endpoints?
 78
 79        //group @WebService annotations in the deployment by wsdl contract location
 80        Map<String, List<AnnotationInstance>> map = new HashMap<String, List<AnnotationInstance>>();
 81        for (AnnotationInstance webServiceAnnotation : webServiceAnnotations) {
 82            final AnnotationValue wsdlLocation = webServiceAnnotation.value(WSDL_LOCATION);
 83            final AnnotationValue port = webServiceAnnotation.value(PORT_NAME);
 84            final AnnotationValue service = webServiceAnnotation.value(SERVICE_NAME);
 85            //support for contract-first development only: pick-up @WebService annotations referencing a provided wsdl contract only
 86            if (wsdlLocation != null && port != null && service != null) {
 87                String key = wsdlLocation.asString();
 88                List<AnnotationInstance> annotations = map.get(key);
 89                if (annotations == null) {
 90                    annotations = new LinkedList<AnnotationInstance>();
 91                    map.put(key, annotations);
 92                }
 93                annotations.add(webServiceAnnotation);
 94            }
 95        }
 96
 97        //extract SOAP-over-JMS 1.0 bindings
 98        final JMSEndpointsMetaData endpointsMetaData = new JMSEndpointsMetaData();
 99        if (!map.isEmpty()) {
100
101            for (String wsdlLocation : map.keySet()) {
102                try {
103                    final ResourceRoot resourceRoot = getWsdlResourceRoot(unit, wsdlLocation);
104                    if (resourceRoot == null) continue;
105                    final UnifiedVirtualFile uvf = new VirtualFileAdaptor(resourceRoot.getRoot());
106                    URL url = uvf.findChild(wsdlLocation).toURL();
107                    SOAPAddressWSDLParser parser = new SOAPAddressWSDLParser(url);
108                    for (AnnotationInstance ai : map.get(wsdlLocation)) {
109                        String port = ai.value(PORT_NAME).asString();
110                        String service = ai.value(SERVICE_NAME).asString();
111                        AnnotationValue targetNS = ai.value(TARGET_NAMESPACE);
112                        String tns = targetNS != null ? targetNS.asString() : null;
113                        QName serviceName = new QName(tns, service);
114                        QName portName = new QName(tns, port);
115                        String soapAddress = parser.filterSoapAddress(serviceName, portName, SOAPAddressWSDLParser.SOAP_OVER_JMS_NS);
116                        if (soapAddress != null) {
117                            ClassInfo webServiceClassInfo = (ClassInfo) ai.target();
118                            String beanClassName = webServiceClassInfo.name().toString();
119                            //service name ?
120                            JMSEndpointMetaData endpointMetaData = new JMSEndpointMetaData(endpointsMetaData);
121                            endpointMetaData.setEndpointName(port);
122                            endpointMetaData.setName(beanClassName);
123                            endpointMetaData.setImplementor(beanClassName);
124                            //endpointMetaData.setName(name);
125                            endpointMetaData.setSoapAddress(soapAddress);
126                            endpointMetaData.setWsdlLocation(wsdlLocation);
127                            endpointsMetaData.addEndpointMetaData(endpointMetaData);
128                        }
129                    }
130                } catch (Exception ignore) {
131                    ROOT_LOGGER.cannotReadWsdl(wsdlLocation);
132                }
133            }
134
135        }
136        unit.putAttachment(JMS_ENDPOINT_METADATA_KEY, endpointsMetaData);
137    }
138
139    @Override
140    public void undeploy(final DeploymentUnit context) {
141        // NOOP
142    }
143
144    private static ResourceRoot getWsdlResourceRoot(final DeploymentUnit unit, final String wsdlPath) throws MalformedURLException {
145        final AttachmentList<ResourceRoot> resourceRoots = new AttachmentList<ResourceRoot>(ResourceRoot.class);
146        final ResourceRoot root = unit.getAttachment(DEPLOYMENT_ROOT);
147        resourceRoots.add(root);
148        final AttachmentList<ResourceRoot> otherResourceRoots = unit.getAttachment(RESOURCE_ROOTS);
149        if (otherResourceRoots != null) {
150            resourceRoots.addAll(otherResourceRoots);
151        }
152        for (final ResourceRoot resourceRoot : resourceRoots) {
153            VirtualFile file = resourceRoot.getRoot().getChild(wsdlPath);
154            if (file.exists()) return resourceRoot;
155        }
156        return null;
157    }
158
159}