eliorsh
eliorsh

Reputation: 195

Dynamically Spring AOP with client-server application in JAVA?

I'm using Eclipse Juno IDE and Tomcat 7.0

I have a server, within the server I have TaxiStation class. Now when an event is occur in the station I'm logging it with spring AOP.

From the other side I have a client. The client is a Web application. so when the user want to see if there are taxis in the station (I have vectors that holds the data), he clicks on a button, then the servlet asking from the Server the information and then it's display the required jsp page with the information. If the vectors are empty it works fine, but when there is even one element I'm getting an exception.

Here is my code:

The server side:

ApplicationContext.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/aop 
       http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
    http://www.springframework.org/schema/beans  
            http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/context 
            http://www.springframework.org/schema/context/spring-context.xsd">
    <aop:aspectj-autoproxy>
        <aop:include name="Logging"/>
    </aop:aspectj-autoproxy>
    <bean id="Logging" class="pack.aop.Logging"/>

    <bean id="Station" class="pack.bl.Station" scope ="prototype" lazy-init="true"/>

The Server c'tor:

public MyServer()
{
    al = new ArrayList<ClientHandler>();
    try {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
        si = (StationInterface)ctx.getBean("Station",StationInterface.class);
    } catch (SecurityException e) {
        e.printStackTrace();
    }
}

SI is the station interface (I have station class that implements this interface)

ClientHandler

    ClientHandler(Socket client)
    {
        this.socket = client;

        try{
            to_client   = new ObjectOutputStream(socket.getOutputStream());
            from_client = new ObjectInputStream(socket.getInputStream());
            si.set_server(MyServer.this);
        }
        catch(IOException ioe)
        {
            // error when create the streams
            return;
        }
    }

    public void run(){

        boolean is_running = true;
            try
            {
                data_from_client = (Vector)from_client.readObject();

                 if (data_from_client.elementAt(0).equals("taxis_waits") && 
                      data_from_client.elementAt(1).equals("taxis_break"))
                {
                    Object t_b = si.get_taxis_on_break();
                    Object t_w = si.get_taxis_on_waiting();
                    to_client.writeObject(t_w);
                    to_client.writeObject(t_b);
                    to_client.flush();
                }
                else if (data_from_client.elementAt(0).equals("all_passengers"))
                {
                    Object x = si.get_passengesrs();
                    to_client.writeObject(x);
                    to_client.flush();
                }
            }
    }

NOTE: the methods: get_taxis_on_break(), get_taxis_on_waiting() and get_passengers(), returning Vector. (of taxi or passenger) so when the vectors are empty it seems to work fine and the server writing the data to the servlet, and the servlet read it fine, but when there is an element I'm getting an exception in the client side (the servlet (WebApplication)):

The Exception:

SEVERE: Servlet.service() for servlet [pack.servlets.servlet2] in context with path  
[/TaxiWeb] threw exception
java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: 
org.springframework.aop.aspectj.annotation.InstantiationModelAwarePointcutAdvisorImpl
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readArray(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(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.defaultReadFields(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.defaultReadFields(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.defaultReadFields(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.readArray(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(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 pack.servlets.servlet2.doPost(servlet2.java:90)
at pack.servlets.servlet2.doGet(servlet2.java:47)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
 Caused by: java.io.NotSerializableException: 
 org.springframework.aop.aspectj.annotation.InstantiationModelAwarePointcutAdvisorImpl
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeArray(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeArray(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.access$300(Unknown Source)
at java.io.ObjectOutputStream$PutFieldImpl.writeFields(Unknown Source)
at java.io.ObjectOutputStream.writeFields(Unknown Source)
at java.util.Vector.writeObject(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io.ObjectStreamClass.invokeWriteObject(Unknown Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeObject(Unknown Source)
at pack.my_server.MyServer$ClientHandler.run(MyServer.java:186)

Upvotes: 0

Views: 1203

Answers (1)

MaVRoSCy
MaVRoSCy

Reputation: 17839

your Station Class must implement the java.io.Serializable interface if it is to be serialized.

UPDATED

or you can extend your interface and make it Serializable

public interface SI extends Serializable{
  //interface code here
}

Upvotes: 1

Related Questions