Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

exception in GWT RPC app

Tags:

java

rpc

gwt

I am using GWT RPC & Hibernate to insert and retrieve data from MySQL using eclipse environment. I have written two methods in service interfaces to insert & retrieve data from a single MySQL table.

The program is running fine but it is raising this exception.

Exception in thread "UnitCacheLoader" java.lang.RuntimeException: Unable to read from byte cache     at com.google.gwt.dev.util.DiskCache.transferFromStream(DiskCache.java:166)     at com.google.gwt.dev.util.DiskCacheToken.readObject(DiskCacheToken.java:87)     at sun.reflect.GeneratedMethodAccessor2.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.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 com.google.gwt.dev.javac.PersistentUnitCache.loadUnitMap(PersistentUnitCache.java:493)     at com.google.gwt.dev.javac.PersistentUnitCache.access$000(PersistentUnitCache.java:92)     at com.google.gwt.dev.javac.PersistentUnitCache$UnitCacheMapLoader.run(PersistentUnitCache.java:122) Caused by: java.io.StreamCorruptedException: unexpected EOF in middle of data block     at java.io.ObjectInputStream$BlockDataInputStream.refill(Unknown Source)     at java.io.ObjectInputStream$BlockDataInputStream.read(Unknown Source)     at java.io.ObjectInputStream.read(Unknown Source)     at java.io.InputStream.read(Unknown Source)     at com.google.gwt.dev.util.DiskCache.transferFromStream(DiskCache.java:154)     ... 16 more 

ServiceImpl class:

package rpctest.server;  import java.util.ArrayList; import java.util.Iterator; import java.util.List;  import com.google.gwt.user.server.rpc.RemoteServiceServlet; //import com.hib.HibernateUtil;  import org.hibernate.Session; import org.hibernate.Transaction; import rpctest.shared.User; import rpctest.client.RpctestService;  public class RpctestServiceImpl extends RemoteServiceServlet  implements RpctestService {          public String addUser(String name1, String name2)             throws IllegalArgumentException {                Transaction trns = null;               Session session = HibernateUtil.getSessionFactory().openSession();               try {                trns = session.beginTransaction();                 User user = new User();                 user.setFirstName(name1);                user.setLastName(name2);                 session.save(user);                 session.getTransaction().commit();               } catch (RuntimeException e) {                if(trns != null){                 trns.rollback();                }                e.printStackTrace();               } finally{                session.flush();                session.close();               }          return name1+name2; // to test flextable entris only      }      @Override     public  User[] getUser()              {                List<User> getUser = null;                Transaction trns = null;               Session session = HibernateUtil.getSessionFactory().openSession();               try {                trns = session.beginTransaction();                getUser = session.createQuery("from User").list();                 //* for (Iterator<User> iter = getUser.iterator(); iter.hasNext();)                //{                 //User user = iter.next();                 //               //*}                              trns.commit();               } catch (RuntimeException e) {                if(trns != null){                 trns.rollback();                }                e.printStackTrace();               } finally{                session.flush();                session.close();              }               return getUser.toArray(new User[getUser.size()]);         } } 

entrypoint class:

package rpctest.client;  import java.util.ArrayList;  import rpctest.shared.User; import rpctest.shared.FieldVerifier; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.core.client.GWT; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.dom.client.KeyCodes; import com.google.gwt.event.dom.client.KeyPressEvent; import com.google.gwt.event.dom.client.KeyUpEvent; import com.google.gwt.event.dom.client.KeyUpHandler; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.DialogBox; import com.google.gwt.user.client.ui.FlexTable; import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.HorizontalPanel; import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.TextBox; import com.google.gwt.user.client.ui.VerticalPanel;  import com.google.gwt.event.dom.client.KeyCodes; import com.google.gwt.event.dom.client.KeyPressEvent; import com.google.gwt.event.dom.client.KeyPressHandler;  /**  * Entry point classes define <code>onModuleLoad()</code>.  */ public class Rpctest implements EntryPoint {      final TextBox firstName = new TextBox();     final TextBox lastName = new TextBox();     final Button ans = new Button("Add User");     //final Label label1 = new Label("First Name");     //final Label label2 = new Label("Last Name");     private FlexTable userFlexTable = new FlexTable();     //final Label errorLabel = new Label();      private VerticalPanel mainpanel = new VerticalPanel();     private HorizontalPanel addpanel1 = new HorizontalPanel();     private HorizontalPanel addpanel2 = new HorizontalPanel();     private final RpctestServiceAsync calNumbers = GWT             .create(RpctestService.class);      /**      * This is the entry point method.      */     public void onModuleLoad() {          userFlexTable.setText(0, 0, "User ID");         userFlexTable.setText(0, 1, "First Name");         userFlexTable.setText(0, 2, "Second Name");         userFlexTable.setText(0, 3, "Remove");          //add input boxes to panel         addpanel1.add(firstName);         addpanel1.add(lastName);          firstName.setFocus(true);          //add input          mainpanel.add(userFlexTable);         mainpanel.add(addpanel1);         addpanel1.add(ans);          ans.addClickHandler(new ClickHandler() {             @Override             public void onClick(ClickEvent event) {                         addStock();                              }         });          lastName.addKeyPressHandler(new KeyPressHandler() {               public void onKeyPress(KeyPressEvent event) {                   if (event.getCharCode() == KeyCodes.KEY_ENTER) {                       addStock();                   }                 }               });          RootPanel.get().add(mainpanel);         getUser();     }  private void addStock(){          String name1 = firstName.getValue();         // Stock code must be between 1 and 10 chars that are numbers, letters, or dots.         /*if (!name1.matches("^[0-9A-Z\\.]{1,10}$")) {           Window.alert("'" + name1 + "' is not a valid name.");           firstName.selectAll();           return;         }*/          firstName.setValue("");          String name2 = lastName.getValue();         /*if (!name2.matches("^[0-9A-Z\\.]{1,10}$")) {               Window.alert("'" + name1 + "' is not a valid name.");               lastName.selectAll();               return;             }*/         lastName.setValue("");         firstName.setFocus(true);          calNumbers.addUser(name1,name2,             new AsyncCallback<String>() {             public void onFailure(Throwable caught) {                 // Show the RPC error message to the user                     Window.alert("check your inputs");                 }              @Override             public void onSuccess(String result) {             // TODO Auto-generated method stub                 // Add the user to the table.               //  int row = userFlexTable.getRowCount();               //  userFlexTable.setText(row, 1, result);                  getUser();             }         });     }  private void getUser(){         calNumbers.getUser(new AsyncCallback<User[]>() {             public void onFailure(Throwable caught) {                 // Show the RPC error message to the user                     Window.alert("Problem in database connection");                 }              @Override             public void onSuccess(User[] result) {                 // TODO Auto-generated method stub                 for(int i = 0; i < result.length; i ++)                     {                      //String s = result[i].getFirstName();                                     int row = userFlexTable.getRowCount();                      userFlexTable.setText(row, 0, result[i].getId().toString());                      userFlexTable.setText(row, 1, result[i].getFirstName());                      userFlexTable.setText(row, 2, result[i].getLastName());                         }                }         });        } } 
like image 895
enterprize Avatar asked Dec 15 '11 14:12

enterprize


People also ask

How does GWT RPC work?

GWT RPC is servlet based. GWT RPC is asynchronous and client is never blocked during communication. Using GWT RPC Java objects can be sent directly between the client and the server (which are automatically serialized by the GWT framework). Server-side servlet is termed as service.

What is RequestFactory?

RequestFactory is an alternative to GWT-RPC for creating data-oriented services. RequestFactory and its related interfaces (RequestContext and EntityProxy) make it easy to build data-oriented (CRUD) apps with an ORM-like interface on the client.

What is GWT Servlet?

GWT provides an RPC mechanism based on Java Servlets to provide access to server-side resources. This mechanism includes generation of efficient client-side and server-side code to serialize objects across the network using deferred binding.

What is RPC in GWT framework?

The GWT RPC framework makes it easy for the client and server components of your web application to exchange Java objects over HTTP. The server-side code that gets invoked from the client is often referred to as a service. The implementation of a GWT RPC service is based on the well-known Java servlet architecture.

What is the problem with GWT RPC?

There is a problem with RPC, as JavaScript runs in web browser and the RPC call from browser it hangs browser until the response is received. To avoid the browser hanging, GWT RPC call is made " Asynchronous " and the browser does not hang while waiting for the response. The implementation of GWT RPC is based on the Java Servlet technology.

How do I deploy my GWT application to production?

When you deploy your GWT application, you can use any servlet container to host your services. Make sure your client code invokes the service using the URL the servlet is mapped to in the web.xml configuration file. To learn how to deploy GWT RPC servlets to a production server, see the Developer’s Guide, Deploying RPC

How do I test a GWT RPC service?

For more information about GWT RPC, see the Developer’s Guide, Remote Procedure Calls. During testing, you can use development mode’s built-in servlet container to test the server-side code for your RPC services—just as you did in this tutorial.


1 Answers

You mean your code works fine but you see this exception in logs? Exception basically means that compilation cache failed to load for some reason. Most likely cache has become corrupted for some reason, so try to remove folder gwt-UnitCache from your project, this should help.

like image 198
jusio Avatar answered Oct 02 '22 11:10

jusio