Search code examples
javaeclipsegwtgwt-syncproxy

GWT syncProxy: createProxy MethodNotSupportedException


I want to perform simple unit tests in Java for my server using GWT-RPC.

I have created a GWT project (GWT 2.7) in Eclipse (with the default GreetingService). It works and I can start it as a servlet in a Tomcat server.

Next I have created an Eclipse project to call the GreetingService using syncProxy.

            try {
            SyncProxy.setBaseURL("http://127.0.0.1:8080/mywebapp/mywebapp/");
            GreetingService svc = SyncProxy.createSync(GreetingService.class);
            String greeting = svc.greetServer("Hello");
            System.out.println("Result: " +greeting);
         }
         catch ( Exception e )
         {
            throw new RuntimeException ( e );
         }

When I execute this code I get the following exception:

juin 08, 2015 8:57:14 AM com.gdevelop.gwt.syncrpc.RpcPolicyFinder searchPolicyFileInClassPath
Infos: No RemoteService in the classpath
juin 08, 2015 8:57:14 AM com.gdevelop.gwt.syncrpc.SyncProxy populatePolicyMap
Infos: Populating Policy Map
juin 08, 2015 8:57:14 AM com.gdevelop.gwt.syncrpc.RpcPolicyFinder fetcherSerializationPolicyNameJS
Infos: Remote Services found with JS Fetcher
juin 08, 2015 8:57:14 AM com.gdevelop.gwt.syncrpc.SyncProxy defaultUnsetSettings
Infos: Updating Default Settings for Unset Values
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/MethodNotSupportedException
        at com.gdevelop.gwt.syncrpc.SyncProxy.createProxy(SyncProxy.java:120)
        at com.gdevelop.gwt.syncrpc.SyncProxy.createSync(SyncProxy.java:138)
        at myJmeterPlugin.TestGWT.main(TestGWT.java:11)
Caused by: java.lang.ClassNotFoundException: org.apache.http.MethodNotSupportedException
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 3 more

In the class path I have the .jars files from the GWT Project, syncProxy and gwt-servlet.jar.

Do you have an idea how to solve this issue? Regards,

Sébastien.


Solution

  • Just to verify, you are creating a Java eclipse project (not Android)? Assuming as much, then make sure you also include the gwt-user-2.7.0 and gwt-dev-2.7.0 jar's in your classpath. In regard's to Lev's answer, the MethodNotSupportedException class is actually in the gwt-dev-2.7.0 jar, so you do not necessarily need to pull in a separate resource. However, for GSP to work, you will need the User and Dev jar's available in your test project (Not just a link into the GWT Project under test). In case you are linking your test project with your main project, check to see if those jar's are checked in the Order and Export tab of the main project's Build Path. Alternatively, make those two jars available directly in your test project. If you still have problems, verify and report back exactly which jar's are setup in the Build Path (in Eclipse) since the specified build path and classpath sometimes match up correctly (hence the below note on moving to gradle).

    As a point of note, I am working on a new branch (https://github.com/jcricket/gwt-syncproxy/tree/gradlify) that is gradle based and will have dependency management available, so the next GSP release should remove issues like this from occurring.