Java EE 6 教程,使用 helloservice 出现 404 错误

发布于 2024-11-19 06:11:06 字数 1077 浏览 2 评论 0原文

我正在学习 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 技术交流群。

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

发布评论

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

评论(3

ぺ禁宫浮华殁 2024-11-26 06:11:06

确保您使用的是 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.

娇俏 2024-11-26 06:11:06

如果您从管理控制台读取 web.xml,您可以看到这一点。

<servlet-mapping>
    <servlet-name>HelloService</servlet-name>
    <url-pattern>/hello</url-pattern>
</servlet-mapping>

我尝试了 http://localhost:8080/helloservice/hello?wsdl 而不是 http://localhost:8080/helloservice/HelloService?wsdl (教程中的一个)及其工作得很好。猜测教程没有正确更新。

If you read web.xml from admin console, you can see this.

<servlet-mapping>
    <servlet-name>HelloService</servlet-name>
    <url-pattern>/hello</url-pattern>
</servlet-mapping>

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.

泅渡 2024-11-26 06:11:06

但是,虽然它的构建和部署没有错误,但当我尝试使用它时,我从 GlassFish 收到 404 错误。我查看了 GlassFish 日志,没有发现任何问题。

这通常表明服务器上部署的工件没有问题。毕竟 404 错误表明客户端发出了无效的 HTTP 请求。简而言之,发出的 GET 请求不正确,您应该发送不同的请求。

根据我所读到的内容,@WebService 应该公开服务名称为 HelloService 的类(基类名称 +“Service”)

是的,这是默认的。但是,更重要的是,您是否正确指定了应用程序的上下文根?以下是教程中 glassfish-web.xml 的内容:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app error-url="">
  <context-root>/helloservice</context-root>
  <class-loader delegate="true"/>
  <jsp-config>
    <property name="keepgenerated" value="true">
      <description>Keep a copy of the generated servlet class' java code.</description>
    </property>
  </jsp-config>
</glassfish-web-app>

请注意 /helloservice 元素的使用,它出现在 URL 中的服务名称之前。您可能在请求中使用了不正确的上下文根,从而导致 404 错误。

如果您需要验证打算将请求发送到的位置,您会在 Web 服务部署的 Glassfish 日志中找到相同的提示,如下所示

信息:WS00018:已部署 Web 服务端点

Hello 正在监听 http://localhost:8080/helloservice/HelloService

信息:Metro 监控根名称已成功设置为:amx:pp=/mon/server-mon[server],type=WSEndpoint,name=/helloservice-HelloService-HelloPort

信息:WEB0671:正在 [/helloservice] 加载应用程序 [helloservice]

信息:helloservice 在 1,616 毫秒内成功部署。

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.

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.

Based on what I've read, @WebService should expose the class with the service name HelloService (base class name + "Service")

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:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app error-url="">
  <context-root>/helloservice</context-root>
  <class-loader delegate="true"/>
  <jsp-config>
    <property name="keepgenerated" value="true">
      <description>Keep a copy of the generated servlet class' java code.</description>
    </property>
  </jsp-config>
</glassfish-web-app>

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

INFO: WS00018: Webservice Endpoint deployed

Hello listening at address at http://localhost:8080/helloservice/HelloService

INFO: Metro monitoring rootname successfully set to: amx:pp=/mon/server-mon[server],type=WSEndpoint,name=/helloservice-HelloService-HelloPort

INFO: WEB0671: Loading application [helloservice] at [/helloservice]

INFO: helloservice was successfully deployed in 1,616 milliseconds.

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