Java, BlazeDS, Flex - Error #10566: Cannot create property smallMessage on AcknowledgeMessage? - java

I have a working Flex/Java application, but if I log out of the channelSet and log back in, in the debug console I am seeing numerous instances of this error:
ReferenceError: Error #1056: Cannot create property smallMessage on mx.messaging.messages.AcknowledgeMessage.
The error itself doesn't seem to interfere with app.
The AcknowledgeMessage class is not my class -- and I don't know why the Java side and Flex side don't match up with regard to properties on their internal classes.
Any help is appreciated.
Versions:
Flex 4.1.0.16076
BlazeDS 4.0.0.14931
Spring-Flex 1.5.0.RELEASE

We are having exactly the same problem in our application. I've managed to hide the error using the following ugly hack.
First, create a class like so:
public class FixedAcknowledgeMessage extends AcknowledgeMessage {
private var _smallMessage : *;
public function FixedAcknowledgeMessage() { }
public function get smallMessage() : * {
return _smallMessage;
}
public function set smallMessage(value : *) : void {
_smallMessage = value;
}
}
And then, in your startup code, replace AcknowledgeMessage with your fixed one:
registerClassAlias("flex.messaging.messages.AcknowledgeMessage", FixedAcknowledgeMessage);
We also do the same hack for the classes ErrorMessage and AsyncMessage, which seem to suffer from the same problem. I have no idea if this hack may have some negative side effects, and I would love to find a more proper fix for it.

don't use same name as primary key what you used in the table name...
Use different name .....
for example......
VO object...
public class ColumnNameVO
{
public var ifId:int;
public var formatId:int;
public var position:int;
public var name:String;
public function ColumnNameVO() { }
}
Table pojo classs:
public class ColumnNameVO
{
public var Id:int;
public var formatId:int;
public var position:int;
public var name:String;
}

Related

Where to use #SuppressWarnings("requestfactory")

I'm trying to build a simple (read-only) web app with GWT and RequestFactory, and I can't work out how to get rid of following warning:
warning: The domain type DDisplay is not default-instantiable. Calling RequestContext.create(DDisplayProxy.class) will cause a server error.
Add #SuppressWarnings("requestfactory") to dismiss.
The problem being, I have pasted #SuppressWarnings("requestfactory") above every possibly relevant class, interface and method, but I still get this message.
As my requestfactory is read-only, I'm not going to call RequestContext.create, so this is not a concern. It would just be nice to get rid of the warning (without creating a DDisplay locator class).
On the server side I have a domain object DDisplay, and a DAO, DDisplayService.
public class DDisplay {
public String getTitle () {
return "title";
}
}
and
public class DDisplayService {
public DDisplay getDisplayByUUID (String uuid) {
return new DDisplay ();
}
}
I have the following for RequestFactory:
#ProxyForName("com.foobar.server.display.DDisplay")
public interface DDisplayProxy extends EntityProxy {
String getTitle ();
}
and
public interface DisplayRequestFactory extends RequestFactory {
#ServiceName(
value="com.foobar.server.display.DDisplayService"
,locator="com.foobar.server.display.SpringServiceLocator"
)
public interface DisplayRequestContext extends RequestContext {
Request <DDisplayProxy> getDisplayByUUID (String id);
}
DisplayRequestContext display ();
}
Can anyone tell me where to put the #SuppressWarnings("requestfactory") to get rid of this error please? Or is there another way of doing this - do I just need to add a never-used Locator class?
thanks,
Jim
From reading the source where the error message come from, it appears that you can add this to your EntityProxy, DDisplayProxy. Something like this:
#SuppressWarnings("requestfactory")
#ProxyForName("com.foobar.server.display.DDisplay")
public interface DDisplayProxy extends EntityProxy {
String getTitle();
}
This from reading the source of com.google.web.bindery.requestfactory.apt.DomainChecker#visitType, which if currentTypeIsProxy is true and there is no locator, and the type isn't instatiable, the warning is emitted. From inside of state.warn(...) (which is given the proxy type element), it checks for the presence of the #SuppressWarnings annotation on that type.

Flex very strange casting error

I'm going mad with an error non error on my web-app Flex 3.6 based (using BlazeDS). I try to describe my issue: I have a java class:
public class User {...}
and the binding one in .as:
[Bindable]
[RemoteClass(alias="it.dto.User")]
public class User {...}
I also have a DataManager.as to do the Async call like this:
public function getUser():void {
var token:AsyncToken = _service.getUser();
token.addResponder(new AsyncResponder(userOnResult,userOnFault));
}
private function userOnFault(event:FaultEvent,token:Object):void {
var _fail:String = "Error";
}
private function socOnResult(event:ResultEvent,token:Object):void {
_resUser = event.result as ArrayCollection;
dispatchEvent(new MyEvent("USER_EVENT",_resUser));
}
Now I implemented the following code in two different .as file (different package), which refers to two different .mxml:
var data:DataManager = new DataManager;
....
data.addEventListener("USER_EVENT",userResult);
....
data.getUser();
....
private function userResult(dataEvent:MyEvent):void {
var user:ArrayCollection = new ArrayCollection;
user = dataEvent.result as ArrayCollection;
for (var i:int = 0;i<user.length; i++) {
var u:User = new User;
u = (User)(user.getItemAt(i));
}
_dm.removeEventListener("USER_EVENT",userResult);
}
The drama is that in the first .as it works perfectly, and in the second .as give me a Error of coercion failed. In the second file seems how it can't recognize the User class.
Do you have any idea?? I'm going mad!!
Thank you
#Stacktrace error:
TypeError: Error #1034: Type Coercion failed: cannot convert appcode.dto::SocietaDTO#b4dbfc1 to appcode.dto.SocietaDTO.
at modules::ReportIspezioni/onSocResult()[D:\workspace\maga\aga\flex_src\modules\ReportIspezioni_src.as:80]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at appcode.dao::DataManager/socOnResult()[D:\workspace\maga\aga\flex_src\appcode\dao\DataManager.as:180]
at mx.rpc::AsyncResponder/result()[C:\autobuild\3.x\frameworks\projects\rpc\src\mx\rpc\AsyncResponder.as:82]
at mx.rpc::AsyncToken/http://www.adobe.com/2006/flex/mx/internal::applyResult()[C:\autobuild\3.x\frameworks\projects\rpc\src\mx\rpc\AsyncToken.as:199]
at mx.rpc.events::ResultEvent/http://www.adobe.com/2006/flex/mx/internal::callTokenResponders()[C:\autobuild\3.x\frameworks\projects\rpc\src\mx\rpc\events\ResultEvent.as:172]
at mx.rpc::AbstractOperation/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()[C:\autobuild\3.x\frameworks\projects\rpc\src\mx\rpc\AbstractOperation.as:199]
at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()[C:\autobuild\3.x\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:263]
at mx.rpc::Responder/result()[C:\autobuild\3.x\frameworks\projects\rpc\src\mx\rpc\Responder.as:46]
at mx.rpc::AsyncRequest/acknowledge()[C:\autobuild\3.x\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:74]
at NetConnectionMessageResponder/resultHandler()[C:\autobuild\3.x\frameworks\projects\rpc\src\mx\messaging\channels\NetConnectionChannel.as:524]
at mx.messaging::MessageResponder/result()[C:\autobuild\3.x\frameworks\projects\rpc\src\mx\messaging\MessageResponder.as:199]
Obviusly the User class written above is just for example, to understand the code logic. The real class is a DTO calls SocietaDTO.
N.B: The code works perfectly in another module of my project.. I don't understand why here it doesn't work.
Thanks a lot
I never save browser cache when developing.. Anyway I solve the Issue by adding this:
registerClassAlias("it.mec.dto.SocietaDTO", SocietaDTO);
In the class were exception launch.
Thanks anyway

Design patterns that can replace if statements

Our application is getting complex, it has mainly 3 flow and have to process based on one of the 3 type. Many of these functionalities overlap each other.
So currently code is fully of if-else statements, it is all messed up and not organised. How to make a pattern so that 3 flows are clearly separated from each other but making use of power of re-usability.
Please provide some thoughts, this is a MVC application, where we need to produce and consume web servicees using jaxb technology.
May be you can view the application as a single object as input on which different strategies needs to be implemented based on runtime value.
You did not specify what your if-else statements are doing. Say they filtering depending on some value.
If I understand your question correctly, you want to look at Factory Pattern.
This is a clean approach, easy to maintain and produces readable code. Adding or removing a Filter is also easy, Just remove the class and remove it from FilterFactory hashmap.
Create an Interface : Filter
public interface Filter {
void Filter();
}
Create a Factory which returns correct Filter according to your value. Instead of your if-else now you can just use the following :
Filter filter = FilterFactory.getFilter(value);
filter.filter();
One common way to write FilterFactory is using a HashMap inside it.
public class FilterFactory{
static HashMap<Integer, Filter> filterMap;
static{
filterMap = new HashMap<>();
filterMap.put(0,new Filter0());
...
}
// this function will change depending on your needs
public Filter getFilter(int value){
return filterMap.get(value);
}
}
Create your three(in your case) Filters like this: (With meaningful names though)
public class Filter0 implements Filter {
public void filter(){
//do something
}
}
NOTE: As you want to reuse some methods, create a FilterUtility class and make all your filters extend this class so that you can use all the functions without rewriting them.
Your question is very broad and almost impossible to answer without some description or overview of the structure of your application. However, I've been in a similar situation and this is the approach I took:
Replace conditions with Polymorphism where possible
it has mainly 3 flow and have to process based on this one of the 3
type. Many of these functionalities overlap each other.
You say your project has 3 main flows and that much of the code overlaps each other. This sounds to me like a strategy pattern:
You declare an interface that defines the tasks performed by a Flow.
public interface Flow{
public Data getData();
public Error validateData();
public void saveData();
public Error gotoNextStep();
}
You create an abstract class that provides implementation that is common to all 3 flows. (methods in this abstract class don't have to be final, but you definitely want to consider it carefully.)
public abstract class AbstractFlow{
private FlowManager flowManager
public AbstractFlow(FlowManager fm){
flowManager = fm;
}
public final void saveData(){
Data data = getData();
saveDataAsXMl(data);
}
public final Error gotoNextStep(){
Error error = validateData();
if(error != null){
return error;
}
saveData();
fm.gotoNextStep();
return null;
}
}
Finally, you create 3 concrete classes that extend from the abstract class and define concrete implementation for the given flow.
public class BankDetailsFlow extends AbstractFlow{
public BankDetailsData getData(){
BankDetailsData data = new BankDetailsData();
data.setSwiftCode(/*get swift code somehow*/);
return data;
}
public Error validateData(){
BankDetailsData data = getData();
return validate(data);
}
public void onFormSubmitted(){
Error error = gotoNextStep();
if(error != null){
handleError(error);
}
}
}
Lets take example, suppose you have model say "Data" [which has some attributes and getters,setters, optional methods].In context of Mobile application ,in particular Android application there can be two modes Off-line or On-line. If device is connected to network , data is sent to network else stored to local database of device.
In procedural way someone can , define two models as OnlineData,OfflineData and write code as[The code is not exact ,its just like pseudo code ]:
if(Connection.isConnected()){
OnlineData ond=new OnlineData();
ond.save();//save is called which stores data on server using HTTP.
}
else{
OfflineData ofd=new Onlinedata();
ofd.save();//save is called which stores data in local database
}
A good approach to implement this is using OOPS principles :
Program to interface not Implementation
Lets see How to DO THIS.
I am just writing code snippets that will be more effectively represent what I mean.The snippets are as follows:
public interface Model {
long save();//save method
//other methods .....
}
public class OnlineData extends Model {
//attributes
public long save(){
//on-line implementation of save method for Data model
}
//implementation of other methods.
}
public class OfflineData extends Model {
//attributes
public long save(){
//off-line implementation of save method for Data model
}
//implementation of other methods.
}
public class ObjectFactory{
public static Model getDataObject(){
if(Connection.isConnected())
return new OnlineData();
else
return new OfflineData();
}
}
and Here is code that your client class should use:
public class ClientClass{
public void someMethod(){
Model model=ObjectFactory.getDataObject();
model.save();// here polymorphism plays role...
}
}
Also this follows:
Single Responsibility Principle [SRP]
because On-line and Off-line are two different responsibilities which we can be able to integrate in Single save() using if-else statement.
After loong time I find opensource rule engine frameworks like "drools" is a great alternative to fit my requirement.

I want to use hashmap in a java class which produces XML format, but I am getting JAXB exceptions

This is my java class where I have to use hash map for getting key-value:
#XmlRootElement
public class Combo {
private Map<Combo, List<Combo>> businessDomainAndBusinessSubDomainsPair = new HashMap<Combo, List<Combo>>();
public Map<Combo, List<Combo>> getBusinessDomainAndBusinessSubDomainsPair() {
return businessDomainAndBusinessSubDomainsPair;
}
public void setBusinessDomainAndBusinessSubDomainsPair(
Map<Combo, List<Combo>> businessDomainAndBusinessSubDomainsPair) {
this.businessDomainAndBusinessSubDomainsPair = businessDomainAndBusinessSubDomainsPair;
}
}
But in angular code I am getting this error on debug:
I tried using LinkedHashMap also but still I am getting error. Can any one please suggest a solution for this.

Reusing the Result of a Controller in another Controller in the Play framework

Apologies if this has been answered already - I've had a look and can't find anything.
Using the Play framework, I have defined two controllers - one is a public API that returns JSON, and one is a consumer of this API which presents the JSON as HTML. E.g. my routes file look as follows:
GET /foos controllers.App.foos() #produces HTML
GET /api/foos controllers.API.foos() #produces JSON
A requirement of the project is that our data should only be accessed via our public API. Therefore, the way that I'd like to implement this is to have App.foos() invoke API.foos(), parse the JSON result, and pass it to a template to be rendered. For example:
public App extends Controller {
public static Result foos() {
Result result = API.foos();
// TODO: get the JSON out of the result object
}
}
Can anyone tell me how I can extract the JSON from the result object? I can get the body of the object as an Enumerator using ((SimpleResult)result.getWrappedResult()).body(), but I am still unclear how I can get out the JSON.
Because I am new to the Play framework, perhaps I am going about this wrong and there is an easier/better way to do this?
Many thanks in advance,
James
The easiest way would be to expose the underlying method.
public Api extends Controller {
public static Result foos() {
Ok(foosJson());
}
public static JsValue foosJson() {
// ...
}
}
public App extends Controller {
public static Result foos() {
JsValue json = API.foosJson();
}
}

Categories