Java EE 6 教程,使用 helloservice 出现 404 错误
我正在学习 Java EE 6 教程,并且正在学习有关 Web 服务的部分。我正在尝试让 helloservice 运行,因为我需要在不久的将来做类似的事情。然而,虽然它的构建和部署没有错误,但当我尝试使用它时,我从 GlassFish 收到 404 错误。我查看了 GlassFish 日志,没有发现任何问题。以下是服务中的代码:
package helloservice.endpoint;
import javax.jws.WebService;
import javax.jws.WebMethod;
@WebService
public class Hello {
private String message = "Hello, ";
public void Hello() {
}
@WebMethod
public String sayHello(String name) {
return message + name + ".";
}
}
根据我所读到的内容,@WebService 应该公开服务名称为 HelloService 的类(基类名称 +“Service”)。但是,当我转到:
http://localhost:8080/helloservice/HelloService?wsdl
我收到 404 错误。我已经完成了前面的所有示例,因此我知道 GlassFish 正在运行,并且它正在端口 8080 上响应我部署的其他应用程序。我可以在管理控制台中看到 helloservice 已部署并正在运行。 “asadmin list-domains”显示我的domain1(我唯一的域)正在运行。我认为 @WebService 注释的默认值可能是错误的,因此我使用 @WebService(serviceName = "Foobar") 设置了一个显式值,但是当我尝试检查 wsdl(用 Foobar 替换 HelloService)时,这并没有什么区别。
我看到其他人也遇到了类似的问题,但我没有看到任何解决方案。谁能解释一下可能出了什么问题,或者如何解决?
I'm working my way through the Java EE 6 tutorial and I'm on the section about web services. I'm trying to get the helloservice running, because I'm going to need to do something similar in the near future. However, while it builds and deploys with no errors, when I try to use it, I get 404 errors from GlassFish. I've looked in the GlassFish logs and found nothing indicating any problems. Here's the code from the service:
package helloservice.endpoint;
import javax.jws.WebService;
import javax.jws.WebMethod;
@WebService
public class Hello {
private String message = "Hello, ";
public void Hello() {
}
@WebMethod
public String sayHello(String name) {
return message + name + ".";
}
}
Based on what I've read, @WebService should expose the class with the service name HelloService (base class name + "Service"). However, when I go to:
http://localhost:8080/helloservice/HelloService?wsdl
I get a 404 error. I've worked through all the prior examples, so I know that GlassFish is running and that it is responding on port 8080 for other applications I've deployed. I can see in the admin console that helloservice is deployed and running. "asadmin list-domains" shows that my domain1 (my only domain) is running. I thought perhaps the default for the @WebService annotation was wrong, so I set an explicit value using @WebService(serviceName = "Foobar") but that didn't make a difference when I tried checking the wsdl (replacing HelloService with Foobar).
I've seen some other people have had a similar problem, but I have not seen any solutions posted. Can anyone explain what might be wrong, or how to fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
确保您使用的是 Glassfish 完整配置文件,而不是 Glassfish Web 配置文件。部署 war 后,启动 Glassfish 管理控制台,单击“应用程序”。您的“Engines”列应类似于:
[ejb,jpa,web,webservices,weld]
如果不存在 webservices,则您的 Glassfish 实现不会看到您的 SOAP 服务。
Ensure that you are using the Glassfish full profile and not the Glassfish web profile. After your war is deployed, start the Glassfish Administration Console, click on "Applications". Your "Engines" column should look something like:
[ejb,jpa,web,webservices,weld]
If webservices isn't there, your Glassfish implementation isn't seeing your SOAP service.
如果您从管理控制台读取 web.xml,您可以看到这一点。
我尝试了 http://localhost:8080/helloservice/hello?wsdl 而不是 http://localhost:8080/helloservice/HelloService?wsdl (教程中的一个)及其工作得很好。猜测教程没有正确更新。
If you read web.xml from admin console, you can see this.
I tried http://localhost:8080/helloservice/hello?wsdl instead of http://localhost:8080/helloservice/HelloService?wsdl (one in tutorial) and it worked fine. Guess tutorial wasn't updated properly.
这通常表明服务器上部署的工件没有问题。毕竟 404 错误表明客户端发出了无效的 HTTP 请求。简而言之,发出的 GET 请求不正确,您应该发送不同的请求。
是的,这是默认的。但是,更重要的是,您是否正确指定了应用程序的上下文根?以下是教程中
glassfish-web.xml
的内容:请注意
/helloservice
元素的使用,它出现在 URL 中的服务名称之前。您可能在请求中使用了不正确的上下文根,从而导致 404 错误。如果您需要验证打算将请求发送到的位置,您会在 Web 服务部署的 Glassfish 日志中找到相同的提示,如下所示
This usually indicates that there are no issues with the deployed artifacts on the server. After all a 404 error indicates that the client has issued an invalid HTTP request. In simpler words, the GET request issued is incorrect, and that you ought to send a different one.
Yes, that is the default. But, more importantly, have you specified the context root of the application correctly? The following is the content of
glassfish-web.xml
from the tutorial:Notice the use of the
<context-root>/helloservice</context-root>
element, which appears before the Service name in the URL. It is likely that you are using an incorrect context root in your request, resulting in the 404 error.If you need to verify the location that you intend to be sending requests to, you would find hints of the same in the Glassfish logs on deployment of the web service, like the one listed below