Log4j初始化错误JBoss RestEasy

发布于 2024-12-28 10:07:57 字数 1614 浏览 1 评论 0原文

我使用的是JBoss 6.0。我正在使用 jboss.resteasy 库运行一个简单的 Web 服务器,为 HTTP 请求提供简单的 XML 响应。

我有: - 一台服务器 - 创建 GET 请求的简单 Java 客户端

现在的问题是,如果我使用浏览器访问 URL,我就会得到想要的 XML。但是如果我使用我的 Java 客户端,它具有以下代码:

//Register the fake instrument
GetMethod get = new GetMethod("http:/localhost:8080/"+PROJECT_NAME+"/webserver/registerInstrument/?name=FakeClient&value=0");
HttpClient client = new HttpClient();

try {
    int status = client.executeMethod(get);
} catch (HttpException e) {
    System.out.println("[FakeClient] HttpException executing AddInstrument GET request: "+e);
} catch (IOException e) {
    System.out.println("[FakeClient] IOException executing AddInstrument GET request: "+e);
}

然后我得到以下异常:

log4j:WARN No appenders could be found for logger (org.apache.commons.httpclient.params.DefaultHttpParams).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" java.lang.IllegalArgumentException: Host name may not be null
at org.apache.commons.httpclient.HttpHost.<init>(HttpHost.java:68)
at org.apache.commons.httpclient.HttpHost.<init>(HttpHost.java:107)
at org.apache.commons.httpclient.HttpMethodBase.setURI(HttpMethodBase.java:280)
at org.apache.commons.httpclient.HttpMethodBase.<init>(HttpMethodBase.java:220)
at org.apache.commons.httpclient.methods.GetMethod.<init>(GetMethod.java:89)
at client.FakeClient.<init>(FakeClient.java:30)
at client.FakeClient.main(FakeClient.java:22)

起初我认为这可能是 JBoss 日志记录的问题,但如果我通过浏览器访问 URL,我会获得所需的 XML没有问题。

这是 Java 客户端应用程序的问题吗?

谢谢

I am using JBoss 6.0. I am running a simple webserver using the jboss.resteasy library to provide simple XML responses to HTTP requests.

I have:
- A server
- A simple Java Client that creates a GET request

Now the thing is, if I use the browser to access the URL, I get the wanted XML. But if I use my Java client, which has the following code:

//Register the fake instrument
GetMethod get = new GetMethod("http:/localhost:8080/"+PROJECT_NAME+"/webserver/registerInstrument/?name=FakeClient&value=0");
HttpClient client = new HttpClient();

try {
    int status = client.executeMethod(get);
} catch (HttpException e) {
    System.out.println("[FakeClient] HttpException executing AddInstrument GET request: "+e);
} catch (IOException e) {
    System.out.println("[FakeClient] IOException executing AddInstrument GET request: "+e);
}

Then I get the following exception:

log4j:WARN No appenders could be found for logger (org.apache.commons.httpclient.params.DefaultHttpParams).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" java.lang.IllegalArgumentException: Host name may not be null
at org.apache.commons.httpclient.HttpHost.<init>(HttpHost.java:68)
at org.apache.commons.httpclient.HttpHost.<init>(HttpHost.java:107)
at org.apache.commons.httpclient.HttpMethodBase.setURI(HttpMethodBase.java:280)
at org.apache.commons.httpclient.HttpMethodBase.<init>(HttpMethodBase.java:220)
at org.apache.commons.httpclient.methods.GetMethod.<init>(GetMethod.java:89)
at client.FakeClient.<init>(FakeClient.java:30)
at client.FakeClient.main(FakeClient.java:22)

At first I thought this could be a problem with the JBoss logging, but if I access the URL through the browser, I obtain the desired XML with no problems.

Is this a problem with the Java client application?

Thank you

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

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

发布评论

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

评论(1

み格子的夏天 2025-01-04 10:07:57

“log4j:WARN”只是一个警告。它与抛出的实际异常无关。

异常消息指出“主机名可能不为空”。这清楚地表明主机名有问题。看着你的代码,我可以发现一个错误。

您需要添加额外的正斜杠:

GetMethod get = new GetMethod("http://localhost:8080/" ...

The 'log4j:WARN' is just a warning. It has nothing do to with the actual exception being thrown.

The exception message states that 'Host name may not be null'. This clearly indicates that there is something wrong the the hostname. And looking at you code, I can spot one error.

You need to add an extra forward slash:

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