Return-Path:
Delivered-To: apmail-commons-commits-archive@minotaur.apache.org
Received: (qmail 51544 invoked from network); 17 Jul 2010 04:24:40 -0000
Received: from unknown (HELO mail.apache.org) (140.211.11.3)
by 140.211.11.9 with SMTP; 17 Jul 2010 04:24:40 -0000
Received: (qmail 41042 invoked by uid 500); 17 Jul 2010 04:24:40 -0000
Delivered-To: apmail-commons-commits-archive@commons.apache.org
Received: (qmail 40685 invoked by uid 500); 17 Jul 2010 04:24:37 -0000
Mailing-List: contact commits-help@commons.apache.org; run by ezmlm
Precedence: bulk
List-Help:
List-Unsubscribe:
List-Post:
List-Id:
Reply-To: dev@commons.apache.org
Delivered-To: mailing list commits@commons.apache.org
Received: (qmail 40673 invoked by uid 99); 17 Jul 2010 04:24:36 -0000
Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230)
by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 17 Jul 2010 04:24:36 +0000
X-ASF-Spam-Status: No, hits=-2000.0 required=10.0
tests=ALL_TRUSTED
X-Spam-Check-By: apache.org
Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4)
by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 17 Jul 2010 04:24:32 +0000
Received: by eris.apache.org (Postfix, from userid 65534)
id 3076B2388A36; Sat, 17 Jul 2010 04:23:38 +0000 (UTC)
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: svn commit: r965009 - in
/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/remoting:
JaxRpcProvider.java RmiProvider.java SessionBeanProvider.java package.html
Date: Sat, 17 Jul 2010 04:23:38 -0000
To: commits@commons.apache.org
From: jcarman@apache.org
X-Mailer: svnmailer-1.0.8
Message-Id: <20100717042338.3076B2388A36@eris.apache.org>
X-Virus-Checked: Checked by ClamAV on apache.org
Author: jcarman
Date: Sat Jul 17 04:23:37 2010
New Revision: 965009
URL: http://svn.apache.org/viewvc?rev=965009&view=rev
Log:
All tests pass (with some commented out to get a clean compile)
Added:
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/remoting/JaxRpcProvider.java
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/remoting/RmiProvider.java
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/remoting/SessionBeanProvider.java
commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/remoting/package.html
Added: commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/remoting/JaxRpcProvider.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/remoting/JaxRpcProvider.java?rev=965009&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/remoting/JaxRpcProvider.java (added)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/remoting/JaxRpcProvider.java Sat Jul 17 04:23:37 2010
@@ -0,0 +1,171 @@
+/*
+ * 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.commons.proxy.provider.remoting;
+
+import org.apache.commons.proxy.ObjectProvider;
+import org.apache.commons.proxy.exception.ObjectProviderException;
+
+import javax.xml.namespace.QName;
+import javax.xml.rpc.Service;
+import javax.xml.rpc.ServiceException;
+import javax.xml.rpc.ServiceFactory;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+/**
+ * Returns a proxy for a JAX-RPC-based service.
+ *
+ *
+ * Dependencies:
+ *
+ * - A JAX-RPC implementation
+ *
+ *
+ *
+ * @author James Carman
+ * @since 1.0
+ */
+public class JaxRpcProvider implements ObjectProvider
+{
+//**********************************************************************************************************************
+// Fields
+//**********************************************************************************************************************
+
+ private Class serviceInterface;
+ private String wsdlUrl;
+ private String serviceNamespaceUri;
+ private String serviceLocalPart;
+ private String servicePrefix;
+ private String portNamespaceUri;
+ private String portLocalPart;
+ private String portPrefix;
+
+//**********************************************************************************************************************
+// Constructors
+//**********************************************************************************************************************
+
+ public JaxRpcProvider()
+ {
+ }
+
+ public JaxRpcProvider( Class serviceInterface )
+ {
+ this.serviceInterface = serviceInterface;
+ }
+
+//**********************************************************************************************************************
+// ObjectProvider Implementation
+//**********************************************************************************************************************
+
+ public T getObject()
+ {
+ try
+ {
+ final Service service = ( wsdlUrl == null ?
+ ServiceFactory.newInstance().createService(getServiceQName()) : ServiceFactory
+ .newInstance().createService(new URL(wsdlUrl), getServiceQName()) );
+ final QName portQName = getPortQName();
+ return serviceInterface.cast(portQName == null ? service.getPort(serviceInterface) :
+ service.getPort(portQName, serviceInterface));
+ }
+ catch( ServiceException e )
+ {
+ throw new ObjectProviderException("Unable to create JAX-RPC service proxy.", e);
+ }
+ catch( MalformedURLException e )
+ {
+ throw new ObjectProviderException("Invalid URL given.", e);
+ }
+ }
+
+//**********************************************************************************************************************
+// Getter/Setter Methods
+//**********************************************************************************************************************
+
+ public void setPortLocalPart( String portLocalPart )
+ {
+ this.portLocalPart = portLocalPart;
+ }
+
+ public void setPortNamespaceUri( String portNamespaceUri )
+ {
+ this.portNamespaceUri = portNamespaceUri;
+ }
+
+ public void setPortPrefix( String portPrefix )
+ {
+ this.portPrefix = portPrefix;
+ }
+
+ public void setServiceInterface( Class serviceInterface )
+ {
+ this.serviceInterface = serviceInterface;
+ }
+
+ public void setServiceLocalPart( String serviceLocalPart )
+ {
+ this.serviceLocalPart = serviceLocalPart;
+ }
+
+ public void setServiceNamespaceUri( String serviceNamespaceUri )
+ {
+ this.serviceNamespaceUri = serviceNamespaceUri;
+ }
+
+ public void setServicePrefix( String servicePrefix )
+ {
+ this.servicePrefix = servicePrefix;
+ }
+
+ public void setWsdlUrl( String wsdlUrl )
+ {
+ this.wsdlUrl = wsdlUrl;
+ }
+
+//**********************************************************************************************************************
+// Other Methods
+//**********************************************************************************************************************
+
+ private QName getPortQName()
+ {
+ return getQName(portNamespaceUri, portLocalPart, portPrefix);
+ }
+
+ private QName getQName( String namespaceUri, String localPart, String prefix )
+ {
+ if( namespaceUri != null && localPart != null && prefix != null )
+ {
+ return new QName(namespaceUri, localPart, prefix);
+ }
+ else if( namespaceUri != null && localPart != null )
+ {
+ return new QName(namespaceUri, localPart);
+ }
+ else if( localPart != null )
+ {
+ return new QName(localPart);
+ }
+ return null;
+ }
+
+ private QName getServiceQName()
+ {
+ return getQName(serviceNamespaceUri, serviceLocalPart, servicePrefix);
+ }
+}
+
Added: commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/remoting/RmiProvider.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/remoting/RmiProvider.java?rev=965009&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/remoting/RmiProvider.java (added)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/remoting/RmiProvider.java Sat Jul 17 04:23:37 2010
@@ -0,0 +1,152 @@
+/*
+ * 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.commons.proxy.provider.remoting;
+
+import org.apache.commons.proxy.ObjectProvider;
+import org.apache.commons.proxy.exception.ObjectProviderException;
+
+import java.rmi.NotBoundException;
+import java.rmi.RemoteException;
+import java.rmi.registry.LocateRegistry;
+import java.rmi.registry.Registry;
+import java.rmi.server.RMIClientSocketFactory;
+
+/**
+ * Provides an object by looking it up in an RMI registry.
+ *
+ * @author James Carman
+ * @since 1.0
+ */
+public class RmiProvider implements ObjectProvider
+{
+//**********************************************************************************************************************
+// Fields
+//**********************************************************************************************************************
+
+ private String host = "localhost";
+ private int port = Registry.REGISTRY_PORT;
+ private RMIClientSocketFactory clientSocketFactory;
+ private String name;
+
+//**********************************************************************************************************************
+// Constructors
+//**********************************************************************************************************************
+
+ public RmiProvider()
+ {
+ }
+
+ public RmiProvider( String name )
+ {
+ setName(name);
+ }
+
+ public RmiProvider( String host, String name )
+ {
+ setHost(host);
+ setName(name);
+ }
+
+ public RmiProvider( String host, int port, String name )
+ {
+ setHost(host);
+ setName(name);
+ setPort(port);
+ }
+
+ public RmiProvider( String host, int port, RMIClientSocketFactory clientSocketFactory, String name )
+ {
+ setHost(host);
+ setPort(port);
+ setClientSocketFactory(clientSocketFactory);
+ setName(name);
+ }
+
+//**********************************************************************************************************************
+// ObjectProvider Implementation
+//**********************************************************************************************************************
+
+ @SuppressWarnings("unchecked")
+ public T getObject()
+ {
+ Registry reg;
+ try
+ {
+ reg = getRegistry();
+ return (T)reg.lookup(name);
+ }
+ catch( NotBoundException e )
+ {
+ throw new ObjectProviderException("Name " + name + " not found in registry at " + host + ":" + port + ".",
+ e);
+ }
+ catch( RemoteException e )
+ {
+ throw new ObjectProviderException(
+ "Unable to lookup service named " + name + " in registry at " + host + ":" + port + ".", e);
+ }
+ }
+
+//**********************************************************************************************************************
+// Getter/Setter Methods
+//**********************************************************************************************************************
+
+ public void setClientSocketFactory( RMIClientSocketFactory clientSocketFactory )
+ {
+ this.clientSocketFactory = clientSocketFactory;
+ }
+
+ public void setHost( String host )
+ {
+ this.host = host;
+ }
+
+ public void setName( String name )
+ {
+ this.name = name;
+ }
+
+ public void setPort( int port )
+ {
+ this.port = port;
+ }
+
+//**********************************************************************************************************************
+// Other Methods
+//**********************************************************************************************************************
+
+ private Registry getRegistry()
+ {
+ try
+ {
+ if( clientSocketFactory != null )
+ {
+ return LocateRegistry.getRegistry(host, port, clientSocketFactory);
+ }
+ else
+ {
+ return LocateRegistry.getRegistry(host, port);
+ }
+ }
+ catch( RemoteException e )
+ {
+ throw new ObjectProviderException("Unable to locate registry at " + host + ":" + port + ".", e);
+ }
+ }
+}
+
Added: commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/remoting/SessionBeanProvider.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/remoting/SessionBeanProvider.java?rev=965009&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/remoting/SessionBeanProvider.java (added)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/remoting/SessionBeanProvider.java Sat Jul 17 04:23:37 2010
@@ -0,0 +1,103 @@
+/*
+ * 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.commons.proxy.provider.remoting;
+
+import org.apache.commons.proxy.ObjectProvider;
+import org.apache.commons.proxy.ProxyUtils;
+import org.apache.commons.proxy.exception.ObjectProviderException;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.rmi.PortableRemoteObject;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Properties;
+
+/**
+ * Provides a reference to a session bean by looking up the home object and calling (via reflection) the no-argument
+ * create() method. This will work for both local and remote session beans.
+ *
+ * @author James Carman
+ * @since 1.0
+ */
+public class SessionBeanProvider implements ObjectProvider
+{
+//**********************************************************************************************************************
+// Fields
+//**********************************************************************************************************************
+
+ private final String jndiName;
+ private final Class homeInterface;
+ private final Properties properties;
+
+//**********************************************************************************************************************
+// Constructors
+//**********************************************************************************************************************
+
+ public SessionBeanProvider( String jndiName, Class homeInterface )
+ {
+ this.jndiName = jndiName;
+ this.homeInterface = homeInterface;
+ this.properties = null;
+ }
+
+ public SessionBeanProvider( String jndiName, Class homeInterface, Properties properties )
+ {
+ this.jndiName = jndiName;
+ this.homeInterface = homeInterface;
+ this.properties = properties;
+ }
+
+//**********************************************************************************************************************
+// ObjectProvider Implementation
+//**********************************************************************************************************************
+
+ @SuppressWarnings("unchecked")
+ public T getObject()
+ {
+ try
+ {
+ final InitialContext initialContext = properties == null ? new InitialContext() :
+ new InitialContext(properties);
+ Object homeObject = PortableRemoteObject.narrow(initialContext.lookup(jndiName), homeInterface);
+ final Method createMethod = homeObject.getClass().getMethod("create", ProxyUtils.EMPTY_ARGUMENT_TYPES);
+ return (T)createMethod.invoke(homeObject, ProxyUtils.EMPTY_ARGUMENTS);
+ }
+ catch( NoSuchMethodException e )
+ {
+ throw new ObjectProviderException(
+ "Unable to find no-arg create() method on home interface " + homeInterface.getName() + ".", e);
+ }
+ catch( IllegalAccessException e )
+ {
+ throw new ObjectProviderException(
+ "No-arg create() method on home interface " + homeInterface.getName() + " is not accessible.",
+ e); // Should never happen!
+ }
+ catch( NamingException e )
+ {
+ throw new ObjectProviderException("Unable to lookup EJB home object in JNDI.", e);
+ }
+ catch( InvocationTargetException e )
+ {
+ throw new ObjectProviderException(
+ "No-arg create() method on home interface " + homeInterface.getName() + " threw an exception.", e);
+ }
+ }
+}
+
Added: commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/remoting/package.html
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/remoting/package.html?rev=965009&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/remoting/package.html (added)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/remoting/package.html Sat Jul 17 04:23:37 2010
@@ -0,0 +1,25 @@
+
+
+
+
+
+ This package contains some useful ObjectProvider implementations for use
+ in remoting situations (EJB, RMI, Burlap, Hessian, JAX-RPC, etc).
+
+
+