0

我创建了一个在 Win7 上运行良好的 Jersey-Grizzy-Server。但是在 Linux 上开始之后,我会得到一个奇怪的、总是重复的异常

java.lang.IllegalArgumentException: java.net.URISyntaxException: Expected hostname at index 8: https://:443/

,即使没有调用服务器。休息服务一直在工作。有人知道为什么会出现这个异常,或者如何开始调试 grizzly2 Httpserver?

服务器启动是这样实现的(简化):

boolean https = true;
int port = 9960;
URI baseURI = UriBuilder.fromUri("http" + (https ? "s" : "") + "://0.0.0.0/").port(port).build();

//Jersey Service Config
final ResourceConfig rc = new UriExtensionsConfig(GcardApplication.getConfigPackages());

// create Grizzly Container
final HttpHandler handler = ContainerFactory.createContainer(HttpHandler.class, rc);

//do the ssl Config
SLEngineConfigurator ssl = configSSL(https);

HttpServer server = GrizzlyServerFactory.createHttpServer(baseURI, handler, https, ssl);

有异常的日志:

INFO: Initiating Jersey application, version 'Jersey: 1.11 12/09/2011 10:27 AM'
May 7, 2012 8:20:45 PM org.glassfish.grizzly.http.server.NetworkListener start
INFO: Started listener bound to [0.0.0.0:9960]
May 7, 2012 8:20:45 PM org.glassfish.grizzly.http.server.HttpServer start
INFO: [HttpServer] Started.
Crm WS Server started at https://localhost:9960/

Hit Ctrl C to stop the server ...
May 7, 2012 8:20:46 PM org.glassfish.grizzly.http.server.HttpHandler doHandle
SEVERE: service exception
java.lang.IllegalArgumentException: java.net.URISyntaxException: Expected hostname at index 8: https://:443/
    at com.sun.jersey.server.impl.container.grizzly2.GrizzlyContainer.getBaseUri(GrizzlyContainer.java:226)
    at com.sun.jersey.server.impl.container.grizzly2.GrizzlyContainer._service(GrizzlyContainer.java:195)
    at com.sun.jersey.server.impl.container.grizzly2.GrizzlyContainer.service(GrizzlyContainer.java:185)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:163)
    at org.glassfish.grizzly.http.server.HttpHandlerChain.service(HttpHandlerChain.java:195)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:163)
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:158)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:286)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:223)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:155)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:134)
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:78)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:827)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:103)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:111)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:131)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:508)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:488)
    at java.lang.Thread.run(Thread.java:662)
Caused by: java.net.URISyntaxException: Expected hostname at index 8: https://:443/
    at java.net.URI$Parser.fail(URI.java:2810)
    at java.net.URI$Parser.failExpecting(URI.java:2816)
    at java.net.URI$Parser.parseHostname(URI.java:3352)
    at java.net.URI$Parser.parseServer(URI.java:3198)
    at java.net.URI$Parser.parseAuthority(URI.java:3117)
    at java.net.URI$Parser.parseHierarchical(URI.java:3059)
    at java.net.URI$Parser.parse(URI.java:3015)
    at java.net.URI.<init>(URI.java:662)
    at com.sun.jersey.server.impl.container.grizzly2.GrizzlyContainer.getBaseUri(GrizzlyContainer.java:223)
    ... 20 more
May 7, 2012 8:20:49 PM org.glassfish.grizzly.http.server.HttpHandler doHandle
SEVERE: service exception
java.lang.IllegalArgumentException: java.net.URISyntaxException: Expected hostname at index 8: https://:443/
    at com.sun.jersey.server.impl.container.grizzly2.GrizzlyContainer.getBaseUri(GrizzlyContainer.java:226)
    at com.sun.jersey.server.impl.container.grizzly2.GrizzlyContainer._service(GrizzlyContainer.java:195)
    at com.sun.jersey.server.impl.container.grizzly2.GrizzlyContainer.service(GrizzlyContainer.java:185)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:163)
    at org.glassfish.grizzly.http.server.HttpHandlerChain.service(HttpHandlerChain.java:195)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:163)
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:158)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:286)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:223)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:155)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:134)
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:78)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:827)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:103)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:111)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:131)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:508)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:488)
    at java.lang.Thread.run(Thread.java:662)
Caused by: java.net.URISyntaxException: Expected hostname at index 8: https://:443/
    at java.net.URI$Parser.fail(URI.java:2810)
    at java.net.URI$Parser.failExpecting(URI.java:2816)
    at java.net.URI$Parser.parseHostname(URI.java:3352)
    at java.net.URI$Parser.parseServer(URI.java:3198)
    at java.net.URI$Parser.parseAuthority(URI.java:3117)
    at java.net.URI$Parser.parseHierarchical(URI.java:3059)
    at java.net.URI$Parser.parse(URI.java:3015)
    at java.net.URI.<init>(URI.java:662)
    at com.sun.jersey.server.impl.container.grizzly2.GrizzlyContainer.getBaseUri(GrizzlyContainer.java:223)
    ... 
4

2 回答 2

0

https://:443/不是有效的 URL - 没有主机名。

从您的代码中,我看到您致电UriBuilder.fromUri("https://0.0.0.0/")

这里真的"0.0.0.0"是一个有效值吗?

检查命令的输出hostnamedomainname;他们应该返回有用的值(domainname不是那么重要,但如果它有一些有用的价值会更好)。

另请参阅此答案如何确定自己的IP地址:如何通过Java获取Linux上计算机的IP?

[编辑]您可能正在查看代码中的错误位置。在构造函数中设置断点URISyntaxException并找出损坏的 URI 的来源。

于 2012-05-08T10:36:39.317 回答
0

问题的根源是 ReversProxys Healthcheck 的配置,它具有以下发送字符串

GET / HTTP/1.1\r\nHost: \r\nConnection: close\r\n\r\n

我们必须将获取请求更正为

GET https://servername:9960/ HTTP/1.1\r\nHost: originalservername\r\nConnection: close\r\n\r\n
于 2012-05-09T08:53:17.023 回答