Question

Is there a way to call a GreetingServiceImpl 's Method from other Java class in Server Side package. I want to extract a piece of data from a method in GreetingServiceImpl but I am unable to do so since it requires 'static' methods and GWT RPC methods are not static. I tried

GreetingServiceImpl obj=new GreetingServiceImpl();
String mSelect=obj.getModel(Manufacturer);

but the code is not working. It's not even executing

I also tried Googling but didn't find anything relevant that can do the thing easily. Is there a simple way to do it?

Was it helpful?

Solution

You are doing it correctly. Debug and make sure your method isn't doing anything that requires a ServletContainer. For example, if your GreetingServiceImpl has init() and destroy() implementations, they won't get called since you are using it as a Java class instead of a HttpServlet. Also make sure your method doesn't need a HttpSession since you won't have one.

I also recommend you use an instance variable instead of calling new GreetingServiceImpl(); all the time:

private static GreetingServiceImpl instance = null;
public static GreetingServiceImpl getInstance() {
    if (instance == null) {
        instance = new GreetingServiceImpl();
    }
    return instance;
}

So from then on, from the server side, you'd call:

String mSelect=GreetingServiceImpl.getInstance().getModel(Manufacturer);

OTHER TIPS

Methods in the remote service implementation (GreetingServiceImpl in this case) are intended to be called by client code, through the asynchronous interface. If you need to call them from server-side code, you are likely doing something wrong or not using it as it is intended to be used.

I can't tell you what you are are doing wrong without seeing more of your code, however. If you edit your question to show the code for your method implementations, we may be able to suggest a better way of achieving your goal.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top