Sorry to be so brief.
I wasn't sure that what I had reported was an error within the IntraVMHandler.
Here's the scoop on what I had done; which i'm pulling from my memory (or my ass as my
grandmother would say)
I basically created a stateful session bean to hold a collection of remote beans. I
stored the handle to the session bean within an object wrapper and put that into the
request.setAttribute.
When the user selected a specific record to modify I wanted to use the handle to to
recreate the session and use the cached beans within the session.
The error occured when I tried to retrieve the session handle or the session using a
ByteArrayOutputStream with an ObjectOutputStream.
Attached is a copy of the ServiceLocator class. The methods used are:
1. public String getId(EJBObject session) throws Exception{
2. public EJBObject getService(String id) throws Exception{
The workaround, since I'm developing locally, was to save the reference to the session
object. It works, but, the object never get's passivated (or written?). Which is
what I had thought the reason for the error.
Jacek, does that describe what is happening?
Here's the two methods which I've referred to:
// converts serialized string into EJBHandle then to EJBObject
public EJBObject getService(String id) throws Exception{
if(null == id)
throw new Exception("NO STRING HANDLE FOR EJB OBJECT");
try{
byte[] bytes = new String(id).getBytes();
InputStream io = new ByteArrayInputStream(bytes);
ObjectInputStream os = new ObjectInputStream(io);
javax.ejb.Handle handle = (javax.ejb.Handle)os.readObject();
return handle.getEJBObject();
}catch(Exception ex){
throw ex;
}
}
// returns the string that represents the given
// EJBObject's handle in serialized format
public String getId(EJBObject session) throws Exception{
try{
javax.ejb.Handle handle = session.getHandle();
System.out.println("handle -- >" +handle.toString());
// ByteArrayOutputStream fo = new ByteArrayOutputStream();
// ObjectOutputStream so = new ObjectOutputStream(fo);
// so.writeObject(handle);
// so.flush();
// so.close();
// return new String(fo.toByteArray());
return handle.toString();
}catch(RemoteException ex){
throw ex;
}catch(IOException ex){
throw ex;
}
}
--
--------- Original Message ---------
DATE: Tue, 15 Jun 2004 12:39:14
From: Jacek Laskowski <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
Cc:
>graham king wrote:
>
>> thanks Jacek. i just used a workaround...
>
>What was that? Could you please share it here? It would others before
>the code has been corrected.
>
>I'm testing the changes to OpenEJB and its integration stuff with Tomcat
>(finally got it to work yesterday).
>
>Best,
>Jacek
>
____________________________________________________________
Find what you are looking for with the Lycos Yellow Pages
http://r.lycos.com/r/yp_emailfooter/http://yellowpages.lycos.com/default.asp?SRC=lycos10/*
* ServiceLocator.java
*
* Created on April 28, 2004, 8:51 PM
* Core J2EE Patterns - Best Practices and Design Strategies pge 381, copyright 2001
* Deepak Alur, John Crupi, Dan Malks
*/
package com.thejanehuts.util;
import java.util.*;
import javax.naming.*;
import java.rmi.RemoteException;
import javax.ejb.*;
import javax.rmi.PortableRemoteObject;
import java.io.*;
import javax.sql.DataSource;
/**
*
* @author Graham King
*/
public class ServiceLocator implements Serializable{
private static ServiceLocator locator;
InitialContext context = null;
/** Creates a new instance of ServiceLocator */
private ServiceLocator() throws Exception{
Properties env = new Properties();
String jndiProvider = "org.openejb.client.LocalInitialContextFactory";
env.put( "java.naming.factory.initial", jndiProvider );
try{
context = new InitialContext(env);
}catch(NamingException ex){
throw ex;
}
}
// return instance of this
public static ServiceLocator getInstance() throws Exception{
if(null == locator)
locator = new ServiceLocator();
return locator;
}
// converts serialized string into EJBHandle then to EJBObject
public EJBObject getService(String id) throws Exception{
if(null == id)
throw new Exception("NO STRING HANDLE FOR EJB OBJECT");
try{
byte[] bytes = new String(id).getBytes();
InputStream io = new ByteArrayInputStream(bytes);
ObjectInputStream os = new ObjectInputStream(io);
javax.ejb.Handle handle = (javax.ejb.Handle)os.readObject();
return handle.getEJBObject();
}catch(Exception ex){
throw ex;
}
}
// returns the string that represents the given
// EJBObject's handle in serialized format
public String getId(EJBObject session) throws Exception{
try{
javax.ejb.Handle handle = session.getHandle();
System.out.println("handle -- >" +handle.toString());
// ByteArrayOutputStream fo = new ByteArrayOutputStream();
// ObjectOutputStream so = new ObjectOutputStream(fo);
// so.writeObject(handle);
// so.flush();
// so.close();
// return new String(fo.toByteArray());
return handle.toString();
}catch(RemoteException ex){
throw ex;
}catch(IOException ex){
throw ex;
}
}
// returns the EJBHome object fo requested service name.
// Throws ServiceLocatorException (in our case Exception)
// if there are any errors in the lookup
public EJBHome getHome(String name, Class clazz) throws Exception{
try{
Object objref = context.lookup(name);
EJBHome home = (EJBHome)PortableRemoteObject.narrow(objref, clazz);
return home;
}catch(Exception ex){
throw ex;
}
}
// returns the DataSource object for requested database
// throws Exception if errors in lookup
public DataSource getDataSource(String name)throws NameNotFoundException,
NamingException{
try{
System.out.println("name-->"+name);
DataSource myDataSource = (DataSource)context.lookup(name);
return myDataSource;
}catch(NameNotFoundException ex){
throw ex;
}catch(NamingException ex){
throw ex;
}
}
public void list(String name){
System.out.println("listing bindings for---> "+name);
try{
NamingEnumeration enum = context.listBindings(name);
while(enum.hasMore()){
NameClassPair ncPair = (NameClassPair)enum.next();
System.out.println(ncPair.getName()+"(type:");
System.out.println(ncPair.getClassName()+")");
}
}catch(NamingException e){
e.printStackTrace();
}
System.out.println("listing---> for "+name);
try{
NamingEnumeration enum = context.list(name);
while(enum.hasMore()){
NameClassPair ncPair = (NameClassPair)enum.next();
System.out.println(ncPair.getName()+"(type:");
System.out.println(ncPair.getClassName()+")");
}
}catch(NamingException e){
e.printStackTrace();
}
}
}