tomj 02/02/12 09:28:33
Modified: java/src/org/apache/axis/providers/java JavaProvider.java
EJBProvider.java
Log:
Rework EJBProvider to use the correct Remote Interface class information to generate
WSDL
In the process commented and cleaned up EJVProvider.
Revision Changes Path
1.35 +33 -23
xml-axis/java/src/org/apache/axis/providers/java/JavaProvider.java
Index: JavaProvider.java
===================================================================
RCS file:
/home/cvs/xml-axis/java/src/org/apache/axis/providers/java/JavaProvider.java,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- JavaProvider.java 8 Feb 2002 03:09:25 -0000 1.34
+++ JavaProvider.java 12 Feb 2002 17:28:32 -0000 1.35
@@ -253,6 +253,12 @@
category.debug(JavaUtils.getMessage("exit00", "JavaProvider::invoke ("
+ this + ")"));
}
+ /**
+ * Generate the WSDL for this service.
+ *
+ * Put in the "WSDL" property of the message context
+ * as a org.w3c.dom.Document
+ */
public void generateWSDL(MessageContext msgContext) throws AxisFault {
if (category.isDebugEnabled())
category.debug(JavaUtils.getMessage("enter00", "JavaProvider::editWSDL
(" + this + ")"));
@@ -264,18 +270,6 @@
/* Now get the service (RPC) specific info */
/********************************************/
- String clsName = getServiceClassName(service);
- Object obj = null;
- try {
- obj = getServiceObject(msgContext,
- service,
- clsName);
- } catch( Exception exp ) {
- category.error( exp );
- throw AxisFault.makeFault(exp);
- }
-
- JavaClass jc = JavaClass.find(obj.getClass());
String allowedMethods = getAllowedMethods(service);
/** ??? Should we enforce setting methodName? As it was,
@@ -293,19 +287,21 @@
allowedMethods = null;
/** If the class knows what it should be exporting,
- * respect its wishes.
- */
- if (obj instanceof AxisServiceConfig) {
- allowedMethods = ((AxisServiceConfig)obj).getMethods();
- }
+ * respect its wishes.
+ * XXX - this system (AxisSeriviceConfig interface) is going to be
+ * removed per the TODO list, so it wont work for WSDL right now
+ * [EMAIL PROTECTED]
+ */
+// if (obj instanceof AxisServiceConfig) {
+// allowedMethods = ((AxisServiceConfig)obj).getMethods();
+// }
try {
- ClassLoader cl = msgContext.getClassLoader();
- Class cls = jc.getJavaClass();
String url = msgContext.getStrProp(MessageContext.TRANS_URL);
String urn = (String)msgContext.getTargetService();
String description = "Service";
+ Class cls = getServiceClass(msgContext, getServiceClassName(service));
Emitter emitter = new Emitter();
emitter.setClsSmart(cls,url);
emitter.setAllowedMethods(allowedMethods);
@@ -343,7 +339,7 @@
/**
* Default java service object comes from simply instantiating the
- * class wrapped in jc
+ * class wrapped in jc
*
*/
protected Object getNewServiceObject(MessageContext msgContext,
@@ -352,13 +348,13 @@
{
ClassLoader cl = msgContext.getClassLoader();
ClassCache cache = msgContext.getAxisEngine().getClassCache();
- JavaClass jc = cache.lookup(clsName, cl);
+ JavaClass jc = cache.lookup(clsName, cl);
return jc.getJavaClass().newInstance();
}
/**
- *
+ * Return the class name of the service
*/
protected String getServiceClassName(Handler service)
{
@@ -366,10 +362,24 @@
}
/**
- *
+ * Return the option in the configuration that contains the service class
+ * name
*/
protected String getServiceClassNameOptionName()
{
return classNameOption;
}
+
+ /**
+ * Returns the Class info about the service class.
+ */
+ protected Class getServiceClass(MessageContext msgContext, String clsName)
throws Exception {
+ Handler service = msgContext.getServiceHandler();
+ Object obj = getServiceObject(msgContext,
+ service,
+ clsName);
+
+ return obj.getClass();
+ }
+
}
1.13 +143 -48
xml-axis/java/src/org/apache/axis/providers/java/EJBProvider.java
Index: EJBProvider.java
===================================================================
RCS file:
/home/cvs/xml-axis/java/src/org/apache/axis/providers/java/EJBProvider.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- EJBProvider.java 8 Feb 2002 22:14:11 -0000 1.12
+++ EJBProvider.java 12 Feb 2002 17:28:33 -0000 1.13
@@ -70,6 +70,7 @@
* A basic EJB Provider
*
* @author Carl Woolf ([EMAIL PROTECTED])
+ * @author Tom Jordahl ([EMAIL PROTECTED])
*/
public class EJBProvider extends RPCProvider
{
@@ -91,20 +92,144 @@
///////////////////////////////////////////////////////////////
/**
- *
+ * Return a object which implements the service.
+ *
+ * @param msgContext the message context
+ * @param clsName The JNDI name of the EJB home class
+ * @return an object that implements the service
*/
protected Object getNewServiceObject(MessageContext msgContext,
String clsName)
throws Exception
{
Handler serviceHandler = msgContext.getServiceHandler();
- Object home;
+
+ // Get the EJB Home object from JNDI
+ Object ejbHome = getEJBHome(msgContext, clsName);
+
+ // Get the Home class name from the configuration file
+ // NOTE: Do we really need to have this in the config file
+ // since we can get it from ejbHome.getClass()???
+ String homeName = (String) getStrOption(homeInterfaceNameOption,
+ serviceHandler);
+ if (homeName == null)
+ throw new AxisFault(
+ JavaUtils.getMessage("noOption00",
+ homeInterfaceNameOption,
+ msgContext.getTargetService()));
+
+ // Load the Home class name given in the config file
+ Class homeClass = msgContext.getClassLoader().loadClass(homeName);
+
+ // Make sure the object we got back from JNDI is the same type
+ // as the what is specified in the config file
+ Object ehome = javax.rmi.PortableRemoteObject.narrow(ejbHome, homeClass);
+
+ // Invoke the create method of the ejbHome class without actually
+ // touching any EJB classes (i.e. no cast to EJBHome)
+ Method createMethod = homeClass.getMethod("create", empty_class_array);
+ Object result = createMethod.invoke(ehome, empty_object_array);
+
+ return result;
+ }
+
+ /**
+ * Return the option in the configuration that contains the service class
+ * name. In the EJB case, it is the JNDI name of the bean.
+ */
+ protected String getServiceClassNameOptionName()
+ {
+ return beanNameOption;
+ }
+
+ /**
+ * Get a String option by looking first in the service options,
+ * and then at the Handler's options. This allows defaults to be
+ * specified at the provider level, and then overriden for particular
+ * services.
+ *
+ * @param optionName the option to retrieve
+ * @return String the value of the option or null if not found in
+ * either scope
+ */
+ private String getStrOption(String optionName, Handler service)
+ {
+ String value = null;
+ if (service != null)
+ value = (String)service.getOption(optionName);
+ if (value == null)
+ value = (String)getOption(optionName);
+ return value;
+ }
+
+ /**
+ * Get the class description for the EJB Remote Interface, which is what
+ * we are interested in exposing to the world (i.e. in WSDL).
+ *
+ * @param msgContext the message context
+ * @param beanJndiName the JNDI name of the EJB
+ * @return the class info of the EJB remote interface
+ */
+ protected Class getServiceClass(MessageContext msgContext, String beanJndiName)
throws Exception {
+ Handler serviceHandler = msgContext.getServiceHandler();
+
+ // Get the EJB Home object from JNDI
+ Object ejbHome = getEJBHome(msgContext, beanJndiName);
+
+ String homeName = (String) getStrOption(homeInterfaceNameOption,
+ serviceHandler);
+ if (homeName == null)
+ throw new AxisFault(
+ JavaUtils.getMessage("noOption00",
+ homeInterfaceNameOption,
+ msgContext.getTargetService()));
+
+ // Load the Home class name given in the config file
+ Class homeClass = msgContext.getClassLoader().loadClass(homeName);
+
+ // Make sure the object we got back from JNDI is the same type
+ // as the what is specified in the config file
+ Object ehome = javax.rmi.PortableRemoteObject.narrow(ejbHome, homeClass);
+
+ // This code requires the use of ejb.jar, so we do the funny stuff below
+ // EJBHome ejbHome = (EJBHome) ehome;
+ // EJBMetaData meta = ejbHome.getEJBMetaData();
+ // Class interfaceClass = meta.getRemoteInterfaceClass();
+
+ // Invoke the getEJBMetaData method of the ejbHome class without actually
+ // touching any EJB classes (i.e. no cast to EJBHome)
+ Method getEJBMetaData =
+ homeClass.getMethod("getEJBMetaData", empty_class_array);
+ Object metaData =
+ getEJBMetaData.invoke(ehome, empty_object_array);
+ Method getRemoteInterfaceClass =
+ metaData.getClass().getMethod("getRemoteInterfaceClass",
+ empty_class_array);
+ Class interfaceClass =
+ (Class) getRemoteInterfaceClass.invoke(metaData,
+ empty_object_array);
+
+ // got it, return it
+ return interfaceClass;
+
+ }
+
+ /**
+ * Common routine to do the JNDI lookup on the Home interface object
+ */
+ private Object getEJBHome(MessageContext msgContext, String beanJndiName)
throws AxisFault {
+ Handler serviceHandler = msgContext.getServiceHandler();
+ Object ejbHome;
Properties properties = null;
+ // Set up an InitialContext and use it get the beanJndiName from JNDI
try
{
+ // collect all the properties we need to access JNDI:
+ // username, password, factoryclass, contextUrl
String username = (String)getStrOption(jndiUsername,
serviceHandler);
+ // username
if (username == null)
username = msgContext.getUsername();
if (username != null) {
@@ -113,6 +238,7 @@
username);
}
+ // password
String password = (String)getStrOption(jndiPassword,
serviceHandler);
if (password == null)
@@ -123,6 +249,7 @@
password);
}
+ // factory class
String factoryClass = (String)getStrOption(jndiContextClass,
serviceHandler);
if (factoryClass != null) {
@@ -131,6 +258,7 @@
factoryClass);
}
+ // contextUrl
String contextUrl = (String)getStrOption(jndiURL,
serviceHandler);
if (contextUrl != null) {
@@ -139,67 +267,34 @@
contextUrl);
}
+ // if we got any stuff from the configuration file
+ // create a new context using these properties
+ // otherwise, we can get a default context and cache it for next time
InitialContext context = null;
- if (properties != null)
+ if (properties != null) {
context = new InitialContext(properties);
- else
- {
+ } else {
if (cached_context == null)
cached_context = new InitialContext();
context = cached_context;
}
-
+
+ // if we didn't get a context, fail
if (context == null)
throw new AxisFault(
JavaUtils.getMessage("cannotCreateInitialContext00"));
- home = context.lookup(clsName);
- if (home == null)
- throw new AxisFault(
JavaUtils.getMessage("cannotFindJNDIHome00",clsName));
+ // Do the JNDI lookup
+ ejbHome = context.lookup(beanJndiName);
+ if (ejbHome == null)
+ throw new AxisFault(
JavaUtils.getMessage("cannotFindJNDIHome00",beanJndiName));
}
// Should probably catch javax.naming.NameNotFoundException here
catch (Exception exception)
{
throw AxisFault.makeFault(exception);
}
-
- String homeName = (String) getStrOption(homeInterfaceNameOption,
-
serviceHandler);
- if (homeName == null)
- throw new AxisFault(JavaUtils.getMessage("noOption00",
homeInterfaceNameOption, msgContext.getTargetService()));
-
- Class homeClass = msgContext.getClassLoader().loadClass(homeName);
- Object ehome = javax.rmi.PortableRemoteObject.narrow(home, homeClass);
- Method createMethod = homeClass.getMethod("create", empty_class_array);
- Object result = createMethod.invoke(ehome, empty_object_array);
-
- return result;
+ return ejbHome;
}
- /**
- *
- */
- protected String getServiceClassNameOptionName()
- {
- return beanNameOption;
- }
- /**
- * Get a String option by looking first in the service options,
- * and then at the Handler's options. This allows defaults to be
- * specified at the provider level, and then overriden for particular
- * services.
- *
- * @param optionName the option to retrieve
- * @return String the value of the option or null if not found in
- * either scope
- */
- private String getStrOption(String optionName, Handler service)
- {
- String value = null;
- if (service != null)
- value = (String)service.getOption(optionName);
- if (value == null)
- value = (String)getOption(optionName);
- return value;
- }
-}
+}
\ No newline at end of file