View Poll Results: If you read it, did you find DirectJNgine User's Guide adequate?
- Voters
- 54. You may not vote on this poll
-
Yes
40 74.07% -
No
14 25.93%
-
13 Nov 2009 1:25 AM #141
No, you are not missing something. And yes, I agree: state management is very, very important.
Now, I think there is an expectations mismatch.
DirectJNgine is *not* competing against JSF or other frameworks/libraries. DJN is just a Java implementation of the Ext.Direct communication protocol, nothing more.
If you were using ExtJs + Java before, it will probably make your life much easier. If you were not, you willl need to check whether ExtJs + Java will fit the bill. When evaluating this, you should take what DJN provides into account.
ExtJs does not attempt to solve all problems of web development, including that of state management. ExtJs is all about providing an amazingly rich client side UI, and in that respect I think it is unsurpassed. But that power comes with a cost.
So, when it comes to the "what is the applicability of DJN?" question, I think you should change your question to "what is the the applicability of ExtJS?". If ExtJs is applicable, then DJN will certainly make your life easier.
...
Support for handling state management in a robust and performant way is one of those funny things I would love to implement. But this is a non-for-profit project, I have to make a living, and days have 24 hours -a constraining environment for innovation ;-).
I want to encourage the community to attempt to solve the problem of state management for ExtJs + DJN -and contribute their code back. Maybe you could give it a try :-).
Best regardsPedro Agulló, Barcelona (Spain)
Agile team building, consulting, training & development
DirectJNgine: http://code.google.com/p/directjngine - Log4js-ext: http://www.softwarementors.com/projects/p/log4js-ext/
-
13 Nov 2009 1:54 AM #142
Jay,
Do you just need access to
- HttpServletRequest
- HttpServletResponse
- HttpSession
- ServletContext
- ServletConfig?
I am not familiar with DWR, but so far what I've seen it provides when it comes to servlet support is just this -as seen in http://directwebremoting.org/dwr/server/javaapi.html. Can you provide me with links to that functionality you are missing?
While I do not plan on undertaking support for complex state handling (or rather what I consider to be "complex state handling"), providing support for this is so easy I might implement it if you guys are really interested in it.
What else is there in DWR that you are missing in DJN? Code is what I need, can you provide me with code samples for those things you are doing with DWR now that you can't do with DJN?
I need you guys to go down to details if I am to consider additions/modifications.
Best regards,Pedro Agulló, Barcelona (Spain)
Agile team building, consulting, training & development
DirectJNgine: http://code.google.com/p/directjngine - Log4js-ext: http://www.softwarementors.com/projects/p/log4js-ext/
-
13 Nov 2009 6:08 AM #143
I fully understand what you are saying when it comes to complex session management, but having some sort of solution for session management is paramount to be able to use this framework in the context of a multi-user web application.
We are currently investigating (today) the Spring / DirectJngine integration and am hoping that this provides a solution for our problem.
Having said this we have yet to investigate the in & outs of session management in a Java based web application (which I would agree is probably a big undertaking and complex), but I am going to assume that either the JSP or JSF frameworks have integration hooks for this beyond the servlet filter option.
Maybe another approach to the same question would be easier. How in your opinion was this going to support a multi-user web application. In particular, how would I be able to access user state stored on the server. Unless you are taking a sometimes touted Microsoft approach where everything is stateless, you must be able to access the session somehow.
Whatty
-
16 Nov 2009 4:38 AM #144
Adding access to HttpSession, ServletContext to DirectJNgine
Adding access to HttpSession, ServletContext to DirectJNgine
Of course, I'm not advocating a "100% stateless" approach, and this means in practice that you probably have to use the HttpSession in one way or other -whether you do it directly or your library/framewok does it for you under the covers.
The filter technique discussed elsewhere is intended to give you access to HttpSession, ServletContext, ServletRequest and ServletResponse from your DJN methods, so that you can manage state on your own -just that.
Very raw, but useful and workable. When I have implemented it, it has worked with no problem at all.
Why is such approach *not* a part of DJN right now?
1) I wanted to avoid people thinking this is *The Right And Only Way* with DJN.
And, in fact, I have thought of a much more advanced state management solution, to be built on top of DJN, rather than as part of it. No time/financing for that, though -so,just a dream.
2) I think state management and communication should be orthogonal.
DJN is an implementation of a communication protocol, Ext.Direct. I wanted DJN to remain blissfully unaware of sessions and the like, as state managment is a different concern.
3) I felt writing such a filter was so easy that DJN users would write their own as needed.
If you take a look at the code below, you will see that it is rather short.
Nowadays, due to popular demand, I'm leaning towards providing and out of the box implementation of such a mechanism for the next DJN version. But before I do, I would like to get feedback on this issue from as many real DJN users as possible.
Here is the source code for a "just in an hour" filter + WebContext class that makes sessions etc. available to DJN methods + a simple test DJN method. Maybe this code might be the basis for the desired functionality. (Note: this might not work with multithreaded request handling for batched request, so just disable it)
Filter
====
Class giving access to HttpSession, etc. from a DJN methodCode:package com.softwarementors.extjs.djn.servlet; import java.io.IOException; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.log4j.NDC; public class DirectJNgineFilter implements Filter { private ServletContext servletContext; public void destroy() { // Do nothing } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { boolean initializeContext = request instanceof HttpServletRequest && response instanceof HttpServletResponse; WebContext context = null; if( initializeContext ) { context = WebContext.initializeWebContext( (HttpServletRequest)request, (HttpServletResponse)response, this.servletContext); NDC.push( "session=" + ((HttpServletRequest)request).getSession().getId() ); } chain.doFilter(request, response); if(initializeContext) { assert context != null; NDC.pop(); context.close(); } } public void init(FilterConfig config) throws ServletException { this.servletContext = config.getServletContext(); } }
=============================================
DJN method accessing session and other contextual infoCode:package com.softwarementors.extjs.djn.servlet; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; public class WebContext { private static ThreadLocal<WebContext> webContext = new ThreadLocal<WebContext>(); private HttpServletRequest request; private HttpServletResponse response; private ServletContext servletContext; private boolean initialized; private WebContext( HttpServletRequest request, HttpServletResponse response, ServletContext servletContext ) { assert request != null; assert response != null; assert servletContext != null; this.request = request; this.response = response; this.servletContext = servletContext; this.initialized = true; } public static WebContext get() { assert isWebContextInitialized(); return webContext.get(); } /* package */ static WebContext initializeWebContext( HttpServletRequest request, HttpServletResponse response, ServletContext servletContext) { assert request != null; assert response != null; assert servletContext != null; assert !isWebContextInitialized(); WebContext result = new WebContext(request, response, servletContext ); webContext.set( result ); return result; } /* package */ void close() { assert isWebContextInitialized(); // WebContext context = webContext.get(); this.request = null; this.response = null; this.servletContext = null; this.initialized = false; webContext.set(null); } /* package */ static boolean isWebContextInitialized() { WebContext context = webContext.get(); return context != null; } public boolean isInitialized() { return this.initialized; } public HttpServletRequest getRequest() { assert isInitialized(); return this.request; } public HttpServletResponse getResponse() { assert isInitialized(); return this.response; } public HttpSession getSession() { assert isInitialized(); return this.request.getSession(); } public ServletContext getServletContext() { assert isInitialized(); return this.servletContext; } }
=============================================
Filter configuration in web.xmlCode:package com.softwarementors.extjs.djn.test.servlet; import javax.servlet.ServletContext; import javax.servlet.http.HttpSession; import com.softwarementors.extjs.djn.config.annotations.DirectMethod; import com.softwarementors.extjs.djn.servlet.WebContext; public class WebContextTest { public static class WebContextInfo { public int callsInSession = 0; public int callsInApplication = 0; public String sessionId; } @DirectMethod public WebContextInfo test_webContext() { WebContext context = WebContext.get(); HttpSession session = context.getSession(); ServletContext application = context.getServletContext(); // Keep a counter of how many times we have called this method in this session Integer callsInSession = (Integer)session.getAttribute("callsInSession"); if( callsInSession == null ) { callsInSession = new Integer(0); } callsInSession = new Integer(callsInSession.intValue() + 1); session.setAttribute("callsInSession", callsInSession); // Keep a counter of how many times we have called this method in this application Integer callsInApplication = (Integer)application.getAttribute("callsInApplication"); if( callsInApplication == null ) { callsInApplication = new Integer(0); } callsInApplication = new Integer(callsInApplication.intValue() + 1); application.setAttribute("callsInApplication", callsInApplication); // Return status information WebContextInfo result = new WebContextInfo(); result.callsInApplication = callsInApplication.intValue(); result.callsInSession = callsInSession.intValue(); result.sessionId = context.getSession().getId(); return result; } }
======================
Code:<filter> <filter-name>djnFilter</filter-name> <filter-class>com.softwarementors.extjs.djn.servlet.DirectJNgineFilter</filter-class> </filter> <filter-mapping> <filter-name>djnFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
@Whatty
Is the approach used by the enclosed code ok for you? If so, use the code and let us know how it goes. You can add it to the already existing demo app -remember to add the new test class to web.xml
@Jay and other DWR users
Still interested in taking a look at code illustrating what DWR is giving you that DJN does not.
I'm always interested in making DJN better, real code exemplifying real needs is what will provide fuel for it to move forward
.
@All
Now, I want to know whether people wants the "make HttpSession, etc. available to DJN methods" functionality included as part of DJN 1.2: just vote in this thread
Best regards,Pedro Agulló, Barcelona (Spain)
Agile team building, consulting, training & development
DirectJNgine: http://code.google.com/p/directjngine - Log4js-ext: http://www.softwarementors.com/projects/p/log4js-ext/
-
16 Nov 2009 8:51 AM #145
djn-spring configuration
djn-spring configuration
Good morning,
We are working with the djn-spring integration with a fair amount of success.
Just wanted to confirm one item, our action classes that should be hooked up the djnEngine and ultimately have their API generated to the API.JS file need to implement the
and in our SpringGlobalConfiguration configuration file, we use the following:Code:IAutoWiredDirectAction interface
This works but is it the prescribed method for wiring up our Spring managed beans to the DJN API.Code:<bean id="autowiredActionApiConfiguration" class="com.extjs.djn.spring.test.autowired.api.AutowiredActionApiConfiguration"> <property name="apiName" value="PureFees-API" /> <property name="apiNamespace" value="Ext.app" /> <property name="apiFileName" value="PureFees-API.js" /> <property name="apiFolder" value="djn/api" /> </bean>
Additionally, is there any way to get the Spring integration to recognize that a class has one of the DJN annotations and automatically wire it up as opposed to having to implement the interface
Thanks in advance.Code:IAutoWiredDirectAction
Whatty
BTW, thanks for the effort to all in getting these two frameworks to work together.
-
16 Nov 2009 7:07 PM #146
yes you are right, thats all about DWR, nothing more.
I know its a very simple task for you to enhance the DJN to support the above java objects, as I've also investigated the source code of DJN before.
Although the java servlet objects are not designated to be supported by DJN in its purpose, but this extra bonus supports will make everything becomes easy.
I'm happy to see that now DJN is going to support the basic session controls, deeply appreciated to your work! thanks!
-
16 Nov 2009 11:56 PM #147
I'm happy to see that now DJN is going to support the basic session controls.
+1
I'd like too.
RamziBest Regards,
Ramzi Youssef
MEDIACEPT Technology
-
17 Nov 2009 1:37 AM #148
I think it's the best way to wiring up beans it doesn't need further declaration.
Spring autowiring features need to know the type or the name of the bean you want to be autowired.
http://static.springsource.org/sprin...ctory-autowire
In Spring context bean's name is an unique value. The com.extjs.djn.spring.test.autowired.api.AutowiredActionApiConfiguration was created to define many action that's why I use the injection by type. Interface is the most useful type to do this.
In your project instead of using the test implementation of ActionApiConfiguration write your own with the common type of your action. I didn't implement the AutowiredActionApiConfiguration in the core API because each project may have its own action interface or abstract class...
If you have many action using different type you can also add an autowired setter with the corresponding type. But it's make no sense to have one setter per action...
I hope giving you a good explanation.
Do not hesitate to send me some modification requests or remarks
-
17 Nov 2009 6:19 AM #149
Thanks for the response.
Just a quick clarification, the "test.autowired" hierarchy was for your testing purposes and you did not include them in the base package since you expected people to have their own action hierarchy already in place.
Thus to include my action classes in the API generation I would do something like the following:
and my action classes would only need to implementCode:public class MyApiConfiguration extends BaseActionApiConfiguration<IMyDirectAction> { @Autowired @Override public void setListActions(List<IMyDirectAction> listActions) { super.setListActions(listActions); } }
With the appropriate changes to my configCode:IMyDirectAction
If I already happen to have a abstract class or interface in place (which I do) I would just change the MyApiConfiguration to use that interface / class instead.
Well done!
Have you been following the discussion's related to session management in the base jNgine. I know that Spring has a WEB framework and related web session management packages and was wondering if it would be possible to hook into Spring's WEB frameworks to assist with this session management, or would this unneccessarily tie the underlying jNgine to the SPRING framework (unless the web framework can be yanked out of the base SPRING framework)?
Thanks
Whatty
-
17 Nov 2009 8:58 AM #150
httpSession
httpSession
Actually in my project we doesn't need to manage session but I understand your need and I'm quite sure I will need to have this feature... We use Ext-direct only for request like search,...
I'm not a great Spring-web user but for all I know I think Spring-web is not a solution.
It's a 'mvc' implementation for web application ''like'' Struts/JSF(?)/... there is now way to map Ext-direct request to 'spring/struts/..-action' through Djn!
What you need is to configure your web application framework (SpringWeb,JSF,..) to return json instead of html and to accept receiving JSON. But I'm not sure it's possible..
I didn't test but may be something is possible with restlet http://www.restlet.org/ but you will have to do some development (e.g. generate an API-js like Djn do with your restlet resources)... This framework accept a lot of input type and a lot of output type.. JSON is accepted in standard and it's allow to manage user session.
I have no time to search further workaround but what about the filter given by pedro ? It's not what you need ?
You have to keep in mind that-Djn is not designed to be in front of, or behind, a Web application framework....
-Djn-Spring only allow to configure action without declaration in the web.xml (except servlet) and with the autowiring feature with a small number of bean declaration.
I think I will take a look at this issue but before I should release the djn-spring 1.1
Regards,
Vincent
(I hope to be clear as you can read english is not my mother tong :p)



Reply With Quote