001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.axis.builder;
017:
018: import java.lang.reflect.Method;
019: import java.net.MalformedURLException;
020: import java.net.URI;
021: import java.net.URISyntaxException;
022: import java.net.URL;
023: import java.util.ArrayList;
024: import java.util.Collection;
025: import java.util.Collections;
026: import java.util.HashMap;
027: import java.util.HashSet;
028: import java.util.Iterator;
029: import java.util.List;
030: import java.util.Map;
031: import java.util.Set;
032: import java.util.jar.JarFile;
033:
034: import javax.jws.WebService;
035: import javax.wsdl.Binding;
036: import javax.wsdl.BindingOperation;
037: import javax.wsdl.Definition;
038: import javax.wsdl.Operation;
039: import javax.wsdl.Port;
040: import javax.wsdl.PortType;
041: import javax.wsdl.extensions.soap.SOAPAddress;
042: import javax.wsdl.extensions.soap.SOAPBinding;
043: import javax.xml.namespace.QName;
044: import javax.xml.rpc.handler.HandlerInfo;
045: import javax.xml.ws.WebServiceProvider;
046:
047: import org.apache.axis.constants.Style;
048: import org.apache.axis.description.JavaServiceDesc;
049: import org.apache.axis.handlers.HandlerInfoChainFactory;
050: import org.apache.axis.handlers.soap.SOAPService;
051: import org.apache.axis.providers.java.RPCProvider;
052: import org.apache.axis.soap.SOAPConstants;
053: import org.apache.commons.logging.Log;
054: import org.apache.commons.logging.LogFactory;
055: import org.apache.geronimo.axis.client.AxisServiceReference;
056: import org.apache.geronimo.axis.client.OperationInfo;
057: import org.apache.geronimo.axis.client.SEIFactory;
058: import org.apache.geronimo.axis.client.SEIFactoryImpl;
059: import org.apache.geronimo.axis.server.AxisWebServiceContainer;
060: import org.apache.geronimo.axis.server.POJOProvider;
061: import org.apache.geronimo.axis.server.ServiceInfo;
062: import org.apache.geronimo.common.DeploymentException;
063: import org.apache.geronimo.gbean.GBeanData;
064: import org.apache.geronimo.gbean.GBeanInfo;
065: import org.apache.geronimo.gbean.GBeanInfoBuilder;
066: import org.apache.geronimo.gbean.AbstractName;
067: import org.apache.geronimo.j2ee.deployment.Module;
068: import org.apache.geronimo.j2ee.deployment.WebServiceBuilder;
069: import org.apache.geronimo.j2ee.deployment.HandlerInfoInfo;
070: import org.apache.geronimo.j2ee.deployment.WebModule;
071: import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
072: import org.apache.geronimo.xbeans.geronimo.naming.GerPortCompletionType;
073: import org.apache.geronimo.xbeans.geronimo.naming.GerPortType;
074: import org.apache.geronimo.xbeans.geronimo.naming.GerServiceCompletionType;
075: import org.apache.geronimo.xbeans.geronimo.naming.GerServiceRefType;
076: import org.apache.geronimo.xbeans.j2ee.JavaWsdlMappingType;
077: import org.apache.geronimo.xbeans.j2ee.JavaXmlTypeMappingType;
078: import org.apache.geronimo.xbeans.j2ee.ServiceEndpointInterfaceMappingType;
079: import org.apache.geronimo.xbeans.j2ee.ServiceEndpointMethodMappingType;
080: import org.apache.geronimo.deployment.util.DeploymentUtil;
081: import org.apache.geronimo.deployment.DeploymentContext;
082: import org.apache.geronimo.deployment.service.EnvironmentBuilder;
083: import org.apache.geronimo.webservices.SerializableWebServiceContainerFactoryGBean;
084: import org.apache.geronimo.webservices.builder.DescriptorVersion;
085: import org.apache.geronimo.webservices.builder.PortInfo;
086: import org.apache.geronimo.webservices.builder.SchemaInfoBuilder;
087: import org.apache.geronimo.webservices.builder.WSDescriptorParser;
088: import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
089: import org.apache.geronimo.kernel.repository.Environment;
090:
091: /**
092: * @version $Rev: 561663 $ $Date: 2007-07-31 22:15:55 -0700 (Tue, 31 Jul 2007) $
093: */
094: public class AxisBuilder implements WebServiceBuilder {
095:
096: private static final Log LOG = LogFactory.getLog(AxisBuilder.class);
097:
098: private static final SOAPConstants SOAP_VERSION = SOAPConstants.SOAP11_CONSTANTS;
099:
100: private final Environment defaultEnvironment;
101: private static final String KEY = AxisBuilder.class.getName();
102:
103: public AxisBuilder() {
104: defaultEnvironment = null;
105: }
106:
107: public AxisBuilder(Environment defaultEnvironment) {
108: this .defaultEnvironment = defaultEnvironment;
109: }
110:
111: public void findWebServices(Module module, boolean isEJB,
112: Map servletLocations, Environment environment,
113: Map sharedContext) throws DeploymentException {
114: findWebServices(module.getModuleFile(), isEJB,
115: servletLocations, environment, sharedContext);
116: }
117:
118: public void findWebServices(JarFile moduleFile, boolean isEJB,
119: Map servletLocations, Environment environment,
120: Map sharedContext) throws DeploymentException {
121: final String path = isEJB ? "META-INF/webservices.xml"
122: : "WEB-INF/webservices.xml";
123: try {
124: URL wsDDUrl = DeploymentUtil.createJarURL(moduleFile, path);
125: Map portMap = WSDescriptorParser.parseWebServiceDescriptor(
126: wsDDUrl, moduleFile, isEJB, servletLocations);
127: if (portMap != null) {
128: if (defaultEnvironment != null) {
129: EnvironmentBuilder.mergeEnvironments(environment,
130: defaultEnvironment);
131: }
132: sharedContext.put(KEY, portMap);
133: } else {
134: sharedContext.put(KEY, Collections.EMPTY_MAP);
135: }
136: } catch (MalformedURLException e) {
137: // The webservices.xml file doesn't exist.
138: }
139: }
140:
141: public boolean configurePOJO(GBeanData targetGBean,
142: String servletName, Module module, String servletClassName,
143: DeploymentContext context) throws DeploymentException {
144: Map sharedContext = ((WebModule) module).getSharedContext();
145: Map portInfoMap = (Map) sharedContext.get(KEY);
146: PortInfo portInfo = (PortInfo) portInfoMap.get(servletName);
147: if (portInfo == null) {
148: //not ours
149: return false;
150: }
151:
152: ClassLoader cl = context.getClassLoader();
153: Class serviceClass = loadClass(servletClassName, cl);
154: if (isJAXWSWebService(serviceClass)) {
155: if (DescriptorVersion.J2EE.equals(portInfo
156: .getDescriptorVersion())) {
157: // This is a JAX-WS web service in J2EE descriptor so throw an exception
158: throw new DeploymentException(
159: "JAX-WS web service '"
160: + portInfo.getPortComponentName()
161: + "' cannot be specified in J2EE webservices.xml descriptor.");
162: } else {
163: // This is a JAX-WS web service in JAVAEE descriptor so ignore
164: return false;
165: }
166: }
167:
168: portInfo.initialize(module.getModuleFile());
169:
170: LOG.debug("Publishing JAX-RPC '"
171: + portInfo.getPortComponentName() + "' service at "
172: + portInfo.getContextURI());
173:
174: ServiceInfo serviceInfo = AxisServiceBuilder.createServiceInfo(
175: portInfo, cl);
176: JavaServiceDesc serviceDesc = serviceInfo.getServiceDesc();
177:
178: targetGBean.setAttribute("pojoClassName", servletClassName);
179: RPCProvider provider = new POJOProvider();
180:
181: SOAPService service = new SOAPService(null, provider, null);
182: service.setServiceDescription(serviceDesc);
183: service.setOption("className", servletClassName);
184:
185: HandlerInfoChainFactory handlerInfoChainFactory = new HandlerInfoChainFactory(
186: serviceInfo.getHandlerInfos());
187: service.setOption(
188: org.apache.axis.Constants.ATTR_HANDLERINFOCHAIN,
189: handlerInfoChainFactory);
190:
191: URI location;
192: try {
193: location = new URI(serviceDesc.getEndpointURL());
194: } catch (URISyntaxException e) {
195: throw new DeploymentException(
196: "Invalid webservice endpoint URI", e);
197: }
198: URI wsdlURI;
199: try {
200: wsdlURI = new URI(serviceDesc.getWSDLFile());
201: } catch (URISyntaxException e) {
202: throw new DeploymentException("Invalid wsdl URI", e);
203:
204: }
205:
206: AxisWebServiceContainer axisWebServiceContainer = new AxisWebServiceContainer(
207: location, wsdlURI, service, serviceInfo.getWsdlMap(),
208: cl);
209: AbstractName webServiceContainerFactoryName = context
210: .getNaming().createChildName(
211: targetGBean.getAbstractName(),
212: "webServiceContainer",
213: NameFactory.GERONIMO_SERVICE);
214: GBeanData webServiceContainerFactoryGBean = new GBeanData(
215: webServiceContainerFactoryName,
216: SerializableWebServiceContainerFactoryGBean.GBEAN_INFO);
217: webServiceContainerFactoryGBean.setAttribute(
218: "webServiceContainer", axisWebServiceContainer);
219: try {
220: context.addGBean(webServiceContainerFactoryGBean);
221: } catch (GBeanAlreadyExistsException e) {
222: throw new DeploymentException(
223: "Could not add webServiceContainerFactoryGBean", e);
224: }
225: targetGBean.setReferencePattern("WebServiceContainerFactory",
226: webServiceContainerFactoryName);
227: return true;
228: }
229:
230: public boolean configureEJB(GBeanData targetGBean, String ejbName,
231: Module module, Map sharedContext, ClassLoader classLoader)
232: throws DeploymentException {
233: Map portInfoMap = (Map) sharedContext.get(KEY);
234: PortInfo portInfo = (PortInfo) portInfoMap.get(ejbName);
235: if (portInfo == null) {
236: //not ours
237: return false;
238: }
239:
240: String beanClassName = (String) targetGBean
241: .getAttribute("ejbClass");
242: Class serviceClass = loadClass(beanClassName, classLoader);
243: if (isJAXWSWebService(serviceClass)) {
244: if (DescriptorVersion.J2EE.equals(portInfo
245: .getDescriptorVersion())) {
246: // This is a JAX-WS web service in J2EE descriptor so throw an exception
247: throw new DeploymentException(
248: "JAX-WS web service '"
249: + portInfo.getPortComponentName()
250: + "' cannot be specified in J2EE webservices.xml descriptor.");
251: } else {
252: // This is a JAX-WS web service in JAVAEE descriptor so ignore
253: return false;
254: }
255: }
256:
257: portInfo.initialize(module.getModuleFile());
258:
259: LOG.debug("Publishing EJB JAX-RPC '"
260: + portInfo.getPortComponentName() + "' service at "
261: + portInfo.getContextURI());
262:
263: ServiceInfo serviceInfo = AxisServiceBuilder.createServiceInfo(
264: portInfo, classLoader);
265: targetGBean.setAttribute("serviceInfo", serviceInfo);
266: JavaServiceDesc serviceDesc = serviceInfo.getServiceDesc();
267: URI location = portInfo.getContextURI();
268: targetGBean.setAttribute("location", location);
269: URI wsdlURI;
270: try {
271: wsdlURI = new URI(serviceDesc.getWSDLFile());
272: } catch (URISyntaxException e) {
273: throw new DeploymentException("Invalid wsdl URI", e);
274: }
275: targetGBean.setAttribute("wsdlURI", wsdlURI);
276: return true;
277: }
278:
279: //ServicereferenceBuilder
280: public Object createService(Class serviceInterface, URI wsdlURI,
281: URI jaxrpcMappingURI, QName serviceQName,
282: Map portComponentRefMap, List handlerInfos,
283: Object serviceRefType, Module module,
284: ClassLoader classLoader) throws DeploymentException {
285: GerServiceRefType gerServiceRefType = (GerServiceRefType) serviceRefType;
286: JarFile moduleFile = module.getModuleFile();
287: SchemaInfoBuilder schemaInfoBuilder = null;
288: JavaWsdlMappingType mapping = null;
289: if (wsdlURI != null) {
290: schemaInfoBuilder = new SchemaInfoBuilder(moduleFile,
291: wsdlURI);
292:
293: mapping = WSDescriptorParser.readJaxrpcMapping(moduleFile,
294: jaxrpcMappingURI);
295: }
296:
297: return createService(serviceInterface, schemaInfoBuilder,
298: mapping, serviceQName, SOAP_VERSION, handlerInfos,
299: gerServiceRefType, module, classLoader);
300: }
301:
302: public Object createService(Class serviceInterface,
303: SchemaInfoBuilder schemaInfoBuilder,
304: JavaWsdlMappingType mapping, QName serviceQName,
305: SOAPConstants soapVersion, List handlerInfos,
306: GerServiceRefType serviceRefType, Module module,
307: ClassLoader classloader) throws DeploymentException {
308: Map seiPortNameToFactoryMap = new HashMap();
309: Map seiClassNameToFactoryMap = new HashMap();
310: if (schemaInfoBuilder != null) {
311: buildSEIFactoryMap(schemaInfoBuilder, serviceRefType,
312: mapping, handlerInfos, serviceQName, soapVersion,
313: seiPortNameToFactoryMap, seiClassNameToFactoryMap,
314: classloader);
315: }
316: return new AxisServiceReference(serviceInterface.getName(),
317: seiPortNameToFactoryMap, seiClassNameToFactoryMap);
318: }
319:
320: public void buildSEIFactoryMap(SchemaInfoBuilder schemaInfoBuilder,
321: GerServiceRefType serviceRefType,
322: JavaWsdlMappingType mapping, List handlerInfos,
323: QName serviceQName, SOAPConstants soapVersion,
324: Map seiPortNameToFactoryMap, Map seiClassNameToFactoryMap,
325: ClassLoader classLoader) throws DeploymentException {
326: Map exceptionMap = WSDescriptorParser.getExceptionMap(mapping);
327:
328: Definition definition = schemaInfoBuilder.getDefinition();
329: //check for consistency
330: if (definition.getServices().size() == 0) {
331: //partial wsdl
332: if (serviceRefType == null
333: || !serviceRefType.isSetServiceCompletion()) {
334: throw new DeploymentException(
335: "Partial wsdl, but no service completion supplied");
336: }
337: GerServiceCompletionType serviceCompletion = serviceRefType
338: .getServiceCompletion();
339: String serviceLocalName = serviceCompletion
340: .getServiceName().trim();
341: String namespace = definition.getTargetNamespace();
342: serviceQName = new QName(namespace, serviceLocalName);
343: javax.wsdl.Service service = definition.createService();
344: service.setQName(serviceQName);
345: GerPortCompletionType[] portCompletions = serviceCompletion
346: .getPortCompletionArray();
347: for (int i = 0; i < portCompletions.length; i++) {
348: GerPortCompletionType portCompletion = portCompletions[i];
349: GerPortType port = portCompletion.getPort();
350: URL location = getLocation(port);
351: String portName = port.getPortName().trim();
352: String bindingName = portCompletion.getBindingName()
353: .trim();
354: QName bindingQName = new QName(namespace, bindingName);
355: Binding binding = definition.getBinding(bindingQName);
356: if (binding == null) {
357: throw new DeploymentException(
358: "No binding found with qname: "
359: + bindingQName);
360: }
361: String credentialsName = port.isSetCredentialsName() ? port
362: .getCredentialsName().trim()
363: : null;
364: mapBinding(binding, mapping, serviceQName, classLoader,
365: soapVersion, schemaInfoBuilder, portName,
366: location, handlerInfos,
367: seiPortNameToFactoryMap,
368: seiClassNameToFactoryMap, credentialsName,
369: exceptionMap);
370:
371: }
372: } else {
373: //full wsdl
374: if (serviceRefType != null
375: && serviceRefType.isSetServiceCompletion()) {
376: throw new DeploymentException(
377: "Full wsdl, but service completion supplied");
378: }
379: //organize the extra port info
380: Map portMap = new HashMap();
381: if (serviceRefType != null) {
382: GerPortType[] ports = serviceRefType.getPortArray();
383: for (int i = 0; i < ports.length; i++) {
384: GerPortType port = ports[i];
385: String portName = port.getPortName().trim();
386: portMap.put(portName, port);
387: }
388: }
389:
390: //find the service we are working with
391: javax.wsdl.Service service = getService(serviceQName,
392: schemaInfoBuilder.getDefinition());
393: if (serviceQName == null) {
394: serviceQName = service.getQName();
395: }
396:
397: Map wsdlPortMap = service.getPorts();
398: for (Iterator iterator = wsdlPortMap.entrySet().iterator(); iterator
399: .hasNext();) {
400: Map.Entry entry = (Map.Entry) iterator.next();
401: String portName = (String) entry.getKey();
402: Port port = (Port) entry.getValue();
403:
404: GerPortType gerPort = (GerPortType) portMap
405: .get(portName);
406:
407: URL location = gerPort == null ? getAddressLocation(port)
408: : getLocation(gerPort);
409: //skip non-soap ports
410: if (location == null) {
411: continue;
412: }
413: String credentialsName = gerPort == null
414: || gerPort.getCredentialsName() == null ? null
415: : gerPort.getCredentialsName().trim();
416:
417: Binding binding = port.getBinding();
418:
419: mapBinding(binding, mapping, serviceQName, classLoader,
420: soapVersion, schemaInfoBuilder, portName,
421: location, handlerInfos,
422: seiPortNameToFactoryMap,
423: seiClassNameToFactoryMap, credentialsName,
424: exceptionMap);
425: }
426: }
427: }
428:
429: private void mapBinding(Binding binding,
430: JavaWsdlMappingType mapping, QName serviceQName,
431: ClassLoader classLoader, SOAPConstants soapVersion,
432: SchemaInfoBuilder schemaInfoBuilder, String portName,
433: URL location, List handlerInfos,
434: Map seiPortNameToFactoryMap, Map seiClassNameToFactoryMap,
435: String credentialsName, Map exceptionMap)
436: throws DeploymentException {
437: Style portStyle = getStyle(binding);
438:
439: PortType portType = binding.getPortType();
440:
441: ServiceEndpointInterfaceMappingType[] endpointMappings = mapping
442: .getServiceEndpointInterfaceMappingArray();
443:
444: //port type corresponds to SEI
445: List operations = portType.getOperations();
446: OperationInfo[] operationInfos = new OperationInfo[operations
447: .size()];
448: if (endpointMappings.length == 0) {
449: doLightweightMapping(serviceQName, portType, mapping,
450: classLoader, operations, binding, portStyle,
451: soapVersion, operationInfos, schemaInfoBuilder,
452: portName, location, handlerInfos,
453: seiPortNameToFactoryMap, seiClassNameToFactoryMap,
454: credentialsName);
455: } else {
456: doHeavyweightMapping(serviceQName, portType,
457: endpointMappings, classLoader, operations, binding,
458: portStyle, soapVersion, exceptionMap,
459: schemaInfoBuilder, mapping, operationInfos,
460: portName, location, handlerInfos,
461: seiPortNameToFactoryMap, seiClassNameToFactoryMap,
462: credentialsName);
463: }
464: }
465:
466: private URL getLocation(GerPortType port)
467: throws DeploymentException {
468: String protocol = port.getProtocol().trim();
469: String host = port.getHost().trim();
470: int portNum = port.getPort();
471: String uri = port.getUri().trim();
472: String locationURIString = protocol + "://" + host + ":"
473: + portNum + uri;
474: URL location;
475: try {
476: location = new URL(locationURIString);
477: } catch (MalformedURLException e) {
478: throw new DeploymentException(
479: "Could not construct web service location URL from "
480: + locationURIString, e);
481: }
482: return location;
483: }
484:
485: private javax.wsdl.Service getService(QName serviceQName,
486: Definition definition) throws DeploymentException {
487: javax.wsdl.Service service;
488: if (serviceQName != null) {
489: service = definition.getService(serviceQName);
490: if (service == null) {
491: throw new DeploymentException(
492: "No service wsdl for supplied service qname "
493: + serviceQName);
494: }
495: } else {
496: Map services = definition.getServices();
497: if (services.size() > 1) {
498: throw new DeploymentException(
499: "no serviceQName supplied, and there are "
500: + services.size() + " services");
501: }
502: if (services.size() == 0) {
503: throw new DeploymentException(
504: "No service in wsdl, and no service completion supplied!");
505: } else {
506: service = (javax.wsdl.Service) services.values()
507: .iterator().next();
508: }
509: }
510: return service;
511: }
512:
513: private Style getStyle(Binding binding) throws DeploymentException {
514: SOAPBinding soapBinding = (SOAPBinding) SchemaInfoBuilder
515: .getExtensibilityElement(SOAPBinding.class, binding
516: .getExtensibilityElements());
517: // String transportURI = soapBinding.getTransportURI();
518: String portStyleString = soapBinding.getStyle();
519: return Style.getStyle(portStyleString);
520: }
521:
522: private URL getAddressLocation(Port port)
523: throws DeploymentException {
524: SOAPAddress soapAddress;
525: try {
526: soapAddress = (SOAPAddress) SchemaInfoBuilder
527: .getExtensibilityElement(SOAPAddress.class, port
528: .getExtensibilityElements());
529: } catch (DeploymentException e) {
530: //a http: protocol REST service. Skip it.
531: return null;
532: }
533: String locationURIString = soapAddress.getLocationURI();
534: URL location;
535: try {
536: location = new URL(locationURIString);
537: } catch (MalformedURLException e) {
538: throw new DeploymentException(
539: "Could not construct web service location URL from "
540: + locationURIString, e);
541: }
542: return location;
543: }
544:
545: private void doHeavyweightMapping(QName serviceName,
546: PortType portType,
547: ServiceEndpointInterfaceMappingType[] endpointMappings,
548: ClassLoader classLoader, List operations, Binding binding,
549: Style portStyle, SOAPConstants soapVersion,
550: Map exceptionMap, SchemaInfoBuilder schemaInfoBuilder,
551: JavaWsdlMappingType mapping,
552: OperationInfo[] operationInfos, String portName,
553: URL location, List handlerInfos,
554: Map seiPortNameToFactoryMap, Map seiClassNameToFactoryMap,
555: String credentialsName) throws DeploymentException {
556: Class serviceEndpointInterface;
557: SEIFactory seiFactory;
558: //complete jaxrpc mapping file supplied
559: QName portTypeQName = portType.getQName();
560: ServiceEndpointInterfaceMappingType endpointMapping = WSDescriptorParser
561: .getServiceEndpointInterfaceMapping(endpointMappings,
562: portTypeQName);
563: String fqcn = endpointMapping.getServiceEndpointInterface()
564: .getStringValue();
565: try {
566: serviceEndpointInterface = classLoader.loadClass(fqcn);
567: } catch (ClassNotFoundException e) {
568: throw new DeploymentException(
569: "Could not load service endpoint interface", e);
570: }
571: // Class enhancedServiceEndpointClass = enhanceServiceEndpointInterface(serviceEndpointInterface, context, module, classLoader);
572:
573: Collection operationDescs = new ArrayList();
574: ServiceEndpointMethodMappingType[] methodMappings = endpointMapping
575: .getServiceEndpointMethodMappingArray();
576: int i = 0;
577: Set wrapperElementQNames = new HashSet();
578: JavaXmlTypeMappingType[] javaXmlTypeMappings = mapping
579: .getJavaXmlTypeMappingArray();
580: boolean hasEncoded = false;
581: for (Iterator ops = operations.iterator(); ops.hasNext();) {
582: Operation operation = (Operation) ops.next();
583: String operationName = operation.getName();
584: //the obvious method seems to be buggy
585: // BindingOperation bindingOperation = binding.getBindingOperation(operationName, operation.getInput().getName(), operation.getOutput() == null ? null : operation.getOutput().getName());
586: BindingOperation bindingOperation = null;
587: List bops = binding.getBindingOperations();
588: for (Iterator iterator = bops.iterator(); iterator
589: .hasNext();) {
590: BindingOperation bindingOperation1 = (BindingOperation) iterator
591: .next();
592: if (bindingOperation1.getOperation().equals(operation)) {
593: bindingOperation = bindingOperation1;
594: break;
595: }
596: }
597: if (bindingOperation == null) {
598: throw new DeploymentException(
599: "No BindingOperation for operation: "
600: + operationName
601: + ", input: "
602: + operation.getInput().getName()
603: + ", output: "
604: + (operation.getOutput() == null ? "<none>"
605: : operation.getOutput()
606: .getName()));
607: }
608: ServiceEndpointMethodMappingType methodMapping = WSDescriptorParser
609: .getMethodMappingForOperation(operationName,
610: methodMappings);
611: HeavyweightOperationDescBuilder operationDescBuilder = new HeavyweightOperationDescBuilder(
612: bindingOperation, mapping, methodMapping,
613: portStyle, exceptionMap, schemaInfoBuilder,
614: javaXmlTypeMappings, classLoader,
615: serviceEndpointInterface);
616: OperationInfo operationInfo = operationDescBuilder
617: .buildOperationInfo(soapVersion);
618: operationInfos[i++] = operationInfo;
619: operationDescs.add(operationInfo.getOperationDesc());
620: wrapperElementQNames.addAll(operationDescBuilder
621: .getWrapperElementQNames());
622: hasEncoded |= operationDescBuilder.isEncoded();
623: }
624: HeavyweightTypeInfoBuilder builder = new HeavyweightTypeInfoBuilder(
625: classLoader, schemaInfoBuilder
626: .getSchemaTypeKeyToSchemaTypeMap(),
627: wrapperElementQNames, operationDescs, hasEncoded);
628: List typeInfo = builder.buildTypeInfo(mapping);
629:
630: seiFactory = createSEIFactory(serviceName, portName,
631: serviceEndpointInterface.getName(), typeInfo, location,
632: operationInfos, handlerInfos, credentialsName);
633: seiPortNameToFactoryMap.put(portName, seiFactory);
634: seiClassNameToFactoryMap.put(
635: serviceEndpointInterface.getName(), seiFactory);
636: }
637:
638: private void doLightweightMapping(QName serviceName,
639: PortType portType, JavaWsdlMappingType mapping,
640: ClassLoader classLoader, List operations, Binding binding,
641: Style portStyle, SOAPConstants soapVersion,
642: OperationInfo[] operationInfos,
643: SchemaInfoBuilder schemaInfoBuilder, String portName,
644: URL location, List handlerInfos,
645: Map seiPortNameToFactoryMap, Map seiClassNameToFactoryMap,
646: String credentialsName) throws DeploymentException {
647: Class serviceEndpointInterface;
648: SEIFactory seiFactory;
649: //lightweight jaxrpc mapping supplied
650: serviceEndpointInterface = getServiceEndpointInterfaceLightweight(
651: portType, mapping, classLoader);
652: // Class enhancedServiceEndpointClass = enhanceServiceEndpointInterface(serviceEndpointInterface, context, module, classLoader);
653:
654: int i = 0;
655: for (Iterator ops = operations.iterator(); ops.hasNext();) {
656: Operation operation = (Operation) ops.next();
657: Method method = WSDescriptorParser.getMethodForOperation(
658: serviceEndpointInterface, operation);
659: BindingOperation bindingOperation = binding
660: .getBindingOperation(operation.getName(), operation
661: .getInput().getName(), operation
662: .getOutput() == null ? null : operation
663: .getOutput().getName());
664: operationInfos[i++] = buildOperationInfoLightweight(method,
665: bindingOperation, portStyle, soapVersion);
666: }
667: LightweightTypeInfoBuilder builder = new LightweightTypeInfoBuilder(
668: classLoader, schemaInfoBuilder
669: .getSchemaTypeKeyToSchemaTypeMap(),
670: Collections.EMPTY_SET);
671: List typeInfo = builder.buildTypeInfo(mapping);
672:
673: seiFactory = createSEIFactory(serviceName, portName,
674: serviceEndpointInterface.getName(), typeInfo, location,
675: operationInfos, handlerInfos, credentialsName);
676: seiPortNameToFactoryMap.put(portName, seiFactory);
677: seiClassNameToFactoryMap.put(
678: serviceEndpointInterface.getName(), seiFactory);
679: }
680:
681: private Class getServiceEndpointInterfaceLightweight(
682: PortType portType, JavaWsdlMappingType mappings,
683: ClassLoader classLoader) throws DeploymentException {
684: QName portTypeQName = portType.getQName();
685: String portTypeNamespace = portTypeQName.getNamespaceURI();
686: String portTypePackage = WSDescriptorParser
687: .getPackageFromNamespace(portTypeNamespace, mappings);
688: StringBuffer shortInterfaceName = new StringBuffer(
689: portTypeQName.getLocalPart());
690: shortInterfaceName.setCharAt(0, Character
691: .toUpperCase(shortInterfaceName.charAt(0)));
692: //TODO just use one buffer!
693: String fqcn = portTypePackage + "."
694: + shortInterfaceName.toString();
695: try {
696: return classLoader.loadClass(fqcn);
697: } catch (ClassNotFoundException e) {
698: throw new DeploymentException(
699: "Could not load service endpoint interface type", e);
700: }
701: }
702:
703: public SEIFactory createSEIFactory(QName serviceName,
704: String portName, String enhancedServiceEndpointClassName,
705: List typeInfo, URL location,
706: OperationInfo[] operationInfos, List handlerInfoInfos,
707: String credentialsName) throws DeploymentException {
708: List handlerInfos = buildHandlerInfosForPort(portName,
709: handlerInfoInfos);
710: return new SEIFactoryImpl(serviceName, portName,
711: enhancedServiceEndpointClassName, operationInfos,
712: typeInfo, location, handlerInfos, credentialsName);
713: }
714:
715: private List buildHandlerInfosForPort(String portName,
716: List handlerInfoInfos) {
717: List handlerInfos = new ArrayList();
718: for (Iterator iterator = handlerInfoInfos.iterator(); iterator
719: .hasNext();) {
720: HandlerInfoInfo handlerInfoInfo = (HandlerInfoInfo) iterator
721: .next();
722: Set portNames = handlerInfoInfo.getPortNames();
723: if (portNames.isEmpty() || portNames.contains(portName)) {
724: HandlerInfo handlerInfo = new HandlerInfo(
725: handlerInfoInfo.getHandlerClass(),
726: handlerInfoInfo.getHandlerConfig(),
727: handlerInfoInfo.getSoapHeaders());
728: handlerInfos.add(handlerInfo);
729:
730: //TODO what about the soap roles??
731: }
732: }
733: return handlerInfos;
734: }
735:
736: public OperationInfo buildOperationInfoLightweight(Method method,
737: BindingOperation bindingOperation, Style defaultStyle,
738: SOAPConstants soapVersion) throws DeploymentException {
739: LightweightOperationDescBuilder operationDescBuilder = new LightweightOperationDescBuilder(
740: bindingOperation, method);
741: return operationDescBuilder.buildOperationInfo(soapVersion);
742: }
743:
744: Class<?> loadClass(String className, ClassLoader loader)
745: throws DeploymentException {
746: try {
747: return loader.loadClass(className);
748: } catch (ClassNotFoundException ex) {
749: throw new DeploymentException(
750: "Unable to load Web Service class: " + className);
751: }
752: }
753:
754: static boolean isJAXWSWebService(Class clazz) {
755: return (clazz.isAnnotationPresent(WebService.class) || clazz
756: .isAnnotationPresent(WebServiceProvider.class));
757: }
758:
759: public static final GBeanInfo GBEAN_INFO;
760:
761: static {
762: GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(
763: AxisBuilder.class, NameFactory.MODULE_BUILDER);
764: infoBuilder.addInterface(WebServiceBuilder.class);
765: infoBuilder.addAttribute("defaultEnvironment",
766: Environment.class, true, true);
767:
768: infoBuilder
769: .setConstructor(new String[] { "defaultEnvironment" });
770:
771: GBEAN_INFO = infoBuilder.getBeanInfo();
772: }
773:
774: public static GBeanInfo getGBeanInfo() {
775: return GBEAN_INFO;
776: }
777:
778: }
|