问题
I've set out on an endeavour to implement support for a feature similar to mod_xsendfile on torquebox (www.torquebox.org). Torquebox is basically a bunch of code on top of JBoss AS 7, which makes my effort kinda equivalent to making sendfile work on JBoss AS 7.
The main problem here is probably my confusion over JBoss, but after wasting way too many hours exhausting all my googling resources, I have to beleive that there's someone out there who actually know how this thing works in AS 7.
As I understand this, sendfile is supported in JBoss by using the JBoss Web native connectors (http://www.jboss.org/jbossweb/downloads/jboss-native-2-0-10), namely the APR http connector.
After spending hours failing to install these on AS 7, which seems works like a charm for others (https://community.jboss.org/message/614790), grep'ing my local JBoss dir tells me, that these native connectors are appearently bundled with AS 7. In my case, the dll needed is placed in
%JBOSS_HOME%\modules\org\jboss\as\web\main\lib\win-x86_64
So epic fail, trying to install something that's already there. Inspecting my standalone.xml configuration file also reveal this native connector is being used
<subsystem xmlns="urn:jboss:domain:web:1.1" default-virtual-server="default-host">
<connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/>
<virtual-server name="default-host" enable-welcome-root="false">
<alias name="localhost"/>
<alias name="example.com"/>
</virtual-server>
</subsystem>
Switching all logging levels to debug and inspecting the log shows the log message
standalone/log/server.log.2012-02-10:324:23:12:17,964 INFO [org.apache.coyote.http11.Http11AprProtocol] (MSC service thread 1-5) Starting Coyote HTTP/1.1 on http-127.0.0.1-127.0.0.1-8080
Where Http11AprProtocol indicates that the APR http connector is used. However, many posts on the web mention that the following line should also be shown:
org.apache.catalina.core.AprLifecycleListener init INFO: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
No matter the logging level, the AprLifecycleListener line never shows.
When I review this, is seems that the APR http connector is now in use.
According to the docs, I can get the following servlet to work
public class Sendfile extends HttpServlet {
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
if(Boolean.TRUE == request.getAttribute("org.apache.tomcat.sendfile.support")){
// Send all the files!!
}
else{
throw new ServletException("BOOM!");
}
}
}
But no. The org.apache.tomcat.sendfile.support attribute is null and if try attempt to set http headers for sending a file (ignoring the support attribute) and set the rest of the required sendfile attributes, my browser thinks that it's receiving a file, but no data is transferred... and the connection is left hanging.
To conclude the question, it seems the required APR native connector is in use, sendfile should be enabled by default, but the server has no clue what Im trying to make it do.
How to proceed?
回答1:
I was also lost hours trying to learn how it works. You did everything right. Just missed putting the Web System as native=true
:
<subsystem xmlns="urn:jboss:domain:web:1.1"
default-virtual-server="default-host" native="true">
Startup with it:
11:00:26,018 DEBUG [org.apache.catalina.core.AprLifecycleListener] (MSC service thread 1-3) Loaded: apr-1
11:00:26,039 DEBUG [org.jboss.modules] (ServerService Thread Pool -- 58) Module org.jboss.xb:main defined by local module loader @d8d9850 (roots: /home/mmagnani/Development/jboss-eap/jboss-eap-6.0/modules)
11:00:26,070 DEBUG [org.apache.catalina.core.AprLifecycleListener] (MSC service thread 1-3) Loaded: z
11:00:26,071 DEBUG [org.apache.catalina.core.AprLifecycleListener] (MSC service thread 1-3) Loaded: crypto
11:00:26,072 DEBUG [org.apache.catalina.core.AprLifecycleListener] (MSC service thread 1-3) Loaded: ssl
11:00:26,079 DEBUG [org.jboss.as.ejb3] (ServerService Thread Pool -- 36) Adding EJB @Asynchronous support
11:00:26,082 DEBUG [org.jboss.as.ejb3] (ServerService Thread Pool -- 36) Configuring timers
11:00:26,092 DEBUG [org.jboss.as.ejb3] (ServerService Thread Pool -- 36) Adding EJB IIOP support
11:00:26,101 FINE [org.hornetq.core.server.impl.HornetQServerImpl] (MSC service thread 1-6) Starting server HornetQServerImpl::
11:00:26,120 DEBUG [org.apache.catalina.core.AprLifecycleListener] (MSC service thread 1-3) Loaded: tcnative-1
11:00:26,141 DEBUG [org.apache.catalina.core.AprLifecycleListener] (MSC service thread 1-3) Loaded Apache Tomcat Native library 1.1.23.
11:00:26,141 DEBUG [org.apache.catalina.core.AprLifecycleListener] (MSC service thread 1-3) APR capabilities: IPv6 [true], sendfile [true], random [true].
Good Luck :)
来源:https://stackoverflow.com/questions/9239920/jboss-as7-apr-native-connectors-and-sendfile