Estou querendo enviar imagens capturadas de um scanner por um applet, via RMI para um servidor.
O problema que estou tendo é que ele nao deixa trafegar um list de BufferedImage pq BufferedImage nao implementa Serializable.
Verifica se RenderedImage implementa Serializable.
Se não for o caso, então use os dados da imagem (via PixelGrabber, Raster, etc…), e use uma classe própria para enviar e depois reconstruir a imagem no lado do servidor.
javaBeats[quote]Verifica se RenderedImage implementa Serializable. [/quote]
Tipow, RenderedImage já é uma interface, ela não pode implementar uma interface, ela só pode extender uma interface, e se ela fosse extends Serializable, o meu BufferedImage + RMI funcionaria, porque BufferedImage implementa RenderedImage, logo, BufferedImage implementaria Serializable, mas não é o caso!
Vou tentar fazer isso sim.
Obrigado pelo post javaBeats, vou tentar fazer da forma que você indicou.
Ah! também tentei fazer o seguinte:
package digitalizacao;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.IndexColorModel;
import java.awt.image.WritableRaster;
import java.io.Serializable;
import java.util.Hashtable;
public class ImagemDigitalizacao extends BufferedImage implements Serializable
{
public ImagemDigitalizacao(ColorModel arg0, WritableRaster arg1, boolean arg2, Hashtable<?, ?> arg3)
{
super(arg0, arg1, arg2, arg3);
}
public ImagemDigitalizacao(int arg0, int arg1, int arg2, IndexColorModel arg3)
{
super(arg0, arg1, arg2, arg3);
}
public ImagemDigitalizacao(int arg0, int arg1, int arg2)
{
super(arg0, arg1, arg2);
}
public static ImagemDigitalizacao getImagemDigitalizacao(BufferedImage image)
{
Hashtable hashtable = null;
String[] propriedades = image.getPropertyNames();
if(propriedades != null)
{
hashtable = new Hashtable(propriedades.length);
for(int i = 0; i < propriedades.length; i++)
{
hashtable.put(propriedades[i],image.getProperty(propriedades[i]));
}
}
else
hashtable = new Hashtable();
return new ImagemDigitalizacao(image.getColorModel(), image.getRaster(), image.isAlphaPremultiplied(),hashtable);
}
}
Tentei criar uma classe que extends BufferedImage, pra pegar por herança as caracteristicas do BufferedImage e a classe implementa Serializable pra poder fazer o transporte RMI.
Mas esta dando o seguinte erro na hora de mandar pro servidor a lista de imagens!
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.io.InvalidClassException: digitalizacao.ImagemDigitalizacao; no valid constructor
at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(Unknown Source)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(Unknown Source)
at $Proxy0.salvaDocumento(Unknown Source)
at digitalizacao.Indexar$4.actionPerformed(Indexar.java:542)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.Dialog$1.run(Unknown Source)
at java.awt.Dialog$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Dialog.show(Unknown Source)
at digitalizacao.Indexar.initialize(Indexar.java:100)
at digitalizacao.Indexar.<init>(Indexar.java:87)
at digitalizacao.AppletDigitalizacao$2.actionPerformed(AppletDigitalizacao.java:169)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.io.InvalidClassException: digitalizacao.ImagemDigitalizacao; no valid constructor
at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.InvalidClassException: digitalizacao.ImagemDigitalizacao; no valid constructor
at java.io.ObjectStreamClass.<init>(Unknown Source)
at java.io.ObjectStreamClass.lookup(Unknown Source)
at java.io.ObjectStreamClass.initNonProxy(Unknown Source)
at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
at java.io.ObjectInputStream.readClassDesc(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at java.util.ArrayList.readObject(Unknown Source)
at sun.reflect.GeneratedMethodAccessor24.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at sun.rmi.server.UnicastRef.unmarshalValue(Unknown Source)
... 7 more
Se alguem souber me dizer porque esta dando essa exception, ou o que eu poderia fazer pra resolver, ficaria agradecido!