Flex+JPA/Hibernate+BlazeDS+MySQL how to debug this monster? - java

Ok so I'm making a "simple" web app using the technologies from the topic, recently I found http://www.adobe.com/devnet/flex/articles/flex_hibernate.html so I'm following it and I try to apply it to my app, the only difference being I'm working on a Mac and I'm using MAMP for the database (so no command line for me).
The thing is I'm having some trouble with retrieving/connecting to the database.
I have the remoting-config.xml, persistance.xml, a News.java class (my Entity), a NewsService.java class, a News.as class - all just like in the tutorial. I have of course this line in one of my .mxmls:
<mx:RemoteObject id="loaderService" destination="newsService" result="handleLoadResult(event)" fault="handleFault(event)" showBusyCursor="true" />
And my remoting-config.xml looks like this (well part of it):
<destination id="newsService">
<properties><source>com.gamelist.news.NewsService</source></properties>
</destination>
NewsService has a method:
public List<News> getLatestNews() {
EntityManagerFactory emf = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT);
EntityManager em = emf.createEntityManager();
Query findLatestQuery = em.createNamedQuery("news.findLatest");
List<News> news = findLatestQuery.getResultList();
return news;
}
And the named query is in the News class:
#Entity
#Table(name="GLT_NEWS")
#NamedQueries({
#NamedQuery(name="news.findLatest", query="from GLT_NEWS order by new_date_added limit 5 ")
})
The handledLoadResult looks like this:
private function handleLoadResult(ev:ResultEvent):void {
newsList = ev.result as ArrayCollection;
newsRecords = newsList.length;
}
Where:
[Bindable]
private var newsList:ArrayCollection = new ArrayCollection();
But when I try to trigger:
loaderService.getLatestNews();
nothing happens, newsList is empty.
Few things I need to point out:
1) as I said I didn't install mysql manually, but I'm using MAMP (yes, the server's running), could this cause some trouble?
2) I already have a "gladm" database and I have a "GLT_NEWS" table with all the fields, is this bad?
Basically the question is how am I suppose to debug this thing so I can find the mistake I'm making? I know that loadData() is executed (did a trace()), but I have no idea what happens with loaderService.getLatestNews()...
#EDIT: ok so I see I'm getting an error in the "fault handler" which says
"Error: Client.Error.MessageSend - Channel.Connect.Failed error NetConnection.Call.Failed: HTTP: Status 404: url: 'http://localhost:8080/WebContent/messagebroker/amf' - "
#EDIT2: Ok i solved the problem, as it turns out my ContextRoot was incorrect, the funny thing is I couldn't edit it by going to Project properties->Flex Server as it was uneditable! I had to find the .flexProject file and edit it (obviously my Flex Navigator didn't show it and by accident I noticed it was being filtered).

To answer your question as to, in general, debug this monster...here is what I do.
Set break points in my Java code
Start up the Java application server with the appropriate debug JVM properties set (e.g. -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n)
From Eclipse, I attach a remote debugger to the app server on the default port 8000. The Java Debugger will open up when a break point is hit.
Set breakpoints in my Flex application (or one of its modules).
From Eclipse (with Flash Builder) I launch a debug configuration for my Flex app. The Flex Debugger will open up when a break point is hit.
At this point I have two debuggers open and everything work great. Two other things I do:
a) extend the transaction system timeout, so it doesn't get trigger while I am sitting there think for a few minutes
b) use Charles Proxy (in reverse proxy mode) inbetween the client and server to watch the AMF traffic and view payloads, etc.
Hope this helps.

your error means you are not calling the server on the right way. Something is wrong there, the url the web.config file or other BlazeDS config files.

Related

Why RDF4J won't work in Bluemix Cloud Foundry

RDF4J is an apache open source graph db that i use often on my PC.
It comes with 2 webApp : RDF4J-server and RDF4J-workbench (a user interface)
On my PC i push the 2 wars in the same Tomcat and everything is ok.
I begin an experiment to push these apps in the Bluemix Cloud (which is a cloud foundry)
The java-tomcat boilerplate wants a single War in order to associate it with the URL of the new container, so i create 2 separate apps in 2 java containers :
1 for RDF4J-Server,
1 for RDF4J-WB.
Both apps are running and i can access to default pages.
In WB, the form 'connect to server' allows you to give the URL of the server you want to work with.
I enter the URL https://rdf4jmyserver.mybluemix.net. WB finds the server but loops on the form, unable to open a db.
I suppose first that a split in 2 containers can be an issue, but i do the following test :
-run RD4J workbench in a local Tomcat on my machine
-connect to the rdf4Jmyserver on the cloud
-> Everything is ok !
So the pb is not to run in 2 separate places.
I investigate a bit more, dowload the source code (thanks open source) and recompile with more and more debug traces .
After a long day, i found the bug in the Workbench code, despite the fact this code is as old as the previous version Sesame: Nobody catch it .
Philosophy for today :
Bluemix works well, but pushing an app in the cloud can reveal old weakness !
I will give the patch in a next post.
Explanation :
When the selected server by workbench is not the default one ( which is supposed to be on the same root url ), the program establish a new cookie to keep trace of the new choice.
The wrong code is here , in CookieHandler.java :
private void initCookie(final Cookie cookie, final HttpServletRequest req) {
final String context = req.getContextPath();
cookie.setPath(null == context ? "/" : context);
}
}
The url is something like https://rdf4j-mywb.mybluemix.net
So, when there is no context for the cookie, the software wants to add a / .
But this code is false.
Going back to the java API, one can see :
public java.lang.String getContextPath()
Returns the portion of the request URI that indicates the context of the request.
The context path always comes first in a request URI.
The path starts with a "/" character but does not end with a "/" character.
For servlets in the default (root) context, this method returns "".
The container does not decode this string.
So this old buried bug can be fixed by :
// cookie.setPath(null == context ? "/" : context);
cookie.setPath(context.isEmpty()? "/" : context);
And now, Workbench works well on Bluemix !
HTH
PS: as rdf4Jserver runs also in a cloud container, datas on disk can disappear when container is reset. Another job has to be done : using an objectstore service in Bluemix. ( another day)

OpenJMS : Failed to start database 'openjmsdb', see the next exception for details

Yesterday, I created a topic and a queue on my OpenJMS server, graphically (using admin.sh). I was able to start it with openjms/bin/admin.sh and then clicking on the menus "Start OpenJMS server>Start connections, etc." and even by executing only openjms/bin/startupt.sh (instead of admin.sh).
Today, I deleted all the topic and queue (graphically, by right-cliking on "Delete" on each node Topic and Queue ).
And now, when I type openjms/bin/startup.sh, it displays this exception : http://pastebin.com/PY2wpBkv
Do you know why and how to solve this problem ?
NB : the graphical tool (so admin.sh) still works well.
In fact one must use the classes from package org.exolab.jms.administration (and not use javax.jms.Session's create<Queue||Topic> methods). Read this page : http://openjms.sourceforge.net/usersguide/admin.html

Randomly Channel.Connect.Failed error when calling to a Java server from Flex application using AMF protocol

I have a project published in the Internet that is used by thousands of users every day. Basically, I'm using a server in AmazonAWS with the server part compiled in Java 6 running in a Tomcat. I'm using AMF to publish the services and my client is built in Flex 4.6 using Flash Builder to generate the classes to connect to the AMF services. The code I'm using to connect to the services is this:
public var cpcService:RemotingServicesImpl;
private function callService():void
{
FlexGlobals.topLevelApplication.callingService=true;
encryptedSession=ResourcesUtil.buildSessionId(globalSettings.sessionId, globalSettings);
var responder:Responder=new Responder(gameStateLoaded, gameStateFailed);
var token:AsyncToken=cpcService.getGameState(encryptedSession, taskKey);
token.addResponder(responder);
}
private function gameStateFailed(ev:FaultEvent=null):void
{
DisplayUtil.trackErrorInfoEvent("FATAL - FatalError", "getGameState-" + FlexGlobals.topLevelApplication.mainView.currentState, ev, encryptedSession);
}
private function gameStateLoaded(ev:Object):void
{
// my fantastic code when everything is ok
}
Normally, everything is ok and my application is working, but some calls (like 1 every 500) are not working, I know it because in the trackErrorInfoEvent function I'm registering an event in the Google Analytics, so I know this is randomly happening. This is the error:
faultCode = "Client.Error.MessageSend"
faultDetail = "Channel.Connect.Failed error NetConnection.Call.Failed: HTTP: Failed: url: 'https://appcog.cognifit.com/messagebroker/amf'"
faultString = "Send failed"
rootCause = (null)
Of course the URL is correct and is working all times.
I have seen in some blogs that adding this line:
<add-no-cache-headers>false</add-no-cache-headers>
the problem is fixed, but I have that line in my config file and is still happening.
I have checked my server logs and I have no records for service interruptions at any time.
I really apreciate any help, thanks in advance!

ClientAbortException on Jersey REST resource

I added a new method to my REST resource (Jersey). When I'm trying to test it I fails with:
ClientAbortException: java.io.IOException: An established connection was aborted by the software in your host machine.
When I'm debugging it, I can see that my code gets to the return statement, by somewhere afterwards fail.
BTW, I have many other methods that works just fine, all return JSON objects.
This happened when I'm trying to call the new method from Jersey Client or simply from a web browser.
My code:
#GET
#Path("/metrics/samples")
#Produces(MediaType.APPLICATION_JSON)
public MetricSamples getFragmentMetricsSamples(#DefaultValue ("-1") #QueryParam ("from")long from, #DefaultValue ("-1") #QueryParam)
{
//Calling DAO code. Everything is OK here.
//I can even see in debug that that return statement is executed successfully.
return metricSamplesDataObject;
}
What can cause the connection to abort?
EDIT
I just came home and seems like the problem is relevant only while working at office.
So, the issue is that this specific method cause ClientAbortExcpetion at work only.
Could it be something related to the network security? Maybe because that amount of data?
Thanks

Verification failure while using openid4java for 'login with google'

I am using openid4java library for implementing the 'login with google' functionality in a spring-mvc application.
It works fine on my local tomcat server but on the remote server it has suddenly stopped working. It was working fine before there too.
After doing some logging in catalina.out I found that the verification of the response fails after google redirects to the return url
VerificationResult verification = openIdService.getConsumerManager().verify(
receivingURL.toString(),
response, discovered);
Identifier verified = verification.getVerifiedId(); //Null
The value of verified is null on the remote server. On local server its an uri
I am aware that while handling the response, ConsumerManager needs to be the same
instance used to place the authentication request.
The rest of the code is implemented as follows
There is an OpenIdController in which OpenIdService is Autowired.
The OpenIdServiceImpl implements OpenIdService and has the getConsumerManager method which returns the consumerManager instance.
In the construct of the OpenIdServiceImpl, an instance of ConsumerManager is created.
The actions that create the form for submission and handle the response are written in the
OpenIdController and access the consumerManager instance using the getConsumerManager method.
Edit:
I tried logging the Discovery information before the form submission and in the call back here it the output
Debugging OpenId: Discovered (before) OpenID2
OP-endpoint:https://www.google.com/accounts/o8/ud
ClaimedID:null
Delegate:null
Debugging OpenId: Discovered (after) OpenID2
OP-endpoint:https://www.google.com/accounts/o8/ud
ClaimedID:null
Delegate:nul
Am I doing anything wrong here ? But it works on local server!
Or something to do with tomcat configuration on the remote server ?
Any help is appreciated. I can post code if required.
Thanks.
I could resolve this problem by adding the following lines after creating an instance of ConsumerManager.
consumerManager.setAssociations(new InMemoryConsumerAssociationStore());
consumerManager.setNonceVerifier(new InMemoryNonceVerifier(5000));
consumerManager.setMinAssocSessEnc(AssociationSessionType.DH_SHA256);
I found it mentioned it in one of the comments to the SampleConsumer example here - http://code.google.com/p/openid4java/wiki/SampleConsumer
see response #3 from the bottom.
Haven't yet tried to figure out what it does, but hope its the right way to solve it :)

Categories