0

I've finished working on some lengthy method launched from the client side using GWT-RPC. doSomething()

Suppose the following classes: (copied from GWT: invoke the same RPC-methods on the server-side as on the client-side)

//MyClassService.java - client package
@RemoteServiceRelativePath("myService")
public interface MyClassService extends RemoteService{
   public doSomething();
}

//MyClassServiceAsync.java - client package
public interface MyClassServiceAsync{
   public void doSomething(AsyncCallback<Void> callback);
}

//MyClassServiceImpl.java - server package
public class MyClassServiceImpl extends RemoteServiceServlet implements MyClassService{
   @Override
   public void doSomething()
   {
      //interacts with DB and another stuff
   }
}

Now I'd wish to launch the very same method from my ScheduledTask infrastructure but I don't know if this is posible. The ScheduledTask infrastructure is in the server side. I've barely worked the networking side of any language and I'm lost. So far I've tried:

    MyClassServiceImpl a = new MyClassServiceImpl();
    a.doSomething();

The problem appear (NullPointerException) as soon as it hits the first doSomething() line with some call to getServletConfig().getServletContext() as it returns null.

Plus, MyClassServiceImpl init() method which I've overrided so it reads some params from web.xml, is also not invoked.

Thx in advance!

jpp1jpp1
  • 181
  • 1
  • 16
  • https://stackoverflow.com/questions/32741692/how-to-call-one-servlet-to-another-servlet-in-gwt-using-java – Spiff Jun 20 '17 at 16:10
  • I'm sorry I don't see the answer there. Client/Frontside is not involved in my problem – jpp1jpp1 Jun 21 '17 at 09:27

1 Answers1

0

Not specifically GWT related, but:

1) Move your initialization parameters out of web.xml. It is an awful mechanism and should never have been in the servlet specification. If you build a war file, it means that you have to rebuild the war file every time the parameters changes. And if you need to different parameters for dev, acceptance, and prod, that means three separate war files. Instead put a properties file somewhere on the file system. Start your web container with an extra Java parameter setting a value for a custom property, for example -Dmyapp.conf=d:\\conf\\apps\\myapp.conf.

2) Now that you have moved your parameters out of web.xml, you can write a standalone class that initializes itself from the system defined parameters file (System.getProperty("myapp.conf")), with no dependency on anything servlet related.

3) Use the class from your GWT servlet, your scheduler, etc...

Tony BenBrahim
  • 7,040
  • 2
  • 36
  • 49