You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wsif-dev@ws.apache.org by ow...@apache.org on 2003/02/04 14:54:13 UTC
cvs commit: xml-axis-wsif/java/src/org/apache/wsif/providers/ejb WSIFOperation_EJB.java WSIFPort_EJB.java
owenb 2003/02/04 05:54:13
Modified: java/src/org/apache/wsif/providers/ejb
WSIFOperation_EJB.java WSIFPort_EJB.java
Log:
Fixes to bugzillas:
- 16610 No args constructor (create method on home interface) issue
(see http://nagoya.apache.org/bugzilla/show_bug.cgi?id=16610)
- 16757 Serialization issues with EJB provider
(see http://nagoya.apache.org/bugzilla/show_bug.cgi?id=16757)
Revision Changes Path
1.28 +47 -5 xml-axis-wsif/java/src/org/apache/wsif/providers/ejb/WSIFOperation_EJB.java
Index: WSIFOperation_EJB.java
===================================================================
RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/providers/ejb/WSIFOperation_EJB.java,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- WSIFOperation_EJB.java 13 Jan 2003 20:40:21 -0000 1.27
+++ WSIFOperation_EJB.java 4 Feb 2003 13:54:12 -0000 1.28
@@ -2,7 +2,7 @@
* The Apache Software License, Version 1.1
*
*
- * Copyright (c) 2002 The Apache Software Foundation. All rights
+ * Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -50,13 +50,16 @@
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, 2002, International
- * Business Machines, Inc., http://www.apache.org. For more
+ * Business Machines, Inc., http://www.ibm.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.wsif.providers.ejb;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -110,8 +113,8 @@
protected WSIFPort_EJB fieldPort;
protected javax.wsdl.BindingOperation fieldBindingOperationModel;
protected EJBOperation fieldEJBOperationModel;
- protected Method fieldMethod = null;
- protected Method[] fieldAllMethods = null;
+ transient protected Method fieldMethod = null;
+ transient protected Method[] fieldAllMethods = null;
protected String[] fieldInParameterNames = null;
protected String[] fieldOutParameterNames = null;
// key: position, value: name
@@ -182,7 +185,7 @@
if (fieldIsHomeInterface) {
fieldAllMethods = fieldPort.getEjbHome().getClass().getMethods();
} else {
- fieldAllMethods = fieldPort.getEjbObject().getClass().getMethods();
+ fieldAllMethods = fieldPort.getEjbObjectMethods();
}
if (Trc.ON)
@@ -1460,4 +1463,43 @@
}
return buff;
}
+
+ /**
+ * Override default deserialization
+ */
+ private void writeObject(ObjectOutputStream oos) throws IOException {
+ oos.defaultWriteObject();
+ }
+
+ /**
+ * Override default deserialization
+ */
+ private void readObject(ObjectInputStream ois)
+ throws ClassNotFoundException, IOException {
+ ois.defaultReadObject();
+
+ // Reproduce list of methods
+ if (fieldPort == null) {
+ throw new IOException("Unable to deserialize WSIFOperation_EJB, reference to WSIFPort_EJB is null");
+ }
+
+ String ejbInterface = fieldEJBOperationModel.getEjbInterface();
+ if (ejbInterface != null) {
+ if (ejbInterface.equals("home")) {
+ fieldIsHomeInterface = true;
+ } else if (!ejbInterface.equals("remote")) {
+ String name = (fieldBindingOperationModel != null) ? fieldBindingOperationModel.getName() : "unknown";
+ throw new IOException(
+ "EJB binding interface not recognized for operation '"
+ + name
+ + "'. Valid values are 'home' and 'remote'");
+ }
+ }
+
+ if (fieldIsHomeInterface) {
+ fieldAllMethods = fieldPort.getEjbHome().getClass().getMethods();
+ } else {
+ fieldAllMethods = fieldPort.getEjbObjectMethods();
+ }
+ }
}
1.11 +124 -6 xml-axis-wsif/java/src/org/apache/wsif/providers/ejb/WSIFPort_EJB.java
Index: WSIFPort_EJB.java
===================================================================
RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/providers/ejb/WSIFPort_EJB.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- WSIFPort_EJB.java 16 Dec 2002 11:27:59 -0000 1.10
+++ WSIFPort_EJB.java 4 Feb 2003 13:54:13 -0000 1.11
@@ -2,7 +2,7 @@
* The Apache Software License, Version 1.1
*
*
- * Copyright (c) 2002 The Apache Software Foundation. All rights
+ * Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -50,14 +50,19 @@
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, 2002, International
- * Business Machines, Inc., http://www.apache.org. For more
+ * Business Machines, Inc., http://www.ibm.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.wsif.providers.ejb;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
import java.lang.reflect.Method;
+import java.rmi.RemoteException;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
@@ -65,6 +70,8 @@
import javax.ejb.EJBHome;
import javax.ejb.EJBObject;
+import javax.ejb.Handle;
+import javax.ejb.HomeHandle;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import javax.wsdl.BindingOperation;
@@ -95,13 +102,23 @@
private javax.wsdl.Definition fieldDefinition = null;
private javax.wsdl.Port fieldPortModel = null;
- private EJBHome fieldEjbHome = null; // 'factory for physical connection'
- private EJBObject fieldEjbObject = null; // 'physical connection'
+ transient private EJBHome fieldEjbHome = null; // 'factory for physical connection'
+ transient private EJBObject fieldEjbObject = null; // 'physical connection'
+ private final boolean separatedEJBRefs; // DO NOT INITIALIZE UNTIL CONSTRUCTOR
+ transient private Class ejbObjectClass;
+ transient private Method[] ejbObjectMethods = null;
- protected Map operationInstances = new HashMap();
+ transient protected Map operationInstances = new HashMap();
public WSIFPort_EJB(Definition def, Port port, WSIFDynamicTypeMap typeMap) {
Trc.entry(this, def, port, typeMap);
+
+ // Flag to indicate that the EJB references are written after this object
+ // when this object is serialized to a stream. Older versions of this class may
+ // not do this and so the flag will be missing in the stream and default to false
+ // when the object is deserialized (flag must not be initialized where declared
+ // because it is final and would not default to false!)
+ separatedEJBRefs = true;
fieldDefinition = def;
fieldPortModel = port;
@@ -210,7 +227,7 @@
}
Trc.exit(fieldEjbHome);
return fieldEjbHome;
- }
+ }
public EJBObject getEjbObject() throws WSIFException {
Trc.entry(this);
@@ -231,6 +248,57 @@
return fieldEjbObject;
}
+ /**
+ * Gets the Java class of the EJB remote interface without having to create the object
+ * @return Class the class of the service object
+ */
+ Class getEjbObjectClass() throws WSIFException {
+ // no method access modifier as it used by WSIFOperation_Java
+ Trc.entry(this);
+ if (ejbObjectClass == null) {
+
+ if (fieldEjbObject != null) {
+ ejbObjectClass = fieldEjbObject.getClass();
+ } else {
+ // Lookup the EJBHome. If it has already been resolved, this call will simply
+ // return it, which we ignore.
+ getEjbHome();
+
+ if (fieldEjbHome == null) {
+ throw new WSIFException("Unable to get EJBObject class, fieldEjbHome is null");
+ }
+
+ try {
+ ejbObjectClass =
+ fieldEjbHome.getEJBMetaData().getRemoteInterfaceClass();
+ } catch (RemoteException re) {
+ Trc.exception(re);
+ throw new WSIFException(
+ "Unable to get EJBObject class",
+ re);
+ }
+ }
+ }
+
+ Trc.exit(ejbObjectClass);
+ return ejbObjectClass;
+ }
+
+ /**
+ * Gets the methods of the EJB's remote interface without having to create the object
+ * @return Method[] the methods of the EJB's remote interface
+ */
+ Method[] getEjbObjectMethods() throws WSIFException {
+ // no method access modifier as it used by WSIFOperation_Java
+ Trc.entry(this);
+ if (ejbObjectMethods == null) {
+ Class c = getEjbObjectClass();
+ ejbObjectMethods = c.getMethods();
+ }
+ Trc.exit(ejbObjectMethods);
+ return ejbObjectMethods;
+ }
+
public Port getPortModel() {
Trc.entry(this);
Trc.exit(fieldPortModel);
@@ -333,4 +401,54 @@
return buff;
}
+
+ /**
+ * Override default serialization
+ */
+ private void writeObject(ObjectOutputStream oos) throws IOException {
+ oos.defaultWriteObject();
+
+ // References to the EJBHome and EJBObject objects should be stored as handles
+ if (fieldEjbHome != null) {
+ HomeHandle homeHandle = fieldEjbHome.getHomeHandle();
+ oos.writeObject(homeHandle);
+ } else {
+ oos.writeObject(fieldEjbHome);
+ }
+ if (fieldEjbObject != null) {
+ Handle handle = fieldEjbObject.getHandle();
+ oos.writeObject(handle);
+ } else {
+ oos.writeObject(fieldEjbObject);
+ }
+ }
+
+ /**
+ * Override default deserialization
+ */
+ private void readObject(ObjectInputStream ois)
+ throws ClassNotFoundException, IOException {
+ ois.defaultReadObject();
+
+ // If the EJBHome and EJBObject handles have been written after the WSIFPort, recover
+ // the objects now
+ if (separatedEJBRefs) {
+ Object objHome = ois.readObject();
+ if (objHome != null && objHome instanceof HomeHandle) {
+ HomeHandle homeHandle = (HomeHandle) objHome;
+ fieldEjbHome = homeHandle.getEJBHome();
+ }
+ // else - If the object is null then we don't need to do anything
+
+ Object obj = ois.readObject();
+ if (obj != null && obj instanceof Handle) {
+ Handle handle = (Handle) obj;
+ fieldEjbObject = handle.getEJBObject();
+ }
+ // else - If the object is null then we don't need to do anything
+ }
+
+ // Reset the operation instances
+ operationInstances = new HashMap();
+ }
}