我創建了一個灰熊Web服務器,用於從tomcat運行我的球衣應用程序來加速測試。Grizzly http服務器失敗了一些請求
我是灰熊初學者,但翻翻網我把一些代碼行在一起,使灰熊Web服務器和運行不到一個工作日:)
不幸的是我的類有一些麻煩在併發請求中,經常出現一個或多個失敗的莫名其妙的NullPointerException。
問題通常是當我刷新我的網頁時,灰熊必須返回大約25個非緩存文件。這是註冊的異常:
9-set-2010 10.45.21 com.sun.grizzly.http.servlet.ServletAdapter doService
GRAVE: service exception:
java.lang.NullPointerException
at com.sun.grizzly.http.servlet.FilterChainImpl.doFilter(FilterChainImpl.java:178)
at com.sun.grizzly.http.servlet.FilterChainImpl.invokeFilterChain(FilterChainImpl.java:139)
at com.sun.grizzly.http.servlet.ServletAdapter.doService(ServletAdapter.java:376)
at com.sun.grizzly.http.servlet.ServletAdapter.service(ServletAdapter.java:324)
.....
靜態文件是從類礦山的服事,乃是日誌告訴我everithing是確定的,當我在Tomcat使用的應用程序,一切正常。 我真的不知道如何解決這個問題..
這是從網上抄我創建的代碼/,以啓動項目:
public class LaunchApp {
/** Find in internet, used to use argument port as default, only if there is no JERSEY_HTTP_PORT env port enabled*/
private static int getPort(int defaultPort) {
String port = System.getenv("JERSEY_HTTP_PORT");
if (null != port) {
try {
return Integer.parseInt(port);
} catch (NumberFormatException e) {
}
}
return defaultPort;
}
private static URI getBaseURI() {
return UriBuilder.fromUri("http://localhost/").port(getPort(8080)).build();
}
public static final URI BASE_URI = getBaseURI();
protected static GrizzlyWebServer startServer() throws IOException {
final String rootFolder = "/Users/davide/dev/my-project/src/main/webapp";
GrizzlyWebServer ws = new GrizzlyWebServer("/Users/davide/dev/my-project/src/main/webapp");
try{
ServletAdapter adapter = new ServletAdapter();
adapter.addContextParameter("contextConfigLocation","classpath:applicationContext.xml");
adapter.addServletListener("org.springframework.web.context.ContextLoaderListener");
adapter.addServletListener("org.springframework.web.context.request.RequestContextListener");
adapter.addInitParameter("com.sun.jersey.config.property.packages", "it.treis.zero.web.rest");
adapter.addInitParameter("com.sun.jersey.spi.container.ContainerRequestFilters","com.sun.jersey.api.container.filter.LoggingFilter");
adapter.addInitParameter("com.sun.jersey.spi.container.ContainerResponseFilters","com.sun.jersey.api.container.filter.LoggingFilter");
adapter.setProperty("load-on-startup", 1);
adapter.setServletInstance(new SpringServlet());
adapter.setRootFolder(rootFolder);
// Add Open Session In View Hibernate Filter.
adapter.addFilter(new org.springframework.orm.hibernate3.support.OpenSessionInViewFilter(), "openSessionInViewFilter", null);
ws.addGrizzlyAdapter(adapter);
ws.start();
} catch(IOException ex){
ex.printStackTrace();
}
return ws;
}
public static void main(String[] args) throws IOException {
System.out.println("Starting Jersey");
GrizzlyWebServer ws = startServer();
System.out.println("Jersey rightly started, press any key to shutdown");
System.in.read();
ws.stop();
System.exit(0);
}
}
任何建議表示讚賞。
Ciao,Davide。
我改變了一些事情,試圖解決問題,我衝昏了灰熊部署者,並試圖用這個偉大的產品來解決。 \t \t \t \t GrizzlyWebServerDeployer gws = new GrizzlyWebServerDeployer(); \t \t \t DeployerConfiguration conf = new DeployerConfiguration(); \t conf.cometEnabled = false; \t conf.forcedContext =「/ java-zero」; \t conf.locations =「./ target/java-zero /」; \t \t嘗試{ \t \t \t \t //準備推出 \t \t GWS。發射(CONF); \t \t} catch(Exception e){ \t \t e.printStackTrace(); \t \t} 不幸的是,應用程序接縫開始,但日誌告訴我球衣找不到資源... – Davide 2010-09-21 23:11:38