1 /** 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package org.apache.geronimo.cxf.builder; 19 20 import java.io.IOException; 21 import java.net.URI; 22 import java.util.Map; 23 24 import javax.xml.namespace.QName; 25 26 import org.apache.geronimo.common.DeploymentException; 27 import org.apache.geronimo.cxf.client.CXFServiceReference; 28 import org.apache.geronimo.gbean.GBeanInfo; 29 import org.apache.geronimo.gbean.GBeanInfoBuilder; 30 import org.apache.geronimo.j2ee.deployment.Module; 31 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; 32 import org.apache.geronimo.jaxws.builder.EndpointInfoBuilder; 33 import org.apache.geronimo.jaxws.builder.JAXWSServiceRefBuilder; 34 import org.apache.geronimo.jaxws.client.EndpointInfo; 35 import org.apache.geronimo.kernel.repository.Environment; 36 import org.apache.geronimo.naming.deployment.ServiceRefBuilder; 37 import org.apache.geronimo.xbeans.geronimo.naming.GerServiceRefType; 38 import org.apache.geronimo.xbeans.javaee.PortComponentRefType; 39 import org.apache.geronimo.xbeans.javaee.ServiceRefType; 40 import org.slf4j.Logger; 41 import org.slf4j.LoggerFactory; 42 43 public class CXFServiceRefBuilder extends JAXWSServiceRefBuilder { 44 45 private static final Logger LOG = LoggerFactory.getLogger(CXFServiceRefBuilder.class); 46 47 public CXFServiceRefBuilder(Environment defaultEnvironment, 48 String[] eeNamespaces) { 49 super(defaultEnvironment, eeNamespaces); 50 } 51 52 public Object createService(ServiceRefType serviceRef, GerServiceRefType gerServiceRef, 53 Module module, ClassLoader cl, Class serviceInterface, 54 QName serviceQName, URI wsdlURI, Class serviceReference, 55 Map<Class, PortComponentRefType> portComponentRefMap) throws DeploymentException { 56 EndpointInfoBuilder builder = new EndpointInfoBuilder(serviceInterface, 57 gerServiceRef, portComponentRefMap, module, cl, 58 wsdlURI, serviceQName); 59 builder.build(); 60 61 wsdlURI = builder.getWsdlURI(); 62 serviceQName = builder.getServiceQName(); 63 Map<Object, EndpointInfo> seiInfoMap = builder.getEndpointInfo(); 64 65 String handlerChainsXML = null; 66 try { 67 handlerChainsXML = getHandlerChainAsString(serviceRef.getHandlerChains()); 68 } catch (IOException e) { 69 // this should not happen 70 LOG.warn("Failed to serialize handler chains", e); 71 } 72 73 String serviceReferenceName = (serviceReference == null) ? null : serviceReference.getName(); 74 75 return new CXFServiceReference(serviceInterface.getName(), serviceReferenceName, wsdlURI, 76 serviceQName, module.getModuleName(), handlerChainsXML, seiInfoMap); 77 } 78 79 public static final GBeanInfo GBEAN_INFO; 80 81 static { 82 GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic( 83 CXFServiceRefBuilder.class, NameFactory.MODULE_BUILDER); 84 infoBuilder.addInterface(ServiceRefBuilder.class); 85 infoBuilder.addAttribute("defaultEnvironment", Environment.class, true, 86 true); 87 infoBuilder.addAttribute("eeNamespaces", String[].class, true, true); 88 89 infoBuilder.setConstructor(new String[] { "defaultEnvironment", 90 "eeNamespaces"}); 91 92 GBEAN_INFO = infoBuilder.getBeanInfo(); 93 } 94 95 public static GBeanInfo getGBeanInfo() { 96 return GBEAN_INFO; 97 } 98 }