2

我通过 maven 制作了一个 wicket-atmosphere webapp,它可以工作。如果我在没有 maven 的情况下创建了一个新的 webapp,并且我将所有依赖项复制为 jar,它就不再起作用了。

在 AjaxLink 的 onClick 中,我调用 EventBus.get().post() 并导致 NullPoiinterException。您可以在下面阅读完整的堆栈跟踪。我刚刚错过了什么?

public void onClick(AjaxRequestTarget art){
                EventBus.get().post( message = getRandomText() );
            }

罐子:

javax.servlet-api-3.0.1.jar
slf4j-simple-1.6.4.jar
slf4j-api-1.6.4.jar
wicket-core-6.9.0.jar
wicket-request-6.9.0.jar
wicket-util-6.9.0.jar
wicket-atmosphere-0.10.jar
atmosphere-compat-jbossweb-1.0.8.jar
atmosphere-compat-tomcat-1.0.8.jar
atmosphere-compat-tomcat7-1.0.8.jar
atmosphere-runtime-1.0.8.jar
guava-11.0.0.jar
jsr305-1.3.9.jar

我的xmls:

META-INF/context.xml

<?xml version="1.0" encoding="UTF-8"?>
<Context>
    <!-- <Loader className="org.atmosphere.util.AtmosphereClassloader"/> -->
    <Loader delegate="true"/>
</Context>

META-INF/atmosphere.xml

<atmosphere-handlers>
    <atmosphere-handler context-root="/*"
        class-name="org.atmosphere.handler.ReflectorServletProcessor">
        <property name="filterClassName" value="com.myapp.wicket.DebugWicketFilter" />
    </atmosphere-handler>
</atmosphere-handlers> 

WEB-INF/web.xml:

    <?xml version="1.0" encoding="ISO-8859-1"?>
<web-app 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"
    version="3.0">

    <display-name>myproject</display-name>

    <servlet>
        <description>Atmospherefilter</description>
        <servlet-name>Atmospherefilter</servlet-name>
        <servlet-class>org.atmosphere.cpr.AtmosphereServlet</servlet-class>
        <init-param>
            <param-name>applicationClassName</param-name>
            <param-value>com.myapp.wicket.Application</param-value>
        </init-param>
        <init-param>
            <param-name>configuration</param-name>
            <param-value>development</param-value>
        </init-param>
        <init-param>
            <param-name>org.atmosphere.useWebSocket</param-name>
            <param-value>false</param-value>
        </init-param>
        <init-param>
            <param-name>org.atmosphere.useNative</param-name>
            <param-value>true</param-value>
        </init-param>
                <init-param>
                        <param-name>org.atmosphere.cpr.CometSupport.maxInactiveActivity</param-name>
                        <param-value>30000</param-value>
                </init-param>
        <init-param>
            <param-name>filterMappingUrlPattern</param-name>
            <param-value>/*</param-value>
        </init-param>
        <init-param>
            <param-name>org.atmosphere.websocket.WebSocketProtocol</param-name>
            <param-value>org.atmosphere.websocket.protocol.EchoProtocol</param-value>
        </init-param>
        <init-param>
            <param-name>org.atmosphere.cpr.broadcastFilterClasses</param-name>
            <param-value>org.apache.wicket.atmosphere.TrackMessageSizeFilter</param-value>
        </init-param>
        <load-on-startup>0</load-on-startup>
        <async-supported>true</async-supported>
    </servlet>
    <servlet-mapping>
        <servlet-name>Atmospherefilter</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
</web-app>

WEB-INF/beans.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans 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/beans_1_0.xsd">
</beans>

WEB-INF/glassfish-web.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app error-url="">
  <parameter-encoding default-charset="UTF-8"/>
  <class-loader delegate="true"/>
</glassfish-web-app>

com/myapp/wicket/DebugWicketFilter.java

public class DebugWicketFilter extends WicketFilter {
    private static final Logger log = LoggerFactory.getLogger(DebugWicketFilter.class);

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        log.info("URI: " + request.toString());
        super.doFilter(request, response, chain);
    }
} 

完整的堆栈跟踪:

WicketMessage: Method onRequest of interface org.apache.wicket.behavior.IBehaviorListener targeted at org.apache.wicket.ajax.markup.html.AjaxLink$1@32048 on component [AjaxLink [Component id = link]] threw an exception

java.lang.NullPointerException
     at org.apache.wicket.protocol.http.servlet.ServletWebRequest.getContextRelativeUrl(ServletWebRequest.java:194)
     at org.apache.wicket.protocol.http.servlet.ServletWebRequest.<init>(ServletWebRequest.java:113)
     at org.apache.wicket.protocol.http.servlet.ServletWebRequest.<init>(ServletWebRequest.java:83)
     at org.apache.wicket.protocol.http.WebApplication.newWebRequest(WebApplication.java:448)
     at org.apache.wicket.atmosphere.EventBus.post(EventBus.java:318)
     at org.apache.wicket.atmosphere.EventBus.postToSingleResource(EventBus.java:298)
     at org.apache.wicket.atmosphere.EventBus.post(EventBus.java:273)
     at com.myapp.wicket.HomePage$1.onClick(HomePage.java:28)
     at org.apache.wicket.ajax.markup.html.AjaxLink$1.onEvent(AjaxLink.java:86)
     at org.apache.wicket.ajax.AjaxEventBehavior.respond(AjaxEventBehavior.java:123)
     at org.apache.wicket.ajax.AbstractDefaultAjaxBehavior.onRequest(AbstractDefaultAjaxBehavior.java:626)
     at java.lang.reflect.Method.invoke(Method.java:601)
     at org.apache.wicket.RequestListenerInterface.internalInvoke(RequestListenerInterface.java:258)
     at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:241)
     at org.apache.wicket.core.request.handler.ListenerInterfaceRequestHandler.invokeListener(ListenerInterfaceRequestHandler.java:247)
     at org.apache.wicket.core.request.handler.ListenerInterfaceRequestHandler.respond(ListenerInterfaceRequestHandler.java:226)
     at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:861)
     at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64)
     at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:261)
     at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:218)
     at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:289)
     at org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(WicketFilter.java:259)
     at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:201)
     at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:282)
     at com.myapp.wicket.DebugWicketFilter.doFilter(DebugWicketFilter.java:34)
     at org.atmosphere.util.AtmosphereFilterChain.doFilter(AtmosphereFilterChain.java:155)
     at org.atmosphere.util.AtmosphereFilterChain.invokeFilterChain(AtmosphereFilterChain.java:132)
     at org.atmosphere.handler.ReflectorServletProcessor$FilterChainServletWrapper.service(ReflectorServletProcessor.java:314)
     at org.atmosphere.handler.ReflectorServletProcessor.onRequest(ReflectorServletProcessor.java:172)
     at org.atmosphere.cpr.AsynchronousProcessor.action(AsynchronousProcessor.java:256)
     at org.atmosphere.cpr.AsynchronousProcessor.suspended(AsynchronousProcessor.java:166)
     at org.atmosphere.container.GrizzlyCometSupport.service(GrizzlyCometSupport.java:119)
     at org.atmosphere.cpr.AtmosphereFramework.doCometSupport(AtmosphereFramework.java:1307)
     at org.atmosphere.cpr.AtmosphereServlet.doPost(AtmosphereServlet.java:293)
     at org.atmosphere.cpr.AtmosphereServlet.doGet(AtmosphereServlet.java:279)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
     at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
     at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
     at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
     at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
     at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
     at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
     at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
     at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
     at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
     at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
     at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
     at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
     at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
     at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
     at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
     at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
     at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
     at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
     at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
     at java.lang.Thread.run(Thread.java:722)
4

0 回答 0