Sunday, August 22, 2010

GWT error - com.google.gwt.user.client.rpc.ServiceDefTarget $NoServiceEntryPointSpecifiedException: Service implementation URL not specified

Note that the solution depends on the GWT version. I was using GWT 2.0+

Just ensure that service relative path is mentioned in your client service interface via annotation

com.google.gwt.user.client.rpc.RemoteServiceRelativePath

An example,

@RemoteServiceRelativePath("sampleService")
public interface SampleService extends RemoteService {
..
}

If you want to understand why 
or
if you using older version of GWT then the annotation won't be available for you so 
here is the answer.

This is mentioned in GWT dev guide under 'Common pitfall' but i didn't read it earlier,
"When running your RPC call, development mode displays an excaption NoServiceEntryPointSpecifiedException: Service implementation URL not specified. This error means that you did not specify a @RemoteServiceRelativePath in your service interface, and you also did not manually set target path by calling ServiceDefTarget.setServiceEntryPoint()."
    Also note this one that's closely related to above one,
    "If invoking your RPC call fails with a 404 StatusCodeException, your web.xml may be misconfigured. Make sure you specified a @RemoteServiceRelativePath and that the <url-pattern> specified in your web.xml matches this value, prepended with the location of your GWT output directory within the war directory."

    For every annotation definition given above, corresponding entry for service impl should be given in web deployment descriptor i.e web.xml. As an example,

       <servlet>
            <servlet-name>sampleServlet</servlet-name>
            <servlet-class>samples.gwt.SampleServiceImpl</servlet-class>
        </servlet>

        <servlet-mapping>
            <servlet-name>sampleServlet</servlet-name>
            <url-pattern>/sample-gwt-module/sampleService</url-pattern>
        </servlet-mapping>
     
    where


     sample-gwt-module

    is the (alternate) name of the sample GWT module as defined in module definition as


    <module rename-to='addressbookmain'>

    GWT error: 'samples.gwt.Model' is not assignable to 'com.google.gwt.user.client.rpc.IsSerializable' or 'java.io.Serializable' nor does it have a custom field serializer (reached via samples.gwt.Model)


    This could really be because of multiple reasons and i have listed solution pertaining to my case here.

    See if the class in err i.e. (samples.gwt.Model here) implements
    java.io.Serializable; 


    i did and this solved the prob in my case. If err still persists, before further analysis you could ensure that following are intact though these might not be directly related.

      Make sure the class (samples.gwt.Model here) that could not be assigned to RPC is defined in shared package (per GWT convention it is the package with leaf folder in name of 'shared' for eg. 'samples.gwt.shared') that's visible to both server and client.
    The point is the class should not only be defined in client package (say samples.gwt.client) that's translated to javascript finally and not visible to server part.
    (and as a note, you should/would have mentioned this path in corresponding module definition XML as <source path='shared'/>)

     Also if the class in err i.e. is defined in GWT module A (say) and the RPC service class in error is one that's present in module B (say), in this case, ensure that module A is inherited in module B XML definition
    via inherit tag.
    eg. 
    <inherits name='samples.gwt.A'/>

    Hope this helps.


    GWT error - Unable to find 'Sample.gwt.xml' on your classpath; could be a typo, or maybe you forgot to include a classpath entry for source


    How to solve the error in question?

    The solution is in the err message itself, thanks to GWT.
    Though the exact cause depends on your environment, following addresses common scenarios

    a. If the module definition XML (i.e. 'Sample.gwt.xml' here) is in the same GWT module that you are compiling via GWT compiler (or running in development mode) then check if the desired xml has been put in package that's just before above your client package. Importantly the module definition should be in the source path so that it falls in the GWT module's classpath.
     i.e. if your client package is 
    samples.gwt.client
    then Sample.gwt.xml should go into 
    samples.gwt

    b. If the module definition XML is in a dependent module that you have inherited in your parent (or main) module definition Main.gwt.xml (say) then ensure that the logical name of inherited module definition XML mentioned in <inherit> tag is correct

    i.e. you should have 
    <inherits name='samples.gwt.Sample'/> 
    in 
    Main.gwt.xml

    This logical name is irrespective of the alternate name, if any, that you have given to 'Sample.gwt.xml' like

    <module rename-to='sample-alt-name'>

    Also to ensure the trivial case, if you are using IDE check that dependent module exists in Project -> Build Path
    and if you use Maven then the dependent module should have been mentioned in <dependency> tag of parent project. 
    Hope this helps.





    GWT error - Deferred binding result type should not be abstract (or) Rebind result must be a class



    When you encounter following GWT error message

    either 

    'Deferred binding result type should not be abstract'

    in hosted or development mode

    or

    'Rebind result must be a class'

    upon GWT compilation

    then mostly it means that your GWT client service interface didn't extend the required marker interface 

    com.google.gwt.user.client.rpc.RemoteService

    So change your service from 

    interface SampleService{
         ..
    }

    to

    import com.google.gwt.user.client.rpc.RemoteService;

    interface SampleService extends RemoteService {
         ..
    }

    Hope this helps. Thanks to this post that helped me initially.