Getting GWT RPC Serialization Error while populating liststore of ComboBox - gwt

I am using GWT 2.9 and I am getting below error
SEVERE: Exception while dispatching incoming RPC call
com.google.gwt.user.client.rpc.SerializationException: Type 'com.xyz.nos.model.NosOptionModel' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.: instance = com.xyz.nos.model.NosOptionModel#6cad8f33
SEVERE: Exception while dispatching incoming RPC call
com.google.gwt.user.client.rpc.SerializationException: Type 'com.xyz.nos.model.NosOptionModel' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.: instance = com.xyz.nos.model.NosOptionModel#5fc5e111
SEVERE: Exception while dispatching incoming RPC call
com.google.gwt.user.client.rpc.SerializationException: Type 'com.xyz.nos.model.NosCaseDetailModel' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.: instance = com.xyz.nos.model.NosCaseDetailModel#af3642f
SEVERE: Exception while dispatching incoming RPC call
com.google.gwt.user.client.rpc.SerializationException: Type 'com.xyz.nos.model.CountryGroupModel' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.: instance = com.xyz.nos.model.CountryGroupModel#51987007
SEVERE: Exception while dispatching incoming RPC call
com.google.gwt.user.client.rpc.SerializationException: Type 'com.xyz.nos.model.NosUser' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.: instance = com.xyz.nos.model.NosUser#28bbfa7f
I am doing GWT RPC for populating liststore of combobox and getting above exception while performing it from EntryPoint class. All the above classes are Pojo's and all the fields of these classes are Serializable
I have tried all possible solutions given in GWT - RPC SerializationException
I have defined my service as below
public interface INamedComboListDataProvider<M> extends RemoteService {
public List<M> load(String name);
}
I also have checked my serializationWhitelist and it only contain following 25 classes
{class com.google.gwt.user.client.ui.TreeListenerCollection=true, class java.lang.String=true, class com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException=true, class com.google.gwt.user.client.ui.FocusListenerCollection=true, class com.google.gwt.user.client.rpc.RpcTokenException=true, class java.util.LinkedList=true, class java.lang.RuntimeException=false, class com.google.gwt.user.client.ui.LoadListenerCollection=true, class com.google.gwt.user.client.ui.ClickListenerCollection=true, class com.google.gwt.user.client.ui.FormHandlerCollection=true, class java.lang.Throwable=false, class com.google.gwt.user.client.ui.KeyboardListenerCollection=true, class com.google.gwt.user.client.ui.MouseListenerCollection=true, class com.google.gwt.user.client.ui.TabListenerCollection=true, class java.util.Vector=true, class com.google.gwt.user.client.ui.ChangeListenerCollection=true, class com.google.gwt.user.client.ui.ScrollListenerCollection=true, class com.google.gwt.user.client.ui.PopupListenerCollection=true, class com.google.gwt.user.client.ui.MouseWheelListenerCollection=true, class java.util.Arrays$ArrayList=true, class java.lang.Exception=false, class java.util.ArrayList=true, class java.util.Collections$EmptyList=true, class java.util.Collections$SingletonList=true, class com.google.gwt.user.client.ui.TableListenerCollection=true}
I also have added project folder structure below
client
model
service
services
util
Common.gwt.xml
Main.gwt.xml
Can anybody guide me where I am going wrong and why does the serializationwhilteList does not contain the pojo models ?

Related

InvalidDefinitionException: Cannot construct instance of `org.slf4j.Logger`

I have a akka cluster of microservices running on nodes. I'm trying to use the Jackson serializer for application specific messages exchanged between the nodes (microservices).
My code is written in scala, not Java
I'm using scala 'case class' as akka messages exchanged between actors and each message (case class) have a val LOG:org.slf4j.Logger built in to log specific business logic processing information.
When I send messages between nodes I'm getting the exception
WARN akka.remote.artery.Deserializer - Failed to deserialize message from [akka://MyCluster#127.0.0.1:25251] with serializer id [33] and manifest [com...MyCaseClassMessage]. com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of org.slf4j.Logger (no Creators, like default constructor, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information
at [Source: ..."[truncated 'n' bytes]; line: 'n', column: 'n'] (through reference chain: com...MyCaseClassMessage["LOG"])
My case class essentially is something like:
case class MyCaseClassMessage()
extends CborSerializable {
override val LOG:Logger = LoggerFactory.getLogger(classOf[MyCaseClassMessage])
val businessLogic:Array[Byte] = ...
def apply():Array[Byte] = ...
}
I have no idea of how to specify to Jackson how to serialize and (or) deserialize a "val LOG:Logger" in my case class. I just know that if I remove my Logger, substituing it to (for example) println("message") I don't have any problem with serialization and deserialization.
Any help?
Because Jackson relies on reflection and does not understand the convention in Scala case classes that only the constructor parameters are required for defining the message, it will attempt to serialize every field of the object.
The LOG field can be ignored by Jackson by annotating it with an #JsonIgnore annotation (com.fasterxml.jackson.annotation.JsonIgnore):
#JsonIgnore
override val LOG: Logger = LoggerFactory.getLogger(classOf[MyCaseClassMessage])

ESAPI logger when implemented for class extending SqlMapClientDaoSupport gives class cast exception

We are using ESAPI logger as per resolution for a flaw reported by Veracode. When we changed the logger for class which extends SqlMapClientDaoSupport it gave class cast exception. The reason is SqlMapClientDaoSupport has a protected data member which is org.apache.commons.logging logger. Is there a way we can use esapi loggers in the classes which extend classes having org.apache.commons.logging?

Spring MVC calling webservice endpoint from the browser

I want to be able to call my web service directly from the browser. Calling it from a HTTPClient via the web browser is OK, but if i try and call it directly via the browser I get the following error:
SEVERE: [Request processing failed; nested exception is org.springframework.http.converter.HttpMessageConversionException: Could not instantiate JAXBContext for class [class com.mycompanay.MyClass]: 8 counts of IllegalAnnotationExceptions; nested exception is com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 8 counts of IllegalAnnotationExceptions
com.mycompany.MyInterface is an interface, and JAXB can't handle interfaces.
this problem is related to the following location:
com.mycompany.myInteface
at private java.util.List com.mycompanay.MyClass.values
at com.mycompanay.myClass
#XmlAttribute/#XmlValue need to reference a Java type that maps to text in XML.
this problem is related to the following location:
I've tried to reference the implmentation class via the #XMLElement annotation but i'm getting the same error:
public MyClass {
#XmlElement(type=MyInterfaceImpl.class, name="values")
private List<MyInterface> values;
#XmlElement(type=MyInterfaceImpl.class, name="values")
public void getValues() {
return values;
}
}
You were correct to use the #XmlElement annotation to specify the implementation type. The problem is still occurring because by default JAXB will treat public properties as mapped. This is why it is still trying to process the interfaces. Since you have annotated tr field you can add XmlAccessorType(XmlAccessType.FIELD) to your class.
For More Information
http://blog.bdoughan.com/2011/06/using-jaxbs-xmlaccessortype-to.html
http://blog.bdoughan.com/2011/05/jaxb-and-interface-fronted-models.html

com.db4o.internal.query.ObjectSetFacade' was not included

GWT + Springs + DB4o: Any idea how to make this work without adding a new RPC class
[WARN] Exception while dispatching incoming RPC call
com.google.gwt.user.client.rpc.SerializationException: Type 'com.db4o.internal.query.ObjectSetFacade' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.: instance = [com.ppp.prm.portal.shared.dto.MComments#2214ab5, com.ppp.prm.portal.shared.dto.MComments#4fda105f, com.ppp.prm.portal.shared.dto.MComments#7568f5ed, com.ppp.prm.portal.shared.dto.MComments#3de9d6d3, com.ppp.prm.portal.shared.dto.MComments#4316d666, com.ppp.prm.portal.shared.dto.MComments#1055e4f3, com.ppp.prm.portal.shared.dto.MComments#772a15e5, com.ppp.prm.portal.shared.dto.MComments#6c03aa81]
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:619)
at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:126)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter$ValueWriter$8.write(ServerSerializationStreamWriter.java:153)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeValue(ServerSerializationStreamWriter.java:539)
at com.google.gwt.user.server.rpc.RPC.encodeResponse(RPC.java:616)
Issue
RPC 101 - Objects need to implement IsSerializable or Serializable interface. None of the classes ObjectSetFacade or its super class implement them. Reference more rules - https://developers.google.com/web-toolkit/doc/latest/tutorial/clientserver
DB4o is non gwt java library. You cannot send com.db4o.internal.query.ObjectSetFacade in any RPC call.
Solution
1) You should convert from db40 objects to domain objects/pojos compatible with GWT and RPC.
2) Example - we convert Hibernate objects to Domain pojos using Dozer on server. https://developers.google.com/web-toolkit/articles/using_gwt_with_hibernate

How to send any Serializable object to the client side in GWT

Imagine that you want to send any Serializable class to the client side of your GWT application, with the use of a DTO:
public class MyDTO implements Serializable {
public Serializable value;
}
Also, anything that gets used as value will be checked if it's Serializable before it is set. GWT does throw a couple of warnings in the dev console:
DEBUG: com.example.app.shared.MyDTO.
DEBUG: Analyzing the fields of type 'com.example.app.shared.MyDTO' that qualify for serialization.
DEBUG: private java.io.Serializable value.
DEBUG: java.io.Serializable.
DEBUG: Verifying instantiability.
DEBUG: java.util.ArrayList<? extends java.lang.Object>.
WARN: Checking all subtypes of Object which qualify for serialization.
DEBUG: com.google.gwt.validation.client.impl.PathImpl.
DEBUG: Verifying instantiability.
DEBUG: com.google.gwt.validation.client.impl.PathImpl.
DEBUG: Analyzing the fields of type 'com.google.gwt.validation.client.impl.PathImpl' that qualify for serialization.
WARN: Field 'private final java.util.List<javax.validation.Path.Node> nodes' will not be serialized because it is final.
But! Unfortunately, this results in GWT throwing an RPC SerializationException when it gets sent through to the client side:
com.google.gwt.user.client.rpc.SerializationException: Type 'com.example.app.shared.MyDTO' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.: instance = com.example.app.shared.MyDTO#577f52ed
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:619)
at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:126)
at com.google.gwt.user.client.rpc.core.java.util.Collection_CustomFieldSerializerBase.serialize(Collection_CustomFieldSerializerBase.java:44)
...
Bottomline:
How do you prevent GWT from throwing a fit about Serializable subtypes?
EDIT:
I've ended up creating a subclass for each class I needed.
GWT should know the type of class in compile time. So you need to specify exact class which implements Serializable.
To overcome, I think you may use a map to send your data as key-value pairs.