How to share a GWT RPC RemoteServiceServlet among multiple client modules / apps - gwt

I have several GWT modules and web apps running in Jetty. They each want to use my LoginService RPC interface, so I put this interface and its servlet implementation in a common module. I serve the servlet (LoginServiceImpl) from my root web context, and web.xml exposes it at the url "/loginService". In a another GWT module, to use this service, I had to set the entry point, like this...
LoginServiceAsync loginService = GWT.create(LoginService.class);
ServiceDefTarget t = (ServiceDefTarget)loginService;
t.setServiceEntryPoint("/loginService");
Now, the module trying to use the loginService is called discussions, and I get this error on the server.
ERROR: The serialization policy file
'/discussions/discussions/7B344C69AD493C1EC707EC98FE148AA0.gwt.rpc' was not found;
did you forget to include it in this deployment?
So the servlet is reporting an error that mentions the client (the discussions module). I'm guessing that the RPC plumbing passed the name of this .rpc file through from the client, and the servlet is now looking for it. (?) As an experiment, I copied, the *.gwt.rpc files from the discussions module into the root web context, so the servlet could find them. This did stop the error. But I still get another error:
com.google.gwt.user.client.rpc.SerializationException: Type
'mystuff.web.shared.User' was not assignable to
'com.google.gwt.user.client.rpc.IsSerializable' and did not have a custom field
serializer. For security purposes, this type will not be serialized.: ...
This class is serializable; it worked before in other modules, so now I'm lost.
What is the right way to use the LoginService from multiple clients modules?
Update:
This error was showing up in hosted devmode, and it went away after a full compile. Maybe this is related to gwt serialization policy hosted mode out of sync . I will update again if I can better reproduce the problem.

See my answer here. The short answer is: you'll need to make mystuff.web.shared.Users source available at compile-time to your discussions module.

Related

java.xml.namepsace error - SOAP (Webservice) in Java

I have no experience with WebService, especially SOAP, but I have to deal with it. I work with Java 11 and with the latest Eclipse IDE. In the beginning I read a lot and also developed my own WebService. This service can only calculate the BMI. There are no errors in this service on the server side.
I had the client automatically generated with the Java API for XML Webservices. However, several errors are displayed in the generated classes.
First Error:
"The package javax.xml.namespace is accessible from more than one module: java.xml, jaxrpc"
If I try to fix the error, then there is a new error. Let's get back to trying to fix the bug. In some other forums I have read that in the module information "module-info.java" the "requires java.xml" should be commented out. The error seems to disappear for now, but it leads to two new errors:
"The type javax.xml.namespace.QName is not accessible" and "The type javax.xml.namespace.QName cannot be resolved. It is indirectly referenced from required .class files"
Here are a few code:
module Client {
exports ws;
requires axis;
requires java.instrument;
requires java.logging;
requires java.management;
requires java.naming;
requires java.net.http;
requires java.prefs;
requires java.rmi;
//requires java.xml;
requires jaxrpc;}
Here is a example of the DemolmplServiceLocater where java.xml.namepace are underlined red:
public DemolmplServiceLocator(java.lang.String wsdlLoc, javax.xml.namespace.QName sName) throws javax.xml.rpc.ServiceException {
super(wsdlLoc, sName);
}
This is the class DemolmplService.java with the second error and "fixed" first error.
The lost one ist the Build Path from my project.
Among other things I opened a client in Java-SE1.8 project and tried out the client there. There no error was displayed and the method bmi(weight,height) was executed successfully. But I need the project at least in Java 10 or higher.
Can anyone offer me a solution, preferably a step-by-step guide?
I thank you in advance!

java.lang.NoSuchFieldError returns when trying to create a stateless session to the Rules Execution Server

I am using Ilog JRules Studio 7.1.1 for the rules development. I am using JUnit test cases to test the developed rules.
When i am trying to create a stateless session to the RES, it's returning with the below error.
IlrStatelessSession session = factory.createStatelessSession();
Anyone is having any idea?
java.lang.NoSuchFieldError: ilog/rules/res/decisionservice/plugin/IlrWsdlGenerationInteractionSpec.FUNCTION_NAME_BACKPORT_GENERATE_WSDL
at ilog.rules.res.decisionservice.plugin.IlrWsdlGeneratorInteractionExtension.getSupportedFunctionNames(IlrWsdlGeneratorInteractionExtension.java:418)
at ilog.rules.res.xu.plugin.impl.IlrPluginManager.createPlugins(IlrPluginManager.java:222)
at ilog.rules.res.xu.plugin.impl.IlrPluginManager.changePlugins(IlrPluginManager.java:173)
at ilog.rules.res.xu.plugin.impl.IlrPluginManager.start(IlrPluginManager.java:135)
at ilog.rules.res.xu.spi.IlrManagedXUConnectionFactory.createConnectionFactory(IlrManagedXUConnectionFactory.java:648)
at ilog.rules.res.xu.spi.IlrManagedXUConnectionFactory.createConnectionFactory(IlrManagedXUConnectionFactory.java:668)
at ilog.rules.res.session.util.IlrJ2SEConnectionFactoryFinder.findConnectionFactory(IlrJ2SEConnectionFactoryFinder.java:23)
at ilog.rules.res.session.IlrJ2SESessionFactory.createClientFactory(IlrJ2SESessionFactory.java:93)
at ilog.rules.res.session.IlrJ2SESessionFactory.getClientFactory(IlrJ2SESessionFactory.java:129)
at ilog.rules.res.session.IlrJ2SESessionFactory.createStatelessSession(IlrJ2SESessionFactory.java:62)
Regards,
Hari
Nothing to do with the session.
JRules is crashing because it is not able to generate the WSDL, meaning there is something wrong with your project at first.
Try to run it locally first.
The thing is a web service is automatically provided if the XOM is based on XSD
There is an error somewhere in your project. If you use XSD (which I guess) then have a look to your rule project.
If you use JAVA XOM then there is an error in your web service server (which I doubt) because I cannot see why JRules would complain for your own code.
Verify your in/output parameters
Make it simple first then complicate the process.If simple then redeploy...
Hope it helps

GWT logging to file

I am writing my first GWT and i confess i have no idea how to set up loggers.
I am deploying the application to tomcat and want to be able to set up a logger so that i can log to a file in $catalina.home. Gwt came with logging.properties for a java util style log and log4j.properties; i have looked at documentation for the gwt java util logger and it seems to just write to console so it must be log4j i need?
In the past ive seen org.apache.log4j.Logger used, is this what i want?
Could somebody please point me to somewhere where this is documented?
Thanks.
The documentation is here. You can't use file appenders directly because the GWT code runs as Javascript in the browser (when not in development mode). If you want to log to a file you need to enable remote logging.
If there is a server side part logging works as normal. But then it has not much to do with GWT, except for being in the same project and providing services (via a custom protocol).
What do you want to log? rpc service servlets or client logic?
Log4j is just for java not javascript. So it is intended to log your classes in your /server/ package that will be deployed in your server.
Your /client/ package classes will be translated to javascript and will run in the client browser. So, no Java at all!
You can use log4j "emulated" to javascript with http://code.google.com/p/gwt-log/ which will send your client logs using a RemoteLogger to the server via rpc and then you can log them to a file.

Strange GWT Error with external jar on server side

I want to use a external jar (Apache Mahout) on the server side of my GWT Applicatopn.
As far as i know using external jars on the server side shouldn't cause an error. Only on the client side but when i try to run the code i get the following error:
"no source code is available for de.unimannheim.paniscus.server..."
Whats wrong here ?
Please help me i need to solve this for my thesis
Hi guys i created now an collbaorative.gwt.xml where i inherited all classes from apache mahout that are used within de.unimannheim.paniscus.server.collaborative but it's still not working. Sorry i'm helpless whats wrong here ?
I agree with Dusty Campbell, you should not inherit the jar in the *.gwt.xml. The <inherits> tag in the *.gwt.xml specifies gwt-modules which should be inherited. So only client-side-compatible code can be inherited.
Citation from the gwt docs: "<inherits name="logical-module-name" /> : Inherits all the settings from the specified module as if the contents of the inherited module's XML were copied verbatim. Any number of modules can be inherited in this manner"
see also: http://code.google.com/webtoolkit/doc/1.6/DevGuideOrganizingProjects.html#DevGuideInheritingModules
My guess is that you (by mistake) use a class from the "de.unimannheim.paniscus.server" package in client-side or shared code. Even just an import statement (import de.unimannheim.paniscus.server.*) will cause this exception.

Second compilation of same sources produces different set of gwt.rpc files

I would like to follow up on this question gwt-serialization-policy-hosted-mode-out-of-sync. In short - when I do a RPC from hosted browser then this call fails on server with the exception.
INFO: GwtRpcEventSrvc: ERROR: The serialization policy file '/84EC7BA65AF8175BAA99B47877FDE163.gwt.rpc' was not found; did you forget to include it in this deployment?
SEVERE: GwtRpcEventSrvc: WARNING: Failed to get the SerializationPolicy '84EC7BA65AF8175BAA99B47877FDE163' for module 'http://host:19980/MYAPP/'; a legacy, 1.3.3 compatible, serialization policy will be used. Youmay experience SerializationExceptions as a result.
SEVERE: Exception while dispatching incoming RPC call
While when I do the same RPC from browser then the request is performed successfully on server.
In addition I observed a strange behavior of GWT compiler that could result in a problem with hosted browser mode.
I assume when I do two subsequent compilations of an exact same code then the result of the individual compilations is supposed to be same. I mean at least the xxxxx.html and yyyyy.gwt.rpc files have to be same. (Where xxxxx and yyyyy are the long numbers such as 84EC7BA65AF8175BAA99B47877FDE163.)
Currently I have two versions of my project.
An old project compiled by GWT 1.7 that does not suffer from problem with the hosted browser described in gwt-serialization-policy-hosted-mode-out-of-sync
A new project that is compiled by GWT 2.0.4. This new project is based on the old project. This project suffer from the hosted browser problem.
Case 1: Old project with GWT 1.7
I took my old project that was compiled by GWT 1.7. I did two compilations and I compared compilation artifacts. gwt.rpc files were same while html files had different content and name. Since the gwt.rpc files were alwas same I did not have a problem with hosted browser.
Case 2: New project with GWT 2.0.4
I compiled it twice and both gwt.rpc and html files were different. Therefore RPC call in hosted browser failed on server because of missing gwt.rpc file.
Case 3: Old project with GWT 2.0.4
I compiled it twice and both gwt.rpc and html files were different. Therefore RPC call in hosted browser failed on server because of missing gwt.rpc file.
I did some investigation and identified that when I comment out a data member in a class Data that is transmitted from server to client, then compiled files start being same.
class Data implements IsSerializable {
List<IsSerializable> data;
...
}
I wanted to do same thing in the new project but it seems that there are many classes to be modified. So the problem is growing as the project is growing.
I don't know what to use instead of
List<IsSerializable> data;
to transfer data.
You need to read some more on GWT serialization policies:
Serializable Types
Usually you don't mingle with .rpc files unless your are doing advanced RPC calls directly to your server.
Your serializable object :
class Data implements IsSerializable {
List<IsSerializable> data;
...
}
A user-defined class is serializable if all of the following apply:
It is assignable to IsSerializable or Serializable, either because it directly implements one of these interfaces or because it derives from a superclass that does
All non-final, non-transient instance fields are themselves serializable, and
As of GWT 1.5, it must have a default (zero argument) constructor (with any access modifier) or no constructor at all.
So you should probably have something like:
class Data implements IsSerializable {
List<YOUR_TYPE> data;
...
}
Your list's template is a type, you don't set 'IsSerializable'... it should be something like :
List<int> data;