dwr3-jsf integration cannot call a CDI remotemethod

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

dwr3-jsf integration cannot call a CDI remotemethod

mihaisheng
 hi,everyone:

i use dwr to call a jsf managedbean,
it works when execute a non-cdi method,but run to error when execute a cdi method.

(dwr3.0.RC2,jboss7.1.1.final,jdk1.7).

like this:
1.managedbean
------------------------
import java.io.Serializable;
import javax.enterprise.context.SessionScoped;
import javax.inject.Inject;
import javax.inject.Named;
import org.directwebremoting.annotations.RemoteMethod;
import org.directwebremoting.annotations.RemoteProxy;

@RemoteProxy
@Named("Test")
@SessionScoped
public class Test implements Serializable
{
    private static final long serialVersionUID = -1231439157655757940L;
    @Inject
    private CurrentUser currentUser;
    @Named
  &nb sp; @RemoteMethod
    public String test1(){
        System.out.println("hellow from CDI managedbean");
        return currentUser.getUsername();
    }

    @Named
    @RemoteMethod
    public String test2(){
        System.out.println("hellow from simple managedbean");
        return "hellow from simple managedbean";
    }
}
--------------------------
import java.io.Serializable;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;
@SessionScoped
@Named
public class CurrentUser implements Serializable{
    private static final long serialVersionUID = 1401288096425725460L;
    private String username="user1";
    public String getUsername(){
&n bsp;       return this.username;
    }
}
------------------------

2.web.xml
-----------------------
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

    <error-page>
        <error-code>500</error-code>
        <location>/error.jsf</location>
    </error-page>
    <filter> 
    <filter-name>DwrFacesFilter</filter-name> 
    <filter-class>org.directwebremoting.faces.FacesExtensionFilter</filter-class> 
</filter>
 
<filter-mapping> 
    <filter-name>DwrFacesFilter</filter-name> 
    <url-pattern>/dwr/*</url-pattern> 
</filter-mapping>

<servlet>
        <servlet-name>dwr-invoker</servlet-name>
        <servlet-class>
            org.directwebremoting.servlet.DwrServlet
        </servlet-class>
       
        <init-param>
            <param-name>debug</param-name>
            <param-value>true</param-value>
      &nb sp; </init-param>
        <init-param>
            <param-name>classes</param-name>
            <param-value>
            Test
            </param-value>
        </init-param>
    </servlet>

    <servlet-mapping>
        <servlet-name>dwr-invoker</servlet-name>
        <url-pattern>/dwr/*</url-pattern>
    </servlet-mapping>
</web-app>
-----------------------

3.in a jsf page,to call managedbean's method.
---------------------------------
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets">
      <head>
  <script type='text/javascript' src='dwr/engine.js'></script>
  <script type='text/javascript' src='dwr/util.js'></script>
   <script type='text/javascript' src='dwr/interface/Test.js'></script>  
</head>

<h:form id="loginForm" rendered="#{not identity.loggedIn}">
<p>for dwr:</p>
         <input type="button" value="method simple" onclick="Test.test2(function(i){alert(i);});"/>
&n bsp;        <input type="button" value="method(cdi)" onclick="Test.test1(function(i){alert(i);});"/>
<p>for jsf manner:</p>
         <h:commandButton value="call method(cdi)" action="#{Test.test1}" />
         <h:commandButton value="call method simple" action="#{Test.test2}" />
</h:form>
</html>
------------------------------

i find remote method [test2] run correct in browser.
but remote method [test1] run to error(NullPointerException).im sure this code run well in jsf manner.

4.error message
-----------------------
11:20:10,172 INFO  [org.directwebremoting.log.accessLog] (http--0.0.0.0-8080-1) Method execution failed: : java.lang.NullPointerException
    at Test.test1(Test.java:20)    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_07]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_07]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_07]
    at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0_07]
    at org.directwebremoting.impl.CreatorModule$1.doFilter(CreatorModule.java:229) [dwr-3.0.RC2.jar:]
    at org.directwebremoting.impl.CreatorModule.executeMethod(CreatorModule.java:241) [dwr-3.0.RC2.jar:]
    at org.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:379) [dwr-3.0.RC2.jar:]
    at org.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:332) [dwr-3.0.RC2.jar:]
    at org.directwebremoting.dwrp.BaseCallHandler.handle(BaseCallHandler.java:104) [dwr-3.0.RC2.jar:]
    at org.directw ebremoting.servlet.UrlProcessor.handle(UrlProcessor.java:120) [dwr-3.0.RC2.jar:]
    at org.directwebremoting.servlet.DwrServlet.doPost(DwrServlet.java:141) [dwr-3.0.RC2.jar:]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:754) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
    at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
    at org.apache.catalina. core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
    at org.directwebremoting.faces.FacesExtensionFilter.doFilter(FacesExtensionFilter.java:80) [dwr-3.0.RC2-noncla.jar:]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
    at org.jboss. as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
    at org.apache.coyot e.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
    at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_07]
-------------------------------------

can someone tell me how to make dwr(jsf integration) support a CDI managedBean ????






Reply | Threaded
Open this post in threaded view
|

Re: dwr3-jsf integration cannot call a CDI remotemethod

david@butterdev.com
I answered your question yesterday. 

http://dwr.2114559.n2.nabble.com/dwr-jsf-integration-cant-call-a-CDI-managedbean-td7580749.html

On 10/01/2013 09:24 PM, εδΈ‰ιƒŽ wrote:
 hi,everyone:

i use dwr to call a jsf managedbean,
it works when execute a non-cdi method,but run to error when execute a cdi method.

(dwr3.0.RC2,jboss7.1.1.final,jdk1.7).

like this:
1.managedbean
------------------------
import java.io.Serializable;
import javax.enterprise.context.SessionScoped;
import javax.inject.Inject;
import javax.inject.Named;
import org.directwebremoting.annotations.RemoteMethod;
import org.directwebremoting.annotations.RemoteProxy;

@RemoteProxy
@Named("Test")
@SessionScoped
public class Test implements Serializable
{
    private static final long serialVersionUID = -1231439157655757940L;
    @Inject
    private CurrentUser currentUser;
    @Named
  &nb sp; @RemoteMethod
    public String test1(){
        System.out.println("hellow from CDI managedbean");
        return currentUser.getUsername();
    }

    @Named
    @RemoteMethod
    public String test2(){
        System.out.println("hellow from simple managedbean");
        return "hellow from simple managedbean";
    }
}
--------------------------
import java.io.Serializable;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;
@SessionScoped
@Named
public class CurrentUser implements Serializable{
    private static final long serialVersionUID = 1401288096425725460L;
    private String username="user1";
    public String getUsername(){
&n bsp;       return this.username;
    }
}
------------------------

2.web.xml
-----------------------
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

    <error-page>
        <error-code>500</error-code>
        <location>/error.jsf</location>
    </error-page>
    <filter> 
    <filter-name>DwrFacesFilter</filter-name> 
    <filter-class>org.directwebremoting.faces.FacesExtensionFilter</filter-class> 
</filter>
 
<filter-mapping> 
    <filter-name>DwrFacesFilter</filter-name> 
    <url-pattern>/dwr/*</url-pattern> 
</filter-mapping>

<servlet>
        <servlet-name>dwr-invoker</servlet-name>
        <servlet-class>
            org.directwebremoting.servlet.DwrServlet
        </servlet-class>
       
        <init-param>
            <param-name>debug</param-name>
            <param-value>true</param-value>
      &nb sp; </init-param>
        <init-param>
            <param-name>classes</param-name>
            <param-value>
            Test
            </param-value>
        </init-param>
    </servlet>

    <servlet-mapping>
        <servlet-name>dwr-invoker</servlet-name>
        <url-pattern>/dwr/*</url-pattern>
    </servlet-mapping>
</web-app>
-----------------------

3.in a jsf page,to call managedbean's method.
---------------------------------
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets">
      <head>
  <script type='text/javascript' src='dwr/engine.js'></script>
  <script type='text/javascript' src='dwr/util.js'></script>
   <script type='text/javascript' src='dwr/interface/Test.js'></script>  
</head>

<h:form id="loginForm" rendered="#{not identity.loggedIn}">
<p>for dwr:</p>
         <input type="button" value="method simple" onclick="Test.test2(function(i){alert(i);});"/>
&n bsp;        <input type="button" value="method(cdi)" onclick="Test.test1(function(i){alert(i);});"/>
<p>for jsf manner:</p>
         <h:commandButton value="call method(cdi)" action="#{Test.test1}" />
         <h:commandButton value="call method simple" action="#{Test.test2}" />
</h:form>
</html>
------------------------------

i find remote method [test2] run correct in browser.
but remote method [test1] run to error(NullPointerException).im sure this code run well in jsf manner.

4.error message
-----------------------
11:20:10,172 INFO  [org.directwebremoting.log.accessLog] (http--0.0.0.0-8080-1) Method execution failed: : java.lang.NullPointerException
    at Test.test1(Test.java:20)    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_07]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_07]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_07]
    at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0_07]
    at org.directwebremoting.impl.CreatorModule$1.doFilter(CreatorModule.java:229) [dwr-3.0.RC2.jar:]
    at org.directwebremoting.impl.CreatorModule.executeMethod(CreatorModule.java:241) [dwr-3.0.RC2.jar:]
    at org.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:379) [dwr-3.0.RC2.jar:]
    at org.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:332) [dwr-3.0.RC2.jar:]
    at org.directwebremoting.dwrp.BaseCallHandler.handle(BaseCallHandler.java:104) [dwr-3.0.RC2.jar:]
    at org.directw ebremoting.servlet.UrlProcessor.handle(UrlProcessor.java:120) [dwr-3.0.RC2.jar:]
    at org.directwebremoting.servlet.DwrServlet.doPost(DwrServlet.java:141) [dwr-3.0.RC2.jar:]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:754) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
    at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
    at org.apache.catalina. core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
    at org.directwebremoting.faces.FacesExtensionFilter.doFilter(FacesExtensionFilter.java:80) [dwr-3.0.RC2-noncla.jar:]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
    at org.jboss. as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
    at org.apache.coyot e.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
    at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_07]
-------------------------------------

can someone tell me how to make dwr(jsf integration) support a CDI managedBean ????