DWR : WebContextFactory.get() returns null

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

DWR : WebContextFactory.get() returns null

bala_vel balasubramaniyan
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: DWR : WebContextFactory.get() returns null

david@butterdev.com
This is expected and documented:
http://directwebremoting.org/dwr/documentation/server/javaapi.html

"WebContext and ServerContext are your connection to other parts of DWR
and the general servlet API. WebContext is used when you are in a DWR
thread. It uses a ThreadLocal variable to connect you to the running
container. ServerContext can be used outside of a DWR thread, but as a
result you will need to pass it a ServletContext so it knows where DWR
is running."

I am not sure what you are trying to do but in a test environment you
probably want to mock-out the request.

On 2015-04-21 08:14, bala_vel balasubramaniyan wrote:

> Hi DWR Support,
>
>  I am trying to write a junit for an action class where I have a
> method which has "WebContextFactory.get()".
>
> The "WebContextFactory.get()" is always returning NULL when I try to
> invoke the Action class from my Junit.
>
> My project is a maven project. Hereunder is my code how i am invoking
> my action class using a junit.
>
> 1. PUBLIC CLASS AJAXACTIONTEST EXTENDS TESTCASE {
> 2. public void testGetInfoByNumber() {
> 3. try {
> 4. AJAXACTION _ajaxAction _= new AJAXACTION ();
> 5. _ __ajaxAction .getInfoByNumber("1212121");_
> 6. } catch (Exception e) {
> 7. assertTrue(false);
> 8. }
> 9. }
> 10. }
>
> 1. public class AJAXACTION {
> 2. public _void __getInfoByNumber_(String number) {
> 3. HttpSession session = retrieveCurrentSession();
> 4. }
>
> 5.
> 6. protected HttpSession RETRIEVECURRENTSESSION() {
> 7. WEBCONTEXT CTX = WEBCONTEXTFACTORY.GET();
> 8. HttpServletRequest req = ctx.getHttpServletRequest();
> 9. HttpSession session = null;
> 10. if (req != null) {
> 11. session = req.getSession();
> 12. }
> 13. return session;
> 14. }
>
> Team,
>  whenever I run my Junit AJAXACTIONTEST.JAVA, I reach the
> _getInfoByNumber in _AJAXACTION and that internally calls the
> _retrieveCurrentSession()_ method. But the line# 7 in the AJAXACTION
> always returns NULL and i am unable to get the current session from
> that method. can you please help me on this issue to proceed further.
>
>  DWR version : 3.0.0-rc2
>
> Java version : 1.8.0_25
>
> Maven Version : Maven-3.2.1
>
> Junit Version : 4.11
Reply | Threaded
Open this post in threaded view
|

Re: DWR : WebContextFactory.get() returns null

bala_vel balasubramaniyan
CONTENTS DELETED
The author has deleted this message.