5

Class SecureDispatchService from gwt like this:

@RemoteServiceRelativePath("dispatch")
public interface SecureDispatchService extends RemoteService {
    Result execute( String sessionId, Action<?> action ) throws DispatchException;
}

RemoteServiceRelativePath:

@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface RemoteServiceRelativePath {
  /**
   * The relative path for the {@link RemoteService} implementation.
   * 
   * @return relative path for the {@link RemoteService} implementation
   */
  String value();
}

Test code is very simple:

package com.name.sbts.wbts.sm;

import net.customware.gwt.dispatch.client.secure.SecureDispatchService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;

public class TestClass {

    public static void main(String[] args) {

        Class c = SecureDispatchService.class;
        System.out.println(c.getAnnotation(RemoteServiceRelativePath.class));
        System.out.println(c.getAnnotations().length);
    }
}

But the result is not wanted:

null
0

I was running this code in eclipse, with JRE1.7

SecureDispatchService is in this jar from google:

gwt-dispatch-1.2.0.jar

I used mvn eclipse:eclipse to generate the project. This jar file is as a referenced libraries of eclipse project, and its real path is in my .m2/repostory.

Aleksandr M
  • 24,264
  • 12
  • 69
  • 143
Jerry Z.
  • 2,031
  • 3
  • 22
  • 28
  • 2
    The class file containing the annotation must be in the class path of the running application. Otherwise the JVM will silently drop the annotation while loading the class, which results in the behavior you see. Maybe this is your issue? (If so, I would upgrade my comment to an answer.) – Seelenvirtuose Apr 08 '15 at 09:03
  • Maybe this is the reason, but do you know how to solve this issue? The class SecureDispatchService is delivery by google and it's in a jar file:gwt-dispatch-1.2.0.jar. I use mvn eclipse:eclipse to generated the project in eclipse, and directly run the application in eclipse. – Jerry Z. Apr 08 '15 at 09:31
  • I also tried to add this jar file to CLASS_PATH of my system variable, but seems it doesn't work. – Jerry Z. Apr 08 '15 at 09:38
  • You should not use `mvn eclipse:eclipse` to _eclipsify_ your project. Instead use the [M2E](http://eclipse.org/m2e/) plugin for that. Additionally, your POM should simply have the library as a dependency. That's it. (Manipulating the CLASS_PATH environment variable should never be done.) – Seelenvirtuose Apr 08 '15 at 09:57
  • @Seelenvirtuose, thank you for your help. Although it doesn't really solve this issue. – Jerry Z. Apr 08 '15 at 12:58

1 Answers1

2

This is happening because gwt-dispatch project is compiled using old gwt-user dependency (gwt version 2.0.4). In this version of gwt the RemoteServiceRelativePath annotation doesn't have @Retention(RetentionPolicy.RUNTIME) on it, so the RemoteServiceRelativePath annotation is not available at the runtime.

Aleksandr M
  • 24,264
  • 12
  • 69
  • 143
  • Where is the old information stored, I mean if the gwt-dispatch-1.2.0.jar was compiled while RemoteServiceRelativePath is not with @Retention(RetentionPolicy.RUNTIME), the JVM on my machine should somehow know this, and use this outdate data, but in my environment, there's only gwt-user-2.7.0.jar – Jerry Z. Apr 08 '15 at 11:38
  • @JerryZhang: You are examining `SecureDispatchService` class and it doesn't have information about `RemoteServiceRelativePath` annotation, because it was compiled with old version. – Aleksandr M Apr 08 '15 at 11:40
  • Yes, I understand the statement, but the question is: does the `gwt-dispatch-1.2.0.jar` still hold the information which in `gwt-user-2.0.4.jar`, therefor the jvm can look up a wrong class detail of `remoteServiceRelativePath`. – Jerry Z. Apr 08 '15 at 12:15
  • @JerryZhang: Yes, class holds info about its annotations. If you open `SecureDispatchService` class file in a text editor then you should see something like `RuntimeInvisibleAnnotations` along the lines. – Aleksandr M Apr 08 '15 at 12:18
  • yes, I saw it in the txt opened class. Do you have any idea I can sideways this problem, re-compile a local version of `gwt-dispatch`? – Jerry Z. Apr 08 '15 at 12:20
  • @JerryZhang: Yes you can try to recompile with newer version of the gwt. – Aleksandr M Apr 08 '15 at 12:24