Grizzly http 服务器失败了一些请求

发布于 2024-09-18 05:26:15 字数 3302 浏览 6 评论 0原文

我创建了一个 grizzly Web 服务器,从 tomcat 运行我的球衣应用程序,以加快测试速度。

我是一个 grizzly 初学者,但是通过网络我将一些代码行放在一起,以便在不到一个工作日的时间内启动并运行 grizzly Web 服务器:)

不幸的是,我的类在并发请求上遇到了一些麻烦,通常是一个或多个因莫名其妙的 NullPointerException 失败。

问题通常发生在我刷新网页时,grizzly 必须返回大约 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)
.....

静态文件由我的一个类提供,但日志告诉我一切正常,当我在 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);
}
}

任何建议都表示赞赏。

你好,达维德。

I created a grizzly web server, to run my jersey application out of tomcat, to speed up tests.

I'm a grizzly beginner, but looking through the net I put some code lines together, to make a grizzly web server up and running in less than a working day :)

Unfortunately my class has some troubles on concurrent request, often one or more fails in an inexplicable NullPointerException.

Troubles are typically when I refresh my web page, where grizzly must return about 25 non cached files. This is registered exception:

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)
.....

Static files are served from a class of mine, but logs tells me everithing is ok and when I use application under tomcat, everything is ok.
I really don't know how to solve this problem..

This is the code I created/copied from internet, to startup project:

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);
}
}

Any suggestions are appreciated.

Ciao, Davide.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧瑾黎汐 2024-09-25 05:26:15

这是由于 Grizzly 中的一个 bug,FilterChainImpl 的实现不是线程安全的。该问题已在此处报告:https://grizzly.dev.java。 net/issues/show_bug.cgi?id=819,并在几个月前得到修复。

更新到最新版本(1.9.21)解决了我的问题。

This is due to a bug in Grizzly, the implementation of FilterChainImpl is not threadsafe. The issue has been reported here:https://grizzly.dev.java.net/issues/show_bug.cgi?id=819, and got fixed a couple months ago.

Updating to the latest release (1.9.21) solved the problem for me.

偏爱你一生 2024-09-25 05:26:15

您的配置中有

  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");

两次仅供参考..不确定这是否会成为问题。

https://java.net/jira/browse/GRIZZLY-819

在上面的错误中说票证..如果您注册了多个过滤器,则会发生这种情况:
“我建议至少让这个变量成为线程安全的。
仅当注册了多个过滤器时才会出现该问题。”

you have

  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");

twice in your configuration FYI..not sure if that could be an issue.

https://java.net/jira/browse/GRIZZLY-819

Says in above error ticket..if you register more than one filter this occurs:
"I propose at least to make this variable threadsafe.
The problem only shows if more than filter is registered."

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文