L.Spillner
L.Spillner

Reputation: 1772

GWT unable to retrieve result from servlet

I am currently developing a GUI (with GWT) for something similar to a sorting framework and up to the last step everything works just fine. But I am unable to retrieve the data due to a JavaScriptException:

Tue May 29 09:46:56 GMT+200 2018 debug SEVERE: com.google.gwt.core.client.JavaScriptException: (TypeError) : this$static[signature][0] is not a function
Tue May 29 09:46:56 GMT+200 2018 debug SEVERE: Unknown.$instantiate(0.js@35:10985)
Tue May 29 09:46:56 GMT+200 2018 debug SEVERE: Unknown.instantiate_13(0.js@12:10952)
Tue May 29 09:46:56 GMT+200 2018 debug SEVERE: Unknown.deserialize_18(0.js@30:10259)
Tue May 29 09:46:56 GMT+200 2018 debug SEVERE: Unknown.readObject(0.js@15:10126)
Tue May 29 09:46:56 GMT+200 2018 debug SEVERE: Unknown.deserialize_7(0.js@24:9909)
Tue May 29 09:46:56 GMT+200 2018 debug SEVERE: Unknown.deserialize_5(0.js@3:9875)
Tue May 29 09:46:56 GMT+200 2018 debug SEVERE: Unknown.$deserialize(0.js@28:10977)
Tue May 29 09:46:56 GMT+200 2018 debug SEVERE: Unknown.deserialize_19(0.js@5:10936)
Tue May 29 09:46:56 GMT+200 2018 debug SEVERE: Unknown.deserialize_18(0.js@19:10261)
Tue May 29 09:46:56 GMT+200 2018 debug SEVERE: Unknown.readObject(0.js@15:10126)

To be honest I am absolutely clueless about javascript so I just assumed something went wrong when the returning object was instantiated but in this case I am using java.util.Map<String,java.util.List<?>> and made sure that I really use those from the java.util package.

The responsible code looks as follows:

SortingFramework.java (Interface):

@RemoteServiceRelativePath ( "framework")
public interface SortingFramework<T extends Comparable<T>>
    extends RemoteService
{
  public Map<String,List<?>> getResults();
}

SortingFrameworkAsync.java (Interface):

public interface SortingFrameworkAsync<T extends Comparable<T>>
{
  void getResults( AsyncCallback<Map<String, List<?>>> result ) throws IllegalArgumentException;
}

SortingFrameworkImpl.java (Servlet):

public class SortingFrameworkImpl<E extends Comparable<E>>
    extends RemoteServiceServlet
    implements SortingFramework<E>
{
 Map<String,List<?>> results = new HashMap<String,List<?>>();     

  @Override
  public Map<String, List<?>> getResults()
  {
    boolean b;
    do
    {
         // will return true when everything is done.
         b = !isDone();
     }
     while ( b );

    return new HashMap<String,List<?>>(results); // also tried to simply return results here
  }
}

In this case I omitted how results is populated since it's not part of the problem and I made sure that no values are null or from a different type. In short: The map is exactly as I want it.

Now the calling part:

ResultPresenterImpl.java (Presenter for a ResultView):

public class ResultPresenterImpl
    implements ResultPresenter
{
// gets set at an earlier point than the error occurs
private SortingFrameworkAsync<?> model;

  @Override
  public void initView()
  {
    model.getResults( new AsyncCallback<Map<String,List<?>>>()
    {
      // here the exception gets caught.
      @Override
      public void onFailure( Throwable caught )
      {
        log.severe( caught.toString() );
        for(StackTraceElement element : caught.getStackTrace())
        {
          log.severe( element.toString() );
        }
      }

      @Override
      public void onSuccess( Map<String, List<?>> result )
      {
        addContentToView( result );
      }
    } );
    view.show();
  }
}

The initView() method will only be called when the user confirmed everything neccessary and the remote call procedure should wait for getResult() actually returning something but somehow it fails with the exception mentioned above.

I made sure that everything has a vallue and null does not occure at any point. So my question is: How can the remote procedure call fail? What is the cause of the exception?

At first I thought that GWT might not be able to serialize/desieralize a Map<String,List<?>> but I tried that in an empty project and it worked out just fine.

Upvotes: 1

Views: 57

Answers (1)

Colin Alworth
Colin Alworth

Reputation: 18331

At first I thought that GWT might not be able to serialize/desieralize a Map<String,List<?>> but I tried that in an empty project and it worked out just fine.

Your instinct here is correct - GWT can't tell what ? means, so doesn't prepare any types for serialization, but chances are you are sending some object in that list and it doesn't know how to send it.

this$static[signature][0] is not a function

The value of signature is the name of the class that was serialized by the server, but can't be read by the client. The fact that is says "is not a function" likely means that gwt thinks your data is serializable, but might think it can only be sent in a different direction - the [0] is trying to read a function out of a a set of three functions - one to instantiate a serialized value, one to finish deserializing fields, and one to serialize fields to send to the server.

Upvotes: 2

Related Questions