Return-Path: Delivered-To: apmail-incubator-cxf-commits-archive@locus.apache.org Received: (qmail 50391 invoked from network); 26 Sep 2007 09:00:44 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 26 Sep 2007 09:00:43 -0000 Received: (qmail 84215 invoked by uid 500); 26 Sep 2007 09:00:33 -0000 Delivered-To: apmail-incubator-cxf-commits-archive@incubator.apache.org Received: (qmail 84166 invoked by uid 500); 26 Sep 2007 09:00:33 -0000 Mailing-List: contact cxf-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: cxf-dev@incubator.apache.org Delivered-To: mailing list cxf-commits@incubator.apache.org Received: (qmail 84157 invoked by uid 99); 26 Sep 2007 09:00:33 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 26 Sep 2007 02:00:33 -0700 X-ASF-Spam-Status: No, hits=-97.6 required=10.0 tests=ALL_TRUSTED,URIBL_RHS_DOB,WEIRD_PORT X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 26 Sep 2007 09:02:42 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 1EEBF1A9832; Wed, 26 Sep 2007 02:00:02 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r579522 - in /incubator/cxf/trunk: distribution/src/main/release/samples/integration/jca/inbound/ integration/jca/src/main/java/org/apache/cxf/jca/core/resourceadapter/ integration/jca/src/main/java/org/apache/cxf/jca/cxf/ integration/jca/s... Date: Wed, 26 Sep 2007 08:59:59 -0000 To: cxf-commits@incubator.apache.org From: ningjiang@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20070926090002.1EEBF1A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: ningjiang Date: Wed Sep 26 01:59:58 2007 New Revision: 579522 URL: http://svn.apache.org/viewvc?rev=579522&view=rev Log: CXF-1047 applied the patch of writing EJBInvoker to publish the EJB servant, thanks Jeff Added: incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/servant/EJBEndpoint.java (with props) incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/servant/EJBInvoker.java (with props) incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/servant/EJBServantConfig.java (with props) incubator/cxf/trunk/integration/jca/src/test/java/org/apache/cxf/jca/servant/EJBServantConfigTest.java (with props) Removed: incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/servant/AbstractServant.java incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/servant/CXFConnectEJBServant.java incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/servant/EJBServant.java incubator/cxf/trunk/integration/jca/src/test/java/org/apache/cxf/jca/servant/CXFConnectEJBServantTest.java Modified: incubator/cxf/trunk/distribution/src/main/release/samples/integration/jca/inbound/build.xml incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/core/resourceadapter/ResourceBean.java incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/cxf/JCABusFactory.java incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/cxf/ManagedConnectionFactoryImpl.java incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/cxf/Messages.properties incubator/cxf/trunk/integration/jca/src/main/rar/META-INF/ra.xml incubator/cxf/trunk/integration/jca/src/test/java/org/apache/cxf/jca/cxf/JCABusFactoryTest.java Modified: incubator/cxf/trunk/distribution/src/main/release/samples/integration/jca/inbound/build.xml URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/samples/integration/jca/inbound/build.xml?rev=579522&r1=579521&r2=579522&view=diff ============================================================================== --- incubator/cxf/trunk/distribution/src/main/release/samples/integration/jca/inbound/build.xml (original) +++ incubator/cxf/trunk/distribution/src/main/release/samples/integration/jca/inbound/build.xml Wed Sep 26 01:59:58 2007 @@ -70,7 +70,7 @@ - + @@ -155,7 +155,7 @@ --> + value="GreeterBean={http://apache.org/hello_world_soap_http}Greeter@"/> Modified: incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/core/resourceadapter/ResourceBean.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/core/resourceadapter/ResourceBean.java?rev=579522&r1=579521&r2=579522&view=diff ============================================================================== --- incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/core/resourceadapter/ResourceBean.java (original) +++ incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/core/resourceadapter/ResourceBean.java Wed Sep 26 01:59:58 2007 @@ -42,8 +42,9 @@ public static final String DEFAULT_MONITOR_POLL_INTERVAL = "120"; public static final String EJB_SERVICE_PROPERTIES_URL = "ejb.service.properties.url"; public static final String MONITOR_EJB_SERVICE_PROPERTIES = "monitor.ejb.service.properties"; - public static final String MONITOR_POLL_INTERVAL = "monitor.poll.interval"; - private static final long serialVersionUID = -9186743162164946039L; + public static final String MONITOR_POLL_INTERVAL = "monitor.poll.interval"; + public static final String EJB_SERVANT_BASE_URL = "ejb.servant.base.url"; + static { // first use of log, default init if necessary @@ -74,7 +75,7 @@ public void setProperty(String propName, String propValue) { if (!DEFAULT_VALUE_STRING.equals(propValue)) { - LOG.log(Level.CONFIG, "SETTING_PROPERTY", new Object[] {propName, propValue}); + LOG.log(Level.FINE, "SETTING_PROPERTY", new Object[] {propName, propValue}); getPluginProps().setProperty(propName, propValue); } if (LOG_LEVEL.equals(propName)) { @@ -104,7 +105,7 @@ try { url = createURL(spec, msg); url.openStream(); - LOG.config("Validated url=" + url); + LOG.fine("Validated url=" + url); } catch (IOException ioe) { throw new ResourceAdapterInternalException(msg, ioe); } Modified: incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/cxf/JCABusFactory.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/cxf/JCABusFactory.java?rev=579522&r1=579521&r2=579522&view=diff ============================================================================== --- incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/cxf/JCABusFactory.java (original) +++ incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/cxf/JCABusFactory.java Wed Sep 26 01:59:58 2007 @@ -21,55 +21,36 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.net.InetAddress; import java.net.URL; -import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Enumeration; -import java.util.HashMap; -import java.util.Iterator; import java.util.List; -import java.util.Map; import java.util.Properties; -import java.util.StringTokenizer; +import java.util.ResourceBundle; import java.util.logging.Logger; -import javax.ejb.EJBHome; -import javax.ejb.EJBObject; -import javax.naming.Context; -import javax.naming.InitialContext; -import javax.naming.NamingException; import javax.resource.ResourceException; -import javax.rmi.PortableRemoteObject; -import javax.xml.bind.JAXBException; -import javax.xml.namespace.QName; import org.apache.cxf.Bus; -import org.apache.cxf.BusException; import org.apache.cxf.BusFactory; +import org.apache.cxf.common.i18n.BundleUtils; +import org.apache.cxf.common.i18n.Message; import org.apache.cxf.common.logging.LogUtils; -import org.apache.cxf.common.util.PackageUtils; import org.apache.cxf.endpoint.Server; -import org.apache.cxf.frontend.ServerFactoryBean; -import org.apache.cxf.jaxb.JAXBDataBinding; -import org.apache.cxf.jaxws.JAXWSMethodInvoker; -import org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean; import org.apache.cxf.jca.core.resourceadapter.ResourceAdapterInternalException; import org.apache.cxf.jca.core.resourceadapter.UriHandlerInit; -import org.apache.cxf.service.Service; -import org.apache.cxf.service.factory.ReflectionServiceFactoryBean; +import org.apache.cxf.jca.servant.EJBEndpoint; +import org.apache.cxf.jca.servant.EJBServantConfig; public class JCABusFactory { private static final Logger LOG = LogUtils.getL7dLogger(JCABusFactory.class); - + + private static final ResourceBundle BUNDLE = BundleUtils.getBundle(JCABusFactory.class); + private Bus bus; - private BusFactory bf; private List servantsCache = new ArrayList(); - private InitialContext jndiContext; private ClassLoader appserverClassLoader; private ManagedConnectionFactoryImpl mcf; private Object raBootstrapContext; @@ -81,27 +62,16 @@ protected String[] getBusArgs() throws ResourceException { //There is only setting up the BUSID String busId = mcf.getConfigurationScope(); - LOG.fine("BUSid=" + busId); String busArgs[] = new String[2]; busArgs[0] = "-BUSid"; busArgs[1] = busId; return busArgs; - } - - protected Bus createCXFBus() throws ResourceException { - try { - bf = BusFactory.newInstance(); - bus = bf.createBus(); - } catch (Exception ex) { - throw new ResourceAdapterInternalException("Failed to initialize cxf runtime", ex); - } - return bus; - } + } protected synchronized void init() throws ResourceException { - LOG.info("Initializing the CXF Bus ..."); + LOG.info("Initializing the CXF Bus ..."); new UriHandlerInit(); ClassLoader original = Thread.currentThread().getContextClassLoader(); try { @@ -112,15 +82,16 @@ //TODO Check for the managed connection factory properties //TODO We may need get the configuration file from properties - //mcf.validateProperties(); - bus = createCXFBus(); + + BusFactory bf = BusFactory.newInstance(); + bus = bf.createBus(); initializeServants(); } catch (Exception ex) { if (ex instanceof ResourceAdapterInternalException) { throw (ResourceException)ex; } else { - ex.printStackTrace(); - throw new ResourceAdapterInternalException("Failed to initialize connector runtime", ex); + throw new ResourceAdapterInternalException( + new Message("FAIL_TO_INITIALIZE_JCABUSFACTORY", BUNDLE).toString(), ex); } } finally { Thread.currentThread().setContextClassLoader(original); @@ -128,211 +99,67 @@ } - void initializeServants() throws ResourceException { + protected void initializeServants() throws ResourceException { if (isMonitorEJBServicePropertiesEnabled()) { - LOG.info("ejb service properties update enabled. "); + LOG.info("Ejb service properties auto-detect enabled. "); startPropertiesMonitorThread(); } else { URL propsUrl = mcf.getEJBServicePropertiesURLInstance(); if (propsUrl != null) { - initialiseServantsFromProperties(loadProperties(propsUrl), false); + initializeServantsFromProperties(loadProperties(propsUrl)); } } } - void initialiseServantsFromProperties(Properties ejbServants, boolean abortOnFailure) - throws ResourceException { - // Props format: jndi name = service string - // - // java:/ejbs/A={http:/a/b/b}SoapService@http://localost:wsdls/a.wsdl - - try { - jndiContext = new InitialContext(); - } catch (NamingException ne) { - throw new ResourceAdapterInternalException( - "Failed to construct InitialContext for EJBServant(s) jndi lookup, reason: " - + ne, ne); - } - + private void initializeServantsFromProperties(Properties ejbServants) throws ResourceException { + deregisterServants(bus); - - LOG.info("Initializing EJB endpoints..."); - - Enumeration keys = ejbServants.keys(); - - while (keys.hasMoreElements()) { - String jndiName = (String)keys.nextElement(); - String serviceName = (String)ejbServants.getProperty(jndiName); - LOG.fine("Found ejb endpoint: jndi name=" + jndiName + ", wsdl service=" + serviceName); - - try { - initializeServant(jndiName, serviceName); - } catch (ResourceException re) { - LOG.warning("Error initializing servant with jndi name " - + jndiName + " and service name " - + serviceName + " Exception:" - + re.getMessage()); - if (abortOnFailure) { - throw re; - } - } - } - } - - void initializeServant(String jndiName, String serviceName) throws ResourceException { - - Server servant = null; - EJBObject ejb = null; - QName serviceQName = null; - String nameSpace = ""; - String interfaceName = ""; - String packageName = ""; - Class interfaceClass = null; - ClassLoader ejbClassLoader = null; - ClassLoader currentThreadContextClassLoader = null; - try { - if ("".equals(serviceName)) { - throw new ResourceAdapterInternalException( - "A WSDL service QName must be specified as the value of the EJB JNDI name key: " - + jndiName); - } else { - serviceQName = serviceQNameFromString(serviceName); - - serviceQNameFromString(serviceName); - - // Get ejbObject - ejb = getEJBObject(jndiName); - ejbClassLoader = ejb.getClass().getClassLoader(); - - //NOTE we can use the ejbClassLoader to load WSDL - currentThreadContextClassLoader = Thread.currentThread().getContextClassLoader(); - Thread.currentThread().setContextClassLoader(ejbClassLoader); - - Thread.currentThread().setContextClassLoader(currentThreadContextClassLoader); - - nameSpace = serviceQName.getNamespaceURI(); - packageName = PackageUtils.parsePackageName(nameSpace, null); - - // Get interface of ejbObject - interfaceName = jndiName.substring(0, jndiName.length() - 4); - interfaceName = packageName + "." + interfaceName; - - interfaceClass = Class.forName(interfaceName); - - // NOTE We can check the annoation to descide which kind of frontend we will use - // Almostly we just need to use the jax-ws frontend - // If we have wsdl , then wsdl first, - // else code first + LOG.info("Initializing EJB endpoints from properties file..."); + + try { + Enumeration keys = ejbServants.keys(); + while (keys.hasMoreElements()) { + String theJNDIName = (String)keys.nextElement(); + String value = (String)ejbServants.get(theJNDIName); + EJBServantConfig config = new EJBServantConfig(theJNDIName, value); + EJBEndpoint ejbEndpoint = new EJBEndpoint(config); + ejbEndpoint.setEjbServantBaseURL(mcf.getEJBServantBaseURL()); + Server servant = ejbEndpoint.publish(); - servant = publishServantWithoutWSDL(ejb, jndiName, nameSpace, interfaceClass); + synchronized (servantsCache) { + if (servant != null) { + servantsCache.add(servant); + } + } } } catch (Exception e) { - throw new ResourceAdapterInternalException(e.getMessage()); - } - synchronized (servantsCache) { - if (servant != null) { - servantsCache.add(servant); - } - } - } - - public Server publishServantWithoutWSDL(EJBObject ejb, String jndiName, - String nameSpace, Class interfaceClass) - throws Exception { - - String hostName = ""; - try { - InetAddress addr = InetAddress.getLocalHost(); - //hostName = addr.getHostName(); - hostName = addr.getCanonicalHostName(); - } catch (UnknownHostException e) { e.printStackTrace(); + throw new ResourceException(new Message("FAIL_TO_START_EJB_SERVANTS", BUNDLE).toString(), e); } - String address = "http://" + hostName + ":9999/" + jndiName; - - ReflectionServiceFactoryBean bean = new JaxWsServiceFactoryBean(); - Service service = createService(interfaceClass, bean); - - // REVISIT this is easy to be replace by EJBMethodInvoker - service.setInvoker(new JAXWSMethodInvoker(ejb)); - - ServerFactoryBean svrFactory = new ServerFactoryBean(); - - return createServer(svrFactory, bean, address); - } - - protected Service createService(Class interfaceClass, ReflectionServiceFactoryBean serviceFactory) - throws JAXBException { - serviceFactory.setDataBinding(new JAXBDataBinding()); - serviceFactory.setBus(bus); - serviceFactory.setServiceClass(interfaceClass); - - Map props = new HashMap(); - props.put("test", "test"); - serviceFactory.setProperties(props); - - return serviceFactory.create(); - } - protected Server createServer(ServerFactoryBean serverFactory, - ReflectionServiceFactoryBean serviceFactory, - String address) { - serverFactory.setAddress(address); - serverFactory.setTransportId("http://schemas.xmlsoap.org/soap/http"); - serverFactory.setServiceFactory(serviceFactory); - serverFactory.setBus(bus); - - return serverFactory.create(); - } - - private EJBObject getEJBObject(String jndi) throws BusException { - try { - EJBHome home = getEJBHome(jndiContext, jndi); - -// ejbHomeClassLoader = home.getClass().getClassLoader(); - - Method createMethod = home.getClass().getMethod("create", new Class[0]); - return (EJBObject) createMethod.invoke(home, new Object[0]); - } catch (NamingException e) { - throw new BusException(e); - } catch (NoSuchMethodException e) { - throw new BusException(e); - } catch (IllegalAccessException e) { - throw new BusException(e); - } catch (InvocationTargetException itex) { - Throwable thrownException = itex.getTargetException(); - throw new BusException(thrownException); - } - } - - protected EJBHome getEJBHome(Context ejbContext, String jndiName) throws NamingException { - Object obj = ejbContext.lookup(jndiName); - return (EJBHome) PortableRemoteObject.narrow(obj, EJBHome.class); - } - - void startPropertiesMonitorThread() throws ResourceException { + private void startPropertiesMonitorThread() throws ResourceException { Integer pollIntervalInteger = mcf.getEJBServicePropertiesPollInterval(); int pollInterval = pollIntervalInteger.intValue(); - LOG.info("ejb service properties poll interval is : " + pollInterval + " seconds"); + + LOG.info("Ejb service properties poll interval is : [" + pollInterval + " seconds]"); + EJBServicePropertiesMonitorRunnable r = new EJBServicePropertiesMonitorRunnable(pollInterval); Thread t = new Thread(r); t.setDaemon(true); t.start(); } - boolean isMonitorEJBServicePropertiesEnabled() throws ResourceException { + private boolean isMonitorEJBServicePropertiesEnabled() throws ResourceException { boolean retVal = false; if (mcf.getMonitorEJBServiceProperties().booleanValue()) { URL url = mcf.getEJBServicePropertiesURLInstance(); if (url == null) { throw new ResourceAdapterInternalException( - "MonitorEJBServiceProperties property is set to true," - + " but EJBServicePropertiesURL is not set. " - + "Both properties must be set to enable monitoring."); + new Message("EJB_SERVANT_PROPERTIES_IS_NULL", BUNDLE).toString()); } retVal = isFileURL(url); } @@ -344,20 +171,18 @@ return url != null && "file".equals(url.getProtocol()); } - protected void deregisterServants(Bus aBus) { + private void deregisterServants(Bus aBus) { synchronized (servantsCache) { - if (!servantsCache.isEmpty()) { - Iterator servants = servantsCache.iterator(); - while (servants.hasNext()) { - Server servant = servants.next(); - servant.stop(); - } - servantsCache.clear(); + for (Server servant : servantsCache) { + //REVISIT: seems using server.stop() doesn't release resource properly. + servant.stop(); + LOG.info("Shutdown the EJB Endpoint: " + servant.getEndpoint().getEndpointInfo().getName()); } + servantsCache.clear(); } } - Properties loadProperties(URL propsUrl) throws ResourceException { + protected Properties loadProperties(URL propsUrl) throws ResourceException { Properties props = null; InputStream istream = null; @@ -365,106 +190,22 @@ try { istream = propsUrl.openStream(); - } catch (IOException ioe) { - throw new ResourceAdapterInternalException("Failed to openStream to URL, value=" + propsUrl - + ", reason:" + ioe, ioe); - } - - try { props = new Properties(); props.load(istream); - } catch (IOException ioe) { - props = null; - throw new ResourceAdapterInternalException("Failed to load properties from " + propsUrl, ioe); - } finally { - try { - istream.close(); - } catch (IOException ignored) { - //do nothing here - } - } - - return props; - } - - QName serviceQNameFromString(String qns) throws ResourceAdapterInternalException { - String lp = null; - String nameSpace = null; - - // String re = "(\[(.*)\])?([^\@]+)(@?(.*))??"; - // String[] qna = qns.split("(\[?+[^\]]*\])([^@])@?+(.*)"); - - try { - StringTokenizer st = new StringTokenizer(qns, "{},@", true); - while (st.hasMoreTokens()) { - String t = st.nextToken(); - if ("{".equals(t)) { - nameSpace = st.nextToken(); - st.nextToken(); - // consume '}' - } else if (",".equals(t)) { - st.nextToken(); - // consume 'portName' - } else if ("@".equals(t)) { - st.nextToken(); - // consume 'wsdlLoc' - } else { - lp = t; - } - } - } catch (java.util.NoSuchElementException nsee) { + } catch (IOException e) { throw new ResourceAdapterInternalException( - "Incomplete QName, string is not in expected format: " - + "[{namespace}]local part[@ wsdl location url]. value:" - + qns, nsee); - } - LOG.fine("QN=" + qns + ", ns=" + nameSpace + ", lp=" + lp); - return new QName(nameSpace, lp); - } - - String portNameFromString(String qns) throws ResourceAdapterInternalException { - String portName = null; - try { - StringTokenizer st = new StringTokenizer(qns, ",@", true); - while (st.hasMoreTokens()) { - String t = st.nextToken(); - if (",".equals(t)) { - if (portName != null) { - throw new ResourceAdapterInternalException( - "portName already set, string is not in expected format:" - + " [{namespace}]serviceName[,portName][@ wsdl location url]. value:" - + qns); - } - - portName = st.nextToken(); - - if ("@".equals(portName)) { - throw new ResourceAdapterInternalException( - "Empty portName, string is not in expected format: " - + "[{namespace}]serviceName[,portName][@ wsdl location url]. value:" - + qns); - } + new Message("FAIL_TO_LOAD_EJB_SERVANT_PROPERTIES", BUNDLE, propsUrl).toString(), e); + } finally { + if (istream != null) { + try { + istream.close(); + } catch (IOException e) { + //DO Nothing } } - } catch (java.util.NoSuchElementException nsee) { - throw new ResourceAdapterInternalException( - "Incomplete QName, string is not in expected format: " - + "[{namespace}]serviceName[,portName][@ wsdl location url]. value:" - + qns, nsee); } - return portName; - } - String wsdlLocFromString(String qns) { - String wloc = null; - StringTokenizer st = new StringTokenizer(qns, "@", true); - while (st.hasMoreTokens()) { - String t = st.nextToken(); - if ("@".equals(t)) { - wloc = st.nextToken(); - } - } - return wloc; + return props; } @@ -480,10 +221,6 @@ this.appserverClassLoader = classLoader; } - public InitialContext getInitialContext() { - return jndiContext; - } - public Object getBootstrapContext() { return raBootstrapContext; } @@ -502,7 +239,7 @@ init(); } - class EJBServicePropertiesMonitorRunnable implements Runnable { + private class EJBServicePropertiesMonitorRunnable implements Runnable { private long previousModificationTime; private final int pollIntervalSeconds; private final File propsFile; @@ -521,19 +258,18 @@ do { try { if (isPropertiesFileModified()) { - LOG.info("ejbServicePropertiesFile modified, initialising/updating servants"); - initialiseServantsFromProperties(loadProperties(propsFile.toURI().toURL()), false); + LOG.info("ejbServicePropertiesFile modified, initializing/updating servants"); + initializeServantsFromProperties(loadProperties(propsFile.toURI().toURL())); } Thread.sleep(pollIntervalSeconds * 1000); } catch (Exception e) { LOG.info("MonitorThread: failed to initialiseServantsFromProperties " - + "with properties absolute path=" - + propsFile.getAbsolutePath() + ", reason: " + e.toString()); + + "with properties absolute path=" + propsFile.getAbsolutePath()); } } while (continuing); } - protected boolean isPropertiesFileModified() throws ResourceException { + protected boolean isPropertiesFileModified() { boolean fileModified = false; if (propsFile.exists()) { long currentModificationTime = propsFile.lastModified(); @@ -550,6 +286,8 @@ protected void setBootstrapContext(Object ctx) { raBootstrapContext = ctx; } + + } Modified: incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/cxf/ManagedConnectionFactoryImpl.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/cxf/ManagedConnectionFactoryImpl.java?rev=579522&r1=579521&r2=579522&view=diff ============================================================================== --- incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/cxf/ManagedConnectionFactoryImpl.java (original) +++ incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/cxf/ManagedConnectionFactoryImpl.java Wed Sep 26 01:59:58 2007 @@ -20,6 +20,7 @@ import java.net.URL; import java.util.Properties; +import java.util.ResourceBundle; import java.util.logging.Logger; import javax.resource.ResourceException; @@ -30,6 +31,8 @@ import org.apache.cxf.Bus; //import org.apache.cxf.BusFactory; +import org.apache.cxf.common.i18n.BundleUtils; +import org.apache.cxf.common.i18n.Message; import org.apache.cxf.common.logging.LogUtils; import org.apache.cxf.jca.core.resourceadapter.AbstractManagedConnectionFactoryImpl; import org.apache.cxf.jca.core.resourceadapter.AbstractManagedConnectionImpl; @@ -40,6 +43,8 @@ implements CXFManagedConnectionFactory { private static final Logger LOG = LogUtils.getL7dLogger(ManagedConnectionFactoryImpl.class); + private static final ResourceBundle BUNDLE = BundleUtils.getBundle(ManagedConnectionFactoryImpl.class); + protected JCABusFactory jcaBusFactory; public ManagedConnectionFactoryImpl() { @@ -104,6 +109,14 @@ public URL getEJBServicePropertiesURLInstance() throws ResourceException { return getPropsURL(getEJBServicePropertiesURL()); } + + public String getEJBServantBaseURL() throws ResourceException { + return getPluginProps().getProperty(EJB_SERVANT_BASE_URL); + } + + public void setEJBServantBaseURL(String url) throws ResourceException { + setProperty(EJB_SERVANT_BASE_URL, url); + } // compliance: WL9 checks // need to ensure multiple instances with same config properties are equal @@ -114,15 +127,15 @@ } public Object createConnectionFactory() throws ResourceException { - throw new ResourceAdapterInternalException("Non-Managed usage is not supported, " - + "use createConnectionFactory with a ConnectionManager argument"); + throw new ResourceAdapterInternalException( + new Message("NON_MANAGED_CONNECTION_IS_NOT_SUPPORTED", BUNDLE).toString()); } public Object createConnectionFactory(ConnectionManager connMgr) throws ResourceException { LOG.info("connManager=" + connMgr); if (connMgr == null) { - throw new ResourceAdapterInternalException("Non-Managed usage is not supported, " - + "the ConnectionManager argument can not be null"); + throw new ResourceAdapterInternalException( + new Message("NON_MANAGED_CONNECTION_IS_NOT_SUPPORTED", BUNDLE).toString()); } init(connMgr.getClass().getClassLoader()); LOG.fine("Setting AppServer classloader in jcaBusFactory. " + connMgr.getClass().getClassLoader()); Modified: incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/cxf/Messages.properties URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/cxf/Messages.properties?rev=579522&r1=579521&r2=579522&view=diff ============================================================================== --- incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/cxf/Messages.properties (original) +++ incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/cxf/Messages.properties Wed Sep 26 01:59:58 2007 @@ -22,3 +22,8 @@ IS_NOT_AN_INTERFACE = The [{0}] is not an interface. FAILED_TO_GET_CXF_CONNECTION = Failed to get the CXF Connection with connection parameters: {0} ASSOCIATED_ERROR = Error in associating connection. +FAIL_TO_LOAD_EJB_SERVANT_PROPERTIES = Failed to load EJBServant properties file: {0} +FAIL_TO_START_EJB_SERVANTS = Failed to start ejb servants. +EJB_SERVANT_PROPERTIES_IS_NULL = MonitorEJBServiceProperties property is set to true, but EJBServicePropertiesURL is not set, Both properties must be set to enable monitoring. +FAIL_TO_INITIALIZE_JCABUSFACTORY = Failed to initialize JCABusFactory. +NON_MANAGED_CONNECTION_IS_NOT_SUPPORTED = Non Managed Connection is not supported, use createConnectionFactory with a ConnectionManager argument. \ No newline at end of file Added: incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/servant/EJBEndpoint.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/servant/EJBEndpoint.java?rev=579522&view=auto ============================================================================== --- incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/servant/EJBEndpoint.java (added) +++ incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/servant/EJBEndpoint.java Wed Sep 26 01:59:58 2007 @@ -0,0 +1,123 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.cxf.jca.servant; + +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.logging.Logger; + +import javax.ejb.EJBHome; +import javax.jws.WebService; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.rmi.PortableRemoteObject; + +import org.apache.cxf.common.logging.LogUtils; +import org.apache.cxf.common.util.PackageUtils; +import org.apache.cxf.endpoint.Server; +import org.apache.cxf.frontend.ServerFactoryBean; +import org.apache.cxf.jaxws.JaxWsServerFactoryBean; + + +public class EJBEndpoint { + + private static final Logger LOG = LogUtils.getL7dLogger(EJBEndpoint.class); + + private EJBServantConfig config; + + private Context jndiContext; + + private EJBHome ejbHome; + + private String ejbServantBaseURL; + + public EJBEndpoint(EJBServantConfig ejbConfig) { + this.config = ejbConfig; + } + + public Server publish() throws Exception { + jndiContext = new InitialContext(); + Object obj = jndiContext.lookup(config.getJNDIName()); + ejbHome = (EJBHome) PortableRemoteObject.narrow(obj, EJBHome.class); + + Class interfaceClass = Class.forName(getServiceClassName()); + boolean isJaxws = isJaxWsServiceInterface(interfaceClass); + ServerFactoryBean factory = isJaxws ? new JaxWsServerFactoryBean() : new ServerFactoryBean(); + factory.setServiceClass(interfaceClass); + + if (config.getWsdlURL() != null) { + factory.getServiceFactory().setWsdlURL(config.getWsdlURL()); + } + + factory.setInvoker(new EJBInvoker(ejbHome)); + + String baseAddress = isNotNull(getEjbServantBaseURL()) ? getEjbServantBaseURL() + : getDefaultEJBServantBaseURL(); + String address = baseAddress + "/" + config.getJNDIName(); + factory.setAddress(address); + + LOG.info("Published EJB Endpoint of [" + config.getJNDIName() + "] at [" + address + "]"); + return factory.create(); + } + + public String getServiceClassName() throws Exception { + String packageName = PackageUtils.parsePackageName(config.getServiceName().getNamespaceURI(), null); + String interfaceName = packageName + "." + + config.getJNDIName().substring(0, config.getJNDIName().length() - 4); + return interfaceName; + } + + public String getDefaultEJBServantBaseURL() throws Exception { + String hostName = ""; + try { + InetAddress addr = InetAddress.getLocalHost(); + hostName = addr.getCanonicalHostName(); + } catch (UnknownHostException e) { + hostName = "localhost"; + } + return "http://" + hostName + ":9999"; + } + + private boolean isJaxWsServiceInterface(Class cls) { + if (cls == null) { + return false; + } + if (null != cls.getAnnotation(WebService.class)) { + return true; + } + return false; + } + + public String getEjbServantBaseURL() { + return ejbServantBaseURL; + } + + public void setEjbServantBaseURL(String ejbServantBaseURL) { + this.ejbServantBaseURL = ejbServantBaseURL; + } + + private boolean isNotNull(String value) { + if (value != null && !"".equals(value.trim())) { + return true; + } + return false; + } + +} Propchange: incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/servant/EJBEndpoint.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/servant/EJBEndpoint.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/servant/EJBInvoker.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/servant/EJBInvoker.java?rev=579522&view=auto ============================================================================== --- incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/servant/EJBInvoker.java (added) +++ incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/servant/EJBInvoker.java Wed Sep 26 01:59:58 2007 @@ -0,0 +1,63 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.cxf.jca.servant; + +import java.lang.reflect.Method; + +import javax.ejb.EJBHome; + +import org.apache.cxf.message.Exchange; +import org.apache.cxf.service.invoker.AbstractInvoker; + + +public class EJBInvoker extends AbstractInvoker { + + private static final Object[] EMPTY_OBJECT = new Object[0]; + + private EJBHome home; + + private Method createMethod; + + public EJBInvoker(EJBHome home) { + this.home = home; + try { + if (!home.getEJBMetaData().isSession() || !home.getEJBMetaData().isStatelessSession()) + { + throw new IllegalArgumentException("home must be for a stateless session bean"); + } + createMethod = home.getClass().getMethod("create", new Class[0]); + } catch (Exception ex) { + throw new IllegalArgumentException("Unable to initialize invoker: " + ex); + } + } + + + @Override + public Object getServiceObject(Exchange context) { + Object ejbObject = null; + try { + ejbObject = createMethod.invoke(home, EMPTY_OBJECT); + } catch (Exception e) { + throw new RuntimeException("Error in creating EJB Object"); + } + return ejbObject; + } + +} Propchange: incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/servant/EJBInvoker.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/servant/EJBInvoker.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/servant/EJBServantConfig.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/servant/EJBServantConfig.java?rev=579522&view=auto ============================================================================== --- incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/servant/EJBServantConfig.java (added) +++ incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/servant/EJBServantConfig.java Wed Sep 26 01:59:58 2007 @@ -0,0 +1,97 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.cxf.jca.servant; + +import java.util.StringTokenizer; + +import javax.xml.namespace.QName; + + +public class EJBServantConfig { + + private String jndiName; + + private QName serviceName; + + private String wsdlURL; + + public EJBServantConfig(String jndiName, String value) { + this.jndiName = jndiName; + StringTokenizer st = new StringTokenizer(value, "@", true); + if (st.hasMoreTokens()) { + String theValue = st.nextToken().trim(); + if ("@".equals(theValue)) { + if (st.hasMoreTokens()) { + this.wsdlURL = st.nextToken().trim(); + } + } else { + this.serviceName = getServiceName(theValue); + if (st.hasMoreTokens() && "@".equals(st.nextToken()) && st.hasMoreTokens()) { + this.wsdlURL = st.nextToken().trim(); + } + } + } + + } + + public String getJNDIName() { + return jndiName; + } + + public void setJndiName(String jndiName) { + this.jndiName = jndiName; + } + + public QName getServiceName() { + return serviceName; + } + + public void setServiceName(QName serviceName) { + this.serviceName = serviceName; + } + + public String getWsdlURL() { + return wsdlURL; + } + + public void setWsdlURL(String wsdlURL) { + this.wsdlURL = wsdlURL; + } + + + private QName getServiceName(String sname) { + StringTokenizer st = new StringTokenizer(sname, "}", false); + String namespace = ""; + String localpart = ""; + if (st.hasMoreTokens()) { + String value = st.nextToken().trim(); + if (value.startsWith("{")) { + namespace = value.substring(1); + } else { + localpart = value; + } + } + if (st.hasMoreTokens()) { + localpart = st.nextToken().trim(); + } + return new QName(namespace, localpart); + } + +} Propchange: incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/servant/EJBServantConfig.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/cxf/trunk/integration/jca/src/main/java/org/apache/cxf/jca/servant/EJBServantConfig.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Modified: incubator/cxf/trunk/integration/jca/src/main/rar/META-INF/ra.xml URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/integration/jca/src/main/rar/META-INF/ra.xml?rev=579522&r1=579521&r2=579522&view=diff ============================================================================== --- incubator/cxf/trunk/integration/jca/src/main/rar/META-INF/ra.xml (original) +++ incubator/cxf/trunk/integration/jca/src/main/rar/META-INF/ra.xml Wed Sep 26 01:59:58 2007 @@ -68,6 +68,11 @@ java.lang.Integer 30 + + EJBServantBaseURL + java.lang.String + http://localhost:9999 + org.apache.cxf.connector.CXFConnectionFactory org.apache.cxf.jca.cxf.ConnectionFactoryImpl org.apache.cxf.connector.Connection Modified: incubator/cxf/trunk/integration/jca/src/test/java/org/apache/cxf/jca/cxf/JCABusFactoryTest.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/integration/jca/src/test/java/org/apache/cxf/jca/cxf/JCABusFactoryTest.java?rev=579522&r1=579521&r2=579522&view=diff ============================================================================== --- incubator/cxf/trunk/integration/jca/src/test/java/org/apache/cxf/jca/cxf/JCABusFactoryTest.java (original) +++ incubator/cxf/trunk/integration/jca/src/test/java/org/apache/cxf/jca/cxf/JCABusFactoryTest.java Wed Sep 26 01:59:58 2007 @@ -21,38 +21,15 @@ import java.io.File; import java.io.FileNotFoundException; -//import java.net.MalformedURLException; import java.net.URL; -import java.util.Properties; -// import java.util.ResourceBundle; import javax.resource.ResourceException; -import javax.xml.namespace.QName; - -import org.w3c.dom.Node; import org.apache.cxf.Bus; -// import org.apache.cxf.BusException; -// import org.apache.cxf.common.i18n.Message; -import org.apache.cxf.binding.BindingFactoryManager; -import org.apache.cxf.binding.soap.SoapBindingFactory; -import org.apache.cxf.binding.soap.SoapTransportFactory; -import org.apache.cxf.bus.spring.SpringBusFactory; -import org.apache.cxf.endpoint.Server; -import org.apache.cxf.frontend.ServerFactoryBean; -import org.apache.cxf.jaxws.JAXWSMethodInvoker; -import org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean; import org.apache.cxf.jca.core.resourceadapter.ResourceAdapterInternalException; -import org.apache.cxf.service.Service; -import org.apache.cxf.service.factory.ReflectionServiceFactoryBean; import org.apache.cxf.test.AbstractCXFTest; -import org.apache.cxf.transport.ConduitInitiatorManager; -import org.apache.cxf.transport.DestinationFactoryManager; -import org.apache.cxf.transport.local.LocalTransportFactory; -import org.apache.cxf.wsdl.WSDLManager; -import org.apache.cxf.wsdl11.WSDLManagerImpl; -// import org.apache.cxf.jca.cxf.test.DummyBus; import org.easymock.classextension.EasyMock; +import org.junit.Ignore; import org.junit.Test; public class JCABusFactoryTest extends AbstractCXFTest { @@ -81,199 +58,6 @@ } -// public void testBusInitGetProps() throws Exception { -// DummyBus.reset(); -// System.setProperty("test.bus.class", DummyBus.class.getName()); -// ManagedConnectionFactoryImpl mcf = new ManagedConnectionFactoryImpl(); - -// assertEquals("bus not yet initialized", DummyBus.getInitializeCount(), 0); - - -// JCABusFactory jcaBusFactory = new JCABusFactory(mcf); -// jcaBusFactory.create(null, null); - -// assertEquals("bus initialized ", DummyBus.getInitializeCount(), 1); - -// } - -// public void testInitBusThrowsException() throws Exception { -// DummyBus.reset(); -// System.setProperty("test.bus.class", DummyBus.class.getName()); -// final Exception thrown = new BusException(new Message("tested bus exception!", -// (ResourceBundle)null, new Object[]{})); - -// ClassLoader originalCl = Thread.currentThread().getContextClassLoader(); -// try { -// ManagedConnectionFactoryImpl mcf = new ManagedConnectionFactoryImpl(); - -// JCABusFactory jcaBusFactory = new JCABusFactory(mcf); - -// // do this for MockObject creation -// Thread.currentThread().setContextClassLoader(jcaBusFactory.getClass().getClassLoader()); -// // DummyBus.setThrowException(true); - - -// try { -// jcaBusFactory.create(null, null); -// fail("did not get expected resource exception"); -// } catch (ResourceException re) { -// System.out.println("*************************"); -// System.out.println(" exception: " + re.getMessage()); -// System.out.println("*************************"); -// assertTrue("cause is set", re.getCause() != null); -// assertEquals("cause is expected type", thrown.getClass(), re.getCause().getClass()); -// } - -// assertEquals("init was called once", 1, DummyBus.getInitializeCount()); - -// } finally { -// Thread.currentThread().setContextClassLoader(originalCl); -// } -// } - -// public void testInitBusSetsThreadContextClassLoader() throws Exception { -// DummyBus.reset(); -// System.setProperty("test.bus.class", DummyBus.class.getName()); -// ClassLoader originalCl = Thread.currentThread().getContextClassLoader(); -// try { -// ManagedConnectionFactoryImpl mcf = new ManagedConnectionFactoryImpl(); - -// JCABusFactory jcaBusFactory = new JCABusFactory(mcf); - -// // do this for MockObject creation -// Thread.currentThread().setContextClassLoader(jcaBusFactory.getClass().getClassLoader()); - -// Class dummyBusClass = Class.forName(DummyBus.class.getName(), true, jcaBusFactory.getClass() -// .getClassLoader()); -// // initialise here while thread context classloader is correct -// dummyBusClass.newInstance(); - -// jcaBusFactory.create(null, null); - - -// assertEquals("init was called once", 1, DummyBus.getInitializeCount()); -// assertTrue("loader is correct in init", DummyBus.isCorrectThreadContextClassLoader()); - -// } finally { -// Thread.currentThread().setContextClassLoader(originalCl); -// } -// } - - // service strings to qname localparts - - - @Test - public void testValidQNameFromString() throws Exception { - final Object[][] ejbServantServicePorpsTestStrings = - new Object[][] {{"serviceName", new QName("serviceName")}, - {"a/b", new QName("a/b")}, - {"{http://somenamespace}serviceName,portName", - new QName("http://somenamespace", "serviceName")}, - {"{http://addd}n,portName@http://a", - new QName("http://addd", "n")}, - {"{http://somenamespace}serviceName@file:/a/b/wsdl.wsdl", - new QName("http://somenamespace", "serviceName")}, - {"{http://somenamespace}serviceName@http://a?param=1", - new QName("http://somenamespace", "serviceName")}}; - - ManagedConnectionFactoryImpl mcf = new ManagedConnectionFactoryImpl(); - JCABusFactory jcaBusFactory = new JCABusFactory(mcf); - for (int i = 0; i < ejbServantServicePorpsTestStrings.length; i++) { - String val = (String)ejbServantServicePorpsTestStrings[i][0]; - QName expected = (QName)ejbServantServicePorpsTestStrings[i][1]; - - assertEquals("correct qname from mapping for " + val, expected, jcaBusFactory - .serviceQNameFromString(val)); - } - } - - @Test - public void testInvalidQNameFromString() throws Exception { - ManagedConnectionFactoryImpl mcf = new ManagedConnectionFactoryImpl(); - JCABusFactory jcaBusFactory = new JCABusFactory(mcf); - try { - jcaBusFactory.serviceQNameFromString("a@"); - fail("expecte ex on invalid format"); - } catch (ResourceException expected) { - assertTrue(expected.getCause() instanceof java.util.NoSuchElementException); - } - } - - - - @Test - public void testWsdlLocFromString() throws Exception { - //service strings to wsdl urls - final String[][] ejbServantServicePropsTestStringsWsdlLoc = - new String[][] {{"serviceName", null}, - {"a/b", null}, - {"{http://somenamespace}serviceName", null}, - {"{http://somenamespace}serviceName,portName@file:/a/b/wsdl.wsdl", - "file:/a/b/wsdl.wsdl"}, - {"{http://somenamespace}serviceName,portName@http://a?param=1", - "http://a?param=1"}}; - ManagedConnectionFactoryImpl mcf = new ManagedConnectionFactoryImpl(); - JCABusFactory jcaBusFactory = new JCABusFactory(mcf); - for (int i = 0; i < ejbServantServicePropsTestStringsWsdlLoc.length; i++) { - String val = ejbServantServicePropsTestStringsWsdlLoc[i][0]; - String expectedUrl = ejbServantServicePropsTestStringsWsdlLoc[i][1]; - - assertEquals("correct wsdlLocation from mapping for " + val, expectedUrl, jcaBusFactory - .wsdlLocFromString(val)); - } - } - - - @Test - public void testPortNameFromString() throws Exception { - //service strings to portName - final String[][] ejbServantServicePropsTestStringsPortName = - new String[][] {{"serviceName", null}, - {"a/b", null}, - {"{http://somenamespace}serviceName", null}, - {"{http://somenamespace}serviceName,portName1@file:/a/b/wsdl.wsdl", - "portName1"}, - {"{http://somenamespace}serviceName,portName2@http://a?param=1", - "portName2"}}; - - ManagedConnectionFactoryImpl mcf = new ManagedConnectionFactoryImpl(); - JCABusFactory jcaBusFactory = new JCABusFactory(mcf); - for (int i = 0; i < ejbServantServicePropsTestStringsPortName.length; i++) { - String val = ejbServantServicePropsTestStringsPortName[i][0]; - String expectedUrl = ejbServantServicePropsTestStringsPortName[i][1]; - - assertEquals("correct wsdlLocation from mapping for " + val, expectedUrl, jcaBusFactory - .portNameFromString(val)); - } - } - - @Test - public void testInvalidPortNameFromString() throws Exception { - ManagedConnectionFactoryImpl mcf = new ManagedConnectionFactoryImpl(); - JCABusFactory jcaBusFactory = new JCABusFactory(mcf); - try { - jcaBusFactory.portNameFromString("serviceName,"); - fail("expect ex on invalid format"); - } catch (ResourceException expected) { - assertTrue(expected.getCause() instanceof java.util.NoSuchElementException); - } - - try { - jcaBusFactory.portNameFromString("serviceName,@abc"); - fail("expect ex on invalid format"); - } catch (ResourceException expected) { - assertTrue("Exception message starts with Empty portName", expected.getMessage() - .startsWith("Empty portName")); - } - - try { - jcaBusFactory.portNameFromString("serviceName,abc,uuu"); - fail("expect ex on invalid format"); - } catch (ResourceException expected) { - assertTrue("Exception message starts with portName already set", expected.getMessage() - .startsWith("portName already set")); - } - } @Test public void testLoadNonexistentProperties() throws Exception { @@ -287,7 +71,8 @@ re.getCause() instanceof FileNotFoundException); } } - + + @Test public void testInvalidMonitorConfigNoPropsURL() throws Exception { ManagedConnectionFactoryImpl mcf = new ManagedConnectionFactoryImpl(); mcf.setMonitorEJBServiceProperties(Boolean.TRUE); @@ -303,7 +88,7 @@ } } - + @Ignore @Test public void testInitServants() throws Exception { ManagedConnectionFactoryImpl mcf = new ManagedConnectionFactoryImpl(); @@ -318,278 +103,6 @@ } - @Test - public void testCreateService() throws Exception { - Bus springBus = new SpringBusFactory().createBus(); - - JCABusFactory jcaBusFactory = new JCABusFactory(null); - jcaBusFactory.setBus(springBus); - - ReflectionServiceFactoryBean bean = new JaxWsServiceFactoryBean(); - Service service = jcaBusFactory.createService(HelloInterface.class, bean); - assertEquals("test", service.get("test")); - } - - @Test - public void testCreateServer() throws Exception { - //Bus springBus = new SpringBusFactory().createBus(); - - SoapBindingFactory bindingFactory = new SoapBindingFactory(); - - bus.getExtension(BindingFactoryManager.class) - .registerBindingFactory("http://schemas.xmlsoap.org/wsdl/soap/", bindingFactory); - - DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class); - - SoapTransportFactory soapDF = new SoapTransportFactory(); - soapDF.setBus(bus); - dfm.registerDestinationFactory("http://schemas.xmlsoap.org/wsdl/soap/", soapDF); - dfm.registerDestinationFactory("http://schemas.xmlsoap.org/soap/", soapDF); - - LocalTransportFactory localTransport = new LocalTransportFactory(); - dfm.registerDestinationFactory("http://schemas.xmlsoap.org/soap/http", localTransport); - dfm.registerDestinationFactory("http://schemas.xmlsoap.org/wsdl/soap/http", localTransport); - dfm.registerDestinationFactory("http://cxf.apache.org/bindings/xformat", localTransport); - - ConduitInitiatorManager extension = bus.getExtension(ConduitInitiatorManager.class); - extension.registerConduitInitiator(LocalTransportFactory.TRANSPORT_ID, localTransport); - extension.registerConduitInitiator("http://schemas.xmlsoap.org/wsdl/soap/", localTransport); - extension.registerConduitInitiator("http://schemas.xmlsoap.org/soap/http", localTransport); - extension.registerConduitInitiator("http://schemas.xmlsoap.org/soap/", localTransport); - - bus.setExtension(new WSDLManagerImpl(), WSDLManager.class); - - - JCABusFactory jcaBusFactory = new JCABusFactory(null); - jcaBusFactory.setBus(bus); - - ReflectionServiceFactoryBean bean = new JaxWsServiceFactoryBean(); - Service service = jcaBusFactory.createService(HelloInterface.class, bean); - assertEquals("test", service.get("test")); - - Imple im = new Imple(); - - service.setInvoker(new JAXWSMethodInvoker(im)); - - ServerFactoryBean svrFactory = new ServerFactoryBean(); - - String address = "http://localhost:9999/Hello"; - Server server = jcaBusFactory.createServer(svrFactory, bean, address); - assertNotNull("The server should not be null", server); - - Node res = invoke("http://localhost:9999/Hello", - LocalTransportFactory.TRANSPORT_ID, - "sayHi.xml"); - assertNotNull("We should get the result ", res); - } - - /* - public void testAddServantsCache() throws Exception { - ManagedConnectionFactoryImpl mcf = new ManagedConnectionFactoryImpl(); - JCABusFactory jcaBusFactory = new JCABusFactory(mcf); - ClassLoader cl = this.getClass().getClassLoader(); - Bus bus = jcaBusFactory.initBus(cl); - - Properties props = new Properties(); - String wsdlLocation = - this.getClass().getResource("resources/hello_world.wsdl").toString(); - - System.out.println(" in test wsdlLocation: " + wsdlLocation); - props.put("jndiName", "{http://apache.org/hello_world_soap_http}SOAPService@" - + wsdlLocation); - - assertTrue("there's no registered servants at beginning", jcaBusFactory.getRegisteredServants() - .isEmpty()); - jcaBusFactory.setBus(bus); - jcaBusFactory.initialiseServantsFromProperties(props, true); - - javax.xml.ws.Endpoint ep = (javax.xml.ws.Endpoint) jcaBusFactory.getRegisteredServants().get(0); - - assertTrue("registered servant with the expected service name", ((javax.xml.ws.Endpoint)jcaBusFactory - .getRegisteredServants().get(0)).isPublished()); - ep.stop(); - jcaBusFactory.deregisterServants(bus); - - assertTrue("servants should be deregistered", jcaBusFactory.getRegisteredServants().isEmpty()); - bus.shutdown(true); - } - - */ -// public void testInitServantsFromPropertiesWithPortName() throws Exception { -// ManagedConnectionFactoryImpl mcf = new ManagedConnectionFactoryImpl(); -// JCABusFactory jcaBusFactory = new JCABusFactory(mcf); -// Bus mockBus = EasyMock.createMock(Bus.class); -// jcaBusFactory.setBus(mockBus); -// Properties props = new Properties(); -// props.put("jndiName", "{http://objectweb.org/hello_world_soap_http}SOAPService,SoapPort@file:///"); -// try { -// jcaBusFactory.initialiseServantsFromProperties(props, true); -// } catch (ResourceException expected) { -// assertTrue("reasonable message", expected.toString().indexOf("jndiName") != -1); -// assertTrue(expected instanceof ResourceAdapterInternalException); -// } -// } - -// public void testInitServantsFromPropertiesWithMissingWsdlLocInPropertiesAndConfig() throws Exception { -// ManagedConnectionFactoryImpl mcf = new ManagedConnectionFactoryImpl(); -// JCABusFactory jcaBusFactory = new JCABusFactory(mcf); -// Bus mockBus = EasyMock.createMock(Bus.class); -// jcaBusFactory.setBus(mockBus); -// final String jndiName = "/a/b"; -// try { -// Properties props = new Properties(); -// props.put(jndiName, "{http://ns}ServiceA"); -// jcaBusFactory.initialiseServantsFromProperties(props, true); -// fail("expect ex on missing wsdl loc"); -// } catch (ResourceException expected) { -// assertTrue("reasonable message", expected.toString().indexOf(jndiName) != -1); -// assertTrue(expected instanceof ResourceAdapterInternalException); -// assertTrue(expected.getMessage().indexOf("ServiceA") != -1); -// } -// } - - @Test - public void testInitServantsFromPropertiesWithNoServiceQName() throws Exception { - ManagedConnectionFactoryImpl mcf = new ManagedConnectionFactoryImpl(); - JCABusFactory jcaBusFactory = new JCABusFactory(mcf); - Bus mockBus = EasyMock.createMock(Bus.class); - jcaBusFactory.setBus(mockBus); - final String jndiName = "/a/b"; - try { - Properties props = new Properties(); - props.put(jndiName, ""); - jcaBusFactory.initialiseServantsFromProperties(props, true); - fail("expect ex on missing service QName value"); - } catch (ResourceException expected) { - assertTrue("reasonable message", expected.toString().indexOf(jndiName) != -1); - } - } - -/* so far doesn't support wsdl file - public void testInitFromPropsWithInvalidWsdlLocUrls() throws Exception { - ManagedConnectionFactoryImpl mcf = new ManagedConnectionFactoryImpl(); - JCABusFactory jcaBusFactory = new JCABusFactory(mcf); - - - try { - Properties props = new Properties(); - props.put("/a/b", "{http://ns}ServiceA@unknownprotocol:/a"); - jcaBusFactory.initialiseServantsFromProperties(props, true); - fail("expect ex on unknown protocol"); - } catch (ResourceException expected) { - assertTrue("have a jcaBusFactorye " + expected.getCause(), - expected.getCause() instanceof MalformedURLException); - } - - try { - Properties props = new Properties(); - props.put("/a/b", "{http://ns}ServiceA@a/b"); - jcaBusFactory.initialiseServantsFromProperties(props, true); - - fail("expect ex on invalid format, no scheme"); - } catch (ResourceException expected) { - assertTrue("have a mue " + expected.getCause(), - expected.getCause() instanceof MalformedURLException); - } - - try { - Properties props = new Properties(); - props.put("/a/b", "{http://ns}ServiceA@http://nowhere.plannetx.cupoftea:9090/NoWhere"); - jcaBusFactory.initialiseServantsFromProperties(props, true); - - fail("expect ex on invalid url, dud host name"); - } catch (ResourceException expected) { - // resolving the URL above results in an IOException which - // may be UnknowHostException or something different - // depending on the platoform - assertTrue("unexpected exception received: " + expected.getCause(), - expected.getCause() instanceof java.io.IOException); - - } - - } -*/ - - @Test - public void testInitFromPropsDoesNotThrowExceptionWhenSomethingGoesWrong() throws Exception { - ManagedConnectionFactoryImpl mcf = new ManagedConnectionFactoryImpl(); - JCABusFactory jcaBusFactory = new JCABusFactory(mcf); - Bus mockBus = EasyMock.createMock(Bus.class); - jcaBusFactory.setBus(mockBus); - Properties props = new Properties(); - props.put("/a/b", "{http://ns}ServiceA@unknownprotocol:/a"); - - jcaBusFactory.initialiseServantsFromProperties(props, false); - - } - - /* - public void testPropertiesMonitorThreadCausesSomeFailures() throws Exception { - FileChannel in = null; - FileChannel out = null; - URL propFile = getClass().getResource("resources/ejb_servants_one_wrong.properties"); - - File origFile = new File(propFile.toString().substring(5)); - File tmpFile = File.createTempFile("anyname", "properties"); - File tmpDir = tmpFile.getParentFile(); - - File testFile = new File(tmpDir, "otherunittest.properties"); - if (testFile.exists()) { - testFile.delete(); - } - assertTrue("file: " + testFile.getAbsolutePath() + " does not exist", !(testFile.exists())); - - ManagedConnectionFactoryImpl mcf = new ManagedConnectionFactoryImpl(); - mcf.setEJBServicePropertiesURL(testFile.toURI().toURL().toString()); - JCABusFactory jcaBusFactory = new JCABusFactory(mcf); - Bus mockBus = EasyMock.createMock(Bus.class); - jcaBusFactory.setBus((Bus)mockBus); - - JCABusFactory.EJBServicePropertiesMonitorRunnable propsRunnable = - jcaBusFactory.new EJBServicePropertiesMonitorRunnable(5); - propsRunnable.setContinue(false); - propsRunnable.run(); - //do nothing here - - testFile.createNewFile(); - assertTrue("file exist", testFile.exists()); - try { - in = new FileInputStream(origFile).getChannel(); - out = new FileOutputStream(testFile).getChannel(); - long size = in.size(); - MappedByteBuffer buf = in.map(FileChannel.MapMode.READ_ONLY, 0, size); - out.write(buf); - } finally { - if (in != null) { - in.close(); - } - - if (out != null) { - out.close(); - } - } - - propsRunnable.run(); - testFile.delete(); - - } - - public void testInitServantsWithBootstrapContextNotNull() throws Exception { - System.setProperty("test.bus.class", DummyBus.class.getName()); - ManagedConnectionFactoryImpl mcf = new ManagedConnectionFactoryImpl(); - mcf.setCXFInstallDir(DummyBus.vobRoot()); - mcf.setCXFCEURL(DummyBus.CXFCEURL); - - assertEquals("bus not yet initialized", DummyBus.initializeCount, 0); - - JCABusFactory jcaBusFactory = new JCABusFactory(mcf); - BootstrapContext bc = (BootstrapContext)MockObjectFactory.create(BootstrapContext.class); - assertNotNull("BootstrapContext is not null", bc); - jcaBusFactory.create(null, bc); - assertEquals("BoostrapContext set", jcaBusFactory.getBootstrapContext(), bc); - assertEquals("bus initialized ", DummyBus.initializeCount, 1); - } -*/ } Added: incubator/cxf/trunk/integration/jca/src/test/java/org/apache/cxf/jca/servant/EJBServantConfigTest.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/integration/jca/src/test/java/org/apache/cxf/jca/servant/EJBServantConfigTest.java?rev=579522&view=auto ============================================================================== --- incubator/cxf/trunk/integration/jca/src/test/java/org/apache/cxf/jca/servant/EJBServantConfigTest.java (added) +++ incubator/cxf/trunk/integration/jca/src/test/java/org/apache/cxf/jca/servant/EJBServantConfigTest.java Wed Sep 26 01:59:58 2007 @@ -0,0 +1,98 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.cxf.jca.servant; + +import javax.xml.namespace.QName; +import junit.framework.Assert; + +import org.junit.Test; + + +public class EJBServantConfigTest extends Assert { + + @Test + public void testNoWsdl() throws Exception { + String value = "{http://apache.org/hello_world_soap_http}Greeter"; + QName result = new QName("http://apache.org/hello_world_soap_http", "Greeter"); + EJBServantConfig config = new EJBServantConfig(null, value); + assertEquals(result, config.getServiceName()); + assertNull(config.getWsdlURL()); + } + + @Test + public void testNoWsdlNoLocalPart() throws Exception { + String value = "{http://apache.org/hello_world_soap_http}"; + QName result = new QName("http://apache.org/hello_world_soap_http", ""); + EJBServantConfig config = new EJBServantConfig(null, value); + assertEquals(result, config.getServiceName()); + assertNull(config.getWsdlURL()); + } + + @Test + public void testNoWsdlNoNamespace() throws Exception { + String value = "Greeter"; + QName result = new QName("", "Greeter"); + EJBServantConfig config = new EJBServantConfig(null, value); + assertEquals(result, config.getServiceName()); + assertNull(config.getWsdlURL()); + } + + @Test + public void testAllNull() throws Exception { + String value = ""; + EJBServantConfig config = new EJBServantConfig(null, value); + assertNull(config.getServiceName()); + assertNull(config.getWsdlURL()); + } + + @Test + public void testWithNullWsdl() throws Exception { + String value = "@"; + EJBServantConfig config = new EJBServantConfig(null, value); + assertNull(config.getServiceName()); + assertNull(config.getWsdlURL()); + } + + @Test + public void testWithNullServiceName() throws Exception { + String value = "@wsdl/hello_world.wsdl"; + EJBServantConfig config = new EJBServantConfig(null, value); + assertNull(config.getServiceName()); + assertEquals("wsdl/hello_world.wsdl", config.getWsdlURL()); + } + + @Test + public void testFullValue() throws Exception { + String value = "{http://apache.org/hello_world_soap_http}SOAPService@file:/wsdl/hello_world.wsdl"; + QName result = new QName("http://apache.org/hello_world_soap_http", "SOAPService"); + EJBServantConfig config = new EJBServantConfig(null, value); + assertEquals("file:/wsdl/hello_world.wsdl", config.getWsdlURL()); + assertEquals(result, config.getServiceName()); + } + + @Test + public void testGetServiceClassName() throws Exception { + String value = "{http://apache.org/hello_world_soap_http}Greeter@file:"; + EJBServantConfig config = new EJBServantConfig("GreeterBean", value); + EJBEndpoint endpoint = new EJBEndpoint(config); + assertEquals("org.apache.hello_world_soap_http.Greeter", endpoint.getServiceClassName()); + } + +} Propchange: incubator/cxf/trunk/integration/jca/src/test/java/org/apache/cxf/jca/servant/EJBServantConfigTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/cxf/trunk/integration/jca/src/test/java/org/apache/cxf/jca/servant/EJBServantConfigTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date